casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageHistograms.h
Go to the documentation of this file.
00001 //# ImageHistograms.h: generate histograms from an image
00002 //# Copyright (C) 1996,1997,1999,2000,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: ImageHistograms.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGEHISTOGRAMS_H
00029 #define IMAGES_IMAGEHISTOGRAMS_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <lattices/Lattices/LatticeHistograms.h>
00035 #include <casa/Logging/LogIO.h>
00036 #include <casa/BasicSL/String.h>
00037 
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 template <class T> class ImageInterface;
00043 class IPosition;
00044 
00045 
00046 // <summary>
00047 // Displays histograms of regions from an image.
00048 // </summary>
00049 
00050 // <use visibility=export>
00051 
00052 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00057 //   <li> <linkto class=LatticeHistograms>LatticeHistograms</linkto>
00058 // </prerequisite>
00059 
00060 // <etymology>
00061 // This is a class designed to display histograms from images
00062 // </etymology>
00063 
00064 // <synopsis>
00065 // This class enable you to display and/or retrieve histograms evaluated over 
00066 // specified regions from an image.  The dimension of the region is arbitrary, but 
00067 // the size of each dimension is always the size of the corresponding image axis.
00068 // The histograms are displayed as a function of location of the axes not
00069 // used to evaluate the histograms over.  The axes which you evaluate the histograms 
00070 // over are called the cursor axes, the others are called the display axwes.
00071 //
00072 // For example, consider an image cube (call the axes xyz or [0,1,2]).  You could 
00073 // display histograms from xy planes (cursor axes [0,1]) as a function of z (display
00074 // axes [2]).   Or  you could retrieve histograms from the z axis (cursor axes [2])
00075 // for each [x,y] location (display axes [0,1]).
00076 //
00077 // The hard work is done by LatticeHistograms which this class (clumsily) inherits.
00078 // It generates a "storage lattice" into which it writes the histograms.
00079 // It is from this storage image that the plotting and retrieval
00080 // arrays are drawn.  The storage image is either in core or on disk
00081 // depending upon its size (if > 10% of memory given by .aipsrc system.resources.memory
00082 // then it goes into a disk-based PagedArray).  If on disk,  the
00083 // storage image is deleted when the <src>ImageHistograms</src> 
00084 // object destructs.    
00085 //
00086 // See LatticeHistograms for most of the useful public interface.  ImageHistograms
00087 // exists only so that it can write some world coordinate information to the plots
00088 // and logger.
00089 //
00090 // <note role=tip>
00091 // Note that for complex images, real and imaginary are treated independently.
00092 // They are binned and plotted separately.
00093 // </note>
00094 //
00095 // <note role=tip>
00096 // If you ignore return error statuses from the functions that set the
00097 // state of the class, the internal status of the class is set to bad.
00098 // This means it will just  keep on returning error conditions until you
00099 // explicitly recover the situation.   A message describing the last   
00100 // error condition can be recovered with function errorMessage.
00101 
00102 // </note>
00103 // </synopsis>
00104 
00105 // <example>
00106 // <srcBlock>
00108 //
00109 //      PagedImage<Float> inImage(inName);
00110 //   
00112 //      
00113 //      LogOrigin or("myClass", "myFunction(...)", WHERE);
00114 //      LogIO os(or);
00115 //      ImageHistograms<Float> histo(inImage, os);
00116 //      
00118 //
00119 //      Vector<Int> cursorAxes(2)
00120 //      cursorAxes(0) = 1;
00121 //      cursorAxes(1) = 2;
00122 //      if (!histo.setAxes(cursorAxes)) return 1;
00123 //
00125 //
00126 //      if (!histo.setList(True)) return 1;
00127 //      String device = "/xs";
00128 //      Vector<Int> nxy(2);
00129 //      nxy(0) = 3;
00130 //      nxy(1) = 3;
00131 //      if (!histo.setPlotting(device, nxy)) return 1;
00132 // 
00134 // 
00135 //      if (!histo.display ()) return 1;
00136 //
00138 //
00139 //      Array<Float> values, counts;
00140 //      if (!histo.getHistograms(values, counts)) return 1;
00141 //
00142 // </srcBlock>
00143 // In this example, a <src>PagedImage</src> is constructed.  We set the cursor axes 
00144 // to be the y and z axes so we make a histogram of each yz plane as a function 
00145 // of x location on the PGPLOT device "/xs" with 9 subplots per page.
00146 // After the plotting we also retrieve the histograms into an array.
00147 // </example>
00148 
00149 // <motivation>
00150 // The generation of histograms from an image is a basic and necessary capability.
00151 // </motivation>
00152 //
00153 // <todo asof="2000/04/04">
00154 //   <li> Make ascii listing of histograms as well as plots if desired
00155 // </todo>
00156 //
00157 
00158 
00159 template <class T> class ImageHistograms : public LatticeHistograms<T>
00160 {
00161 public:
00162 
00163 // Constructor takes the image and a <src>LogIO</src> object for logging.
00164 // You can also specify whether you want to see progress meters or not.
00165 // You can force the storage image to be disk based, otherwise
00166 // the decision for core or disk is taken for you.
00167    ImageHistograms(const ImageInterface<T>& image, 
00168                    LogIO& os,
00169                    Bool showProgress=True,
00170                    Bool forceDisk=False);
00171 
00172 // Constructor takes the image only. In the absence of a logger you get no messages.
00173 // This includes error messages and potential listing of statistics.
00174 // You can specify whether you want to see progress meters or not.
00175 // You can force the storage image to be disk based, otherwise
00176 // the decision for core or disk is taken for you.
00177    ImageHistograms(const ImageInterface<T>& image, 
00178                    Bool showProgress=True,
00179                    Bool forceDisk=False);
00180 
00181 // Copy constructor (copy semantics)
00182    ImageHistograms(const ImageHistograms<T> &other);
00183 
00184 // Destructor
00185   virtual ~ImageHistograms ();
00186 
00187 // Assignment operator (copy semantics)
00188    ImageHistograms<T> &operator=(const ImageHistograms<T> &other);
00189 
00190 // Set a new image.  A return value of <src>False</src> indicates the 
00191 // image had an invalid type or that the internal status of the class is bad.
00192    Bool setNewImage (const ImageInterface<T>& image);
00193 
00194 private:
00195    LogIO os_p;
00196    const ImageInterface<T>* pInImage_p;
00197 
00198    // Make a string with pixel and world coordinates of display axes
00199    virtual String writeCoordinates(const IPosition& histPos) const;
00200 
00201   //# Make members of parent class known.
00202 protected:
00203   using LatticeHistograms<T>::locHistInLattice;
00204   using LatticeHistograms<T>::error_p;
00205   using LatticeHistograms<T>::goodParameterStatus_p;
00206   using LatticeHistograms<T>::displayAxes_p;
00207   using LatticeHistograms<T>::cursorAxes_p;
00208 };
00209 
00210 
00211 
00212 } //# NAMESPACE CASA - END
00213 
00214 #ifndef CASACORE_NO_AUTO_TEMPLATES
00215 #include <imageanalysis/ImageAnalysis/ImageHistograms.tcc>
00216 #endif //# CASACORE_NO_AUTO_TEMPLATES
00217 #endif