/// <summary> This function parses the values given for the ROIs with the argument /// -Rroi. Currently only circular and rectangular ROIs are supported. /// /// <p>A rectangular ROI is indicated by a 'R' followed the coordinates for /// the upper left corner of the ROI and then its width and height.</p> /// /// <p>A circular ROI is indicated by a 'C' followed by the coordinates of /// the circle center and then the radius.</p> /// /// <p>Before the R and C values, the component that are affected by the /// ROI are indicated.</p> /// /// </summary> /// <param name="roiopt">The info on the ROIs /// /// </param> /// <param name="nc">number of components /// /// </param> /// <param name="roiVector">The vcector containing the ROI parsed from the cmd line /// /// </param> /// <returns> The ROIs specified in roiopt /// /// </returns> protected internal static System.Collections.ArrayList parseROIs(System.String roiopt, int nc, System.Collections.ArrayList roiVector) { //ROI[] ROIs; ROI roi; SupportClass.Tokenizer stok; //char tok; int nrOfROIs = 0; //char c; int ulx, uly, w, h, x, y, rad; // comp removed bool[] roiInComp = null; stok = new SupportClass.Tokenizer(roiopt); System.String word; while (stok.HasMoreTokens()) { word = stok.NextToken(); switch (word[0]) { case 'c': // Components specification roiInComp = ModuleSpec.parseIdx(word, nc); break; case 'R': // Rectangular ROI to be read nrOfROIs++; try { word = stok.NextToken(); ulx = (System.Int32.Parse(word)); word = stok.NextToken(); uly = (System.Int32.Parse(word)); word = stok.NextToken(); w = (System.Int32.Parse(word)); word = stok.NextToken(); h = (System.Int32.Parse(word)); } catch (System.FormatException) { throw new System.ArgumentException("Bad parameter for " + "'-Rroi R' option : " + word); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "h'-Rroi R' option."); } // If the ROI is component-specific, check which comps. if (roiInComp != null) for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, ulx, uly, w, h); roiVector.Add(roi); } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, ulx, uly, w, h); roiVector.Add(roi); } } break; case 'C': // Circular ROI to be read nrOfROIs++; try { word = stok.NextToken(); x = (System.Int32.Parse(word)); word = stok.NextToken(); y = (System.Int32.Parse(word)); word = stok.NextToken(); rad = (System.Int32.Parse(word)); } catch (System.FormatException) { throw new System.ArgumentException("Bad parameter for " + "'-Rroi C' option : " + word); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi C' option."); } // If the ROI is component-specific, check which comps. if (roiInComp != null) for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, x, y, rad); roiVector.Add(roi); } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, x, y, rad); roiVector.Add(roi); } } break; case 'A': // ROI wth arbitrary shape nrOfROIs++; System.String filename; ImgReaderPGM maskPGM = null; try { filename = stok.NextToken(); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi A' option."); } try { maskPGM = new ImgReaderPGM(filename); } catch (System.IO.IOException) { throw new System.ApplicationException("Cannot read PGM file with ROI"); } // If the ROI is component-specific, check which comps. if (roiInComp != null) for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, maskPGM); roiVector.Add(roi); } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, maskPGM); roiVector.Add(roi); } } break; default: throw new System.ApplicationException("Bad parameters for ROI nr " + roiVector.Count); } } return roiVector; }
/// <summary> Constructor for ROI with arbitrary shape /// /// </summary> /// <param name="comp">The component the ROI belongs to /// /// </param> /// <param name="maskPGM">ImgReaderPGM containing the ROI /// </param> public ROI(int comp, ImgReaderPGM maskPGM) { arbShape = true; rect = false; this.comp = comp; this.maskPGM = maskPGM; }