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 class WCDifference; 00031 00032 // <summary> 00033 // An ordered list of annotations and comments representing an ascii region file. 00034 // </summary> 00035 // <author>Dave Mehringer</author> 00036 // <use visibility=export> 00037 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00038 // </reviewed> 00039 // <prerequisite> 00040 00041 // </prerequisite> 00042 00043 // <etymology> 00044 // An order list of annotations and comments representing an ascii region file. 00045 // </etymology> 00046 00047 // <synopsis> 00048 // A list of regions and annotations and comments representing an ascii region file. 00049 // See the region file format proposal attached to CAS-2285 (https://bugs.nrao.edu/browse/CAS-2285) 00050 // </synopsis> 00051 00052 class RegionTextList { 00053 00054 public: 00055 00056 // <group> 00057 // create an empty list which can be appended to. This constructor 00058 // is used for constructing an annotation list on the fly, possibly 00059 // to be written to a file when complete. Do not use this constructor 00060 // if you want to determine the final composite region. 00061 RegionTextList(); 00062 00063 // create an empty list which can be appended to. This constructor 00064 // is used for constructing an annotation list on the fly, possibly 00065 // to be written to a file when complete. It can be used to determine 00066 // the composite region as well but it is the caller's responsibility 00067 // to ensure the regions added to this object are constructed 00068 // in a consistent manner (eg using the same coordinate system). 00069 // <src>shape</src> is the image shape and is only used if 00070 // the first region is a difference; in that case, the all pixels in entire 00071 // shape are set to good initially. 00072 // <src>globalOverrideChans</src> override all spectral selections in the file 00073 // or text by using this channel selection<src> 00074 // <src>globalOverrideStokes</src> override all correlation selections in the file 00075 // or text by using this polarization selection<src> 00076 RegionTextList( 00077 const CoordinateSystem& csys, const IPosition shape 00078 ); 00079 00080 // create a list by reading it from a file. 00081 // An exception is thrown if the file is not in the correct 00082 // format or does not exist. The coordinate system is used for 00083 // setting defaults and reference frames to be used. 00084 // <src>shape</src> is the image shape and is only used if 00085 // the first region is a difference; in that case, the all pixels in entire 00086 // shape are set to good initially. 00087 RegionTextList( 00088 const String& filename, const CoordinateSystem& csys, 00089 const IPosition shape, const String& prependRegion="", 00090 const String& globalOverrideChans="", const String& globalOverrrideStokes="", 00091 const Int requireAtLeastThisVersion=RegionTextParser::CURRENT_VERSION 00092 ); 00093 00094 // create a list by reading it from a text string. 00095 // An exception is thrown if the text is not in the correct 00096 // format. The coordinate system is used for 00097 // setting defaults and reference frames to be used. 00098 // <src>shape</src> is the image shape and is only used if 00099 // the first region is a difference; in that case, the all pixels in entire 00100 // shape are set to good initially. 00101 RegionTextList( 00102 const CoordinateSystem& csys, const String& text, 00103 const IPosition shape, 00104 const String& prependRegion="", 00105 const String& globalOverrideChans="", 00106 const String& globalOverrrideStokes="" 00107 ); 00108 //</group> 00109 00110 ~RegionTextList(); 00111 00112 // add a line to the end of the list 00113 void addLine(const AsciiAnnotationFileLine& line); 00114 00115 // number of lines in the list 00116 uInt nLines() const; 00117 00118 // get the line at the specified index 00119 AsciiAnnotationFileLine lineAt(const uInt i) const; 00120 00121 // get all lines in the list 00122 inline const Vector<AsciiAnnotationFileLine>& getLines() const { 00123 return _lines; 00124 } 00125 00126 ostream& print(ostream& os) const; 00127 00128 // get the composite region. 00129 CountedPtr<const WCRegion> getRegion() const; 00130 00131 // get the composite region as a region record. 00132 Record regionAsRecord() const; 00133 00134 private: 00135 Vector<AsciiAnnotationFileLine> _lines; 00136 vector<SHARED_PTR<const WCRegion> > _regions; 00137 CoordinateSystem _csys; 00138 IPosition _shape; 00139 Bool _canGetRegion; 00140 // if false, then the corresponding region is complementary to 00141 // the result of the previous region operations in the sequence 00142 vector<Bool> _union; 00143 mutable vector<SHARED_PTR<const WCDifference> > _myDiff; 00144 mutable SHARED_PTR<const WCRegion> _composite; 00145 }; 00146 00147 inline ostream &operator<<(ostream& os, const RegionTextList& list) { 00148 return list.print(os); 00149 }; 00150 00151 } 00152 00153 #endif /* IMAGES_ASCIIREGIONFILE_H_ */