/// <summary> /// Constructor con asignacion. Se crea una copia del elemento CCuadrado que se pasa como argumento /// </summary> /// <param name="copia">Elemento CCuadrado que se va a duplicar</param> public CCuadrado(CCuadrado copia) { nombre = copia.nombre; x = copia.x; y = copia.y; width = copia.width; }
/// <summary> /// Establece las coordenadas para la segmentacion del Phantom1 con el tipo de dato CCuadrado /// </summary> /// <param name="elemento">CCuadrado que contiene la informacion del cuadrado</param> public void SetPhantom1(CCuadrado elemento) { this.areaPhantom1 = new CCuadrado(elemento); this.areaPhantom1.nombre = "Phantom1"; }
/// <summary> /// Establece las coordenadas para la segmentacion del Core con el tipo de dato CCuadrado /// </summary> /// <param name="elemento">CCuadrado que contiene la informacion del cuadrado</param> public void SetCore(CCuadrado elemento) { this.areaCore = new CCuadrado(elemento); this.areaCore.nombre = "Core"; // se corrigen las coordenadas y ancho del cuadrado }
/// <summary> /// Genera la totalidad de las segmentaciones circulares de cores usando threads /// </summary> /// <param name="area">Objeto CCuadrado con la información del area a segmentar</param> public void SegCircThread(CCuadrado area) { int nseg = dataCube.Count; ManualResetEvent[] doneEvents = new ManualResetEvent[nseg]; AuxThread[] threads = new AuxThread[nseg]; int width = Convert.ToInt32(dataCube[0].selector.Columns.Data); int height = Convert.ToInt32(dataCube[0].selector.Rows.Data); for (int i = 0; i < nseg; i++) { doneEvents[i] = new ManualResetEvent(false); AuxThread thread = new AuxThread(this.dataCube[i].pixelData, area.x, area.y, area.width, width, height, doneEvents[i]); threads[i] = thread; ThreadPool.QueueUserWorkItem(thread.ThreadSegmentar, i); } foreach (var e in doneEvents) e.WaitOne(); for (int i = 0; i < nseg; i++) { this.dataCube[i].segCore = threads[i].Segmentacion; } }
/// <summary> /// Se calcula el nuevo elemento usando los 3-clicks realizados sobre la imagen, y se agrega al List /// </summary> public void AddElemento() { // tomado del script calcCircle.m CCuadrado punto = new CCuadrado(); double epsilon = 0.000000001; bool ax_is_0 = (Math.Abs(tempClicks[1].x - tempClicks[0].x) <= epsilon); bool bx_is_0 = (Math.Abs(tempClicks[2].x - tempClicks[1].x) <= epsilon); // check whether both lines are vertical - collinear if (ax_is_0 && bx_is_0) { MessageBox.Show("Los puntos ingresados pertenecen a una misma linea recta", "Error al dibujar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int delta_a_x = tempClicks[1].x - tempClicks[0].x; int delta_a_y = tempClicks[1].y - tempClicks[0].y; int delta_b_x = tempClicks[2].x - tempClicks[1].x; int delta_b_y = tempClicks[2].y - tempClicks[1].y; // make sure delta gradients are not vertical // swap points to change deltas if (ax_is_0) { int temp; temp = tempClicks[1].x; tempClicks[1].x = tempClicks[2].x; tempClicks[2].x = temp; temp = tempClicks[1].y; tempClicks[1].y = tempClicks[2].y; tempClicks[2].y = temp; delta_a_x = tempClicks[1].x - tempClicks[0].x; delta_a_y = tempClicks[1].y - tempClicks[0].y; } if (bx_is_0) { int temp; temp = tempClicks[0].x; tempClicks[0].x = tempClicks[1].x; tempClicks[1].x = temp; temp = tempClicks[0].y; tempClicks[0].y = tempClicks[1].y; tempClicks[1].y = temp; delta_b_x = tempClicks[2].x - tempClicks[1].x; delta_b_y = tempClicks[2].y - tempClicks[1].y; } double grad_a = (double)delta_a_y / (double)delta_a_x; double grad_b = (double)delta_b_y / (double)delta_b_x; // check whether the given points are collinear if (Math.Abs(grad_a - grad_b) <= epsilon) { MessageBox.Show("Los puntos ingresados pertenecen a una misma linea recta", "Error al dibujar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // swap grads and points if grad_a is 0 if (Math.Abs(grad_a) <= epsilon) { double temp2; temp2 = grad_a; grad_a = grad_b; grad_b = temp2; int temp; temp = tempClicks[0].x; tempClicks[0].x = tempClicks[2].x; tempClicks[2].x = temp; temp = tempClicks[0].y; tempClicks[0].y = tempClicks[2].y; tempClicks[2].y = temp; } countAreas++; // calculate centre - where the lines perpendicular to the centre of segments a and b intersect punto.x = Convert.ToInt32((grad_a * grad_b * (tempClicks[0].y - tempClicks[2].y) + grad_b * (tempClicks[0].x + tempClicks[1].x) - grad_a * (tempClicks[1].x + tempClicks[2].x)) / (2 * (grad_b - grad_a))); punto.y = Convert.ToInt32(((tempClicks[0].x + tempClicks[1].x) / 2 - punto.x) / grad_a + (tempClicks[0].y + tempClicks[1].y) / 2); punto.width = Convert.ToInt32(Math.Sqrt(Math.Pow(punto.x - tempClicks[0].x, 2) + Math.Pow(punto.y - tempClicks[0].y, 2))); punto.nombre = "Area " + countAreas; elementosScreen.Add(punto); AddList(punto); // se obliga al PictureBox que se resetee y dibuje todos los elementos que hayan en memoria controlPaint = true; pictElemento.Invalidate(); btnClean.Enabled = true; btnDelete.Enabled = true; }
private void CheckForm_Load(object sender, EventArgs e) { SetForm(); ResetCountClick(); // se prepara el lapiz con el que se va a pintar pen1 = new System.Drawing.Pen(Color.Red, 2F); float[] dashValues = { 10, 3, 5, 3 }; pen1.DashPattern = dashValues; pen2 = new System.Drawing.Pen(Color.LawnGreen, 2F); pen2.DashPattern = dashValues; pen3 = new System.Drawing.Pen(Color.Red,1F); // se prepara la lista dinamica elementosScreen = new List<CCuadrado>(); controlPaint = false; countAreas = 0; // se cargan los elementos HIGH si existen if (padre.actual.segmentacionDone) { CCuadrado temp; temp = new CCuadrado(padre.actual.GetCore()); elementosScreen.Add(MainForm.CorregirOriginal2PictBox(temp, pictElemento.Image.Height, pictElemento.Height)); if (padre.actual.phantomEnDicom) { temp = new CCuadrado(padre.actual.GetPhantom1()); elementosScreen.Add(MainForm.CorregirOriginal2PictBox(temp, pictElemento.Image.Height, pictElemento.Height)); temp = new CCuadrado(padre.actual.GetPhantom2()); elementosScreen.Add(MainForm.CorregirOriginal2PictBox(temp, pictElemento.Image.Height, pictElemento.Height)); temp = new CCuadrado(padre.actual.GetPhantom3()); elementosScreen.Add(MainForm.CorregirOriginal2PictBox(temp, pictElemento.Image.Height, pictElemento.Height)); } LlenarList(); controlPaint = true; pictElemento.Invalidate(); btnDelete.Enabled = true; btnClean.Enabled = true; } this.Invalidate(); }
private void btnPreview_Click(object sender, EventArgs e) { // si los dicom contienen informacion de phantoms entonces se busca que hallan 4 elementos // si los dicom no contienen informacion de phantoms entonces se busca solo 1 elemento if (padre.actual.phantomEnDicom) { // los dicom contienen informacion de phantom if (elementosScreen.Count < 4) { MessageBox.Show("No se han seleccionado todos los elementos del slide.\n\nNo se puede proceder a previsualizar.", "Error al previsualizar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (elementosScreen.Count > 4) { MessageBox.Show("Se han seleccionado demasiados elementos en el slide.\n\nNo se puede proceder a previsualizar.", "Error al previsualizar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.padre.previewSegForm = new PreviewSegForm(); this.padre.abiertoPreviewSegForm = true; this.padre.previewSegForm.padre = this.padre; // se cortan las imagenes y se envian a PreviewSegForm // se prepara un List de Bitmap List<Bitmap> cortes = new List<Bitmap>(); // primero se hace una copia del List elementosScreen con las coordenadas corregidas List<CCuadrado> tempElementos = new List<CCuadrado>(); for (int i = 0; i < elementosScreen.Count; i++) { CCuadrado temp = new CCuadrado(elementosScreen[i]); tempElementos.Add(MainForm.CorregirPictBox2Original(temp, pictElemento.Image.Height, pictElemento.Height)); } // se ordena el tempElementos de radio mas grande a mas pequeño para sacar el CORE // se ordenan segun el tamano del lado de cuadrado, de mas grande a mas pequeno, y se toma el Core como el elemento mas grande tempElementos.Sort(delegate(CCuadrado x, CCuadrado y) { return y.width.CompareTo(x.width); }); Bitmap aEnviar = new Bitmap(pictElemento.Image); cortes.Add(MainForm.CropCirle(aEnviar, tempElementos[0])); padre.previewSegForm.core = cortes[0]; tempElementos.RemoveAt(0); // se ordenan de izquierda a derecha // se ordenan segun la coordenada X, de izquierda a derecha. Los phantom P1 P2 y P3 se ordenan de izquierda a derecha tempElementos.Sort(delegate(CCuadrado x, CCuadrado y) { return x.x.CompareTo(y.x); }); for (int i = 0; i < tempElementos.Count; i++) { cortes.Add(MainForm.CropCirle(aEnviar, tempElementos[i])); } padre.previewSegForm.p1 = cortes[1]; padre.previewSegForm.p2 = cortes[2]; padre.previewSegForm.p3 = cortes[3]; // se invoca como un cuadro de dialogo modal, no MDIchild this.padre.previewSegForm.ShowDialog(); } else { // los dicom no contienen informacion de dicom if (elementosScreen.Count < 1) { MessageBox.Show("No se han seleccionado un elemento core.\n\nNo se puede proceder a previsualizar.", "Error al previsualizar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (elementosScreen.Count > 1) { MessageBox.Show("Se han seleccionado demasiados elementos en el slide.\n\nNo se puede proceder a previsualizar.", "Error al previsualizar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.padre.previewSegForm = new PreviewSegForm(); this.padre.abiertoPreviewSegForm = true; this.padre.previewSegForm.padre = this.padre; // se cortan las imagenes y se envian a PreviewSegForm // se prepara un List de Bitmap List<Bitmap> cortes = new List<Bitmap>(); // primero se hace una copia del List elementosScreen con las coordenadas corregidas List<CCuadrado> tempElementos = new List<CCuadrado>(); for (int i = 0; i < elementosScreen.Count; i++) { CCuadrado temp = new CCuadrado(elementosScreen[i]); tempElementos.Add(MainForm.CorregirPictBox2Original(temp, pictElemento.Image.Height, pictElemento.Height)); } Bitmap aEnviar = new Bitmap(pictElemento.Image); cortes.Add(MainForm.CropCirle(aEnviar, tempElementos[0])); padre.previewSegForm.core = cortes[0]; tempElementos.RemoveAt(0); padre.previewSegForm.p1 = null; padre.previewSegForm.p2 = null; padre.previewSegForm.p3 = null; // se invoca como un cuadro de dialogo modal, no MDIchild this.padre.previewSegForm.grpPhantoms.Visible = false; this.padre.previewSegForm.ShowDialog(); } }
private void pictCore_Paint(object sender, PaintEventArgs e) { // se busca si existe un elemento en la lista areasCore que se corresponda con el slide actual, y se pinta el area for (int i = 0; i < this.padre.actual.areasCore.Count; i++) { if ((trackElementos.Value >= this.padre.actual.areasCore[i].ini) & (trackElementos.Value <= this.padre.actual.areasCore[i].fin)) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; CCuadrado corregido = new CCuadrado(padre.actual.areasCore[i].x, padre.actual.areasCore[i].y, padre.actual.areasCore[i].width); corregido = MainForm.CorregirOriginal2PictBox(corregido, padre.actual.datacuboHigh.widthSeg, pictCore.Height); e.Graphics.DrawEllipse(pen2, corregido.x - corregido.width, corregido.y - corregido.width, 2 * corregido.width, 2 * corregido.width); //e.Graphics.DrawEllipse(pen2, this.padre.actual.areasCore[i].x - this.padre.actual.areasCore[i].width, this.padre.actual.areasCore[i].y - this.padre.actual.areasCore[i].width, 2 * this.padre.actual.areasCore[i].width, 2 * this.padre.actual.areasCore[i].width); return; // se encontro el elemento areaInteres buscado, no es necesario buscar los otros elementos en la lista } } }
public void DeteccionAutomatica() { // se limpian todas las areas seleccionadas previamente btnClean_Click(new object(),new EventArgs()); // se ejecuta la deteccion de bordes Rectangle[] areas=DetectarBordes(); if (areas != null) { CCuadrado temp; for (int i = 0; i < areas.Length; i++) { countAreas++; temp = new CCuadrado(); temp.width = (int)(areas[i].Width / 2); temp.x = areas[i].X + temp.width; temp.y = areas[i].Y + temp.width; temp.nombre = "Area" + countAreas; elementosScreen.Add(MainForm.CorregirOriginal2PictBox(temp,pictElemento.Image.Height,pictElemento.Height)); // el metodo de correccion de tamaño de coordenadas modifica el CCuadrado temp AddList(temp); } // se obliga al PictureBox que se resetee y dibuje todos los elementos que hayan en memoria controlPaint = true; pictElemento.Invalidate(); btnClean.Enabled = true; btnDelete.Enabled = true; } else { // no hacer nada, no se detectaron los bordes } }
/// <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; }
/// <summary> /// Toma una imagen (el slide completo) y recorta un area circular delimitada por el elemento CCuadrado /// </summary> /// <param name="srcImage">Imagen original de la que se extraera el corte circular</param> /// <param name="elemento">Area de corte</param> /// <returns>Imagen recortada</returns> public static Bitmap CropCirle(Bitmap srcImage, CCuadrado elemento) { // primero se extrae el area rectangular del slide que se pasa como argumento Bitmap bmp = new Bitmap(elemento.width * 2, elemento.width * 2); Graphics g = Graphics.FromImage(bmp); Rectangle selectedArea = new Rectangle(); selectedArea.X = elemento.x - elemento.width; selectedArea.Y = elemento.y - elemento.width; selectedArea.Width = selectedArea.Height = elemento.width * 2; g.DrawImage(srcImage, 0, 0, selectedArea, GraphicsUnit.Pixel); // la imagen bmp contiene el recorte rectangular // ahora se debe volver un circulo Bitmap dstImage = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat); g = Graphics.FromImage(dstImage); using (Brush br = new SolidBrush(Color.Black)) { g.FillRectangle(br, 0, 0, dstImage.Width, dstImage.Height); } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0, 0, dstImage.Width, dstImage.Height); g.SetClip(path); g.DrawImage(bmp, 0, 0); return dstImage; }
/// <summary> /// Toma un CCuadrado, con coordenadas segun el PictureBox, y las transforma segun la imagen original /// </summary> /// <param name="elemento">CCuadrado que contiene la informacion del cuadrado</param> /// <param name="heighto">Alto de la imagen original</param> /// <param name="heigths">Alto del PictureBox</param> /// <returns></returns> public static CCuadrado CorregirPictBox2Original(CCuadrado elemento, int heighto, int heigths) { // se pasa de un tamano de imagen pequeno a grande, por lo tanto la relacion es positiva double relacion = (double)heighto / (double)heigths; // nuevas coordenadas elemento.x = (int)(Math.Ceiling(elemento.x * relacion)); elemento.y = (int)(Math.Ceiling(elemento.y * relacion)); elemento.width = (int)(elemento.width * relacion); return elemento; }
/// <summary> /// Se calcula el nuevo elemento usando los 3-clicks realizados sobre la imagen, y se agrega al List /// </summary> public void AddElemento(CCirculo[] tempClicks, string elemento) { // tomado del script calcCircle.m CCuadrado punto = new CCuadrado(); double epsilon = 0.000000001; bool ax_is_0 = (Math.Abs(tempClicks[1].x - tempClicks[0].x) <= epsilon); bool bx_is_0 = (Math.Abs(tempClicks[2].x - tempClicks[1].x) <= epsilon); // check whether both lines are vertical - collinear if (ax_is_0 && bx_is_0) { MessageBox.Show("Los puntos ingresados pertenecen a una misma linea recta", "Error al dibujar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int delta_a_x = tempClicks[1].x - tempClicks[0].x; int delta_a_y = tempClicks[1].y - tempClicks[0].y; int delta_b_x = tempClicks[2].x - tempClicks[1].x; int delta_b_y = tempClicks[2].y - tempClicks[1].y; // make sure delta gradients are not vertical // swap points to change deltas if (ax_is_0) { int temp; temp = tempClicks[1].x; tempClicks[1].x = tempClicks[2].x; tempClicks[2].x = temp; temp = tempClicks[1].y; tempClicks[1].y = tempClicks[2].y; tempClicks[2].y = temp; delta_a_x = tempClicks[1].x - tempClicks[0].x; delta_a_y = tempClicks[1].y - tempClicks[0].y; } if (bx_is_0) { int temp; temp = tempClicks[0].x; tempClicks[0].x = tempClicks[1].x; tempClicks[1].x = temp; temp = tempClicks[0].y; tempClicks[0].y = tempClicks[1].y; tempClicks[1].y = temp; delta_b_x = tempClicks[2].x - tempClicks[1].x; delta_b_y = tempClicks[2].y - tempClicks[1].y; } double grad_a = (double)delta_a_y / (double)delta_a_x; double grad_b = (double)delta_b_y / (double)delta_b_x; // check whether the given points are collinear if (Math.Abs(grad_a - grad_b) <= epsilon) { MessageBox.Show("Los puntos ingresados pertenecen a una misma linea recta", "Error al dibujar!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // swap grads and points if grad_a is 0 if (Math.Abs(grad_a) <= epsilon) { double temp2; temp2 = grad_a; grad_a = grad_b; grad_b = temp2; int temp; temp = tempClicks[0].x; tempClicks[0].x = tempClicks[2].x; tempClicks[2].x = temp; temp = tempClicks[0].y; tempClicks[0].y = tempClicks[2].y; tempClicks[2].y = temp; } // calculate centre - where the lines perpendicular to the centre of segments a and b intersect punto.x = Convert.ToInt32((grad_a * grad_b * (tempClicks[0].y - tempClicks[2].y) + grad_b * (tempClicks[0].x + tempClicks[1].x) - grad_a * (tempClicks[1].x + tempClicks[2].x)) / (2 * (grad_b - grad_a))); punto.y = Convert.ToInt32(((tempClicks[0].x + tempClicks[1].x) / 2 - punto.x) / grad_a + (tempClicks[0].y + tempClicks[1].y) / 2); punto.width = Convert.ToInt32(Math.Sqrt(Math.Pow(punto.x - tempClicks[0].x, 2) + Math.Pow(punto.y - tempClicks[0].y, 2))); // si no existen areas dibujadas entonces se agrega la primera a la lista // si la nueva area dibujada está al inicio de un area previamente creada entonces la nueva area modifica el area creada if (padre.actual.areasCore.Count < 1) { // se crea la primera area AddArea(punto, elemento); } else { // hay areas creadas, se verifica si se debe sobre escribir o se crea una segunda area if (trackElementos.Value == padre.actual.areasCore[lstAreas.SelectedIndex].ini) { // se cambia el punto obtenido a las coordenadas originales, considerando que el tamaño del pictCore y de la imagen son diferentes CCuadrado corregido = new CCuadrado(punto); corregido = MainForm.CorregirPictBox2Original(corregido, padre.actual.datacuboHigh.widthSeg, pictCore.Height); padre.actual.areasCore[lstAreas.SelectedIndex].x = corregido.x; padre.actual.areasCore[lstAreas.SelectedIndex].y = corregido.y; padre.actual.areasCore[lstAreas.SelectedIndex].width = corregido.width; // se pintan las areas el pictCore controlPaint = true; pictCore.Invalidate(); } else { // se crea una nueva area AddArea(punto, elemento); } } btnClear.Enabled = true; btnDelete.Enabled = true; }
/// <summary> /// Establece las coordenadas para la segmentacion del Phantom2 con el tipo de dato CCuadrado /// </summary> /// <param name="elemento">CCuadrado que contiene la informacion del cuadrado</param> public void SetPhantom2(CCuadrado elemento) { this.areaPhantom2 = new CCuadrado(elemento); this.areaPhantom2.nombre = "Phantom2"; }
/// <summary> /// Se agrega un elemento (CCuadrado) al ListBox /// </summary> private void AddList(CCuadrado punto) { string elemento = punto.nombre; lstElementos.Items.Add(elemento); lstElementos.SelectedIndex = lstElementos.Items.Count - 1; }
/// <summary> /// Establece las coordenadas para la segmentacion del Phantom3 con el tipo de dato CCuadrado /// </summary> /// <param name="elemento">CCuadrado que contiene la informacion del cuadrado</param> public void SetPhantom3(CCuadrado elemento) { this.areaPhantom3 = new CCuadrado(elemento); this.areaPhantom3.nombre = "Phantom3"; }
private void AddArea(CCuadrado punto, string elemento) { // se incrementa el contador de areas countAreas++; // se cambia el punto obtenido a las coordenadas originales, considerando que el tamaño del pictCore y de la imagen son diferentes CCuadrado corregido = new CCuadrado(punto); corregido = MainForm.CorregirPictBox2Original(corregido, padre.actual.datacuboHigh.widthSeg, pictCore.Height); CAreaInteres area = new CAreaInteres(corregido.x, corregido.y, corregido.width, "Area" + countAreas.ToString(), Convert.ToInt32(numActual.Value), padre.actual.datacuboHigh.dataCube.Count); switch (elemento) { case "core": padre.actual.areasCore.Add(area); // se ordenan los elementos de principio a fin this.padre.actual.areasCore.Sort(delegate(CAreaInteres a, CAreaInteres b) { return a.ini.CompareTo(b.ini); }); // se verifica que no se crucen las areas entre si if (this.padre.actual.areasCore.Count > 1) { // solo se verifica que no hayan cruces si y solo si hay mas de una area agregada a la lista for (int i = 1; i < this.padre.actual.areasCore.Count; i++) { if (this.padre.actual.areasCore[i - 1].fin > this.padre.actual.areasCore[i].ini) this.padre.actual.areasCore[i - 1].fin = this.padre.actual.areasCore[i].ini - 1; } } // se llena el ListBox LlenarListAreas(); // se busca que indice del listbox se debe seleccionar, en funcion del slide en el que se encuentra for (int i = 0; i < this.padre.actual.areasCore.Count; i++) { if ((trackElementos.Value >= this.padre.actual.areasCore[i].ini) & (trackElementos.Value <= this.padre.actual.areasCore[i].fin)) lstAreas.SelectedIndex = i; } // se pintan las areas el pictCore controlPaint = true; pictCore.Invalidate(); // se envia el list de areas de interes a la SelectAreas2Form //padre.selecAreas2Form.GetAreasCore(areasCore, pictCore.Image.Width); break; } }