Beispiel #1
0
 /// <summary>
 /// Constructor con duplicacion
 /// </summary>
 /// <param name="phantom">Objeto CPhantom a duplicar</param>
 public CPhantom(CPhantom phantom)
 {
     this.mediaHigh = phantom.mediaHigh;
     this.desvHigh = phantom.desvHigh;
     this.mediaLow = phantom.mediaLow;
     this.desvLow = phantom.desvLow;
     this.densidad = phantom.densidad;
     this.zeff = phantom.zeff;
 }
Beispiel #2
0
        /// <summary>
        /// Con la ruta del archivo RSP se procede a cargar en memoria el proyecto
        /// </summary>
        /// <param name="ruta"></param>
        public bool AbrirProyecto(string ruta)
        {
            StreamReader sr = new StreamReader(ruta);
            string line;
            string name = "";
            string path = "";
            int count = 0;
            int countAreas = 0;
            bool phantoms = false;
            CCuadrado areaCore = new CCuadrado();
            CCuadrado areaP1 = new CCuadrado();
            CCuadrado areaP2 = new CCuadrado();
            CCuadrado areaP3 = new CCuadrado();
            bool segmentacionDone = false;
            bool areasDone = false;
            int toRead = 0;
            int read = 0;
            double meanHigh = 0;
            double meanLow = 0;
            double desvHigh = 0;
            double desvLow = 0;
            double densidad = 0;
            double zeff = 0;
            CPhantom tempP1 = null;
            CPhantom tempP2 = null;
            CPhantom tempP3 = null;
            int x = 0;
            int y = 0;
            int width = 0;
            int ini = 0;
            int fin = 0;
            List<CAreaInteres> areasCore = new List<CAreaInteres>();
            long head=0;
            long tail=0;
            string unidades="";

            while ((line = sr.ReadLine()) != null)
            {
                switch (line)
                {
                    case "NAME":
                        name = sr.ReadLine();
                        break;
                    case "PATH":
                        path = sr.ReadLine();
                        break;
                    case "COUNT":
                        count = Convert.ToInt16(sr.ReadLine());
                        break;
                    case "HEAD":
                        head = Convert.ToInt16(sr.ReadLine());
                        break;
                    case "TAIL":
                        tail = Convert.ToInt16(sr.ReadLine());
                        break;
                    case "UNIDADES":
                        unidades = sr.ReadLine();
                        break;
                    case "PHANTOMS":
                        phantoms = Convert.ToBoolean(sr.ReadLine());

                        toRead = 3; // se deben leer 3 phantoms
                        read = 0;

                        while (read < toRead)
                        {
                            line = sr.ReadLine();
                            switch (line)
                            {
                                case "PHANTOM1":
                                    line = sr.ReadLine(); // densidad
                                    densidad = Convert.ToDouble(sr.ReadLine());
                                    line = sr.ReadLine(); // zeff
                                    zeff = Convert.ToDouble(sr.ReadLine());
                                    if (!phantoms)
                                    {
                                        line = sr.ReadLine(); // media high
                                        meanHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv high
                                        desvHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // media low
                                        meanLow = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv low
                                        desvLow = Convert.ToDouble(sr.ReadLine());
                                    }
                                    tempP1 = new CPhantom(meanHigh, desvHigh, meanLow, desvLow, densidad, zeff);
                                    read++;
                                    break;
                                case "PHANTOM2":
                                    line = sr.ReadLine(); // densidad
                                    densidad = Convert.ToDouble(sr.ReadLine());
                                    line = sr.ReadLine(); // zeff
                                    zeff = Convert.ToDouble(sr.ReadLine());
                                    if (!phantoms)
                                    {
                                        line = sr.ReadLine(); // media high
                                        meanHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv high
                                        desvHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // media low
                                        meanLow = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv low
                                        desvLow = Convert.ToDouble(sr.ReadLine());
                                    }
                                    tempP2 = new CPhantom(meanHigh, desvHigh, meanLow, desvLow, densidad, zeff);
                                    read++;
                                    break;
                                case "PHANTOM3":
                                    line = sr.ReadLine(); // densidad
                                    densidad = Convert.ToDouble(sr.ReadLine());
                                    line = sr.ReadLine(); // zeff
                                    zeff = Convert.ToDouble(sr.ReadLine());
                                    if (!phantoms)
                                    {
                                        line = sr.ReadLine(); // media high
                                        meanHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv high
                                        desvHigh = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // media low
                                        meanLow = Convert.ToDouble(sr.ReadLine());
                                        line = sr.ReadLine(); // desv low
                                        desvLow = Convert.ToDouble(sr.ReadLine());
                                    }
                                    tempP3 = new CPhantom(meanHigh, desvHigh, meanLow, desvLow, densidad, zeff);
                                    read++;
                                    break;
                            }
                        }
                        break;
                    case "SEGMENTACION":
                        segmentacionDone = Convert.ToBoolean(sr.ReadLine());
                        if (segmentacionDone)
                        {
                            read = 0;

                            if (phantoms) toRead = 4; // si hay phantoms en los DICOM entonces se deben leer 4 segmentaciones
                            else toRead = 1; // sino, solo se lee la segmentacion del CORE

                            while (read < toRead)
                            {
                                line = sr.ReadLine();
                                switch (line)
                                {
                                    case "CORE":
                                        line = sr.ReadLine(); // X
                                        x = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // Y
                                        y = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // width
                                        width = Convert.ToInt16(sr.ReadLine());
                                        areaCore = new CCuadrado(x, y, width);
                                        areaCore.nombre = "Core";
                                        read++;
                                        break;
                                    case "PHANTOM1":
                                        line = sr.ReadLine(); // X
                                        x = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // Y
                                        y = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // width
                                        width = Convert.ToInt16(sr.ReadLine());
                                        areaP1 = new CCuadrado(x, y, width);
                                        areaP1.nombre = "Phantom1";
                                        read++;
                                        break;
                                    case "PHANTOM2":
                                        line = sr.ReadLine(); // X
                                        x = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // Y
                                        y = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // width
                                        width = Convert.ToInt16(sr.ReadLine());
                                        areaP2 = new CCuadrado(x, y, width);
                                        areaP2.nombre = "Phantom2";
                                        read++;
                                        break;
                                    case "PHANTOM3":
                                        line = sr.ReadLine(); // X
                                        x = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // Y
                                        y = Convert.ToInt16(sr.ReadLine());
                                        line = sr.ReadLine(); // width
                                        width = Convert.ToInt16(sr.ReadLine());
                                        areaP3 = new CCuadrado(x, y, width);
                                        areaP3.nombre = "Phantom3";
                                        read++;
                                        break;
                                }
                            }
                        }
                        break;

                    case "AREAS DE INTERES":
                        areasDone = Convert.ToBoolean(sr.ReadLine());
                        if (areasDone)
                        {
                            // se leen un par de lineas muertas
                            sr.ReadLine();
                            sr.ReadLine();

                            // total de areas a leer
                            read = Convert.ToInt32(sr.ReadLine());
                            countAreas = 0;

                            for (int i = 0; i < read; i++)
                            {
                                // X
                                sr.ReadLine();
                                x = Convert.ToInt32(sr.ReadLine());
                                // Y
                                sr.ReadLine();
                                y = Convert.ToInt32(sr.ReadLine());
                                // WIDTH
                                sr.ReadLine();
                                width = Convert.ToInt32(sr.ReadLine());
                                // INI
                                sr.ReadLine();
                                ini = Convert.ToInt32(sr.ReadLine());
                                // FIN
                                sr.ReadLine();
                                fin = Convert.ToInt32(sr.ReadLine());

                                countAreas++;
                                areasCore.Add(new CAreaInteres(x,y,width,"area"+countAreas.ToString(),ini,fin));
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

            // se prepara la lista de dicoms a cargar
            List<string> high = new List<string>();
            List<string> low = new List<string>();
            for (int i = 0; i < count; i++)
            {
                high.Add(path + "\\high\\" + i);
                low.Add(path + "\\high\\" + i);
            }

            // se crea el proyecto actual
            actual = new CProyecto(name, high, low, phantoms);
            actual.folderPath = path;
            actual.folderHigh = path + "\\high";
            actual.folderLow = path + "\\low";
            actual.phantomEnDicom = phantoms;
            actual.phantom1 = new CPhantom(tempP1);
            actual.phantom2 = new CPhantom(tempP2);
            actual.phantom3 = new CPhantom(tempP3);
            actual.segmentacionDone = segmentacionDone;
            if (segmentacionDone)
            {
                actual.areaCore = new CCuadrado(areaCore);
                actual.areaPhantom1 = new CCuadrado(areaP1);
                actual.areaPhantom2 = new CCuadrado(areaP2);
                actual.areaPhantom2 = new CCuadrado(areaP2);

                actual.datacuboHigh.widthSeg = actual.areaCore.width * 2;
                actual.datacuboLow.widthSeg = actual.areaCore.width * 2;

                // se genera la segmentacion
                actual.datacuboHigh.SegCircThread(actual.areaCore);
                actual.datacuboLow.SegCircThread(actual.areaCore);

                // se crean los cortes longitudinales
                actual.datacuboHigh.GenerarCoresHorizontales();
                actual.datacuboLow.GenerarCoresHorizontales();
            }
            actual.areasDone = areasDone;
            if (areasDone)
            {
                actual.areasCore = new List<CAreaInteres>();
                for (int i = 0; i < areasCore.Count; i++)
                {
                    actual.areasCore.Add(new CAreaInteres(areasCore[i]));
                }
            }
            this.actual.head = head;
            this.actual.tail = tail;
            this.actual.unidadProfundidad = unidades;

            this.proyectoForm = new ProjectForm();
            this.abiertoProyectoForm = true;
            this.proyectoForm.padre = this;
            this.proyectoForm.MdiParent = this;
            this.proyectoForm.Show();

            // se crean las imagenes de los cortes transversales
            actual.datacuboHigh.CrearBitmapThread();
            actual.datacuboLow.CrearBitmapThread();

            sr.Close();

            return true;
        }