1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkMarchingContourFilter.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   vtkMarchingContourFilter
17  * @brief   generate isosurfaces/isolines from scalar values
18  *
19  * vtkMarchingContourFilter is a filter that takes as input any dataset and
20  * generates on output isosurfaces and/or isolines. The exact form
21  * of the output depends upon the dimensionality of the input data.
22  * Data consisting of 3D cells will generate isosurfaces, data
23  * consisting of 2D cells will generate isolines, and data with 1D
24  * or 0D cells will generate isopoints. Combinations of output type
25  * are possible if the input dimension is mixed.
26  *
27  * This filter will identify special dataset types (e.g., structured
28  * points) and use the appropriate specialized filter to process the
29  * data. For examples, if the input dataset type is a volume, this
30  * filter will create an internal vtkMarchingCubes instance and use
31  * it. This gives much better performance.
32  *
33  * To use this filter you must specify one or more contour values.
34  * You can either use the method SetValue() to specify each contour
35  * value, or use GenerateValues() to generate a series of evenly
36  * spaced contours. It is also possible to accelerate the operation of
37  * this filter (at the cost of extra memory) by using a
38  * vtkScalarTree. A scalar tree is used to quickly locate cells that
39  * contain a contour surface. This is especially effective if multiple
40  * contours are being extracted. If you want to use a scalar tree,
41  * invoke the method UseScalarTreeOn().
42  *
43  * @warning
44  * For unstructured data or structured grids, normals and gradients
45  * are not computed.  This calculation will be implemented in the
46  * future. In the mean time, use vtkPolyDataNormals to compute the surface
47  * normals.
48  *
49  * @sa
50  * vtkMarchingCubes vtkSliceCubes vtkDividingCubes vtkMarchingSquares
51  * vtkImageMarchingCubes
52 */
53 
54 #ifndef vtkMarchingContourFilter_h
55 #define vtkMarchingContourFilter_h
56 
57 #include "vtkFiltersGeneralModule.h" // For export macro
58 #include "vtkPolyDataAlgorithm.h"
59 
60 #include "vtkContourValues.h" // Needed for direct access to ContourValues
61 
62 class vtkIncrementalPointLocator;
63 class vtkScalarTree;
64 
65 class VTKFILTERSGENERAL_EXPORT vtkMarchingContourFilter : public vtkPolyDataAlgorithm
66 {
67 public:
68   vtkTypeMacro(vtkMarchingContourFilter,vtkPolyDataAlgorithm);
69   void PrintSelf(ostream& os, vtkIndent indent) override;
70 
71   /**
72    * Construct object with initial range (0,1) and single contour value
73    * of 0.0.
74    */
75   static vtkMarchingContourFilter *New();
76 
77   //@{
78   /**
79    * Methods to set / get contour values.
80    */
81   void SetValue(int i, double value);
82   double GetValue(int i);
83   double *GetValues();
84   void GetValues(double *contourValues);
85   void SetNumberOfContours(int number);
86   int GetNumberOfContours();
87   void GenerateValues(int numContours, double range[2]);
88   void GenerateValues(int numContours, double rangeStart, double rangeEnd);
89   //@}
90 
91   /**
92    * Modified GetMTime Because we delegate to vtkContourValues
93    */
94   vtkMTimeType GetMTime() override;
95 
96   //@{
97   /**
98    * Set/Get the computation of normals. Normal computation is fairly
99    * expensive in both time and storage. If the output data will be
100    * processed by filters that modify topology or geometry, it may be
101    * wise to turn Normals and Gradients off.
102    */
103   vtkSetMacro(ComputeNormals,vtkTypeBool);
104   vtkGetMacro(ComputeNormals,vtkTypeBool);
105   vtkBooleanMacro(ComputeNormals,vtkTypeBool);
106   //@}
107 
108   //@{
109   /**
110    * Set/Get the computation of gradients. Gradient computation is
111    * fairly expensive in both time and storage. Note that if
112    * ComputeNormals is on, gradients will have to be calculated, but
113    * will not be stored in the output dataset.  If the output data
114    * will be processed by filters that modify topology or geometry, it
115    * may be wise to turn Normals and Gradients off.
116    */
117   vtkSetMacro(ComputeGradients,vtkTypeBool);
118   vtkGetMacro(ComputeGradients,vtkTypeBool);
119   vtkBooleanMacro(ComputeGradients,vtkTypeBool);
120   //@}
121 
122   //@{
123   /**
124    * Set/Get the computation of scalars.
125    */
126   vtkSetMacro(ComputeScalars,vtkTypeBool);
127   vtkGetMacro(ComputeScalars,vtkTypeBool);
128   vtkBooleanMacro(ComputeScalars,vtkTypeBool);
129   //@}
130 
131   //@{
132   /**
133    * Enable the use of a scalar tree to accelerate contour extraction.
134    */
135   vtkSetMacro(UseScalarTree,vtkTypeBool);
136   vtkGetMacro(UseScalarTree,vtkTypeBool);
137   vtkBooleanMacro(UseScalarTree,vtkTypeBool);
138   //@}
139 
140   //@{
141   /**
142    * Set / get a spatial locator for merging points. By default,
143    * an instance of vtkMergePoints is used.
144    */
145   void SetLocator(vtkIncrementalPointLocator *locator);
146   vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
147   //@}
148 
149   /**
150    * Create default locator. Used to create one when none is
151    * specified. The locator is used to merge coincident points.
152    */
153   void CreateDefaultLocator();
154 
155 protected:
156   vtkMarchingContourFilter();
157   ~vtkMarchingContourFilter() override;
158 
159   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
160   int FillInputPortInformation(int port, vtkInformation *info) override;
161 
162   vtkContourValues *ContourValues;
163   vtkTypeBool ComputeNormals;
164   vtkTypeBool ComputeGradients;
165   vtkTypeBool ComputeScalars;
166   vtkIncrementalPointLocator *Locator;
167   vtkTypeBool UseScalarTree;
168   vtkScalarTree *ScalarTree;
169 
170   //special contouring for structured points
171   void StructuredPointsContour(int dim, vtkDataSet *input, vtkPolyData *output);
172   //special contouring for image data
173   void ImageContour(int dim, vtkDataSet *input, vtkPolyData *output);
174   //default if not structured data
175   void DataSetContour(vtkDataSet *input, vtkPolyData *output);
176 private:
177   vtkMarchingContourFilter(const vtkMarchingContourFilter&) = delete;
178   void operator=(const vtkMarchingContourFilter&) = delete;
179 };
180 
181 /**
182  * Set a particular contour value at contour number i. The index i ranges
183  * between 0<=i<NumberOfContours.
184  */
SetValue(int i,double value)185 inline void vtkMarchingContourFilter::SetValue(int i, double value)
186 {
187   this->ContourValues->SetValue(i,value);
188 }
189 
190 /**
191  * Get the ith contour value.
192  */
GetValue(int i)193 inline double vtkMarchingContourFilter::GetValue(int i)
194 {
195   return this->ContourValues->GetValue(i);
196 }
197 
198 /**
199  * Get a pointer to an array of contour values. There will be
200  * GetNumberOfContours() values in the list.
201  */
GetValues()202 inline double *vtkMarchingContourFilter::GetValues()
203 {
204   return this->ContourValues->GetValues();
205 }
206 
207 /**
208  * Fill a supplied list with contour values. There will be
209  * GetNumberOfContours() values in the list. Make sure you allocate
210  * enough memory to hold the list.
211  */
GetValues(double * contourValues)212 inline void vtkMarchingContourFilter::GetValues(double *contourValues)
213 {
214   this->ContourValues->GetValues(contourValues);
215 }
216 
217 /**
218  * Set the number of contours to place into the list. You only really
219  * need to use this method to reduce list size. The method SetValue()
220  * will automatically increase list size as needed.
221  */
SetNumberOfContours(int number)222 inline void vtkMarchingContourFilter::SetNumberOfContours(int number)
223 {
224   this->ContourValues->SetNumberOfContours(number);
225 }
226 
227 /**
228  * Get the number of contours in the list of contour values.
229  */
GetNumberOfContours()230 inline int vtkMarchingContourFilter::GetNumberOfContours()
231 {
232   return this->ContourValues->GetNumberOfContours();
233 }
234 
235 /**
236  * Generate numContours equally spaced contour values between specified
237  * range. Contour values will include min/max range values.
238  */
GenerateValues(int numContours,double range[2])239 inline void vtkMarchingContourFilter::GenerateValues(int numContours,
240                                                      double range[2])
241 {
242   this->ContourValues->GenerateValues(numContours, range);
243 }
244 
245 /**
246  * Generate numContours equally spaced contour values between specified
247  * range. Contour values will include min/max range values.
248  */
GenerateValues(int numContours,double rangeStart,double rangeEnd)249 inline void vtkMarchingContourFilter::GenerateValues(int numContours,
250                                                      double rangeStart,
251                                                      double rangeEnd)
252 {
253   this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);
254 }
255 
256 #endif
257