Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            abrirPaciente(textBox1.Text);

            plan = paciente.Courses.First().PlanSetups.First();
            VMS.TPS.Common.Model.API.Image imagen = plan.StructureSet.Image;
            var isoc = imagen.DicomToUser(imagen.Origin, plan);

            Beam campo = plan.Beams.First();

            //VVector iso = campo.IsocenterPosition.;

            foreach (Structure estructura in plan.StructureSet.Structures)
            {
                for (int z = 0; z < 120; z++)
                {
                    var contorno = estructura.GetContoursOnImagePlane(35);

                    /*if (contorno.Count()>0)
                     * {
                     *  MessageBox.Show(z.ToString() + estructura.Id);
                     * }*/
                }
            }
            Dose dose = plan.Dose;
            IEnumerable <Isodose> isodosis = dose.Isodoses;

            foreach (Isodose iso in isodosis)
            {
                var mesh = iso.MeshGeometry;
            }

            //plan = paciente.Courses.First().PlanSetups.Where(p => p.Id == "Plan2 #").FirstOrDefault();
            Imagen(paciente, plan);
        }
        static string CheckForBlips(StructureSet ss)
        {
            //See https://stackoverflow.com/questions/39853481/is-point-inside-polygon

            int    numBlips  = 0;
            string blipsInfo = "";

            VMS.TPS.Common.Model.API.Image vi = ss.Image;


            foreach (Structure s in ss.Structures.Where(s => s.Id.StartsWithArray(new string[2] {
                "CTV", "GTV"
            })))
            {
                if (s.Id.Contains("z"))
                {
                    continue;
                }

                //loop through each image slice
                for (int i = 0; i < vi.ZSize; i++)
                {
                    VVector[][] www_lower = null;
                    VVector[][] www_upper = null;
                    if (i != 0)
                    {
                        www_lower = s.GetContoursOnImagePlane(i - 1);
                    }
                    if (i != (vi.ZSize - 1))
                    {
                        www_upper = s.GetContoursOnImagePlane(i + 1);
                    }


                    VVector[][] www = s.GetContoursOnImagePlane(i);

                    VVector[] centrepoints = new VVector[www.GetLength(0)];
                    double[]  _areas       = new double[www.GetLength(0)];
                    //if only ONE structure contoured on slice, look for blips
                    if (www.GetLength(0) == 1)
                    {
                        continue;
                    }


                    for (int k = 0; k < www.GetLength(0); k++) // iterate over slice contours
                    {
                        double minX   = www[k][0].x;
                        double maxX   = www[k][0].x;
                        double minY   = www[k][0].y;
                        double maxY   = www[k][0].y;
                        double sliceZ = www[k][0].z;

                        for (int j = 0; j < www[k].Length; j++) // iterate over vertices
                        {
                            if (www[k][j].x > maxX)
                            {
                                maxX = www[k][j].x;
                            }

                            if (www[k][j].x < minX)
                            {
                                minX = www[k][j].x;
                            }

                            if (www[k][j].y > maxY)
                            {
                                maxY = www[k][j].y;
                            }

                            if (www[k][j].y < minY)
                            {
                                minY = www[k][j].y;
                            }
                        }

                        _areas[k]         = (maxX - minX) * (maxY - minY);
                        centrepoints[k].x = (maxX + minX) / 2.0;
                        centrepoints[k].y = (maxY + minY) / 2.0;
                        centrepoints[k].z = sliceZ;

                        //If crudely calculated area of contour is too small, call it a blip
                    } //end k loop

                    for (int m = 0; m < www.GetLength(0); m++) // iterate over slice contours
                    {
                        if (_areas[m] > 10)
                        {
                            continue;
                        }
                        bool found_enclosing = false;

                        for (int n = 0; n < www.GetLength(0); n++)
                        {
                            if (n == m)
                            {
                                continue;
                            }
                            if (IsInPolygon(toPointList(www[n]), toPoint(centrepoints[m])))
                            {
                                found_enclosing = true;
                            }
                        }
                        // Check if blip is enclosed by adjacent slice contours
                        for (int u = 0; u < www_upper.GetLength(0); u++)
                        {
                            if (IsInPolygon(toPointList(www_upper[u]), toPoint(centrepoints[m])))
                            {
                                found_enclosing = true;
                            }
                        }
                        for (int u = 0; u < www_lower.GetLength(0); u++)
                        {
                            if (IsInPolygon(toPointList(www_lower[u]), toPoint(centrepoints[m])))
                            {
                                found_enclosing = true;
                            }
                        }



                        if (!found_enclosing)
                        {
                            VVector blipLocationUser = vi.DicomToUser(centrepoints[m], null);
                            //VVector blipLocationUser2 = vi.DicomToUser(www[n][0], null);
                            string blipX = Math.Round(blipLocationUser.x / 10.0, 2).ToString();
                            string blipY = Math.Round(blipLocationUser.y / 10.0, 2).ToString();
                            string blipZ = Math.Round(blipLocationUser.z / 10.0, 2).ToString();

                            //MessageBox.Show($"{blipY} {Math.Round(blipLocationUser2.y / 10.0, 2).ToString()}");

                            blipsInfo += $"Potential blip or hole (area: {_areas[m].ToString("F1")}) in structure {s.Id} located near: X = {blipX} cm, Y = {blipY} cm, Z = {blipZ} cm. ";

                            numBlips += 1;
                        }
                    }
                }
            }


            //set blipsMessage string to 'OK' if no blips
            if (numBlips == 0)
            {
                return("");
            }
            else
            {
                return(blipsInfo);
            }
        }