1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkBinCellDataFilter.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 * @class vtkBinCellDataFilter
17 * @brief bin source cell data into input cells.
18 *
19 * vtkBinCellDataFilter takes a source mesh containing scalar cell data, an
20 * input mesh and a set of bin values and bins the source mesh's scalar cell
21 * data into the cells of the input mesh. The resulting output mesh is identical
22 * to the input mesh, with an additional cell data field, with tuple size equal
23 * to the number of bins + 1, that represents a histogram of the cell data
24 * values for all of the source cells whose centroid lie within the input cell.
25 *
26 * This filter is useful for analyzing the efficacy of an input mesh's ability
27 * to represent the cell data of the source mesh.
28 */
29
30 #ifndef vtkBinCellDataFilter_h
31 #define vtkBinCellDataFilter_h
32
33 #include "vtkFiltersCoreModule.h" // For export macro
34 #include "vtkDataSetAlgorithm.h"
35 #include "vtkDataSetAttributes.h" // needed for vtkDataSetAttributes::FieldList
36
37 #include "vtkContourValues.h" // Needed for inline methods
38
39 class vtkAbstractCellLocator;
40
41 class VTKFILTERSCORE_EXPORT vtkBinCellDataFilter : public vtkDataSetAlgorithm
42 {
43 public:
44 typedef vtkContourValues vtkBinValues;
45
46 /**
47 * Construct object with initial range (VTK_DOUBLE_MIN, VTK_DOUBLE_MAX) and
48 * a single bin.
49 */
50 static vtkBinCellDataFilter *New();
51
52 //@{
53 /**
54 * Standard methods for type and printing.
55 */
56 vtkTypeMacro(vtkBinCellDataFilter,vtkDataSetAlgorithm);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58 //@}
59
60 //@{
61 /**
62 * Methods to set / get bin values.
63 */
64 void SetValue(int i, double value);
65 double GetValue(int i);
66 double *GetValues();
67 void GetValues(double *binValues);
68 void SetNumberOfBins(int numBins);
69 int GetNumberOfBins();
70 void GenerateValues(int numBins, double range[2]);
71 void GenerateValues(int numBins, double rangeStart, double rangeEnd);
72 //@}
73
74 //@{
75 /**
76 * Specify the data set whose cells will be counted.
77 * The Input gives the geometry (the points and cells) for the output,
78 * while the Source is used to determine how many source cells lie within
79 * each input cell.
80 */
81 void SetSourceData(vtkDataObject *source);
82 vtkDataObject *GetSource();
83 //@}
84
85 /**
86 * Specify the data set whose cells will be counted.
87 * The Input gives the geometry (the points and cells) for the output,
88 * while the Source is used to determine how many source cells lie within
89 * each input cell.
90 */
91 void SetSourceConnection(vtkAlgorithmOutput* algOutput);
92
93 //@{
94 /**
95 * This flag is used only when a piece is requested to update. By default
96 * the flag is off. Because no spatial correspondence between input pieces
97 * and source pieces is known, all of the source has to be requested no
98 * matter what piece of the output is requested. When there is a spatial
99 * correspondence, the user/application can set this flag. This hint allows
100 * the breakup of the probe operation to be much more efficient. When piece
101 * m of n is requested for update by the user, then only n of m needs to
102 * be requested of the source.
103 */
104 vtkSetMacro(SpatialMatch, vtkTypeBool);
105 vtkGetMacro(SpatialMatch, vtkTypeBool);
106 vtkBooleanMacro(SpatialMatch, vtkTypeBool);
107 //@}
108
109 //@{
110 /**
111 * Set whether to store the number of nonzero bins for each cell.
112 * On by default.
113 */
114 vtkSetMacro(StoreNumberOfNonzeroBins, bool);
115 vtkBooleanMacro(StoreNumberOfNonzeroBins, bool);
116 vtkGetMacro(StoreNumberOfNonzeroBins, bool);
117 //@}
118
119 //@{
120 /**
121 * Returns the name of the id array added to the output that holds the number
122 * of nonzero bins per cell.
123 * Set to "NumberOfNonzeroBins" by default.
124 */
125 vtkSetStringMacro(NumberOfNonzeroBinsArrayName)
126 vtkGetStringMacro(NumberOfNonzeroBinsArrayName)
127 //@}
128
129 //@{
130 /**
131 * Set the tolerance used to compute whether a cell centroid in the
132 * source is in a cell of the input. This value is only used
133 * if ComputeTolerance is off.
134 */
135 vtkSetMacro(Tolerance, double);
136 vtkGetMacro(Tolerance, double);
137 //@}
138
139 //@{
140 /**
141 * Set whether to use the Tolerance field or precompute the tolerance.
142 * When on, the tolerance will be computed and the field value is ignored.
143 * Off by default.
144 */
145 vtkSetMacro(ComputeTolerance, bool);
146 vtkBooleanMacro(ComputeTolerance, bool);
147 vtkGetMacro(ComputeTolerance, bool);
148 //@}
149
150 //@{
151 /**
152 * Set/get which component of the scalar array to bin; defaults to 0.
153 */
154 vtkSetMacro(ArrayComponent,int);
155 vtkGetMacro(ArrayComponent,int);
156 //@}
157
158 enum CellOverlapCriterion
159 {
160 CELL_CENTROID=0,
161 CELL_POINTS=1,
162 };
163
164 //@{
165 /**
166 * Set whether cell overlap is determined by source cell centroid or by source
167 * cell points.
168 * Centroid by default.
169 */
170 vtkSetClampMacro(CellOverlapMethod,int,CELL_CENTROID,CELL_POINTS);
171 vtkGetMacro(CellOverlapMethod, int);
172 //@}
173
174 //@{
175 /**
176 * Set/Get a spatial locator for speeding the search process. By
177 * default an instance of vtkStaticCellLocator is used.
178 */
179 virtual void SetCellLocator(vtkAbstractCellLocator *cellLocator);
180 vtkGetObjectMacro(CellLocator,vtkAbstractCellLocator);
181 //@}
182
183 protected:
184 vtkBinCellDataFilter();
185 ~vtkBinCellDataFilter() override;
186
187 vtkTypeBool SpatialMatch;
188
189 bool StoreNumberOfNonzeroBins;
190 double Tolerance;
191 bool ComputeTolerance;
192 int ArrayComponent;
193 int CellOverlapMethod;
194
195 vtkBinValues *BinValues;
196 vtkAbstractCellLocator *CellLocator;
197 virtual void CreateDefaultLocator();
198
199 int RequestData(vtkInformation *, vtkInformationVector **,
200 vtkInformationVector *) override;
201 int RequestInformation(vtkInformation *, vtkInformationVector **,
202 vtkInformationVector *) override;
203 int RequestUpdateExtent(vtkInformation *, vtkInformationVector **,
204 vtkInformationVector *) override;
205
206 char* NumberOfNonzeroBinsArrayName;
207
208 private:
209 vtkBinCellDataFilter(const vtkBinCellDataFilter&) = delete;
210 void operator=(const vtkBinCellDataFilter&) = delete;
211 };
212
213 /**
214 * Set a particular bin value at bin number i. The index i ranges
215 * between 0<=i<NumberOfBins.
216 */
SetValue(int i,double value)217 inline void vtkBinCellDataFilter::SetValue(int i, double value)
218 {this->BinValues->SetValue(i,value);}
219
220 /**
221 * Get the ith bin value.
222 */
GetValue(int i)223 inline double vtkBinCellDataFilter::GetValue(int i)
224 {return this->BinValues->GetValue(i);}
225
226 /**
227 * Get a pointer to an array of bin values. There will be
228 * GetNumberOfBins() values in the list.
229 */
GetValues()230 inline double *vtkBinCellDataFilter::GetValues()
231 {return this->BinValues->GetValues();}
232
233 /**
234 * Fill a supplied list with bin values. There will be
235 * GetNumberOfBins() values in the list. Make sure you allocate
236 * enough memory to hold the list.
237 */
GetValues(double * binValues)238 inline void vtkBinCellDataFilter::GetValues(double *binValues)
239 {this->BinValues->GetValues(binValues);}
240
241 /**
242 * Set the number of bins to place into the list. You only really
243 * need to use this method to reduce list size. The method SetValue()
244 * will automatically increase list size as needed.
245 */
SetNumberOfBins(int number)246 inline void vtkBinCellDataFilter::SetNumberOfBins(int number)
247 {this->BinValues->SetNumberOfContours(number);}
248
249 /**
250 * Get the number of bins in the list of bin values, not counting the overflow
251 * bin.
252 */
GetNumberOfBins()253 inline int vtkBinCellDataFilter::GetNumberOfBins()
254 {return this->BinValues->GetNumberOfContours();}
255
256 /**
257 * Generate numBins equally spaced bin values between specified
258 * range. Bin values will include min/max range values.
259 */
GenerateValues(int numBins,double range[2])260 inline void vtkBinCellDataFilter::GenerateValues(int numBins, double range[2])
261 {this->BinValues->GenerateValues(numBins, range);}
262
263 /**
264 * Generate numBins equally spaced bin values between specified
265 * range. Bin values will include min/max range values.
266 */
GenerateValues(int numBins,double rangeStart,double rangeEnd)267 inline void vtkBinCellDataFilter::GenerateValues(int numBins, double
268 rangeStart, double rangeEnd)
269 {this->BinValues->GenerateValues(numBins, rangeStart, rangeEnd);}
270
271 #endif
272