protected internal static System.Collections.Generic.List<ROI> parseROIs(System.String roiopt, int nc, System.Collections.Generic.List<ROI> 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 e)
{
throw new System.ArgumentException("Bad parameter for " + "'-Rroi R' option : " + word);
}
catch (System.ArgumentOutOfRangeException f)
{
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 e)
{
throw new System.ArgumentException("Bad parameter for " + "'-Rroi C' option : " + word);
}
catch (System.ArgumentOutOfRangeException f)
{
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 e)
{
throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi A' option.");
}
try
{
maskPGM = new ImgReaderPGM(filename);
}
catch (System.IO.IOException e)
{
throw new System.InvalidOperationException("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.InvalidOperationException("Bad parameters for ROI nr " + roiVector.Count);
}
}
return roiVector;
}