1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkPairwiseExtractHistogram2D.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 2009 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 vtkPairwiseExtractHistogram2D - compute a 2D histogram between
21 //  all adjacent columns of an input vtkTable.
22 //
23 // .SECTION Description
24 //  This class computes a 2D histogram between all adjacent pairs of columns
25 //  of an input vtkTable. Internally it creates multiple vtkExtractHistogram2D
26 //  instances (one for each pair of adjacent table columns).  It also
27 //  manages updating histogram computations intelligently, only recomputing
28 //  those histograms for whom a relevant property has been altered.
29 //
30 //  Note that there are two different outputs from this filter.  One is a
31 //  table for which each column contains a flattened 2D histogram array.
32 //  The other is a vtkMultiBlockDataSet for which each block is a
33 //  vtkImageData representation of the 2D histogram.
34 //
35 // .SECTION See Also
36 //  vtkExtractHistogram2D vtkPPairwiseExtractHistogram2D
37 //
38 // .SECTION Thanks
39 //  Developed by David Feng and Philippe Pebay at Sandia National Laboratories
40 //------------------------------------------------------------------------------
41 #ifndef vtkPairwiseExtractHistogram2D_h
42 #define vtkPairwiseExtractHistogram2D_h
43 
44 #include "vtkFiltersImagingModule.h" // For export macro
45 #include "vtkStatisticsAlgorithm.h"
46 #include "vtkSmartPointer.h"  //needed for smart pointer ivars
47 class vtkCollection;
48 class vtkExtractHistogram2D;
49 class vtkImageData;
50 class vtkIdTypeArray;
51 class vtkMultiBlockDataSet;
52 
53 class VTKFILTERSIMAGING_EXPORT vtkPairwiseExtractHistogram2D : public vtkStatisticsAlgorithm
54 {
55 public:
56   static vtkPairwiseExtractHistogram2D* New();
57   vtkTypeMacro(vtkPairwiseExtractHistogram2D, vtkStatisticsAlgorithm);
58   void PrintSelf(ostream& os, vtkIndent indent);
59 
60   // Description:
61   // Set/get the bin dimensions of the histograms to compute
62   vtkSetVector2Macro(NumberOfBins,int);
63   vtkGetVector2Macro(NumberOfBins,int);
64 
65   // Description:
66   // Strange method for setting an index to be used for setting custom
67   // column range. This was (probably) necessary to get this class
68   // to interact with the ParaView client/server message passing interface.
69   vtkSetMacro(CustomColumnRangeIndex,int);
70   void SetCustomColumnRangeByIndex(double,double);
71 
72   // Description:
73   // More standard way to set the custom range for a particular column.
74   // This makes sure that only the affected histograms know that they
75   // need to be updated.
76   void SetCustomColumnRange(int col, double range[2]);
77   void SetCustomColumnRange(int col, double rmin, double rmax);
78 
79   // Description:
80   // Set the scalar type for each of the computed histograms.
81   vtkSetMacro(ScalarType,int);
SetScalarTypeToUnsignedInt()82   void SetScalarTypeToUnsignedInt()
83     {this->SetScalarType(VTK_UNSIGNED_INT);};
SetScalarTypeToUnsignedLong()84   void SetScalarTypeToUnsignedLong()
85     {this->SetScalarType(VTK_UNSIGNED_LONG);};
SetScalarTypeToUnsignedShort()86   void SetScalarTypeToUnsignedShort()
87     {this->SetScalarType(VTK_UNSIGNED_SHORT);};
SetScalarTypeToUnsignedChar()88   void SetScalarTypeToUnsignedChar()
89     {this->SetScalarType(VTK_UNSIGNED_CHAR);};
90   vtkGetMacro(ScalarType,int);
91 
92   // Description:
93   // Get the maximum bin count for a single histogram
94   double GetMaximumBinCount(int idx);
95 
96   // Description:
97   // Get the maximum bin count over all histograms
98   double GetMaximumBinCount();
99 
100   // Description:
101   // Compute the range of the bin located at position (binX,binY) in
102   // the 2D histogram at idx.
103   int GetBinRange(int idx, vtkIdType binX, vtkIdType binY, double range[4]);
104 
105   // Description:
106   // Get the range of the of the bin located at 1D position index bin
107   // in the 2D histogram array at idx.
108   int GetBinRange(int idx, vtkIdType bin, double range[4]);
109 
110   // Description:
111   // Get the width of all of the bins. Also stored in the spacing
112   // ivar of the histogram image output at idx.
113   void GetBinWidth(int idx, double bw[2]);
114 
115   // Description:
116   // Get the histogram extents currently in use, either computed
117   // or set by the user for the idx'th histogram.
118   double* GetHistogramExtents(int idx);
119 
120   // Description:
121   // Get the vtkImageData output of the idx'th histogram filter
122   vtkImageData* GetOutputHistogramImage(int idx);
123 
124   // Description:
125   // Get a pointer to the idx'th histogram filter.
126   vtkExtractHistogram2D* GetHistogramFilter(int idx);
127 
128 //BTX
129   enum OutputIndices
130   {
131     HISTOGRAM_IMAGE=3
132   };
133 //ETX
134 
135   // Description:
136   // Given a collection of models, calculate aggregate model.  Not used
Aggregate(vtkDataObjectCollection *,vtkMultiBlockDataSet *)137   virtual void Aggregate( vtkDataObjectCollection*, vtkMultiBlockDataSet* ) {}
138 
139 protected:
140   vtkPairwiseExtractHistogram2D();
141   ~vtkPairwiseExtractHistogram2D();
142 
143   int NumberOfBins[2];
144   int ScalarType;
145   int CustomColumnRangeIndex;
146 
147   //BTX
148   vtkSmartPointer<vtkIdTypeArray> OutputOutlierIds;
149   vtkSmartPointer<vtkCollection> HistogramFilters;
150   class Internals;
151   Internals* Implementation;
152   //ETX
153 
154   // Description:
155   // Execute the calculations required by the Learn option.
156   // Does the actual histogram computation works.
157   virtual void Learn( vtkTable* inData,
158                       vtkTable* inParameters,
159                       vtkMultiBlockDataSet* outMeta );
160 
161   // Description:
162   // Execute the calculations required by the Derive option. Not used.
Derive(vtkMultiBlockDataSet *)163   virtual void Derive( vtkMultiBlockDataSet* ) {}
164 
165   // Description:
166   // Execute the assess option. Not implemented.
Assess(vtkTable *,vtkMultiBlockDataSet *,vtkTable *)167   virtual void Assess( vtkTable*,
168                        vtkMultiBlockDataSet*,
169                        vtkTable* ) {}
170 
171   // Description:
172   // Execute the calculations required by the Test option.
Test(vtkTable *,vtkMultiBlockDataSet *,vtkTable *)173   virtual void Test( vtkTable*,
174                      vtkMultiBlockDataSet*,
175                      vtkTable* ) { return; };
176 
177   // Description:
178   // Provide the appropriate assessment functor.
SelectAssessFunctor(vtkTable * vtkNotUsed (outData),vtkDataObject * vtkNotUsed (inMeta),vtkStringArray * vtkNotUsed (rowNames),AssessFunctor * & vtkNotUsed (dfunc))179   virtual void SelectAssessFunctor( vtkTable* vtkNotUsed(outData),
180                                     vtkDataObject* vtkNotUsed(inMeta),
181                                     vtkStringArray* vtkNotUsed(rowNames),
182                                     AssessFunctor*& vtkNotUsed(dfunc) ) {}
183 
184   // Description:
185   // Generate a new histogram filter
186   virtual vtkExtractHistogram2D* NewHistogramFilter();
187 
188   virtual int FillOutputPortInformation( int port, vtkInformation* info );
189 
190   vtkTimeStamp BuildTime;
191 private:
192   vtkPairwiseExtractHistogram2D(const vtkPairwiseExtractHistogram2D&); // Not implemented
193   void operator=(const vtkPairwiseExtractHistogram2D&);   // Not implemented
194 };
195 
196 #endif
197