casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatticePADD.h
Go to the documentation of this file.
00001 //# LatticePADD.h: Class for displaying lattices along principal axes
00002 //# Copyright (C) 1998,1999,2000,2001,2002
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_LATTICEPADD_H
00029 #define TRIALDISPLAY_LATTICEPADD_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Quanta/Unit.h>
00033 #include <images/Images/ImageInterface.h>
00034 #include <display/DisplayDatas/PrincipalAxesDD.h>
00035 #include <casa/Containers/Record.h>
00036 #include <display/Display/DParameterChoice.h>
00037 #include <display/Display/DParameterRange.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 class IPosition;
00042 class WCResampleHandler;
00043 class ImageRegion;
00044 class WCLELMask;
00045 class WorldCanvas;
00046 template <class T> class Array;
00047 template <class T> class Lattice;
00048 template <class T> class MaskedLattice;
00049 template <class T> class LatticeStatistics;
00050 
00051 // <summary>
00052 // Partial implementation of PrincipalAxesDD for Lattice-based data.
00053 // </summary>
00054 //
00055 // <synopsis>
00056 // This class is a partial (ie. base) implementation of PrincipalAxesDD
00057 // which adds methods particular to handling Lattice-based data.
00058 // </synopsis>
00059 
00060 template <class T> class LatticePADisplayData : public PrincipalAxesDD {
00061 
00062  public:
00063   // Constructors (no default)
00064   //LatticePADisplayData();
00065 
00066   // Array-based constructors: >2d and 2d
00067   // <group>
00068   LatticePADisplayData(Array<T> *array, const uInt xAxis,
00069                        const uInt yAxis, const uInt mAxis,
00070                        const IPosition fixedPos);
00071   LatticePADisplayData(Array<T> *array, const uInt xAxis,
00072                        const uInt yAxis);
00073   // </group>
00074 
00075   // Image-based constructors: >2d and 2d
00076   // <group>
00077   LatticePADisplayData( ImageInterface<T> *image, const uInt xAxis, const uInt yAxis, const uInt mAxis, const IPosition fixedPos, viewer::StatusSink *sink=0 );
00078   LatticePADisplayData(ImageInterface<T> *image, const uInt xAxis,
00079                        const uInt yAxis);
00080   // </group>
00081 
00082   // Destructor
00083   virtual ~LatticePADisplayData();
00084 
00085   // Format a string containing value information at the 
00086   // given world coordinate
00087   virtual String showValue(const Vector<Double> &world);
00088 
00089   // required functions to help inherited "setup" amongst other things
00090   virtual const IPosition dataShape() const;
00091   virtual const uInt dataDim() const;
00092   virtual const T dataValue(IPosition pos);
00093   virtual const Unit dataUnit() const;
00094 
00095   // Pure virtual function from DisplayData...
00096   String dataType() const { return "image"; }
00097   // Get image analyis about object...
00098   virtual ImageAnalysis *imageanalysis( ) const;
00099   ImageInterface<Float> *imageinterface( );
00100 
00101 
00102   // left as pure virtual for implementation in concrete class
00103   virtual void setupElements() = 0;
00104   virtual void getMinAndMax();
00105 
00106   // return mask value at given position
00107   virtual const Bool maskValue(const IPosition &pos);
00108 
00109   // install the default options for this DisplayData
00110   virtual void setDefaultOptions();
00111 
00112   // apply options stored in val to the DisplayData; return value
00113   // True means a refresh is needed...
00114   virtual Bool setOptions(Record &rec, Record &recOut);
00115 
00116 
00117 
00118   // retrieve the current and default options and parameter types.
00119   virtual Record getOptions();
00120 
00121   // Return the class name of this DisplayData; useful mostly for
00122   // debugging purposes, and perhaps future use in the glish widget
00123   // interface.
00124   virtual String className() { return String("LatticePADisplayData"); }  
00125   String description( ) const
00126         { return itsBaseImagePtr ? itsBaseImagePtr->name( ) : "none available"; }
00127 
00128   virtual WCResampleHandler *resampleHandler() { return itsResampleHandler; }
00129 
00130   
00131 
00132   virtual Display::ComplexToRealMethod complexMode() 
00133     { return itsComplexToRealMethod; }
00134   virtual void setComplexMode(Display::ComplexToRealMethod method) 
00135     { itsComplexToRealMethod = method; }
00136 
00137   virtual MaskedLattice<T> *maskedLattice() 
00138     { return itsMaskedLatticePtr; }
00139 
00140 
00141    // Insert an array into a Record. The array is insert into a "value" field, eg
00142   // somerecord.fieldname.value
00143   virtual Bool insertArray(Record& toGoInto, Vector<Float> toInsert, const String fieldname);
00144   virtual Bool insertFloat(Record& toGoInto, Float toInsert, const String fieldname);
00145 
00146   // Return the last calculated histogram
00147   virtual Record getHist();
00148   
00149   // Return the brightness unit as a string
00150   virtual String getBrightnessUnits();
00151   
00152   // Aids updateHistogram() by computing a stride to use for efficiency
00153   // when computing histograms (could be used elsewhere too).
00154   // Input parameter 'shape' is the shape of the original lattice or array.
00155   // Return value indicates whether striding should be used; if so, the
00156   // recommended stride is returned in the 'stride' parameter.
00157   // maxPixels is the desired maximum number of elements in the sub-lattice
00158   // that would result from using the returned stride (may be exceeded
00159   // because of minPerAxis requirements, or in any case by a few percent).
00160   // A stride greater than 1 will not be returned for an axis if it
00161   // would make the length of that axis in the strided sub-lattice
00162   // less than minPerAxis.
00163   static Bool useStriding(const IPosition& shape, IPosition& stride,
00164                           uInt maxPixels=1000000u, uInt minPerAxis=20u);
00165 
00166 
00167  protected:
00168 
00169   // Called by constructors: set up data for beam drawing, if applicable.
00170   virtual void SetUpBeamData_();
00171   
00172   
00173   // Will draw the beam ellipse if applicable (i.e., the LatticePADD
00174   // has an image with beam data, beam drawing is turned on, and the
00175   // WC's CoordinateSystem is set to sky coordinates).
00176   virtual void drawBeamEllipse_(WorldCanvas* wc);
00177   
00178 
00179   
00180  private:
00181 
00182   // The base image cloned at construction.
00183   ImageInterface<T>* itsBaseImagePtr;
00184 
00185   // The base array cloned at construction.
00186   Array<T>* itsBaseArrayPtr;
00187 
00188   // The image histogram
00189   Record imageHistogram;
00190 
00191   // Whether to always calculate the histogram or not
00192   Bool calcHist;
00193   
00194   // The masked lattice, effectively referencing one of itsBaseImagePtr
00195   // or itsBaseArray, or some sub-region of said.
00196   MaskedLattice<T>* itsMaskedLatticePtr;
00197 
00198   // Says whether the destructor should delete itsMaskedLattice or not
00199   Bool itsDeleteMLPointer;
00200   
00201   // Object to use for calculating statistics.
00202   LatticeStatistics<Float>* itsLatticeStatisticsPtr;
00203 
00204   // Is itsLattice a SubImage?
00205   ImageRegion* itsRegionPtr;
00206 
00207   // OTF mask
00208   WCLELMask* itsMaskPtr;
00209 
00210   // The data unit
00211   Unit itsDataUnit;
00212 
00213   // the complex to real method
00214   Display::ComplexToRealMethod itsComplexToRealMethod;
00215 
00216   // storage for the display parameters
00217   String itsResample;
00218   String itsComplexMode;
00219 
00220   // beam-drawing state
00221   // </group>
00222 
00223   std::vector<std::vector<double> > beams_;
00224   String majorunit_;    //# units of above (should be angular
00225   String minorunit_;    //# (relative world sky coordinates).
00226   String paunit_;       //# angular units of posangle_.
00227   
00228   DParameterChoice* beamOnOff_;         //# User-selectable parameters.
00229   DParameterChoice* beamStyle_;         //# "Outline", "Filled"
00230   DParameterChoice* beamColor_;
00231   DParameterRange<Int>* beamLineWidth_;
00232   DParameterRange<Float>* beamXCenter_;         //# 0=left edge, 1=right edge
00233   DParameterRange<Float>* beamYCenter_;         //# 0=bottom edge, 1=top edge
00234   // </group>
00235   
00236   
00237   
00238   // pointer to resampler
00239   WCResampleHandler *itsResampleHandler;
00240 
00241   // update itsLatticeStatistics
00242   void updateLatticeStatistics();
00243 
00244   // Update the histogram, and attach it to the supplied record 
00245   Bool updateHistogram(Record &rec, MaskedLattice<Complex> &pImage);
00246   Bool updateHistogram(Record &rec, ImageInterface<Float> &pImage);
00247   Bool updateHistogram(Record &rec, const Array<Complex>*);
00248   Bool updateHistogram(Record &rec, const Array<Float>*);
00249   
00250   WCLELMask* makeMask (const RecordInterface& mask);
00251   ImageRegion* makeRegion (const RecordInterface& region);
00252   Bool isMaskDifferent (WCLELMask*& pMask);
00253   Bool isRegionDifferent (ImageRegion*& pRegion);
00254 
00255    // Transfer preferences between CoordinateSystems
00256   Bool transferPreferences (CoordinateSystem& cSysInOut,
00257                              const CoordinateSystem& cSysIn) const;
00258 
00259   // Delete temporary image data
00260   void delTmpImage();
00261 };
00262 
00263 
00264 } //# NAMESPACE CASA - END
00265 
00266 #ifndef AIPS_NO_TEMPLATE_SRC
00267 #include <display/DisplayDatas/LatticePADD.tcc>
00268 //#include <display/DisplayDatas/LatticePADD2.tcc>
00269 #endif //# AIPS_NO_TEMPLATE_SRC
00270 #endif