Esempio n. 1
0
    public void SaveCSV(Color[,,] voxArray, int seqID, int sculptureID)
    {
        string voxCSV = "";

        for (int x = 0; x < voxArray.GetLength(0); x++)
        {
            for (int z = 0; z < voxArray.GetLength(1); z++)
            {
                for (int y = 0; y < voxArray.GetLength(2); y++)
                {
                    voxCSV += x + ", " + z + ", " + y + ", ";
                    voxCSV += voxArray[x, z, y].r.ToString() + ", ";
                    voxCSV += voxArray[x, z, y].g.ToString() + ", ";
                    voxCSV += voxArray[x, z, y].b.ToString() + ", ";
                    voxCSV += voxArray[x, z, y].a.ToString() + "\n";
                }
            }
        }

        byte[] bytes = Encoding.UTF8.GetBytes(voxCSV);
        if (!Directory.Exists(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter))
        {
            Directory.CreateDirectory(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter);
        }
        File.WriteAllBytes(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter + "/sculpture_" + sculptureID + "_" + ".csv", bytes);
    }
Esempio n. 2
0
    /// <summary>
    /// Apply a spatial color mapping to the points in the point cloud.
    /// </summary>
    /// <param name="colorMap">The dense, voxel-based defining the colors distribution of the space.</param>
    public void ApplyColorSpace(Color[, ,] colorMap, Vector3 origin, Vector3 voxelDimensions)
    {
        for (int i = 0; i < particle_count; i++)
        {
            Vector3 particlePos = particles[i].position;

            // Check that the point is within the voxel space's bounds.

            if (particlePos.x < origin.x ||
                particlePos.y < origin.y ||
                particlePos.z < origin.z)
            {
                continue;
            }
            // Find the indices of the voxel that the point belongs in.
            int ind_x = Mathf.RoundToInt((particlePos.x - origin.x) / voxelDimensions.x);
            int ind_y = Mathf.RoundToInt((particlePos.y - origin.y) / voxelDimensions.y);
            int ind_z = Mathf.RoundToInt((particlePos.z - origin.z) / voxelDimensions.z);
            if (ind_x >= colorMap.GetLength(0) ||
                ind_y >= colorMap.GetLength(1) ||
                ind_z >= colorMap.GetLength(2))
            {
                continue;
            }

            particles[i].startColor = colorMap[ind_x, ind_y, ind_z];
        }

        // Trigger a particle system update.
        OnParticlesUpdated();
    }
Esempio n. 3
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         colorMatrix = stringToColorMatrix(richTextBox1.Text);
         tableLayoutPanel1.Refresh();
         panel300.Refresh();
     }
     catch
     {
         if (richTextBox1.Text.Length == 0)
         {
             for (int a = 0; a < 256; a++)
             {
                 fillArray(85, a);
             }
             tableLayoutPanel1.Refresh();
             panel300.Refresh();
         }
         else
         {
             MessageBox.Show("Not Proper Font String");
         }
     }
 }
Esempio n. 4
0
        void ComputeVectorField()
        {
            velocityField = new Vector3[size, size, size];
            colorField    = new Color[size, size, size];
            for (int x = 0; x < size; ++x)
            {
                for (int y = 0; y < size; ++y)
                {
                    for (int z = 0; z < size; ++z)
                    {
                        // compute node position within a unit cube
                        Vector3 normalizedPosition = new Vector3(x, y, z) / (float)(size - 1);
                        Vector3 velocity           = Vector3.zero;
                        Color   color = Color.black;
                        float   mSum  = .0f;

                        for (int i = samplers.Length - 1; i > -1; --i)
                        {
                            Vector3 v;
                            Color   c;
                            samplers[i].Sample(normalizedPosition, out v, out c);
                            velocity += v;
                            float m = v.magnitude; // color weight
                            mSum  += m;
                            color += c * m;
                        }

                        velocityField[x, y, z] = velocity;
                        color              /= Mathf.Max(.0000001f, mSum); // prevent div by 0
                        color.a             = Mathf.Clamp01(color.a);
                        colorField[x, y, z] = color;
                    }
                }
            }
        }
Esempio n. 5
0
    public Runner()
    {
        y     = 30;
        x     = 30;
        z     = 30;
        plane = new Color[x, y, z];


        for (int i = 0; i < y; i++)
        {
            for (int j = 0; j < x; j++)
            {
                for (int k = 0; k < z; k++)
                {
                    if (k == 0)
                    {
                        plane[i, j, k] = Color.Green;
                    }
                    else if (k == z - 1)
                    {
                        plane[i, j, k] = Color.Red;
                    }
                }
            }
        }

        Play();
    }
    public void ApplyColorSpace(Color[, ,] colorMap, Vector3 origin, Vector3 voxelDimensions)
    {
        for (int i = 0; i < particle_count; i++)
        {
            Vector3 particlePos = particles[i].position;
            if (particlePos.x < origin.x ||
                particlePos.y < origin.y ||
                particlePos.z < origin.z)
            {
                continue;
            }
            int ind_x = Mathf.RoundToInt((particlePos.x - origin.x) / voxelDimensions.x);
            int ind_y = Mathf.RoundToInt((particlePos.y - origin.y) / voxelDimensions.y);
            int ind_z = Mathf.RoundToInt((particlePos.z - origin.z) / voxelDimensions.z);

            if (ind_x >= colorMap.GetLength(0) ||
                ind_y >= colorMap.GetLength(1) ||
                ind_z >= colorMap.GetLength(2))
            {
                continue;
            }

            particles[i].startColor = colorMap[ind_x, ind_y, ind_z];
        }
        OnParticlesUpdated();
    }
