casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WCResampleHandler.h
Go to the documentation of this file.
00001 //# WCResampleHandler.h: base class for resampling data pixels to the screen
00002 //# Copyright (C) 1993,1994,1995,1996,1998,1999,2000
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 TRIALDISPLAY_WCRESAMPLEHANDLER_H
00029 #define TRIALDISPLAY_WCRESAMPLEHANDLER_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Vector.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 template <class T> class Matrix;
00037 
00038 // <summary>
00039 // Base class for resampling data pixels to World/PixelCanvas pixels.
00040 // </summary>
00041 //
00042 // <prerequisite>
00043 // <li> Display library image drawing process
00044 // </prerequisite>
00045 //
00046 // <etymology>
00047 // The name of WCResampleHandler comes from
00048 // WorldCanvas + Resample + Handler
00049 // </etymology>
00050 //
00051 // <synopsis>
00052 // WCResampleHandler is the tool used to extract a rectangular
00053 // subregion of an image for purposes of display.  This class is
00054 // abstract and defines the interface the 
00055 // <linkto class="WorldCanvas">WorldCanvas</linkto> sees.
00056 //
00057 // When the resample handler fires, it extracts a rectangular subregion
00058 // of its input matrix and stores it in its output matrix.  If
00059 // the default subregion is the whole image and the output image is
00060 // the same size as the input image, then the output image is
00061 // a copy of the input image.
00062 //
00063 // If not, the subregion of the image is resampled to fit the output
00064 // matrix size.
00065 // </synopsis>
00066 //
00067 // <motivation>
00068 // Objectify the concept of resampling to allow programmers
00069 // to write their own, more complicated versions and register
00070 // them with the WorldCanvas.
00071 // </motivation>
00072 
00073 class WCResampleHandler {
00074 
00075  public:
00076 
00077   // (Required) default constructor.
00078   WCResampleHandler();
00079 
00080   // Copy Constructor (copy semantics)
00081   WCResampleHandler (const WCResampleHandler& other);
00082 
00083   // Assignment operator (copy semantics)
00084   WCResampleHandler& operator=(const WCResampleHandler& other);
00085 
00086   // Destructor.
00087   virtual ~WCResampleHandler();
00088 
00089 
00090   // The output array is presized by the caller to the correct size.  It will
00091   // be filled using information in the input array combined with other
00092   // resample-specific information.  Here again the interface is type expanded
00093   // rather than templated because C++ doesn't yet handle templated member
00094   // functions in a non-templated class.
00095   // <group>
00096   virtual void operator()(Matrix<Bool> &out, const Matrix<Bool> &in) = 0;
00097   virtual void operator()(Matrix<uChar> &out, const Matrix<uChar> &in) = 0;
00098   virtual void operator()(Matrix<Char> &out, const Matrix<Char> &in) = 0;
00099   virtual void operator()(Matrix<uShort> &out, const Matrix<uShort> &in) = 0;
00100   virtual void operator()(Matrix<Short> &out, const Matrix<Short> &in) = 0;
00101   virtual void operator()(Matrix<uInt> &out, const Matrix<uInt> &in) = 0;
00102   virtual void operator()(Matrix<Int> &out, const Matrix<Int> &in) = 0;
00103   virtual void operator()(Matrix<uLong> &out, const Matrix<uLong> &in) = 0;
00104   virtual void operator()(Matrix<Long> &out, const Matrix<Long> &in) = 0;
00105   virtual void operator()(Matrix<Float> &out, const Matrix<Float> &in) = 0;
00106   virtual void operator()(Matrix<Double> &out, const Matrix<Double> &in) = 0;
00107   virtual void operator()(Matrix<Complex> &out, const Matrix<Complex> &in) = 0;
00108   virtual void operator()(Matrix<DComplex> &out, const Matrix<DComplex> &in) = 0;
00109   // </group>
00110 
00111   // These functions resample the input matrix to the output.
00112   // inblc is the location 'within' the input matrix for the
00113   // bottom-left pixel of the output (sim. for intrc); blank is
00114   // the output value where none of the input data is useful.
00115   // The output matrix must be presized to the required size.
00116   // <group>
00117   virtual void operator()(Matrix<Float> &out, const Matrix<Float> &in,
00118                           const Vector<Float> &inblc, 
00119                           const Vector<Float> &intrc, 
00120                           const Float blank = 0.0) = 0;
00121   virtual void operator()(Matrix<Float> &out, Matrix<Bool>& outMask,
00122                           const Matrix<Float> &in, const Matrix<Bool> &inMask,
00123                           const Vector<Float> &inblc, 
00124                           const Vector<Float> &intrc, 
00125                           const Float blank = 0.0) = 0;
00126   virtual void operator()(Matrix<Bool> &out, const Matrix<Bool> &in,
00127                           const Vector<Float> &inblc, 
00128                           const Vector<Float> &intrc, 
00129                           const Bool blank = False) = 0;
00130   // </group>
00131 
00132   // These functions manipulate which subregion in "in" gets expanded
00133   // to "out" Coordinates are the fraction of the image to use, with
00134   // <0.0, 0.0> representing the bottom-left corner of the first pixel
00135   // and <1.0, 1.0> representing the top-right corner of the last
00136   // pixel.  These parameters are interpreted according to the derived
00137   // class.
00138   // <group>
00139   void setSubregion(const Vector<Double> &blc,
00140                     const Vector<Double> &trc) 
00141     { itsBlc = blc; itsTrc = trc; }
00142   void getSubregion(Vector<Double> &blc,
00143                     Vector<Double> &trc) const 
00144     { blc = itsBlc; trc = itsTrc; }
00145   // </group>
00146 
00147 
00148  protected:
00149 
00150   // Get the bottom left corner (range <0-1,0-1>) of the subregion
00151   const Vector<Double> &blc() const 
00152     { return itsBlc; }
00153 
00154   // Get the top right corner (range <0-1,0-1>) of the subregion
00155   const Vector<Double> &trc() const 
00156     { return itsTrc; }
00157 
00158  private:
00159 
00160   // Current subregion
00161   Vector<Double> itsBlc;
00162   Vector<Double> itsTrc;
00163 
00164 };
00165 
00166 
00167 } //# NAMESPACE CASA - END
00168 
00169 #endif