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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1