Esempio n. 7
0
        // create the gaussian and laplacian of gaussian distributions
        private void LogPipeline()
        {
            //creation of the gaussian distribution
            gaussSpheres(positions, ref volumeGaus, kernelSize);

            //computing the LoG
            _shape2 = applyLpoGConvolutionColor();

            _shape3 = volumeLoG.GetPixels();

            for (int i = 0; i < volumeLoG.depth; i++)
            {
                for (int j = 0; j < volumeLoG.depth; j++)
                {
                    for (int k = 0; k < volumeLoG.depth; k++)
                    {
                        _shape3[(k * volumeLoG.depth * volumeLoG.depth) + j * volumeLoG.depth + i] = _shape2[i, j, k];
                    }
                }
            }

            //apply color array to the Volume texture according to the filter

            IsLoG(isLog);
        }
Esempio n. 8
0
        private void button10_Click(object sender, EventArgs e)
        {
            string fileName = "defaultFont.af";

            using (StreamReader reader = new StreamReader(fileName))
            {
                richTextBox1.Text = reader.ReadToEnd();
                colorMatrix       = stringToColorMatrix(richTextBox1.Text);
            }
            tableLayoutPanel1.Refresh();
            panel300.Refresh();
        }
Esempio n. 9
0
        // ----------------------------------------------------------------------------------------
        #region Constructors

        public Wireframe(int hCount, int uCount, int vCount)
        {
            if (hCount <= 0)
            {
                throw new InvalidValueException(nameof(hCount), hCount, 833183);
            }
            HCount           = hCount;
            UCount           = uCount;
            VCount           = vCount;
            _wireframePoints = new WireframePoint[hCount, uCount, vCount];
            _values          = new float[hCount, uCount, vCount];
            _colors          = new Color[hCount, uCount, vCount];
        }
Esempio n. 10
0
 private static void GetColors()
 {
     Colors = new Color[SizeX, SizeY, SizeZ];
     for (int x = 0; x < SizeX; x++)
     {
         for (int y = 0; y < SizeY; y++)
         {
             for (int z = 0; z < SizeZ; z++)
             {
                 Colors[x, y, z] = Data.GetColorFromPalette(Voxels[x, y, z]);
             }
         }
     }
 }
Esempio n. 11
0
        private bool IsBorderVoxel(int i, int j, int k, Color[,,] voxels)
        {
            float a = voxels[i, j, k].a;

            if (a == 0f)
            {
                return(false);
            }
            if ((((voxels[i + 1, j, k].a >= a) && (voxels[i - 1, j, k].a >= a)) && ((voxels[i, j + 1, k].a >= a) && (voxels[i, j - 1, k].a >= a))) && (voxels[i, j, k + 1].a >= a))
            {
                return(voxels[i, j, k - 1].a < a);
            }
            return(true);
        }
Esempio n. 12
0
 public Voxelmap(int x, int y, int z)
 {
     voxels = new Color[x, y, z];
     Width  = x;
     Height = y;
     Depth  = z;
     for (int ix = 0; ix < x; ix++)
     {
         for (int iy = 0; iy < y; iy++)
         {
             for (int iz = 0; iz < z; iz++)
             {
                 voxels[ix, iy, iz] = Color.FromArgb(0);
             }
         }
     }
 }
Esempio n. 13
0
 public void SaveVox(Color[,,] voxArray)
 {
     if (generatedSculptures == null)
     {
         generatedSculptures = new List <List <Color[, , ]> >();
     }
     if (generatedSculptures.Count <= generatedSculpturesCounter)
     {
         generatedSculptures.Add(new List <Color[, , ]>());
     }
     else if (generatedSculptures[generatedSculpturesCounter].Count >= 4)
     {
         generatedSculptures.Add(new List <Color[, , ]>());
         //generatedSculpturesCounter++;
     }
     generatedSculptures[generatedSculpturesCounter].Add(voxArray);
     SaveCSV(voxArray, generatedSculpturesCounter, (generatedSculptures[generatedSculpturesCounter].Count));
 }
Esempio n. 14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string fileName = "lastGenerated.af";

            using (StreamReader reader = new StreamReader(fileName))
            {
                richTextBox1.Text = reader.ReadToEnd();
                colorMatrix       = stringToColorMatrix(richTextBox1.Text);
            }
            panel300.VerticalScroll.Visible   = true;
            panel300.VerticalScroll.Enabled   = true;
            panel300.HorizontalScroll.Visible = false;
            panel300.HorizontalScroll.Enabled = false;
            //ScrollBar vScrollBar1 = new VScrollBar();
            //vScrollBar1.Dock = DockStyle.Right;
            //vScrollBar1.Scroll += (sender, e) => { panel1.VerticalScroll.Value = vScrollBar1.Value; };
            //panel1.Controls.Add(vScrollBar1);
        }
