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