Example #1
0
        public FormSlices(Form1 form, Nodes nodes, DataToRender dataToRender, DeviceContext context)
        {
            this.form = form;
            this.nodes = nodes;
            this.dataToRender = dataToRender;
            InitializeComponent();

            if (!dataToRender.pathToVtk)
            {
                trackBar1.Enabled = false;
                trackBar2.Enabled = false;
                trackBar3.Enabled = false;
                checkBoxXY.Enabled = false;
                checkBoxXZ.Enabled = false;
                checkBoxYZ.Enabled = false;
                DisableOkolie();
                form.StatusInfo = "Set the path to vtk files to enable full functionality!";
            }
            else
            {
                this.SetForSlices();
            }
            checkBox1.Checked = dataToRender.okolie;
            DisableButton2();
            DisableButton3();
            SetComboBox();
        }
Example #2
0
        public Form1()
        {
            InitializeComponent();
            Text = String.Format("{0} {1}", AboutBox1.AssemblyTitle, AboutBox1.AssemblyVersion);
            this.pathOfVtk = Directory.GetCurrentDirectory();

            GraphicsInitialization();
            EffectsInitialization();

            nodes = new Nodes();
            dataToRender = new DataToRender(this);
 
            Rotation = Matrix.RotationX(angleY) * Matrix.RotationY(angleX);
            viewMatrix = Matrix.LookAtRH(new Vector3(0, 0, -3.5f), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = 800;
            aTimer.Enabled = true;

            colorDialog = new ColorDialog();
            colorDialog.Color = System.Drawing.Color.Red;
            StatusInfo = "No data loaded";
            toolStripProgressBar1.Value = 0;
            bielePozadieToolStripMenuItem.Checked = false;
            panel1.Resize += (sender, args) => resized = true;

            Configuration.EnableObjectTracking = false;
            resized = true;
            render = true;
        }
        public void MakeSphereBuffers(int value, Nodes nodes)
        {
            if (!this.meanTrajectories)
            {
                return;
            }
            float red, green, blue, alpha;
            int time_step = 30, lower, upper, pom = 0;

            if (value - time_step < 0) lower = 0;
            else lower = value - time_step;
            if (value + time_step > nodes.NodesTree.Length) upper = nodes.NodesTree.Length;
            else upper = value + time_step;

            for (int i = lower; i < upper; i++)
            {
                for (int k = 0; k < nodes.AveragePosition.Length; k++)
                {
                    red = (nodes.ColorClasses[k] >> 16) & 0xff;
                    green = (nodes.ColorClasses[k] >> 8) & 0xff;
                    blue = (nodes.ColorClasses[k] >> 0) & 0xff;
                    alpha = (nodes.ColorClasses[k] >> 24) & 0xff;
                    for (int j = 0; j < nodes.Sphere.Length; j++)
                    {
                        this.vertices[pom].position = nodes.Sphere[j] + nodes.AveragePosition[k][i];
                        this.vertices[pom].color = new Vector4(red / 255f, green / 255f, blue / 255f, alpha / 255f);
                        pom++;
                    }
                }
            }
            numberOfTrianglesSphere = pom / 3;

            this.CopyToBuffer_Vertices(this.bufferForSphere);
        }
        public void Highlighting(int value, Nodes nodes)
        {
            if (nodes.NodesTree == null || !this.menuHighlightingOption[0] && !this.menuHighlightingOption[1] && !this.menuHighlightingOption[2] && !this.menuHighlightingOption[3] && !this.menuHighlightingOption[4])
                return;

            float Radius = this.radius + 0.0005f;
            int vCounter = 0, iCounter = 0;

            Vector4 trajectoryEndColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
            Vector4 trajectoryStartColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
            Vector4 beforeMitosisColor = new Vector4(1.0f, 1.0f, 0.0f, 1.0f);
            Vector4 afterMitosisColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
            Vector4 orphansColor = new Vector4(0.5f, 0.0f, 0.5f, 1.0f);
            Vector4 offColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

            for (int i = 0; i < nodes.NodesTree[value].Length; i++)
            {
                if (menuColoringOption == MenuColoringOption.originalColor && nodes.NodesTree[value][i].actual_colour == offColor) continue;
                Vector4 truecolor = white;
                if (this.menuHighlightingOption[0] && nodes.NodesTree[value][i].daughter == null)
                {
                    truecolor = trajectoryEndColor;
                    goto vypocet;
                }
                if (this.menuHighlightingOption[1] && nodes.NodesTree[value][i].mother == null)
                {
                    truecolor = trajectoryStartColor;
                    goto vypocet;
                }
                if (this.menuHighlightingOption[2] && nodes.NodesTree[value][i].daughter != null && nodes.NodesTree[value][i].daughter.Length > 1)
                {
                    truecolor = beforeMitosisColor;
                    goto vypocet;
                }
                if (this.menuHighlightingOption[3] && nodes.NodesTree[value][i].mother != null && nodes.NodesTree[value][i].mother.daughter.Length > 1)
                {
                    truecolor = afterMitosisColor;
                    goto vypocet;
                }
                if (this.menuHighlightingOption[4] && nodes.NodesTree[value][i].mother == null && nodes.NodesTree[value][i].daughter == null)
                {
                    truecolor = orphansColor;
                    goto vypocet;
                }
                if (truecolor == white) continue;
            vypocet:
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale - Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale - Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale + Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale - Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale + Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale + Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale + Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale + Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale + Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale + Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale - Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale + Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale - Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale - Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale - Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale - Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale + Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale - Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale + Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale + Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale - Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;
                this.vertices[vCounter].position.X = nodes.NodesTree[value][i].x * this.scale + Radius;
                this.vertices[vCounter].position.Y = nodes.NodesTree[value][i].y * this.scale - Radius;
                this.vertices[vCounter].position.Z = nodes.NodesTree[value][i].z * this.scale - Radius;
                this.vertices[vCounter].color = truecolor;
                vCounter++;

                for (int j = 0; j < 36; j++)
                {
                    this.cubeIndices[iCounter * 36 + j] = vCounter + indices[j];
                }
                iCounter++;
            }
            this.numberOfVertices = vCounter;
            this.numberOfTriangles = iCounter * 36 / 3;
            if (this.vertices.Length == 0) return;

            this.CopyToBuffer_Vertices(this.bufferForHighlight);
            this.CopyToBuffer_Indices(this.bufferForIndicesHighlight);

            for (int i = 0; i < this.numberOfVertices; i++)
                this.vertices[i].color = offColor;

            this.CopyToBuffer_Vertices(this.bufferForNoColor);
        }
        public void MakeLineBuffers(int value, Nodes nodes)
        {
            if (nodes == null) return;
            int h, d;
            counter = 0;
            if (menuTrajectoriesOption == MenuTrajectoriesOption.forward || menuTrajectoriesOption == MenuTrajectoriesOption.both)
            {
                if (value + this.trajectoryLength < nodes.MaximumTime)
                {
                    h = value + this.trajectoryLength;
                }
                else h = nodes.MaximumTime;
                max_depth = h - value;

                for (int i = 0; i < nodes.NodesTree[value].Length; i++)
                {
                    if (this.nodeIsSelected)
                    {
                        if (this.selectedIndex - 1 != i) continue;
                    }

                    if (this.okolie)
                    {
                        if (this.XY)
                        {
                            if (Math.Abs(nodes.NodesTree[value][i].z - this.zz) > 15) continue;
                        }
                        if (this.YZ)
                        {
                            if (Math.Abs(nodes.NodesTree[value][i].x - this.xx) > 15) continue;
                        }
                        if (this.XZ)
                        {
                            if (Math.Abs(nodes.NodesTree[value][i].y - this.yy) > 15) continue;
                        }
                    }

                    if (nodes.NodesTree[value][i].actual_colour == white) continue;
                    if (nodes.NodesTree[value][i].daughter != null)
                    {
                        trav_color = nodes.NodesTree[value][i].actual_colour;
                        int depth = 0;
                        foreach (Node tmp in nodes.NodesTree[value][i].daughter)
                        {
                            Traverse(tmp, depth);
                        }
                    }
                }
            }
            if (menuTrajectoriesOption == MenuTrajectoriesOption.backward || menuTrajectoriesOption == MenuTrajectoriesOption.both)
            {
                if (value > this.trajectoryLength)
                {
                    d = value - this.trajectoryLength;
                }
                else d = 0;

                for (int i = 0; i < nodes.NodesTree[value].Length; i++)
                {
                    if (this.XY)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].z - this.zz) > 15) continue;
                    }
                    if (this.YZ)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].x - this.xx) > 15) continue;
                    }
                    if (this.XZ)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].y - this.yy) > 15) continue;
                    }

                    if (this.nodeIsSelected)
                    {
                        if (this.selectedIndex - 1 != i) continue;
                    }

                    if (nodes.NodesTree[value][i].actual_colour == white) continue;
                    Node tmp = nodes.NodesTree[value][i];
                    Vector4 colour = nodes.NodesTree[value][i].actual_colour;
                    for (int j = d; j < value; j++)
                    {
                        if (tmp.mother == null)
                        {
                            break;
                        }
                        else
                        {
                            this.vertices[counter].position.X = tmp.x * this.scale;
                            this.vertices[counter].position.Y = tmp.y * this.scale;
                            this.vertices[counter].position.Z = tmp.z * this.scale;
                            this.vertices[counter].color = colour;
                            counter++;

                            this.vertices[counter].position.X = tmp.mother.x * this.scale;
                            this.vertices[counter].position.Y = tmp.mother.y * this.scale;
                            this.vertices[counter].position.Z = tmp.mother.z * this.scale;
                            this.vertices[counter].color = colour;
                            counter++;

                            tmp = tmp.mother;
                        }
                    }
                }
            }
            if (menuTrajectoriesOption != MenuTrajectoriesOption.noTrajectories)
            {
                this.numberOfLines = counter / 2;
                this.CopyToBuffer_Vertices(this.bufferForTrajectories);
            }
        }
        public void MakeCubeBuffers(int value, Nodes nodes)
        {
            if (nodes.NodesTree == null) return;
            int pocet = nodes.NodesTree[value].Length;
            int pom = 0;
            Vector4 color = new Vector4();

            for (int i = 0; i < pocet; i++)
            {
                if (this.okolie)
                {
                    if (this.XY)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].z - this.zz) > 15) continue;
                    }
                    if (this.YZ)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].x - this.xx) > 15) continue;
                    }
                    if (this.XZ)
                    {
                        if (Math.Abs(nodes.NodesTree[value][i].y - this.yy) > 15) continue;
                    }
                }
                float stredx = nodes.NodesTree[value][i].x * this.scale;
                float stredy = nodes.NodesTree[value][i].y * this.scale;
                float stredz = nodes.NodesTree[value][i].z * this.scale;
                float tmpxm = stredx - this.radius;
                float tmpym = stredy - this.radius;
                float tmpzm = stredz - this.radius;
                float tmpxp = stredx + this.radius;
                float tmpyp = stredy + this.radius;
                float tmpzp = stredz + this.radius;

                if (menuColoringOption == MenuColoringOption.direction)
                {
                    Node tmpnode = nodes.NodesTree[value][i];
                    int count = 0;
                    float x = 0, y = 0, z = 0, tmp;
                    int interval = 10;
                    for (int k = 0; k < interval; k++)
                    {
                        x += tmpnode.dir_X;
                        y += tmpnode.dir_Y;
                        z += tmpnode.dir_Z;
                        count++;
                        if (tmpnode.mother != null)
                            tmpnode = tmpnode.mother;
                        else break;
                    }
                    tmpnode = nodes.NodesTree[value][i];
                    for (int k = 0; k < interval; k++)
                    {
                        x += tmpnode.dir_X;
                        y += tmpnode.dir_Y;
                        z += tmpnode.dir_Z;
                        count++;
                        if (tmpnode.daughter != null)
                            tmpnode = tmpnode.daughter[0];
                        else break;
                    }
                    tmp = 1f / count;
                    x *= tmp;
                    y *= tmp;
                    z *= tmp;
                    float dlzka = 1f / (float)Math.Sqrt(x * x + y * y + z * z);
                    x *= dlzka;
                    y *= dlzka;
                    z *= dlzka;
                    float red = ((x + 1f) * 0.5f);
                    float green = ((y + 1f) * 0.5f);
                    float blue = ((z + 1f) * 0.5f);
                    color = new Vector4(red, green, blue, 1.0f);
                    nodes.NodesTree[value][i].actual_colour = color;
                }

                if (menuColoringOption == MenuColoringOption.speed)
                {
                    Node tmpnode = nodes.NodesTree[value][i];
                    int count = 0;
                    float speed = 0;
                    int interval = 10;
                    for (int k = 0; k < interval; k++)
                    {
                        speed += tmpnode.speed;
                        count++;
                        if (tmpnode.mother != null)
                            tmpnode = tmpnode.mother;
                        else break;
                    }
                    speed -= nodes.NodesTree[value][i].speed;
                    tmpnode = nodes.NodesTree[value][i];
                    for (int k = 0; k < interval; k++)
                    {
                        speed += tmpnode.speed;
                        count++;
                        if (tmpnode.daughter != null)
                            tmpnode = tmpnode.daughter[0];
                        else break;
                    }
                    speed /= count;
                    int colorIndex = (int)((Math.Min(speed, nodes.AverageSpeed * 2f) / (nodes.AverageSpeed * 2f)) * 255f);
                    int colour = cmap[colorIndex, 0] << 24 | cmap[colorIndex, 1] << 16 | cmap[colorIndex, 2] << 8 | 255;

                    float red = cmap[colorIndex, 0];
                    float green = cmap[colorIndex, 1];
                    float blue = cmap[colorIndex, 2];
                    float alpha = 255f;

                    color = new Vector4(red, green, blue, alpha);
                    color /= 255f;
                    nodes.NodesTree[value][i].actual_colour = color;
                }

                if (menuColoringOption == MenuColoringOption.originalColor)
                {
                    float red = (nodes.NodesTree[value][i].colour >> 16) & 0xff;
                    float green = (nodes.NodesTree[value][i].colour >> 8) & 0xff;
                    float blue = (nodes.NodesTree[value][i].colour >> 0) & 0xff;
                    float alpha = (nodes.NodesTree[value][i].colour >> 24) & 0xff;

                    color = new Vector4(red, green, blue, alpha);
                    color /= 255f;
                    nodes.NodesTree[value][i].actual_colour = color;
                }

                if (menuColoringOption == MenuColoringOption.customColor)
                {
                    color = new Vector4((float)this.customColor.R / 255f, (float)this.customColor.G / 255f, (float)this.customColor.B / 255f, (float)this.customColor.A / 255f);
                    nodes.NodesTree[value][i].actual_colour = color;
                }

                if (color != white)
                {
                    this.vertices[pom * 8 + 0].position.X = tmpxm;
                    this.vertices[pom * 8 + 0].position.Y = tmpym;
                    this.vertices[pom * 8 + 0].position.Z = tmpzp;
                    this.vertices[pom * 8 + 0].color = color;

                    this.vertices[pom * 8 + 1].position.X = tmpxm;
                    this.vertices[pom * 8 + 1].position.Y = tmpyp;
                    this.vertices[pom * 8 + 1].position.Z = tmpzp;
                    this.vertices[pom * 8 + 1].color = color;

                    this.vertices[pom * 8 + 2].position.X = tmpxp;
                    this.vertices[pom * 8 + 2].position.Y = tmpyp;
                    this.vertices[pom * 8 + 2].position.Z = tmpzp;
                    this.vertices[pom * 8 + 2].color = color;

                    this.vertices[pom * 8 + 3].position.X = tmpxp;
                    this.vertices[pom * 8 + 3].position.Y = tmpym;
                    this.vertices[pom * 8 + 3].position.Z = tmpzp;
                    this.vertices[pom * 8 + 3].color = color;

                    this.vertices[pom * 8 + 4].position.X = tmpxm;
                    this.vertices[pom * 8 + 4].position.Y = tmpym;
                    this.vertices[pom * 8 + 4].position.Z = tmpzm;
                    this.vertices[pom * 8 + 4].color = color;

                    this.vertices[pom * 8 + 5].position.X = tmpxm;
                    this.vertices[pom * 8 + 5].position.Y = tmpyp;
                    this.vertices[pom * 8 + 5].position.Z = tmpzm;
                    this.vertices[pom * 8 + 5].color = color;

                    this.vertices[pom * 8 + 6].position.X = tmpxp;
                    this.vertices[pom * 8 + 6].position.Y = tmpyp;
                    this.vertices[pom * 8 + 6].position.Z = tmpzm;
                    this.vertices[pom * 8 + 6].color = color;

                    this.vertices[pom * 8 + 7].position.X = tmpxp;
                    this.vertices[pom * 8 + 7].position.Y = tmpym;
                    this.vertices[pom * 8 + 7].position.Z = tmpzm;
                    this.vertices[pom * 8 + 7].color = color;

                    for (int j = 0; j < 36; j++)
                    {
                        this.cubeIndices[pom * 36 + j] = pom * 8 + indices[j];
                    }
                    pom++;
                }
            }
            this.numberOfCubes = pom;

            this.CopyToBuffer_Vertices(this.bufferForCubes);
            this.CopyToBuffer_Indices(this.bufferForIndices);
        }