casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionTextList.h
Go to the documentation of this file.
00001 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00002 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00003 //# License for more details.
00004 //#
00005 //# You should have received a copy of the GNU Library General Public License
00006 //# along with this library; if not, write to the Free Software Foundation,
00007 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00008 //#
00009 //# Correspondence concerning AIPS++ should be addressed as follows:
00010 //#        Internet email: aips2-request@nrao.edu.
00011 //#        Postal address: AIPS++ Project Office
00012 //#                        National Radio Astronomy Observatory
00013 //#                        520 Edgemont Road
00014 //#                        Charlottesville, VA 22903-2475 USA
00015 //#
00016 
00017 #ifndef ANNOTATIONS_REGIONTEXTLIST_H
00018 #define ANNOTATIONS_REGIONTEXTLIST_H
00019 
00020 #include <casa/aips.h>
00021 #include <casa/Arrays/Vector.h>
00022 #include <coordinates/Coordinates/CoordinateSystem.h>
00023 #include <imageanalysis/IO/AsciiAnnotationFileLine.h>
00024 #include <imageanalysis/IO/RegionTextParser.h>
00025 #include <images/Regions/WCRegion.h>
00026 #include <images/Regions/WCUnion.h>
00027 
00028 namespace casa {
00029 
00030 // <summary>
00031 // An ordered list of annotations and comments representing an ascii region file.
00032 // </summary>
00033 // <author>Dave Mehringer</author>
00034 // <use visibility=export>
00035 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00036 // </reviewed>
00037 // <prerequisite>
00038 
00039 // </prerequisite>
00040 
00041 // <etymology>
00042 // An order list of annotations and comments representing an ascii region file.
00043 // </etymology>
00044 
00045 // <synopsis>
00046 // A list of regions and annotations and comments representing an ascii region file.
00047 // See the region file format proposal attached to CAS-2285 (https://bugs.nrao.edu/browse/CAS-2285)
00048 // </synopsis>
00049 
00050 class RegionTextList {
00051 
00052 public:
00053 
00054         // <group>
00055         // create an empty list which can be appended to. This constructor
00056         // is used for constructing an annotation list on the fly, possibly
00057         // to be written to a file when complete. Do not use this constructor
00058         // if you want to determine the final composite region.
00059         RegionTextList(const Bool deletePointersOnDestruct=True);
00060 
00061         // create an empty list which can be appended to. This constructor
00062         // is used for constructing an annotation list on the fly, possibly
00063         // to be written to a file when complete. It can be used to determine
00064         // the composite region as well but it is the caller's responsibility
00065         // to ensure the regions added to this object are constructed
00066         // in a consistent manner (eg using the same coordinate system).
00067         // <src>shape</src> is the image shape and is only used if
00068         // the first region is a difference; in that case, the all pixels in entire
00069         // shape are set to good initially.
00070         RegionTextList(
00071                 const CoordinateSystem& csys,
00072                 const IPosition shape,
00073                 const Bool deletePointersOnDestruct=True
00074         );
00075 
00076         // create a list by reading it from a file.
00077         // An exception is thrown if the file is not in the correct
00078         // format or does not exist. The coordinate system is used for
00079         // setting defaults and reference frames to be used.
00080         // <src>shape</src> is the image shape and is only used if
00081         // the first region is a difference; in that case, the all pixels in entire
00082         // shape are set to good initially.
00083         RegionTextList(
00084                 const String& filename, const CoordinateSystem& csys,
00085                 const IPosition shape,
00086                 const Int requireAtLeastThisVersion=RegionTextParser::CURRENT_VERSION,
00087                 const Bool deletePointersOnDestruct=True
00088         );
00089 
00090         // create a list by reading it from a text string.
00091         // An exception is thrown if the text is not in the correct
00092         // format. The coordinate system is used for
00093         // setting defaults and reference frames to be used.
00094         // <src>shape</src> is the image shape and is only used if
00095         // the first region is a difference; in that case, the all pixels in entire
00096         // shape are set to good initially.
00097         RegionTextList(
00098                 const CoordinateSystem& csys, const String& text,
00099                 const IPosition shape,
00100                 const Bool deletePointersOnDestruct=True
00101         );
00102         //</group>
00103 
00104         ~RegionTextList();
00105 
00106         // add a line to the end of the list
00107         void addLine(const AsciiAnnotationFileLine& line);
00108 
00109         // number of lines in the list
00110         uInt nLines() const;
00111 
00112         // get the line at the specified index
00113         AsciiAnnotationFileLine lineAt(const uInt i) const;
00114 
00115         // get all lines in the list
00116         inline const Vector<AsciiAnnotationFileLine>& getLines() const {
00117                 return _lines;
00118         }
00119 
00120         ostream& print(ostream& os) const;
00121 
00122         // get the composite region.
00123         WCRegion* getRegion() const;
00124 
00125         // get the composite region as a region record.
00126         Record regionAsRecord() const;
00127 
00128 private:
00129         Vector<AsciiAnnotationFileLine> _lines;
00130         Bool _deletePointersOnDestruct;
00131         PtrBlock<WCRegion *> _regions;
00132         CoordinateSystem _csys;
00133         IPosition _shape;
00134         Bool _canGetRegion;
00135 
00136 };
00137 
00138 inline ostream &operator<<(ostream& os, const RegionTextList& list) {
00139         return list.print(os);
00140 };
00141 
00142 }
00143 
00144 #endif /* IMAGES_ASCIIREGIONFILE_H_ */