KWWidgets
vtkKWHistogram.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWHistogram.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWHistogram - an histogram
15 // .SECTION Description
16 
17 #ifndef __vtkKWHistogram_h
18 #define __vtkKWHistogram_h
19 
20 #include "vtkObject.h"
21 #include "vtkKWWidgets.h" // Needed for export symbols directives
22 
23 class vtkColorTransferFunction;
24 class vtkDataArray;
25 class vtkImageData;
26 class vtkDoubleArray;
27 class vtkIntArray;
28 
29 class KWWidgets_EXPORT vtkKWHistogram : public vtkObject
30 {
31 public:
32  static vtkKWHistogram* New();
33  vtkTypeRevisionMacro(vtkKWHistogram,vtkObject);
34  void PrintSelf(ostream& os, vtkIndent indent);
35 
36  // Description:
37  // Get the histogram range.
38  // Note that Range[1] is exclusive.
39  // The Range is updated automatically by the BuildHistogram method to
40  // match the range of the vtkDataArray passed as parameter.
41  vtkGetVector2Macro(Range, double);
42 
43  // Description:
44  // Direct access to the bins
45  vtkGetObjectMacro(Bins, vtkDoubleArray);
46 
47  // Description:
48  // Get the number of bins
49  virtual vtkIdType GetNumberOfBins();
50 
51  // Description:
52  // Set/Get the maximum number of bins that should be used when
53  // creating the histogram
54  vtkSetMacro(MaximumNumberOfBins, vtkIdType);
55  vtkGetMacro(MaximumNumberOfBins, vtkIdType);
56 
57  // Description:
58  // Get min, max, total occurence
59  virtual double GetMinimumOccurence();
60  virtual double GetMaximumOccurence();
61  virtual double GetTotalOccurence();
62 
63  // Description:
64  // Get the occurence for the bin holding a given value.
65  virtual double GetOccurenceAtValue(double value);
66 
67  // Description:
68  // Get the value at a given accumulated occurence in the histogram.
69  // 'exclude_value' is not NULL, it is a pointer to a value which bin
70  // will be ignored from the computation.
71  virtual double GetValueAtAccumulatedOccurence(
72  double acc, double *exclude_value = 0);
73 
74  // Description:
75  // Build/update the histogram from scalars (given a component)
76  // The Range and number of bins are modified automatically
77  virtual void BuildHistogram(vtkDataArray *scalars, int component);
78 
79  // Description:
80  // Set the histogram range.
81  // Note that Range[1] is exclusive.
82  // The Range is updated automatically by the BuildHistogram method to
83  // match the range of the vtkDataArray passed as parameter.
84  // Nevertheless, you might want to set the Range manually, either after
85  // calling the BuildHistogram method to restrict the histogram to a subset,
86  // or before calling the AccumulateHistogram method, which accumulates
87  // values and update the histogram.
88  // Use the EstimateHistogramRange method to compute the range that
89  // is needed to store a set of scalars.
90  vtkSetVector2Macro(Range, double);
91 
92  // Description:
93  // Estimate the range that will be used by BuildHistogram from scalars
94  // (given a component)
95  virtual void EstimateHistogramRange(
96  vtkDataArray *scalars, int component, double range[2]);
97 
98  // Description:
99  // Accumulate the histogram from scalars (given a component)
100  // The Range is *not* modified automatically, you have to set it
101  // appropriately before calling this method using either:
102  // - a call to SetRange followed by a call to EmptyHistogram
103  // (use the EstimateHistogramRange method to compute the range that
104  // is needed to store a set of scalars)
105  // - or a call to BuildHistogram first, with the appropriate 'scalars'.
106  // This method can be called multiple times with a different 'scalars':
107  // - the 'scalars' range has to lie within the Range ivar.
108  // - the bins are not reset to 0, the values of 'scalars' are used to
109  // update the histogram with more data (accumulate)
110  // => EmptyHistogram will reset the histogram (remove all bins,
111  // forcing all bins to be set to 0 the next time the number
112  // of bins is changed).
113  virtual void AccumulateHistogram(vtkDataArray *scalars, int component);
114 
115  // Description:
116  // Empty this histogram (0 bins). The next time the number of bins is
117  // changed (BuildHistogram or AccumulateHistogram), each bin is set to 0.
118  virtual void EmptyHistogram();
119 
120  // Description:
121  // Compute the image of the histogram in log space (default).
122  virtual void SetLogMode(int);
123  vtkBooleanMacro(LogMode, int);
124  vtkGetMacro(LogMode, int);
125 
126 protected:
127  vtkKWHistogram();
128  ~vtkKWHistogram();
129 
130  double Range[2];
131 
132  vtkDoubleArray *Bins;
133 
134  vtkImageData *Image;
135  vtkIntArray *ImageCoordinates;
136 
137  unsigned long LastImageBuildTime;
138  unsigned long LastTransferFunctionTime;
139  int LogMode;
140  vtkIdType MaximumNumberOfBins;
141 
142  virtual void ComputeStatistics();
143  unsigned long LastStatisticsBuildTime;
144 
145  double MinimumOccurence;
146  double MaximumOccurence;
147  double TotalOccurence;
148 
149  // Description:
150  // Update the histogram from scalars (given a component)
151  // Either reset the range (BuildHistogram) or not (AccumulateHistogram)
152  virtual void UpdateHistogram(
153  vtkDataArray *scalars, int component, int reset_range);
154 
155  // Description:
156  // Estimate the range that will be used by BuildHistogram from scalars
157  // (given a component), and the number of bins
158  virtual void EstimateHistogramRangeAndNumberOfBins(
159  vtkDataArray *scalars, int component,
160  double range[2], vtkIdType *nb_of_bins);
161 
162 public:
163  // Description:
164  // Get an image of the histogram. The image parameters are described
165  // through an instance of the above ImageDescriptor. The histogram
166  // can be drawn for a given data range.
167  // If DrawBackground is false, the background pixels are set to be
168  // transparent and the resulting image is created in RGBA space instead
169  // of RGB.
170  //BTX
171  // @cond nested_class
172  class KWWidgets_EXPORT ImageDescriptor
173  {
174  public:
175  ImageDescriptor();
176 
177  int IsValid() const;
178  int IsEqualTo(const ImageDescriptor *desc);
179  void Copy(const ImageDescriptor *desc);
180 
181  int DrawForeground;
182  int DrawBackground;
183  int DrawGrid;
184  int GridSize;
185 
186  enum
187  {
188  StyleBars = 0,
189  StyleDots
190  };
191  int Style;
192 
193  double Range[2];
194  void SetRange(double range0, double range1);
195  void SetRange(double range[2]);
196 
197  unsigned int Width;
198  unsigned int Height;
199  void SetDimensions(unsigned int width, unsigned int height);
200 
201  double Color[3];
202  void SetColor(double color[3]);
203 
204  double BackgroundColor[3];
205  void SetBackgroundColor(double color[3]);
206 
207  double OutOfRangeColor[3];
208  void SetOutOfRangeColor(double color[3]);
209 
210  double GridColor[3];
211  void SetGridColor(double color[3]);
212 
213  vtkColorTransferFunction *ColorTransferFunction;
214 
215  // When the histogram is drawn, a resampled version of the histogram
216  // is computed where each column-pixel along the Width is a bin.
217  // The histogram itself is scaled vertically so that the bin with
218  // the maximum occurence occupies the full Height.
219  // Each time it occurs, the LastMaximumOccurence ivar is modified
220  // to store this maximum occurence.
221  // If the DefaultMaximumOccurence is set to something other than 0.0
222  // it will override the maximum occurence found so far and be used
223  // to scale the histogram vertically (of course, it has to be >=
224  // to the current maximum occurence).
225  // Using DefaultMaximumOccurence is right now the way to have two
226  // histograms being scaled the same way, under some constraints.
227 
228  double DefaultMaximumOccurence;
229  double LastMaximumOccurence;
230  };
231  // @endcond
232  virtual int IsImageUpToDate(const ImageDescriptor *desc = 0);
233  virtual vtkImageData* GetImage(ImageDescriptor *desc);
234  virtual vtkIntArray* GetImageCoordinates(ImageDescriptor *desc);
235  //ETX
236 
237 protected:
238  //BTX
239  vtkKWHistogram::ImageDescriptor *LastImageDescriptor;
240  //ETX
241 
242  virtual int RefreshImage(ImageDescriptor *desc);
243 
244 private:
245  vtkKWHistogram(const vtkKWHistogram&); // Not implemented
246  void operator=(const vtkKWHistogram&); // Not implemented
247 };
248 
249 #endif
250