Esempio n. 15
0
        public static Texture3D GenerateSeedPositionTexture3DFromArray(Color[,,] array)
        {
            var tex = new Texture3D(array.GetLength(0), array.GetLength(1), array.GetLength(2), TextureFormat.ARGB32, false)
            {
                wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Point
            };

            for (int x = 0; x < array.GetLength(0); x++)
            {
                for (int y = 0; y < array.GetLength(1); y++)
                {
                    for (int z = 0; z < array.GetLength(2); z++)
                    {
                        tex.SetPixel(x, y, z, array[x, y, z]);
                    }
                }
            }
            tex.Apply();
            return(tex);
        }
Esempio n. 16
0
        public void Load(string filename)
        {
            using (StreamReader sr = new StreamReader(filename))
            {
                string   file  = sr.ReadToEnd();
                string[] lines = file.Split('\n');
                Width  = int.Parse(lines[0]);
                Height = int.Parse(lines[1]);
                Depth  = int.Parse(lines[2]);

                voxels = new Color[Width, Height, Depth];
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        for (int k = 0; k < Depth; k++)
                        {
                            voxels[i, j, k] = Color.FromArgb(int.Parse(lines[k + j * Depth + i * Depth * Height + 3]));
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public static Color[,] ComputeAlgorithm(Color[,] currentImage, int Kr, int Kg, int Kb, BackgroundWorker backgroundWorker)
        {
            Color[,] image = new Color[CONST.bitmapWidth, CONST.bitmapHeight];
            Color[,,] listOfAvailableColors = Colors.GetAllAvailableColors(Kr, Kg, Kb);
            object SyncObject = new object();
            int    index      = 0;

            Parallel.For(0, CONST.bitmapWidth, i =>
            {
                for (int j = 0; j < CONST.bitmapHeight; j++)
                {
                    image[i, j] = Colors.GetClosestColor(listOfAvailableColors, currentImage[i, j]);
                }
                lock (SyncObject)
                {
                    index++;
                }
                backgroundWorker.ReportProgress((int)((double)(index + 1) / CONST.bitmapWidth * 100) % 101);
            });

            backgroundWorker.ReportProgress(100);
            return(image);
        }
Esempio n. 18
0
        public static Color[,] Stucky(Color[,] currentImage, int Kr, int Kg, int Kb, BackgroundWorker backgroundWorker)
        {
            Color[,,] listOfAvailableColors = Colors.GetAllAvailableColors(Kr, Kg, Kb);
            Color[,] transformedImage       = (Color[, ])currentImage.Clone();
            for (int j = 0; j < CONST.bitmapHeight; j++)
            {
                for (int i = 0; i < CONST.bitmapWidth; i++)
                {
                    Color oldPixel = transformedImage[i, j];
                    Color newPixel = Colors.GetClosestColor(listOfAvailableColors, oldPixel);
                    transformedImage[i, j] = newPixel;
                    int redError   = oldPixel.R - newPixel.R;
                    int greenError = oldPixel.G - newPixel.G;
                    int blueError  = oldPixel.B - newPixel.B;

                    for (int x = StuckyMatrix.x; x <= 2 * StuckyMatrix.x; x++)
                    {
                        for (int y = 0; y <= 2 * StuckyMatrix.y; y++)
                        {
                            if (Index.IsCorrectIndex(i + y - StuckyMatrix.y, j + x - StuckyMatrix.x))
                            {
                                Color transformingColor = transformedImage[i + y - StuckyMatrix.y, j + x - StuckyMatrix.x];
                                int   r = Values.Round255(transformingColor.R + ((redError * StuckyMatrix.values[x, y]) / StuckyMatrix.division));
                                int   g = Values.Round255(transformingColor.G + ((greenError * StuckyMatrix.values[x, y]) / StuckyMatrix.division));
                                int   b = Values.Round255(transformingColor.B + ((blueError * StuckyMatrix.values[x, y]) / StuckyMatrix.division));
                                transformedImage[i + y - StuckyMatrix.y, j + x - StuckyMatrix.x] = Color.FromArgb(transformingColor.A, r, g, b);
                            }
                        }
                    }
                }
                backgroundWorker.ReportProgress((int)((double)(j + 1) / CONST.bitmapHeight * 100) % 101);
            }

            backgroundWorker.ReportProgress(100);
            return(transformedImage);
        }
    private void Initialize()
    {
        //create object root
        emptyParent      = new GameObject();
        emptyParent.name = outputName;
        emptyParent.transform.position = Vector3.zero;

        uniqueObjectParent = new GameObject();
        uniqueObjectParent.transform.SetParent(emptyParent.transform);
        uniqueObjectParent.name = "Unique";

        terrainObjectParent = new GameObject();
        terrainObjectParent.transform.SetParent(emptyParent.transform);
        terrainObjectParent.name = "Terrain";

        color    = new Color[modelHeight, width, length];
        pixels   = new Pixel[modelHeight, width, length];
        textures = new Texture2D[modelHeight];

        uniqueParents = new List <GameObject>();
        for (int i = 0; i < uniqueObjectsReferences.Count; i++)
        {
            uniqueParents.Add(new GameObject());
            uniqueParents[i].name = uniqueObjectsReferences[i].name;
            uniqueParents[i].transform.SetParent(uniqueObjectParent.transform);
        }

        inputTexture = spr.texture;
        Color[] temp;

        //split spriteSheet
        for (int i = 0; i < modelHeight; i++)
        {
            temp        = inputTexture.GetPixels(0, i * length, width, length);
            textures[i] = new Texture2D(width, length);
            textures[i].SetPixels(temp);
        }

        //get every pixel color
        for (int i = 0; i < modelHeight; i++)
        {
            for (int j = 0; j < width; j++)
            {
                for (int k = 0; k < length; k++)
                {
                    color[i, j, k] = textures[i].GetPixel(j, k);
                    if (color[i, j, k].a == 1)
                    {
                        pixels[i, j, k] = new Pixel(j, k, i, color[i, j, k]);
                    }
                }
            }
        }

        differentMeshes = 0;

        finalObjects = new List <GameObject>();
        meshes       = new List <Mesh>();

        ProcessData(pixels);
    }
Esempio n. 20
0
        public LUTResult(Color[ , , ] data)
        {
            _data = data;

            GenerateTexture();
        }
Esempio n. 21
0
 // Use this for initialization
 void Start()
 {
     // I need to call rebuild - otherwise
     Rebuild();
     colors = new Color[subdivisions,subdivisions,subdivisions];
     baseColor = cubes[0,0,0].renderer.material.color;
 }
Esempio n. 22
0
		public LUTResult( Color[ , , ] data )
		{
			_data = data;

			GenerateTexture();
		}
Esempio n. 23
0
        public virtual bool UpdateData(Color[,,] voxels)
        {
            MarchingCubeDataBase base2 = new MarchingCubeDataBase(this.cubex, this.cubey, this.cubez);

            this.list      = new List <Vector3>(0x9c40);
            this.indices   = new List <short>(0x101d0);
            this.repCount  = new List <int>(0x101d0);
            this.vertColor = new List <Vector3>(0x101d0);
            bool[]    p           = new bool[8];
            Vector3[] vectorArray = new Vector3[8];
            for (int i = 1; i < (this.sizeX - 1); i++)
            {
                for (int j = 1; j < (this.sizeY - 1); j++)
                {
                    for (int k = 1; k < (this.sizeZ - 1); k++)
                    {
                        p[0]           = voxels[i, j, k].a == 1f;
                        p[1]           = voxels[i + 1, j, k].a == 1f;
                        p[2]           = voxels[i + 1, j, k + 1].a == 1f;
                        p[3]           = voxels[i, j, k + 1].a == 1f;
                        p[4]           = voxels[i, j + 1, k].a == 1f;
                        p[5]           = voxels[i + 1, j + 1, k].a == 1f;
                        p[6]           = voxels[i + 1, j + 1, k + 1].a == 1f;
                        p[7]           = voxels[i, j + 1, k + 1].a == 1f;
                        vectorArray[0] = new Vector3(voxels[i, j, k].r, voxels[i, j, k].g, voxels[i, j, k].b);
                        vectorArray[1] = new Vector3(voxels[i + 1, j, k].r, voxels[i + 1, j, k].g, voxels[i + 1, j, k].b);
                        vectorArray[2] = new Vector3(voxels[i + 1, j, k + 1].r, voxels[i + 1, j, k + 1].g, voxels[i + 1, j, k + 1].b);
                        vectorArray[3] = new Vector3(voxels[i, j, k + 1].r, voxels[i, j, k + 1].g, voxels[i, j, k + 1].b);
                        vectorArray[4] = new Vector3(voxels[i, j + 1, k].r, voxels[i, j + 1, k].g, voxels[i, j + 1, k].b);
                        vectorArray[5] = new Vector3(voxels[i + 1, j + 1, k].r, voxels[i + 1, j + 1, k].g, voxels[i + 1, j + 1, k].b);
                        vectorArray[6] = new Vector3(voxels[i + 1, j + 1, k + 1].r, voxels[i + 1, j + 1, k + 1].g, voxels[i + 1, j + 1, k + 1].b);
                        vectorArray[7] = new Vector3(voxels[i, j + 1, k + 1].r, voxels[i, j + 1, k + 1].g, voxels[i, j + 1, k + 1].b);
                        bool[]         flagArray2 = new bool[] { this.IsBorderVoxel(i, j, k, voxels), this.IsBorderVoxel(i + 1, j, k, voxels), this.IsBorderVoxel(i + 1, j, k + 1, voxels), this.IsBorderVoxel(i, j, k + 1, voxels), this.IsBorderVoxel(i, j + 1, k, voxels), this.IsBorderVoxel(i + 1, j + 1, k, voxels), this.IsBorderVoxel(i + 1, j + 1, k + 1, voxels), this.IsBorderVoxel(i, j + 1, k + 1, voxels) };
                        float          x          = i * this.cubex;
                        float          y          = j * this.cubey;
                        float          z          = k * this.cubez;
                        List <Vector3> list       = base2.getFaces(p, x, y, z);
                        for (int m = 0; m < list.Count; m++)
                        {
                            int     num8  = 0;
                            Vector3 color = new Vector3(0f, 0f, 0f);
                            for (int n = 0; n < 8; n++)
                            {
                                if (flagArray2[n])
                                {
                                    color += vectorArray[n];
                                    num8++;
                                }
                            }
                            if (num8 != 0)
                            {
                                color.x /= (float)num8;
                                color.y /= (float)num8;
                                color.z /= (float)num8;
                            }
                            this.addNewVertex(this.list, this.indices, new Vector3(list[m].x, list[m].y, list[m].z), color);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 24
0
 private void Awake()
 {
     chunkData = new Color[width, width, width];
 }
Esempio n. 25
0
    public void TranPDBtoDEN(float resolution = DEFAULT_RESOLUTION, bool cap = true)
    {
        if (cap)
        {
            resolution = CapResolution(resolution);
        }

        delta = new Vector3(resolution, resolution, resolution);

        // We need to refresh the molecule's origin when it's not
        // the first molecule for which we generate a surface.
        origin = MoleculeModel.MinValue;
        Debug.Log("Entering :: Generation of density from PDB");
        X = (int)(((MoleculeModel.MaxValue.x - MoleculeModel.MinValue.x) * resolution) + 40);
        Y = (int)(((MoleculeModel.MaxValue.y - MoleculeModel.MinValue.y) * resolution) + 40);
        Z = (int)(((MoleculeModel.MaxValue.z - MoleculeModel.MinValue.z) * resolution) + 40);

        Debug.Log("Density point X,Y,Z :: " + X + "," + Y + "," + Z);
        Debug.Log("Density minValue :: " + MoleculeModel.MinValue);
        gridS     = new float[X, Y, Z];
        VertColor = new Color[X, Y, Z];


        int    i;
        int    j;
        int    k;
        float  Dist;
        float  bfactor;
        int    atomnumber = 0;
        Color  atomColor;
        string type;
        float  density;

        float maxValue = (float)MoleculeModel.BFactorList[0];

        foreach (float f in MoleculeModel.BFactorList)
        {
            if (f > maxValue)
            {
                maxValue = f;
            }
        }

        for (i = 0; i < X; i++)
        {
            for (j = 0; j < Y; j++)
            {
                for (k = 0; k < Z; k++)
                {
                    VertColor[i, j, k].b = 1f;
                }
            }
        }


        int index = -1;

        foreach (float[] coord in MoleculeModel.atomsLocationlist)
        {
            index++;

            bool useAtomForCalc = true;

            if (!MoleculeModel.useHetatmForSurface)
            {
                Debug.Log((MoleculeModel.atomHetTypeList[index] == "HETATM"));
                if ((MoleculeModel.atomHetTypeList[index] == "HETATM") && (!MoleculeModel.sugarResname.Contains(MoleculeModel.atomsResnamelist[index])))
                {
                    useAtomForCalc = false;
                }
            }

            if (!MoleculeModel.useSugarForSurface)
            {
                if (MoleculeModel.sugarResname.Contains(MoleculeModel.atomsResnamelist[index]))
                {
                    useAtomForCalc = false;
                }
            }

            if (useAtomForCalc)
            {
                i = Mathf.RoundToInt((coord[0] - MoleculeModel.MinValue.x) * delta.x + fudgeFactor.x);
                j = Mathf.RoundToInt((coord[1] - MoleculeModel.MinValue.y) * delta.y + fudgeFactor.y);
                k = Mathf.RoundToInt((coord[2] - MoleculeModel.MinValue.z) * delta.z + fudgeFactor.z);

                /*
                 * float scaleFactor = 10f;
                 * i = Mathf.RoundToInt(coord[0] * scaleFactor);
                 * j = Mathf.RoundToInt(coord[1] * scaleFactor);
                 * k = Mathf.RoundToInt(coord[2] * scaleFactor);
                 */

//			Debug.Log("i,j,k : " + i +","+j+","+k);
//			gridS[i,j,k]=2;
//		}
                type = (MoleculeModel.atomsTypelist[atomnumber]).type;
//			type = "C";
//			Debug.Log("i j k : "+i+","+j+","+k);
                // Vector3 v1 = new Vector3((coord[0]-MoleculeModel.MinValue.x-MoleculeModel.Offset.x)*2+18,
                //                       (coord[1]-MoleculeModel.MinValue.y-MoleculeModel.Offset.y)*2+18,
                //                       (coord[2]-MoleculeModel.MinValue.z-MoleculeModel.Offset.z)*2+18);


                Vector3 v1 = new Vector3((coord[0] - MoleculeModel.MinValue.x) * delta.x + fudgeFactor.x,
                                         (coord[1] - MoleculeModel.MinValue.y) * delta.y + fudgeFactor.y,
                                         (coord[2] - MoleculeModel.MinValue.z) * delta.z + fudgeFactor.z);


                /*
                 * Vector3 v1 = new Vector3(    coord[0] * scaleFactor,
                 *                                                      coord[1] * scaleFactor,
                 *                                                      coord[2] * scaleFactor);
                 */

                float AtomRadius = 1f;

                // Possibilité de créer une liste a la lecture du pdb et de la reprendre ici.
                // Comme cela on peut lire d'autre propriétés biologiques
                switch (type)
                {
                case "C":
                    AtomRadius = 3.4f;
                    atomColor  = MoleculeModel.carbonColor.color;
                    break;

                case "N":
                    AtomRadius = 3.1f;
                    atomColor  = MoleculeModel.nitrogenColor.color;
                    break;

                case "O":
                    AtomRadius = 3.04f;
                    atomColor  = MoleculeModel.oxygenColor.color;
                    break;

                case "S":
                    AtomRadius = 4.54f;
                    atomColor  = MoleculeModel.sulphurColor.color;
                    break;

                case "P":
                    AtomRadius = 3.6f;
                    atomColor  = MoleculeModel.phosphorusColor.color;
                    break;

                case "H":
                    AtomRadius = 2.4f;
                    atomColor  = MoleculeModel.hydrogenColor.color;
                    break;

                default:
                    AtomRadius = 2f;
                    atomColor  = MoleculeModel.unknownColor.color;
                    break;
                }

                if (UIData.toggleSurf && !UIData.toggleBfac)
                {
                    for (int l = i - 8; l < i + 9; l++)
                    {
                        for (int m = j - 8; m < j + 9; m++)
                        {
                            for (int n = k - 8; n < k + 9; n++)
                            {
                                Vector3 v2 = new Vector3(l, m, n);
                                Dist    = Vector3.Distance(v1, v2);
                                density = (float)Math.Exp(-((Dist / AtomRadius) * (Dist / AtomRadius)));
                                if (density > gridS[l, m, n])
                                {
//							if (VertColor[l,m,n].b!=0){
//								if (density > 0.5)
                                    VertColor[l, m, n] = atomColor;
                                }
                                gridS[l, m, n] += density;
                            }
                        }
                    }
                }
                else if (UIData.toggleBfac)                             // these index bounds might need to be express as functions of fudgeFactor
                {
                    for (int l = i - 8; l < i + 9; l++)
                    {
                        for (int m = j - 8; m < j + 9; m++)
                        {
                            for (int n = k - 8; n < k + 9; n++)
                            {
                                Vector3 v2 = new Vector3(l, m, n);
                                Dist = Vector3.Distance(v1, v2);

                                bfactor = ((float)MoleculeModel.BFactorList[atomnumber] / maxValue * 5);
                                if (bfactor > 0)
                                {
                                    gridS[l, m, n] += (float)Math.Exp(-((Dist / bfactor) * (Dist / bfactor)));
                                }
                                else
                                {
                                    gridS[l, m, n] -= (float)Math.Exp(-((Dist / bfactor) * (Dist / bfactor)));
                                }

                                if (VertColor[l, m, n].b == 1f && VertColor[l, m, n].r == 0f)
                                {
                                    VertColor[l, m, n].r += ((float)MoleculeModel.BFactorList[atomnumber] / (maxValue));
                                    VertColor[l, m, n].b -= ((float)MoleculeModel.BFactorList[atomnumber] / (2 * maxValue));
                                }
                                //						if ( (VertColor[l,m,n].r + ((float)MoleculeModel.BFactorList[atomnumber]/(maxValue))) > 1){
                                //							VertColor[l,m,n].r=1f;
                                //							VertColor[l,m,n].b=0f;
                                //						}
                                else
                                {
                                    VertColor[l, m, n].r += ((float)MoleculeModel.BFactorList[atomnumber] / (20 * maxValue));
                                    VertColor[l, m, n].b -= ((float)MoleculeModel.BFactorList[atomnumber] / (20 * maxValue));
                                }
                            }
                        }
                    }
                }
                atomnumber++;
            }
        }

//				}
//			}
//		}

        // export the density in a .dx file readable by pymol or vmd
//		StreamWriter test;
//		test = new StreamWriter("grille.dx");
//		test.Write("# Data from APBS 1.3\n#\n# POTENTIAL (kT/e)\n#\nobject 1 class gridpositions counts "+X+" "+Y+" "+Z+"\n
//					origin -2.330000e+01 -2.34000e+01 -2.550000e+01\ndelta 5.000000e-01 0.000000e+00 0.000000e+00\n
//					delta 0.000000e+00 5.000000e-01 0.000000e+00\ndelta 0.000000e+00 0.000000e+00 5.000000e-01\n
//					object 2 class gridconnections counts "+X+" "+Y+" "+Z+"\nobject 3 class array type double rank 0 items "+X*Y*Z+" data follows\n");
//		for (i=0 ; i< X ; i++){
//			for (j=0 ; j<Y ; j++){
//				for (k=0 ; k<Z ; k++){
//					test.WriteLine(gridS[i,j,k]);
//					}
//				}
//			}
//			test.Write("attribute \"dep\" string \"positions\"\nobject \"regular positions regular connections\" class field\n
//						component \"positions\" value 1\ncomponent \"connections\" value 2\ncomponent \"data\" value 3");
//			test.Close();
    }
Esempio n. 26
0
 public LUT(ColorConversion conversion = null)
 {
     lut = new Color[256, 256, 256];
     CreateLookupTable(conversion);
 }
Esempio n. 27
0
    public void Start()
    {
        if(_instance==null)
            _instance = this;

        _cubes					= new List<VCube>();
        _reBuild				= new List<VCube>();
        _reBuildCollider		= new List<VCube>();
        _reBuildColliderCount	= 0;

        _map					= new byte[width+1, height+1, depth+1];
        _colors					= new Color[width+1, height+1, depth+1];

        // Instantiate all cube
        for(int x=0; x<width/RES; x++)
        for(int y=0; y<height/RES; y++)
        for(int z=0; z<depth/RES; z++)
        {
            Bounds cubeBounds = new Bounds();
            cubeBounds.min = new Vector3(x, y, z)*RES;
            cubeBounds.max = cubeBounds.min + new Vector3(RES, RES, RES);
            VCube cube = new VCube(cubeBounds, this);
            _cubes.Add(cube);
        }

        // Initialise all point in map
        ResetMap();
    }
Esempio n. 28
0
 public VMap(uint size, VoxelChunk chunk)
 {
     this.chunk = chunk;
     this.size  = size;
     map        = new Color[size, size, size];
 }
Esempio n. 29
0
        public Form1()
        {
            InitializeComponent();
            colorMatrix   = new Color[256, tableLayoutPanel1.RowCount, tableLayoutPanel1.ColumnCount];
            coppiedMatrix = new Color[tableLayoutPanel1.RowCount, tableLayoutPanel1.ColumnCount];
            for (int a = 0; a < 256; a++)
            {
                fillArray(85, a);
            }
            tableLayoutPanel1.Refresh();


            for (int a = 0; a < 256; a++)
            {
                int    available = panel300.Width / 50;
                Button newButton = new Button();
                newButton.Location = new System.Drawing.Point(((a % available) * 50) + 3, ((a / available) * 68) + 3);
                newButton.Name     = "button" + (a + 50).ToString();
                newButton.Size     = new System.Drawing.Size(44, 62);
                newButton.TabIndex = 58;
                newButton.Text     = "button11";
                newButton.UseVisualStyleBackColor = true;
                newButton.MouseDown  += new MouseEventHandler(this.button11_Click);
                newButton.MouseHover += new EventHandler(this.button11_Move);
                newButton.Paint      += new System.Windows.Forms.PaintEventHandler(this.button11_Paint);
                newButton.Tag         = a;
                panel300.Controls.Add(newButton);

                showButtons[a] = newButton;
            }

            for (int a = 0; a < 256; a++)
            {
                metroComboBox1.Items.Add((a + 1).ToString());
            }
            metroComboBox1.SelectedIndex = 0;

            byte   tempByte   = 0;
            String lineString = "";

            for (byte a = 0; a < tableLayoutPanel1.ColumnCount; a++)
            {
                for (byte b = 0; b < tableLayoutPanel1.RowCount; b++)
                {
                    tempByte = (byte)(tempByte | (colorToNumber(colorMatrix[selectedChar, b, a]) ? 0x01 << b : 0x00));
                }
                if (format == 0)
                {
                    lineString += tempByte.ToString() + " , ";
                }
                else if (format == 1)
                {
                    lineString += "0X" + tempByte.ToString("X2") + " , ";
                }
                else if (format == 2)
                {
                    lineString += "0B" + Convert.ToString(tempByte, 2).PadLeft(8, '0') + " , ";
                }
                tempByte = 0;
            }
            textBox1.Text = lineString;
        }
Esempio n. 30
0
 public static Color GetClosestColor(Color[,,] allColors, Color color)
 {
     return(allColors[color.R, color.G, color.B]);
 }
Esempio n. 31
0
        public static Result CreateModel(VoxelData data, float scale, LightMapSupportType supportLightMap, bool supportRig, Vector3 pivot)
        {
            if (data == null)
            {
                return(null);
            }

            Data             = data;
            ModelScale       = scale;
            _SupportLightMap = supportLightMap;
            SupportRig       = supportRig;
            Pivot            = pivot;


            var result = new Result {
                VoxelModels = new Result.VoxelModel[1] {
                    new Result.VoxelModel()
                    {
                        Meshs          = new UnlimitiedMesh[data.Voxels.Count],
                        Textures       = new Texture2D[data.Voxels.Count],
                        ModelSize      = new Vector3[data.Voxels.Count],
                        FootPoints     = new Vector3[data.Voxels.Count],
                        MaxModelBounds = new Int3(data.GetBounds()).Max,
                    }
                }
            };

            for (int index = 0; index < data.Voxels.Count; index++)
            {
                UnlimitiedMesh mesh;
                Texture2D      texture;
                PointWeights = null;
                RootBones    = null;
                Voxels       = data.Voxels[index];
                SizeX        = Voxels.GetLength(0);
                SizeY        = Voxels.GetLength(1);
                SizeZ        = Voxels.GetLength(2);
                ModelIndex   = index;

                GetFaces();
                GetColors();
                if (SupportRig)
                {
                    var rootBoneList = GetChildBones(null);
                    if (rootBoneList != null)
                    {
                        RootBones = rootBoneList.ToArray();
                    }
                    GetWeights();
                }
                GetAreas();
                GetResultFromArea(out mesh, out texture);

                result.VoxelModels[0].Meshs[index]      = mesh;
                result.VoxelModels[0].Textures[index]   = texture;
                result.VoxelModels[0].ModelSize[index]  = data.GetModelSize(index);
                result.VoxelModels[0].FootPoints[index] = data.GetFootPoint(index);
                result.VoxelModels[0].RootBones         = RootBones;
            }

            result.VoxelModels[0].RootNode = GetTransformData(result.VoxelModels[0], result.VoxelModels[0].Textures, 0);

            Data         = null;
            Voxels       = null;
            Faces        = null;
            PointWeights = null;
            RootBones    = null;
            Colors       = null;
            AreaList.Clear();
            PackingList.Clear();
            AreaPackingMap.Clear();

            return(result);
        }
Esempio n. 32
0
 private Actions()
 {
     this.block = Cube.GetCube().GetBlock();
 }
Esempio n. 33
0
    /// <summary>
    /// Change voxels in sculpture based on CPPN outputs
    /// </summary>
    private void DrawSculpture()
    {
        processingCPPN = true;

        float halfVoxelSize = voxelSize / 2;

        cppn = new TWEANN(geno);

        Vector4[] outArr = new Vector4[SCULP_X * SCULP_Z * SCULP_Y];

        voxArray = new Color[SCULP_X, SCULP_Z, SCULP_Y];
        for (int x = 0; x < SCULP_X; x++)
        {
            for (int z = 0; z < SCULP_Z; z++)
            {
                for (int y = 0; y < SCULP_Y; y++)
                {
                    float actualX          = -(halfVoxelSize * SCULP_X / 2.0f) + halfVoxelSize + x * halfVoxelSize;
                    float actualZ          = -(halfVoxelSize * SCULP_Z / 2.0f) + halfVoxelSize + z * halfVoxelSize;
                    float actualY          = -(halfVoxelSize * SCULP_Y / 2.0f) + halfVoxelSize + y * halfVoxelSize;
                    float distFromCenter   = GetDistFromCenter(actualX, actualZ, actualY);
                    float distFromCenterXZ = GetDistFromCenterXY(actualX, actualZ);
                    float distfromCenterYZ = GetDistFromCenterZY(actualY, actualZ);
                    float distfromCenterZY = GetDistFromCenterZY(actualX, actualZ);
                    //float[] outputs = cppn.Process(new float[] { actualX, actualY, actualZ, distFromCenter, BIAS});
                    float[] outputs = cppn.Process(new float[] { actualX, actualY, actualZ, distFromCenter, distFromCenterXZ, distfromCenterYZ, distfromCenterZY, BIAS });
                    //TODO move all of the CPPN render out of the draw function
                    if (MaxValue < outputs[THREE_DIMENSIONAL_HUE_INDEX])
                    {
                        MaxValue = outputs[THREE_DIMENSIONAL_HUE_INDEX];
                    }
                    if (MinValue > outputs[THREE_DIMENSIONAL_HUE_INDEX])
                    {
                        MinValue = outputs[THREE_DIMENSIONAL_HUE_INDEX];
                    }

                    outArr[x + (SCULP_Z * z) + (SCULP_Y * y)] = new Vector4(outputs[THREE_DIMENSIONAL_HUE_INDEX], outputs[THREE_DIMENSIONAL_SATURATION_INDEX], outputs[THREE_DIMENSIONAL_BRIGHTNESS_INDEX], outputs[THREE_DIMENSIONAL_VOXEL_INDEX]);
                }
            }
        }

        for (int x = 0; x < SCULP_X; x++)
        {
            for (int z = 0; z < SCULP_Z; z++)
            {
                for (int y = 0; y < SCULP_Y; y++)
                {
                    float[] o = FixHue(outArr[x + (SCULP_Z * z) + (SCULP_Y * y)]);

                    if (o[THREE_DIMENSIONAL_VOXEL_INDEX] > PRESENCE_THRESHOLD)
                    {
                        Color colorHSV = Color.HSVToRGB(
                            o[THREE_DIMENSIONAL_HUE_INDEX],
                            o[THREE_DIMENSIONAL_SATURATION_INDEX],
                            o[THREE_DIMENSIONAL_BRIGHTNESS_INDEX],
                            true
                            );
                        float alpha = 1f;
                        if (transparent)
                        {
                            alpha = ActivationFunctions.Activation(FTYPE.HLPIECEWISE, o[THREE_DIMENSIONAL_VOXEL_INDEX]);
                        }

                        //float alpha = -1.0f;
                        Color color = new Color(colorHSV.r, colorHSV.g, colorHSV.b, alpha);
                        voxArray[x, z, y] = color;
                    }
                    else
                    {
                        // This option will make the voxel turn off (requires matching  = true statement above)
                        voxArray[x, z, y] = new Color(0f, 0f, 0f, 0f);
                        // This option will enable the "glass block" effect
                        //rend.material.SetColor("_Color", new Color(0f, 0f, 0f, 0f));
                    }
                }
            }
        }

        processingCPPN = false;
        needsRedraw    = true;
    }