CSJ2K.j2k.roi.encoder.ROIScaler.parseROIs C# (CSharp) 메소드

parseROIs() 보호된 정적인 메소드

This function parses the values given for the ROIs with the argument -Rroi. Currently only circular and rectangular ROIs are supported.

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.

A circular ROI is indicated by a 'C' followed by the coordinates of the circle center and then the radius.

Before the R and C values, the component that are affected by the ROI are indicated.

protected static parseROIs ( System roiopt, int nc, System roiVector ) : System.Collections.Generic.List
roiopt System The info on the ROIs /// ///
nc int number of components /// ///
roiVector System The vcector containing the ROI parsed from the cmd line /// ///
리턴 System.Collections.Generic.List
        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;
        }