00001 //# LELRegion.h: Class to hold a region as a LEL node 00002 //# Copyright (C) 1999 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 //# 00026 //# $Id$ 00027 00028 #ifndef LATTICES_LELREGION_H 00029 #define LATTICES_LELREGION_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/lattices/LEL/LELInterface.h> 00035 #include <casacore/lattices/LRegions/LatticeRegion.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 class LattRegionHolder; 00041 00042 00043 // <summary> 00044 // Class to hold a region as a LEL node 00045 // </summary> 00046 00047 // <use visibility=local> 00048 00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class="Lattice"> Lattice</linkto> 00054 // <li> <linkto class="LatticeExpr"> LatticeExpr</linkto> 00055 // <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto> 00056 // <li> <linkto class="LELInterface"> LELInterface</linkto> 00057 // </prerequisite> 00058 00059 // <etymology> 00060 // This derived LEL letter class handles regions. 00061 // </etymology> 00062 00063 // <synopsis> 00064 // This LEL letter class is derived from LELInterface. It 00065 // is used to construct LEL objects from regions. 00066 // The internal region is an <linkto class=ImageRegion>ImageRegion</linkto> 00067 // object, thus the region can be of any type. 00068 // With operator [] a region is applied to an image (expression). 00069 // At that stage possible world coordinates are converted to lattice 00070 // coordinates. 00071 // <p> 00072 // The attributes of a LELRegion object define an empty shape, 00073 // because in general the shape of a region is only known after 00074 // it is applied to an image. 00075 // <p> 00076 // A description of the implementation details of the LEL classes can 00077 // be found in 00078 // <a href="../notes/216.html">Note 216</a> 00079 // </synopsis> 00080 00081 // <motivation> 00082 // We needed to be able to handle regions in a LEL expression. 00083 // </motivation> 00084 00085 //# <todo asof="1998/01/21"> 00086 //# </todo> 00087 00088 00089 class LELRegion : public LELInterface<Bool> 00090 { 00091 public: 00092 // Constructor. 00093 LELRegion (const LattRegionHolder& region); 00094 00095 // Constructor. It takes over the pointer. 00096 LELRegion (LattRegionHolder* region); 00097 00098 // Destructor. 00099 ~LELRegion(); 00100 00101 // Get a pointer to the region object. 00102 const LattRegionHolder& region() const 00103 { return *region_p; } 00104 00105 // Getting region data cannot be done (throws an exception). 00106 virtual void eval(LELArray<Bool>&, const Slicer&) const; 00107 00108 // Getting region data cannot be done (throws an exception). 00109 virtual LELScalar<Bool> getScalar() const; 00110 00111 // Do further preparations (e.g. optimization) on the expression. 00112 virtual Bool prepareScalarExpr(); 00113 00114 // Get class name 00115 virtual String className() const; 00116 00117 // Form a compound from the regions. 00118 // <group> 00119 static LELRegion* makeUnion (const LELInterface<Bool>& left, 00120 const LELInterface<Bool>& right); 00121 static LELRegion* makeIntersection (const LELInterface<Bool>& left, 00122 const LELInterface<Bool>& right); 00123 static LELRegion* makeDifference (const LELInterface<Bool>& left, 00124 const LELInterface<Bool>& right); 00125 static LELRegion* makeComplement (const LELInterface<Bool>& expr); 00126 // </group> 00127 00128 private: 00129 // Get the LattRegionHolder after checking that the expression is a region. 00130 static const LattRegionHolder& region (const LELInterface<Bool>& expr); 00131 00132 // Check if both regions have the same type (pixel or world) and if 00133 // no LCSlicer type of region is used. 00134 static void checkTypes (const LattRegionHolder& left, 00135 const LattRegionHolder& right); 00136 00137 // Member variables. 00138 LattRegionHolder* region_p; 00139 }; 00140 00141 00142 00143 00144 // <summary> 00145 // Class to convert a region to a boolean node 00146 // </summary> 00147 00148 // <use visibility=local> 00149 00150 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00151 // </reviewed> 00152 00153 // <prerequisite> 00154 // <li> <linkto class="LELRegion"> Lattice</linkto> 00155 // <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto> 00156 // <li> <linkto class="LELInterface"> LELInterface</linkto> 00157 // </prerequisite> 00158 00159 // <etymology> 00160 // This derived LEL letter class handles a region as a boolean lattice. 00161 // </etymology> 00162 00163 // <synopsis> 00164 // This class makes it possible to handle a region as a true 00165 // boolean lattice without the need to apply the region to an image. 00166 // It means that it is only possible if the region has absolute 00167 // lattice coordinates. 00168 // <p> 00169 // A description of the implementation details of the LEL classes can 00170 // be found in 00171 // <a href="../notes/216.html">Note 216</a> 00172 // </synopsis> 00173 00174 // <motivation> 00175 // It is useful to be able to handle a mask as a boolean lattice. 00176 // </motivation> 00177 00178 //# <todo asof="1998/01/21"> 00179 //# </todo> 00180 00181 00182 class LELRegionAsBool : public LELInterface<Bool> 00183 { 00184 public: 00185 // Constructor. 00186 LELRegionAsBool (const LELRegion& region); 00187 00188 // Destructor. 00189 ~LELRegionAsBool(); 00190 00191 // Get region data. 00192 virtual void eval(LELArray<Bool>& result, 00193 const Slicer& section) const; 00194 00195 // Getting region data as a scalar cannot be done (throws an exception). 00196 virtual LELScalar<Bool> getScalar() const; 00197 00198 // Do further preparations (e.g. optimization) on the expression. 00199 virtual Bool prepareScalarExpr(); 00200 00201 // Get class name 00202 virtual String className() const; 00203 00204 private: 00205 // Member variables. 00206 LatticeRegion region_p; 00207 }; 00208 00209 00210 00211 00212 } //# NAMESPACE CASACORE - END 00213 00214 #endif