debian/tmp/usr/include/KWWidgets/vtkKWHistogram.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    $RCSfile: vtkKWHistogram.h,v $
00004 
00005   Copyright (c) Kitware, Inc.
00006   All rights reserved.
00007   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 // .NAME vtkKWHistogram - an histogram
00015 // .SECTION Description
00016 
00017 #ifndef __vtkKWHistogram_h
00018 #define __vtkKWHistogram_h
00019 
00020 #include "vtkObject.h"
00021 #include "vtkKWWidgets.h" // Needed for export symbols directives
00022 
00023 class vtkColorTransferFunction;
00024 class vtkDataArray;
00025 class vtkImageData;
00026 class vtkDoubleArray;
00027 class vtkIntArray;
00028 
00029 class KWWidgets_EXPORT vtkKWHistogram : public vtkObject
00030 {
00031 public:
00032   static vtkKWHistogram* New();
00033   vtkTypeRevisionMacro(vtkKWHistogram,vtkObject);
00034   void PrintSelf(ostream& os, vtkIndent indent);
00035 
00036   // Description:
00037   // Get the histogram range.
00038   // Note that Range[1] is exclusive.
00039   // The Range is updated automatically by the BuildHistogram method to
00040   // match the range of the vtkDataArray passed as parameter.
00041   vtkGetVector2Macro(Range, double);
00042 
00043   // Description:
00044   // Direct access to the bins
00045   vtkGetObjectMacro(Bins, vtkDoubleArray);
00046 
00047   // Description:
00048   // Get the number of bins
00049   virtual vtkIdType GetNumberOfBins();
00050 
00051   // Description:
00052   // Set/Get the maximum number of bins that should be used when
00053   // creating the histogram
00054   vtkSetMacro(MaximumNumberOfBins, vtkIdType);
00055   vtkGetMacro(MaximumNumberOfBins, vtkIdType);
00056 
00057   // Description:
00058   // Get min, max, total occurence
00059   virtual double GetMinimumOccurence();
00060   virtual double GetMaximumOccurence();
00061   virtual double GetTotalOccurence();
00062 
00063   // Description:
00064   // Get the occurence for the bin holding a given value.
00065   virtual double GetOccurenceAtValue(double value);
00066 
00067   // Description:
00068   // Get the value at a given accumulated occurence in the histogram.
00069   // 'exclude_value' is not NULL, it is a pointer to a value which bin
00070   // will be ignored from the computation.
00071   virtual double GetValueAtAccumulatedOccurence(
00072     double acc, double *exclude_value = 0);
00073 
00074   // Description:
00075   // Build/update the histogram from scalars (given a component)
00076   // The Range and number of bins are modified automatically
00077   virtual void BuildHistogram(vtkDataArray *scalars, int component);
00078 
00079   // Description:
00080   // Set the histogram range.
00081   // Note that Range[1] is exclusive.
00082   // The Range is updated automatically by the BuildHistogram method to
00083   // match the range of the vtkDataArray passed as parameter.
00084   // Nevertheless, you might want to set the Range manually, either after
00085   // calling the BuildHistogram method to restrict the histogram to a subset, 
00086   // or before calling the AccumulateHistogram method, which accumulates
00087   // values and update the histogram.
00088   // Use the EstimateHistogramRange method to compute the range that
00089   // is needed to store a set of scalars.
00090   vtkSetVector2Macro(Range, double);
00091 
00092   // Description:
00093   // Estimate the range that will be used by BuildHistogram from scalars
00094   // (given a component)
00095   virtual void EstimateHistogramRange(
00096     vtkDataArray *scalars, int component, double range[2]);
00097 
00098   // Description:
00099   // Accumulate the histogram from scalars (given a component)
00100   // The Range is *not* modified automatically, you have to set it 
00101   // appropriately before calling this method using either:
00102   //   - a call to SetRange followed by a call to EmptyHistogram
00103   //     (use the EstimateHistogramRange method to compute the range that
00104   //      is needed to store a set of scalars)
00105   //   - or a call to BuildHistogram first, with the appropriate 'scalars'. 
00106   // This method can be called multiple times with a different 'scalars':
00107   //   - the 'scalars' range has to lie within the Range ivar. 
00108   //   - the bins are not reset to 0, the values of 'scalars' are used to
00109   //     update the histogram with more data (accumulate)
00110   //     => EmptyHistogram will reset the histogram (remove all bins,
00111   //        forcing all bins to be set to 0 the next time the number
00112   //        of bins is changed).
00113   virtual void AccumulateHistogram(vtkDataArray *scalars, int component);
00114 
00115   // Description:
00116   // Empty this histogram (0 bins). The next time the number of bins is
00117   // changed (BuildHistogram or AccumulateHistogram), each bin is set to 0.
00118   virtual void EmptyHistogram();
00119 
00120   // Description:
00121   // Compute the image of the histogram in log space (default).
00122   virtual void SetLogMode(int);
00123   vtkBooleanMacro(LogMode, int);
00124   vtkGetMacro(LogMode, int);
00125 
00126 protected:
00127   vtkKWHistogram();
00128   ~vtkKWHistogram();
00129 
00130   double Range[2];
00131 
00132   vtkDoubleArray *Bins;
00133 
00134   vtkImageData *Image;
00135   vtkIntArray  *ImageCoordinates;
00136 
00137   unsigned long LastImageBuildTime;
00138   unsigned long LastTransferFunctionTime;
00139   int           LogMode;
00140   vtkIdType     MaximumNumberOfBins;
00141 
00142   virtual void ComputeStatistics();
00143   unsigned long LastStatisticsBuildTime;
00144 
00145   double MinimumOccurence;
00146   double MaximumOccurence;
00147   double TotalOccurence;
00148 
00149   // Description:
00150   // Update the histogram from scalars (given a component)
00151   // Either reset the range (BuildHistogram) or not (AccumulateHistogram)
00152   virtual void UpdateHistogram(
00153     vtkDataArray *scalars, int component, int reset_range);
00154 
00155   // Description:
00156   // Estimate the range that will be used by BuildHistogram from scalars
00157   // (given a component), and the number of bins
00158   virtual void EstimateHistogramRangeAndNumberOfBins(
00159     vtkDataArray *scalars, int component, 
00160     double range[2], vtkIdType *nb_of_bins);
00161 
00162 public:
00163   // Description:
00164   // Get an image of the histogram. The image parameters are described 
00165   // through an instance of the above ImageDescriptor. The histogram
00166   // can be drawn for a given data range.
00167   // If DrawBackground is false, the background pixels are set to be 
00168   // transparent and the resulting image is created in RGBA space instead
00169   // of RGB.
00170   //BTX
00171   // @cond nested_class
00172   class KWWidgets_EXPORT ImageDescriptor
00173   {
00174   public:
00175     ImageDescriptor();
00176 
00177     int  IsValid() const;
00178     int  IsEqualTo(const ImageDescriptor *desc);
00179     void Copy(const ImageDescriptor *desc);
00180 
00181     int          DrawForeground;
00182     int          DrawBackground;
00183     int          DrawGrid;
00184     int          GridSize;
00185 
00186     enum
00187     {
00188       StyleBars = 0,
00189       StyleDots
00190     };
00191     int          Style;
00192 
00193     double       Range[2];
00194     void SetRange(double range0, double range1);
00195     void SetRange(double range[2]);
00196 
00197     unsigned int Width;
00198     unsigned int Height;
00199     void SetDimensions(unsigned int width, unsigned int height);
00200 
00201     double       Color[3];
00202     void SetColor(double color[3]);
00203 
00204     double       BackgroundColor[3];
00205     void SetBackgroundColor(double color[3]);
00206 
00207     double       OutOfRangeColor[3];
00208     void SetOutOfRangeColor(double color[3]);
00209 
00210     double       GridColor[3];
00211     void SetGridColor(double color[3]);
00212 
00213     vtkColorTransferFunction *ColorTransferFunction;
00214 
00215     // When the histogram is drawn, a resampled version of the histogram
00216     // is computed where each column-pixel along the Width is a bin.
00217     // The histogram itself is scaled vertically so that the bin with
00218     // the maximum occurence occupies the full Height.
00219     // Each time it occurs, the LastMaximumOccurence ivar is modified
00220     // to store this maximum occurence.
00221     // If the DefaultMaximumOccurence is set to something other than 0.0
00222     // it will override the maximum occurence found so far and be used
00223     // to scale the histogram vertically (of course, it has to be >=
00224     // to the current maximum occurence).
00225     // Using DefaultMaximumOccurence is right now the way to have two
00226     // histograms being scaled the same way, under some constraints.
00227 
00228     double       DefaultMaximumOccurence;
00229     double       LastMaximumOccurence;
00230   };
00231   // @endcond
00232   virtual int IsImageUpToDate(const ImageDescriptor *desc = 0);
00233   virtual vtkImageData* GetImage(ImageDescriptor *desc);
00234   virtual vtkIntArray* GetImageCoordinates(ImageDescriptor *desc);
00235   //ETX
00236   
00237 protected:
00238   //BTX
00239   vtkKWHistogram::ImageDescriptor *LastImageDescriptor;
00240   //ETX
00241 
00242   virtual int RefreshImage(ImageDescriptor *desc);
00243 
00244 private:
00245   vtkKWHistogram(const vtkKWHistogram&); // Not implemented
00246   void operator=(const vtkKWHistogram&); // Not implemented
00247 };
00248 
00249 #endif
00250