LCEllipsoid.h

Go to the documentation of this file.
00001 //# LCEllipsoid.h: Define an N-dimensional ellipsoidal region of interest
00002 //# Copyright (C) 1997,1998
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_LCELLIPSOID_H
00029 #define LATTICES_LCELLIPSOID_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/lattices/LRegions/LCRegionFixed.h>
00034 #include <casacore/casa/Arrays/Vector.h>
00035 
00036 
00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00038 
00039 // <summary>
00040 // Define an N-dimensional ellipsoidal region of interest.
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="" date="" tests="">
00046 // </reviewed>
00047 
00048 // <prerequisite>
00049 //   <li> <linkto class=LCRegion>LCRegion</linkto>
00050 // </prerequisite>
00051 
00052 // <synopsis> 
00053 // The LCEllipsoid class is a specialization of class
00054 // <linkto class=LCRegion>LCRegion</linkto>.
00055 // It makes it possible to define an N-dimensional ellipsoidal region
00056 // of interest, which includes the border. A separate constructor exists
00057 // to define the special case of an N-dimensional sphere.
00058 // <br>
00059 // The center and the radii of the ellipsoid do not need to be pixel aligned.
00060 // The center of the ellipsoid may be outside the lattice.
00061 // The current implementation only supports ellipsoids with axes parallel
00062 // to the lattice axes except in the case of a 2-D ellipse for which a
00063 // constructor is provided for specifying the angle between the x-axis
00064 // and major axis of the ellipse.
00065 // <p>
00066 // It can only be used for a lattice of any dimensionality as long as the
00067 // dimensionality of the (hyper-)ellipsoid matches the dimensionality of
00068 // the lattice.
00069 // </synopsis> 
00070 
00071 // <example>
00072 // <srcblock>
00073 // </srcblock>
00074 // </example>
00075 
00076 // <todo asof="1997/11/11">
00077 // <li> Arguments to have ellipsoid axes not parallel to lattice axes for
00078 // dimensions greater than 2. This is a nontrivial problem because of the
00079 // complexity of the rotation matrices involved.
00080 // </todo>
00081 
00082 
00083 class LCEllipsoid: public LCRegionFixed
00084 {
00085 public:
00086     LCEllipsoid();
00087 
00088     // Construct an N-dimensional sphere with the given center and
00089     // radius (in pixels). The center is pixel-aligned.
00090     LCEllipsoid (const IPosition& center, Float radius,
00091                  const IPosition& latticeShape);
00092 
00093     // Construct an N-dimensional sphere with the given center and
00094     // radius (in pixels). The center does not need to be pixel-aligned.
00095     // <group>
00096     LCEllipsoid (const Vector<Float>& center, Float radius,
00097                  const IPosition& latticeShape);
00098     LCEllipsoid (const Vector<Double>& center, Double radius,
00099                  const IPosition& latticeShape);
00100     // </group>
00101 
00102     // Construct an N-dimensional ellipsoid with the given center and
00103     // radii (in pixels). The center does not need to be pixel-aligned.
00104     // (the radii are half the length of the axes of the ellipsoid).
00105     // <group>
00106     LCEllipsoid (const Vector<Float>& center, const Vector<Float>& radii,
00107                  const IPosition& latticeShape);
00108     LCEllipsoid (const Vector<Double>& center, const Vector<Double>& radii,
00109                  const IPosition& latticeShape);
00110     // </group>
00111 
00112     // Construct a two dimensional ellipse with theta being the angle from
00113     // the x-axis to the major axis of the ellipse in radians.
00114     LCEllipsoid (
00115         const Float xcenter, const Float ycenter,
00116         const Float majorAxis, const Float minorAxis,
00117         const Float theta, const IPosition& latticeShape
00118     );
00119 
00120     // Copy constructor (reference semantics).
00121     LCEllipsoid (const LCEllipsoid& other);
00122 
00123     virtual ~LCEllipsoid();
00124 
00125     // Assignment (copy semantics).
00126     LCEllipsoid& operator= (const LCEllipsoid& other);
00127 
00128     // Comparison
00129     virtual Bool operator== (const LCRegion& other) const;
00130 
00131     // Make a copy of the derived object.
00132     virtual LCRegion* cloneRegion() const;
00133 
00134     // Get the center.
00135     const Vector<Float>& center() const;
00136 
00137     // Get the radii.
00138     const Vector<Float>& radii() const;
00139 
00140     // Get the angle of the major axis of the ellipse relative to the x-axis
00141     // 2-D only, throws exception if ellipse is not 2-D.
00142     const Float& theta() const;
00143 
00144     // Get the class name (to store in the record).
00145     static String className();
00146 
00147     // Get the region type.  Returns className()
00148     virtual String type() const;
00149 
00150     // Convert the (derived) object to a record.
00151     virtual TableRecord toRecord (const String& tableName) const;
00152 
00153     // Convert correct object from a record.
00154     static LCEllipsoid* fromRecord (const TableRecord&,
00155                                     const String& tableName);
00156 
00157 protected:
00158     // Construct another LCBox (for e.g. another lattice) by moving
00159     // this one. It recalculates the bounding box.
00160     // A positive translation value indicates "to right".
00161     virtual LCRegion* doTranslate (const Vector<Float>& translateVector,
00162                                    const IPosition& newLatticeShape) const;
00163 
00164 private:
00165     // Fill the itsCenter vector from an IPosition.
00166     void fillCenter (const IPosition& center);
00167 
00168     // Make the bounding box from center, radii, and shape.
00169     Slicer makeBox (const Vector<Float>& radii,
00170                          const IPosition& latticeShape);
00171 
00172     // Define the mask to indicate which elements are inside the ellipsoid.
00173     void defineMask();
00174 
00175     //for 2-D ellipse with non-zero theta. Works for both cases center
00176     // inside or outside the lattice.
00177     void _defineMask2D();
00178 
00179     // set the mask in the case the center lies outside the lattice
00180     void _doOutside();
00181 
00182     Vector<Float> itsCenter;
00183     Vector<Float> itsRadii;
00184     // small offset to guard against roundoff error
00185     Vector<Float> _epsilon;
00186     // for 2-D case only
00187     Float _theta;
00188     // is center inside the lattice?
00189     Bool _centerIsInside;
00190 };
00191 
00192 
00193 inline const Vector<Float>& LCEllipsoid::center() const
00194 {
00195     return itsCenter;
00196 }
00197 inline const Vector<Float>& LCEllipsoid::radii() const
00198 {
00199     return itsRadii;
00200 }
00201 
00202 
00203 
00204 } //# NAMESPACE CASACORE - END
00205 
00206 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1