1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkExtractHistogram2D.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16   Copyright 2011 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 // .NAME vtkExtractHistogram2D - compute a 2D histogram between two columns
21 //  of an input vtkTable.
22 //
23 // .SECTION Description
24 //  This class computes a 2D histogram between two columns of an input
25 //  vtkTable. Just as with a 1D histogram, a 2D histogram breaks
26 //  up the input domain into bins, and each pair of values (row in
27 //  the table) fits into a single bin and increments a row counter
28 //  for that bin.
29 //
30 //  To use this class, set the input with a table and call AddColumnPair(nameX,nameY),
31 //  where nameX and nameY are the names of the two columns to be used.
32 //
33 //  In addition to the number of bins (in X and Y), the domain of
34 //  the histogram can be customized by toggling the UseCustomHistogramExtents
35 //  flag and setting the CustomHistogramExtents variable to the
36 //  desired value.
37 //
38 // .SECTION See Also
39 //  vtkPExtractHistogram2D
40 //
41 // .SECTION Thanks
42 //  Developed by David Feng and Philippe Pebay at Sandia National Laboratories
43 //------------------------------------------------------------------------------
44 #ifndef vtkExtractHistogram2D_h
45 #define vtkExtractHistogram2D_h
46 
47 #include "vtkFiltersImagingModule.h" // For export macro
48 #include "vtkStatisticsAlgorithm.h"
49 
50 class vtkImageData;
51 class vtkIdTypeArray;
52 class vtkMultiBlockDataSet;
53 
54 class VTKFILTERSIMAGING_EXPORT vtkExtractHistogram2D : public vtkStatisticsAlgorithm
55 {
56 public:
57   static vtkExtractHistogram2D* New();
58   vtkTypeMacro(vtkExtractHistogram2D, vtkStatisticsAlgorithm);
59   void PrintSelf(ostream& os, vtkIndent indent);
60 
61 //BTX
62   enum OutputIndices
63   {
64     HISTOGRAM_IMAGE=3
65   };
66 //ETX
67 
68   // Description:
69   // Set/get the number of bins to be used per dimension (x,y)
70   vtkSetVector2Macro(NumberOfBins,int);
71   vtkGetVector2Macro(NumberOfBins,int);
72 
73   // Description:
74   // Set/get the components of the arrays in the two input columns
75   // to be used during histogram computation.  Defaults to component 0.
76   vtkSetVector2Macro(ComponentsToProcess,int);
77   vtkGetVector2Macro(ComponentsToProcess,int);
78 
79   // Description:
80   // Set/get a custom domain for histogram computation.  UseCustomHistogramExtents
81   // must be called for these to actually be used.
82   vtkSetVector4Macro(CustomHistogramExtents,double);
83   vtkGetVector4Macro(CustomHistogramExtents,double);
84 
85   // Description:
86   // Use the extents in CustomHistogramExtents when computing the
87   // histogram, rather than the simple range of the input columns.
88   vtkSetMacro(UseCustomHistogramExtents,int);
89   vtkGetMacro(UseCustomHistogramExtents,int);
90   vtkBooleanMacro(UseCustomHistogramExtents,int);
91 
92   // Description:
93   // Control the scalar type of the output histogram.  If the input
94   // is relatively small, you can save space by using a smaller
95   // data type.  Defaults to unsigned integer.
96   vtkSetMacro(ScalarType,int);
SetScalarTypeToUnsignedInt()97   void SetScalarTypeToUnsignedInt()
98     {this->SetScalarType(VTK_UNSIGNED_INT);};
SetScalarTypeToUnsignedLong()99   void SetScalarTypeToUnsignedLong()
100     {this->SetScalarType(VTK_UNSIGNED_LONG);};
SetScalarTypeToUnsignedShort()101   void SetScalarTypeToUnsignedShort()
102     {this->SetScalarType(VTK_UNSIGNED_SHORT);};
SetScalarTypeToUnsignedChar()103   void SetScalarTypeToUnsignedChar()
104     {this->SetScalarType(VTK_UNSIGNED_CHAR);};
SetScalarTypeToFloat()105   void SetScalarTypeToFloat()
106     {this->SetScalarType(VTK_FLOAT);};
SetScalarTypeToDouble()107   void SetScalarTypeToDouble()
108     {this->SetScalarType(VTK_DOUBLE);};
109   vtkGetMacro(ScalarType,int);
110 
111   // Description:
112   // Access the count of the histogram bin containing the largest number
113   // of input rows.
114   vtkGetMacro(MaximumBinCount,double);
115 
116   // Description:
117   // Compute the range of the bin located at position (binX,binY) in
118   // the 2D histogram.
119   int GetBinRange(vtkIdType binX, vtkIdType binY, double range[4]);
120 
121   // Description:
122   // Get the range of the of the bin located at 1D position index bin
123   // in the 2D histogram array.
124   int GetBinRange(vtkIdType bin, double range[4]);
125 
126   // Description:
127   // Get the width of all of the bins. Also stored in the spacing
128   // ivar of the histogram image output.
129   void GetBinWidth(double bw[2]);
130 
131   // Description:
132   // Gets the data object at the histogram image output port and
133   // casts it to a vtkImageData.
134   vtkImageData* GetOutputHistogramImage();
135 
136   // Description:
137   // Get the histogram extents currently in use, either computed
138   // or set by the user.
139   double* GetHistogramExtents();
140 
141   vtkSetMacro(SwapColumns,int);
142   vtkGetMacro(SwapColumns,int);
143   vtkBooleanMacro(SwapColumns,int);
144 
145   // Description:
146   // Get/Set an optional mask that can ignore rows of the table
147   virtual void SetRowMask(vtkDataArray*);
148   vtkGetObjectMacro(RowMask,vtkDataArray);
149 
150   // Description:
151   // Given a collection of models, calculate aggregate model. Not used.
Aggregate(vtkDataObjectCollection *,vtkMultiBlockDataSet *)152   virtual void Aggregate( vtkDataObjectCollection*, vtkMultiBlockDataSet* ) {}
153 
154 protected:
155   vtkExtractHistogram2D();
156   ~vtkExtractHistogram2D();
157 
158   int SwapColumns;
159   int NumberOfBins[2];
160   double HistogramExtents[4];
161   double CustomHistogramExtents[4];
162   int UseCustomHistogramExtents;
163   int ComponentsToProcess[2];
164   double MaximumBinCount;
165   int ScalarType;
166   vtkDataArray* RowMask;
167 
168   virtual int ComputeBinExtents(vtkDataArray* col1, vtkDataArray* col2);
169 
170   // Description:
171   // Execute the calculations required by the Learn option.
172   // This is what actually does the histogram computation.
173   virtual void Learn( vtkTable* inData,
174                       vtkTable* inParameters,
175                       vtkMultiBlockDataSet* inMeta );
176 
177   // Description:
178   // Execute the calculations required by the Derive option. Not used.
Derive(vtkMultiBlockDataSet *)179   virtual void Derive( vtkMultiBlockDataSet* ) {}
180 
181   // Description:
182   // Execute the calculations required by the Test option.
Test(vtkTable *,vtkMultiBlockDataSet *,vtkTable *)183   virtual void Test( vtkTable*,
184                      vtkMultiBlockDataSet*,
185                      vtkTable* ) { return; };
186 
187   // Description:
188   // Execute the calculations required by the Assess option.
Assess(vtkTable *,vtkMultiBlockDataSet *,vtkTable *)189   virtual void Assess( vtkTable*,
190                        vtkMultiBlockDataSet*,
191                        vtkTable* ) { return; };
192 
193   // Description:
194   // Provide the appropriate assessment functor. Not used.
SelectAssessFunctor(vtkTable * vtkNotUsed (outData),vtkDataObject * vtkNotUsed (inMeta),vtkStringArray * vtkNotUsed (rowNames),AssessFunctor * & vtkNotUsed (dfunc))195   virtual void SelectAssessFunctor( vtkTable* vtkNotUsed(outData),
196                                     vtkDataObject* vtkNotUsed(inMeta),
197                                     vtkStringArray* vtkNotUsed(rowNames),
198                                     AssessFunctor*& vtkNotUsed(dfunc) ) {}
199 
200   virtual int FillOutputPortInformation( int port, vtkInformation* info );
201 
202   // Description:
203   // Makes sure that the image data output port has up-to-date spacing/origin/etc
204   virtual int RequestInformation (vtkInformation *request,
205                                   vtkInformationVector **inputVector,
206                                   vtkInformationVector *outputVector);
207 
208   // Description:
209   // Get points to the arrays that live in the two input columns
210   int GetInputArrays(vtkDataArray*& col1, vtkDataArray*& col2);
211 private:
212   vtkExtractHistogram2D(const vtkExtractHistogram2D&); // Not implemented
213   void operator=(const vtkExtractHistogram2D&);   // Not implemented
214 };
215 
216 #endif
217