00001 //# LattRegionHolder.h: Class to hold a region of interest in an image 00002 //# Copyright (C) 1999,2001 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_LATTREGIONHOLDER_H 00029 #define LATTICES_LATTREGIONHOLDER_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/lattices/LRegions/LatticeRegion.h> 00034 00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00036 00037 //# Forward Declarations 00038 class CoordinateSystem; 00039 class IPosition; 00040 class LCRegion; 00041 class LCSlicer; 00042 class WCRegion; 00043 class String; 00044 class TableRecord; 00045 00046 00047 // <summary> 00048 // Class to hold a region of interest in an image. 00049 // </summary> 00050 00051 // <use visibility=export> 00052 00053 // <reviewed reviewer="" date="" tests=""> 00054 // </reviewed> 00055 00056 // <prerequisite> 00057 // <li> <linkto class=LCSlicer>LCSlicer</linkto> 00058 // <li> <linkto class=WCRegion>LCRegion</linkto> 00059 // </prerequisite> 00060 00061 // <synopsis> 00062 // The only purpose of LattRegionHolder is to have a single object for 00063 // the various kinds of regions. It can hold a 00064 // <linkto class=LCRegion>LCRegion</linkto>, and 00065 // <linkto class=LCSlicer>LCSlicer</linkto>. 00066 // </synopsis> 00067 00068 // <example> 00069 // <srcblock> 00070 // </srcblock> 00071 // </example> 00072 00073 // <motivation> 00074 // It was felt that making an abstract base class LatticeRegion for 00075 // LCRegion and WCRegion would create undesirable dependencies of 00076 // module Lattices on module Coordinates. E.g. it would be impossible 00077 // to have a function toWCRegion. 00078 // Therefore the container class LattRegionHolder is chosen, from which 00079 // the container <linkto class=ImageRegion>ImageRegion</linkto> is derived. 00080 // </motivation> 00081 00082 //# <todo asof="1997/11/11"> 00083 //# <li> 00084 //# </todo> 00085 00086 00087 class LattRegionHolder 00088 { 00089 public: 00090 // Construct from a region based on lattice coordinates. 00091 LattRegionHolder (const LCRegion&); 00092 00093 // Construct from a slicer based on lattice coordinates. 00094 LattRegionHolder (const LCSlicer&); 00095 00096 // Similar constructors as above, but using a pointer. 00097 // It takes over the pointer, so the user should not delete the 00098 // object. It is deleted by the LattRegionHolder destructor. 00099 // <group> 00100 explicit LattRegionHolder (LCRegion*); 00101 explicit LattRegionHolder (LCSlicer*); 00102 // </group> 00103 00104 // Copy constructor (copy semantics). 00105 LattRegionHolder (const LattRegionHolder& other); 00106 00107 virtual ~LattRegionHolder(); 00108 00109 // Assignment (copy semantics). 00110 LattRegionHolder& operator= (const LattRegionHolder& other); 00111 00112 // Clone the object. 00113 virtual LattRegionHolder* clone() const; 00114 00115 // Comparison 00116 // <group> 00117 virtual Bool operator==(const LattRegionHolder& other) const; 00118 Bool operator!=(const LattRegionHolder& other) const; 00119 // </group> 00120 00121 // Test if the underlying region is an LCRegion, etc. 00122 // <group> 00123 Bool isLCRegion() const; 00124 Bool isLCSlicer() const; 00125 virtual Bool isWCRegion() const; 00126 // </group> 00127 00128 // Get the region as a pointer to a LCRegion, LCSlicer, or WCRegion. 00129 // An exception is thrown if the region is not the correct type. 00130 // Functions <src>isWCRegion()</src>, etc. can be used to test the type. 00131 // <group> 00132 const LCRegion* asLCRegionPtr() const; 00133 const LCSlicer* asLCSlicerPtr() const; 00134 virtual const WCRegion* asWCRegionPtr() const; 00135 // </group> 00136 00137 // Get the dimensionality. 00138 uInt ndim() const; 00139 00140 // Convert to a LatticeRegion using the given shape. 00141 LatticeRegion toLatticeRegion (const IPosition& shape) const; 00142 00143 // Convert to a LatticeRegion using the given coordinate system 00144 // (with reference pixel) and shape. 00145 // It will also make the region complete (absolute and non-fractional). 00146 virtual LatticeRegion toLatticeRegion (const CoordinateSystem& cSys, 00147 const IPosition& shape) const; 00148 00149 // Form a compound from this and the other region. 00150 // <group> 00151 virtual LattRegionHolder* makeUnion (const LattRegionHolder& other) const; 00152 virtual LattRegionHolder* makeIntersection 00153 (const LattRegionHolder& other) const; 00154 virtual LattRegionHolder* makeDifference 00155 (const LattRegionHolder& other) const; 00156 virtual LattRegionHolder* makeComplement() const; 00157 // </group> 00158 00159 protected: 00160 // Construct for the given dimensionality (for derived classes). 00161 explicit LattRegionHolder (uInt ndim); 00162 00163 private: 00164 LCRegion* itsLC; 00165 LCSlicer* itsSlicer; 00166 uInt itsNdim; 00167 }; 00168 00169 00170 inline Bool LattRegionHolder::isLCRegion() const 00171 { 00172 return (itsLC != 0); 00173 } 00174 inline Bool LattRegionHolder::isLCSlicer() const 00175 { 00176 return (itsSlicer != 0); 00177 } 00178 inline Bool LattRegionHolder::operator!= (const LattRegionHolder& other) const 00179 { 00180 return (! operator== (other)); 00181 } 00182 inline uInt LattRegionHolder::ndim() const 00183 { 00184 return itsNdim; 00185 } 00186 00187 00188 00189 } //# NAMESPACE CASACORE - END 00190 00191 #endif