00001 //# WCLELMask.h: Class to define a mask as a LEL expression 00002 //# Copyright (C) 2000,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# $Id$ 00026 00027 00028 00029 #ifndef IMAGES_WCLELMASK_H 00030 #define IMAGES_WCLELMASK_H 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/images/Regions/WCRegion.h> 00035 #include <casacore/lattices/LRegions/RegionType.h> 00036 #include <casacore/coordinates/Coordinates/CoordinateSystem.h> 00037 #include <casacore/casa/Arrays/Vector.h> 00038 #include <casacore/casa/Quanta/Quantum.h> 00039 00040 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00041 00042 //# Forward Declarations 00043 class LCRegion; 00044 class TableRecord; 00045 class IPosition; 00046 template<class T> class ImageExpr; 00047 template<class T> class LatticeExpr; 00048 class LatticeExprNode; 00049 00050 00051 // <summary> 00052 // Class to define a mask as a LEL expression 00053 // </summary> 00054 00055 // <use visibility=export> 00056 00057 // <reviewed reviewer="" date="" tests=""> 00058 // </reviewed> 00059 00060 // <prerequisite> 00061 // <li> <linkto class=WCRegion>WCRegion</linkto> 00062 // <li> <linkto class=ImageExpr>ImageExpr</linkto> 00063 // </prerequisite> 00064 00065 // <synopsis> 00066 // The WCLELMask class is a specialization of class 00067 // <linkto class=WCRegion>WCRegion</linkto>. 00068 // <br> 00069 // It can be used to define an on-the-fly mask for an image 00070 // using a boolean <linkto class=LatticeExpr>LatticeExpr</linkto>. 00071 // The contents of the mask are calculated on the fly from the expression. 00072 // Thus the mask may change if the data in the image(s) used in the 00073 // expression change. 00074 // <note role=caution> 00075 // This mask is only persistent if constructed from an expression string. 00076 // When constructed from an <linkto class=ImageExpr>ImageExpr</linkto> 00077 // the mask is not persistent. 00078 // </note> 00079 // </synopsis> 00080 00081 // <example> 00082 // </example> 00083 00084 // <motivation> 00085 // Users must be able to specify a mask based on an expression. 00086 // </motivation> 00087 00088 //# <todo asof="1998/05/20"> 00089 //# <li> 00090 //# </todo> 00091 00092 class WCLELMask : public WCRegion 00093 { 00094 public: 00095 WCLELMask(); 00096 00097 // Construct from the given expression command. 00098 // The command will be parsed and converted to an ImageExpr. 00099 // <group> 00100 explicit WCLELMask (const String& command); 00101 explicit WCLELMask (const char* command); 00102 // </group> 00103 00104 // Construct from the given image expression. 00105 explicit WCLELMask (const ImageExpr<Bool>& expr); 00106 00107 // Construct from the given lattice expression. 00108 explicit WCLELMask (const LatticeExpr<Bool>& expr); 00109 00110 // Construct from the given lattice expression. 00111 // This constructor makes it possible to have an expression with an 00112 // unknown shape (e.g. using LEL function INDEXIN). 00113 // If the shape is known, the LatticeExprNode will be converted to 00114 // a LatticeExpr<Bool>. 00115 explicit WCLELMask (const LatticeExprNode& expr); 00116 00117 // Copy constructor (copy semantics). 00118 WCLELMask (const WCLELMask& other); 00119 00120 // Destructor 00121 virtual ~WCLELMask(); 00122 00123 // Assignment (copy semantics) 00124 WCLELMask& operator= (const WCLELMask& other); 00125 00126 // Comparison 00127 virtual Bool operator== (const WCRegion& other) const; 00128 00129 // Clone a WCLELMask object. 00130 virtual WCRegion* cloneRegion() const; 00131 00132 // Get the dimensionality (i.e. the number of axes). 00133 virtual uInt ndim() const; 00134 00135 // WCLELMask cannot extend a region. 00136 virtual Bool canExtend() const; 00137 00138 // Convert to an LCRegion using the given new coordinate system and shape. 00139 // If the region has coordinates, the WCRegion implementation will 00140 // be called. Otherwise the LatticeExpr is returned after checking 00141 // that the shape matches. 00142 virtual LCRegion* toLCRegion (const CoordinateSystem& cSys, 00143 const IPosition& latticeShape) const; 00144 00145 // Convert to an LCRegion using the supplied <src>CoordinateSystem</src> 00146 // and shape. 00147 // It checks that coordinates match and that axes are not swapped. 00148 virtual LCRegion* doToLCRegion (const CoordinateSystem& cSys, 00149 const IPosition& latticeShape, 00150 const IPosition& pixelAxesMap, 00151 const IPosition& outOrder) const; 00152 00153 // Convert the WCLELMask object to a record. 00154 // The record can be used to make the object persistent. 00155 // The <src>tableName</src> argument can be used by derived 00156 // classes (e.g. LCPagedMask) to put very large objects. 00157 virtual TableRecord toRecord (const String& tableName) const; 00158 00159 // Convert to a WCLELMask from a record. 00160 static WCLELMask* fromRecord (const TableRecord& rec, 00161 const String& tableName); 00162 00163 // Returns WCLELMask 00164 static String className(); 00165 00166 // Return region type. Returns the class name 00167 virtual String type() const; 00168 00169 const ImageExpr<Bool>* getImageExpr() const {return itsImageExpr;} 00170 00171 private: 00172 // Process the command. 00173 void processCommand(); 00174 00175 // Initialize as a LatticeExprNode if expression's shape is unknown. 00176 // Otherwise as a LatticeExpr<Bool> if coordinates are unknown. 00177 // Otherwise as an ImageExpr<Bool>. 00178 void init (const LatticeExprNode& expr); 00179 00180 00181 String itsCommand; 00182 ImageExpr<Bool>* itsImageExpr; 00183 LatticeExpr<Bool>* itsLattExpr; 00184 LatticeExprNode* itsLattNode; 00185 }; 00186 00187 00188 00189 } //# NAMESPACE CASACORE - END 00190 00191 #endif