casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LCSlicer.h
Go to the documentation of this file.
00001 //# LCSlicer.h: Class to define a rectangular box of interest with strides
00002 //# Copyright (C) 1998,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: LCSlicer.h 20505 2009-01-19 14:37:24Z gervandiepen $
00027 
00028 #ifndef LATTICES_LCSLICER_H
00029 #define LATTICES_LCSLICER_H
00030 
00031 //# Includes
00032 #include <lattices/Lattices/RegionType.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/BasicSL/String.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class IPosition;
00040 class Slicer;
00041 class TableRecord;
00042 
00043 
00044 // <summary>
00045 // Class to define a rectangular box of interest with strides.
00046 // </summary>
00047 
00048 // <use visibility=export>
00049 
00050 // <reviewed reviewer="" date="" tests="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //   <li> <linkto class=LCBox>LCBox</linkto>
00055 // </prerequisite>
00056 
00057 // <synopsis> 
00058 // The LCSlicer makes it possible to define a rectangular box
00059 // with strides. Note that this class is not derived from
00060 // <linkto class=LCRegion>LCRegion</linkto>, so it cannot be used in
00061 // a compound region object like <linkto class=LCUnion>LCUnion</linkto>.
00062 // The reason is that strides make it impossible to use a region
00063 // in a compound.
00064 // <br>
00065 // The slicer region has to be defined from an
00066 // <linkto class=LCBox>LCBox</linkto> object defining the blc/trc
00067 // and a vector (of the same length) containing the strides.
00068 // The LCSlicer can be of any type (thus relative, fractional, unspecified),
00069 // while the strides can be defined as a number or a fraction.
00070 // <br>
00071 // It is also possible to construct it directly from a
00072 // <linkto class=Slicer>Slicer</linkto> object, 
00073 // </synopsis> 
00074 
00075 // <example>
00076 // <srcblock>
00077 // </srcblock>
00078 // </example>
00079 
00080 // <todo asof="1997/11/11">
00081 // </todo>
00082 
00083 class LCSlicer
00084 {
00085 public:
00086     LCSlicer();
00087 
00088     // Construct a slicer from the blc, trc, and stride (default 1).
00089     // The vectors can be different in lengths. The longest determines
00090     // the dimensionality of the region. The shorter ones get padded
00091     // with default values.
00092     // <group>
00093     LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
00094               Bool fractionalBlcTrc = False,
00095               RegionType::AbsRelType = RegionType::Abs);
00096     LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
00097               const Vector<Float>& inc, Bool fractionalBlcTrc = False,
00098               RegionType::AbsRelType = RegionType::Abs);
00099     LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
00100               const Vector<Float>& inc,
00101               const Vector<Bool>& fractionalBlc,
00102               const Vector<Bool>& fractionalTrc,
00103               const Vector<Bool>& fractionalInc,
00104               const Vector<Int>& absRelBlc,
00105               const Vector<Int>& absRelTrc);
00106     LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
00107               Bool fractionalBlcTrc = False,
00108               RegionType::AbsRelType = RegionType::Abs);
00109     LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
00110               const Vector<Double>& inc, Bool fractionalBlcTrc = False,
00111               RegionType::AbsRelType = RegionType::Abs);
00112     LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
00113               const Vector<Double>& inc,
00114               const Vector<Bool>& fractionalBlc,
00115               const Vector<Bool>& fractionalTrc,
00116               const Vector<Bool>& fractionalInc,
00117               const Vector<Int>& absRelBlc,
00118               const Vector<Int>& absRelTrc);
00119     LCSlicer (const Slicer& slicer);
00120     LCSlicer (const IPosition& blc, const IPosition& trc,
00121               RegionType::AbsRelType = RegionType::Abs);
00122     LCSlicer (const IPosition& blc, const IPosition& trc,
00123               const IPosition& inc,
00124               RegionType::AbsRelType = RegionType::Abs);
00125     LCSlicer (const IPosition& blc, const IPosition& trc,
00126               const IPosition& inc,
00127               const Vector<Int>& absRelBlc,
00128               const Vector<Int>& absRelTrc);
00129     // </group>
00130 
00131     // Copy constructor (reference semantics).
00132     LCSlicer (const LCSlicer& other);
00133 
00134     ~LCSlicer();
00135 
00136     // Assignment (copy semantics).
00137     LCSlicer& operator= (const LCSlicer& other);
00138 
00139     // Test for equality.
00140     // True is returned when the given region is a slicer with exactly
00141     // the same specification as this slicer.
00142     // It does not compare the comment.
00143     // <group>
00144     Bool operator== (const LCSlicer& other) const;
00145     Bool operator!= (const LCSlicer& other) const;
00146     // </group>
00147 
00148     // The region is completely specified if it is absolute, not fractional,
00149     // and has no unspecified values.
00150     Bool isComplete() const;
00151 
00152     // Get the dimensionality of the region.
00153     uInt ndim() const;
00154 
00155     // Simple accessor functions.
00156     // <group>
00157     const Vector<Float>& blc() const;
00158     const Vector<Float>& trc() const;
00159     const Vector<Float>& inc() const;
00160     Bool isFractional() const;
00161     Bool isAbsolute() const;
00162     Bool isUnspecified() const;
00163     Bool isStrided() const;
00164     // </group>
00165 
00166     // Get the class name (to store in the record).
00167     static String className();
00168 
00169     // Get the region type. Returns className().
00170     String type() const;
00171 
00172     // Get or set the comment.
00173     // <group>
00174     const String& comment() const;
00175     void setComment (const String& comment);
00176     // </group>
00177 
00178     // Make the region complete using the given reference pixel
00179     // and shape. It returns a new region where the relative regions
00180     // are made absolute by translating them with respect to the
00181     // reference pixel. Furthermore unspecified values are filled
00182     // in and fractional values are turned into absolute ones.
00183     // <group>
00184     Slicer toSlicer (const IPosition& referencePixel,
00185                      const IPosition& latticeShape) const;
00186     Slicer toSlicer (const Vector<Double>& referencePixel,
00187                      const IPosition& latticeShape) const;
00188     Slicer toSlicer (const Vector<Float>& referencePixel,
00189                      const IPosition& newLatticeShape) const;
00190     // </group>
00191 
00192     // Convert the object to a record.
00193     TableRecord toRecord (const String& tableName) const;
00194 
00195     // Convert to correct object from a record.
00196     static LCSlicer* fromRecord (const TableRecord&,
00197                                  const String& tablename);
00198 
00199 private:
00200     // Fill the pixel based flags from the general ones.
00201     void fillFlags (Bool fractional, Int absRel,
00202                     uInt nrblc, uInt nrtrc, uInt nrinc);
00203 
00204     // Fill the vectors from the values given as doubles.
00205     void fillFromDouble (const Vector<Double>& blc,
00206                          const Vector<Double>& trc,
00207                          const Vector<Double>& inc);
00208 
00209     // Fill the vectors from the values given as IPositions.
00210     void fillFromIPosition (const IPosition& blc,
00211                             const IPosition& trc,
00212                             const IPosition& inc);
00213 
00214     // Fill the remaining variables.
00215     // It also adjust the lengths of the vectors if they are different.
00216     // Check if everything is given correctly.
00217     void fill();
00218 
00219     //# Variables
00220     Vector<Float> itsBlc;
00221     Vector<Float> itsTrc;
00222     Vector<Float> itsInc;
00223     Vector<Bool>  itsFracBlc;
00224     Vector<Bool>  itsFracTrc;
00225     Vector<Bool>  itsFracInc;
00226     Vector<Int>   itsAbsRelBlc;
00227     Vector<Int>   itsAbsRelTrc;
00228     Bool itsIsFractional;
00229     Bool itsIsAbsolute;
00230     Bool itsIsUnspecified;
00231     Bool itsIsStrided;
00232     String itsComment;
00233 };
00234 
00235 
00236 inline Bool LCSlicer::operator!= (const LCSlicer& other) const
00237 {
00238     return  (! operator==(other));
00239 }
00240 inline uInt LCSlicer::ndim() const
00241 {
00242     return itsBlc.nelements();
00243 }
00244 inline const Vector<Float>& LCSlicer::blc() const
00245 {
00246     return itsBlc;
00247 }
00248 inline const Vector<Float>& LCSlicer::trc() const
00249 {
00250     return itsTrc;
00251 }
00252 inline const Vector<Float>& LCSlicer::inc() const
00253 {
00254     return itsInc;
00255 }
00256 inline Bool LCSlicer::isFractional() const
00257 {
00258     return itsIsFractional;
00259 }
00260 inline Bool LCSlicer::isAbsolute() const
00261 {
00262     return itsIsAbsolute;
00263 }
00264 inline Bool LCSlicer::isUnspecified() const
00265 {
00266     return itsIsUnspecified;
00267 }
00268 inline Bool LCSlicer::isStrided() const
00269 {
00270     return itsIsStrided;
00271 }
00272 inline const String& LCSlicer::comment() const
00273 {
00274     return itsComment;
00275 }
00276 inline void LCSlicer::setComment (const String& comment)
00277 {
00278     itsComment = comment;
00279 }
00280 
00281 
00282 
00283 } //# NAMESPACE CASA - END
00284 
00285 #endif