1 // Copyright (C) 2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 /*=========================================================================
22 Program: Visualization Toolkit
23 Module: vtkMyContourFilter.h
25 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
27 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
29 This software is distributed WITHOUT ANY WARRANTY; without even
30 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31 PURPOSE. See the above copyright notice for more information.
33 =========================================================================*/
35 * @class vtkMyContourFilter
36 * @brief generate isosurfaces/isolines from scalar values
38 * vtkMyContourFilter is a filter that takes as input any dataset and
39 * generates on output isosurfaces and/or isolines. The exact form
40 * of the output depends upon the dimensionality of the input data.
41 * Data consisting of 3D cells will generate isosurfaces, data
42 * consisting of 2D cells will generate isolines, and data with 1D
43 * or 0D cells will generate isopoints. Combinations of output type
44 * are possible if the input dimension is mixed.
46 * To use this filter you must specify one or more contour values.
47 * You can either use the method SetValue() to specify each contour
48 * value, or use GenerateValues() to generate a series of evenly
49 * spaced contours. It is also possible to accelerate the operation of
50 * this filter (at the cost of extra memory) by using a
51 * vtkScalarTree. A scalar tree is used to quickly locate cells that
52 * contain a contour surface. This is especially effective if multiple
53 * contours are being extracted. If you want to use a scalar tree,
54 * invoke the method UseScalarTreeOn().
57 * For unstructured data or structured grids, normals and gradients
58 * are not computed. Use vtkPolyDataNormals to compute the surface
62 * vtkFlyingEdges3D vtkFlyingEdges2D vtkDiscreteFlyingEdges3D
63 * vtkDiscreteFlyingEdges2D vtkMarchingContourFilter vtkMarchingCubes
64 * vtkSliceCubes vtkMarchingSquares vtkImageMarchingCubes
67 #ifndef vtkMyContourFilter_h
68 #define vtkMyContourFilter_h
70 #include <vtkPolyDataAlgorithm.h>
72 #include "vtkContourValues.h" // Needed for inline methods
74 #include "vtkMyCellDataToPointData.h"
76 class vtkIncrementalPointLocator;
78 class vtkSynchronizedTemplates2D;
79 class vtkSynchronizedTemplates3D;
80 class vtkGridSynchronizedTemplates3D;
81 class vtkRectilinearSynchronizedTemplates;
82 class vtkCallbackCommand;
84 class VTK_EXPORT vtkMyContourFilter : public vtkPolyDataAlgorithm
87 vtkTypeMacro(vtkMyContourFilter,vtkPolyDataAlgorithm);
88 void PrintSelf(ostream& os, vtkIndent indent) override;
91 * Construct object with initial range (0,1) and single contour value
94 static vtkMyContourFilter *New();
98 * Methods to set / get contour values.
100 void SetValue(int i, double value);
101 double GetValue(int i);
103 void GetValues(double *contourValues);
104 void SetNumberOfContours(int number);
105 int GetNumberOfContours();
106 void GenerateValues(int numContours, double range[2]);
107 void GenerateValues(int numContours, double rangeStart, double rangeEnd);
111 * Modified GetMTime Because we delegate to vtkContourValues
113 vtkMTimeType GetMTime() override;
117 * Set/Get the computation of normals. Normal computation is fairly
118 * expensive in both time and storage. If the output data will be
119 * processed by filters that modify topology or geometry, it may be
120 * wise to turn Normals and Gradients off.
121 * This setting defaults to On for vtkImageData, vtkRectilinearGrid,
122 * vtkStructuredGrid, and vtkUnstructuredGrid inputs, and Off for all others.
123 * This default behavior is to preserve the behavior of an older version of
124 * this filter, which would ignore this setting for certain inputs.
126 vtkSetMacro(ComputeNormals, bool);
127 vtkGetMacro(ComputeNormals, bool);
128 vtkBooleanMacro(ComputeNormals, bool);
133 * Set/Get the computation of gradients. Gradient computation is
134 * fairly expensive in both time and storage. Note that if
135 * ComputeNormals is on, gradients will have to be calculated, but
136 * will not be stored in the output dataset. If the output data
137 * will be processed by filters that modify topology or geometry, it
138 * may be wise to turn Normals and Gradients off.
140 vtkSetMacro(ComputeGradients, bool);
141 vtkGetMacro(ComputeGradients, bool);
142 vtkBooleanMacro(ComputeGradients, bool);
147 * Set/Get the computation of scalars.
149 vtkSetMacro(ComputeScalars, bool);
150 vtkGetMacro(ComputeScalars, bool);
151 vtkBooleanMacro(ComputeScalars, bool);
156 * Enable the use of a scalar tree to accelerate contour extraction.
158 vtkSetMacro(UseScalarTree, bool);
159 vtkGetMacro(UseScalarTree, bool);
160 vtkBooleanMacro(UseScalarTree, bool);
165 * Enable the use of a scalar tree to accelerate contour extraction.
167 virtual void SetScalarTree(vtkScalarTree*);
168 vtkGetObjectMacro(ScalarTree,vtkScalarTree);
173 * Set / get a spatial locator for merging points. By default,
174 * an instance of vtkMergePoints is used.
176 void SetLocator(vtkIncrementalPointLocator *locator);
177 vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
181 * Create default locator. Used to create one when none is
182 * specified. The locator is used to merge coincident points.
184 void CreateDefaultLocator();
188 * Set/get which component of the scalar array to contour on; defaults to 0.
189 * Currently this feature only works if the input is a vtkImageData.
191 void SetArrayComponent(int);
192 int GetArrayComponent();
198 * If this is enabled (by default), the output will be triangles
199 * otherwise, the output will be the intersection polygon
200 * WARNING: if the contour surface is not planar, the output
201 * polygon will not be planar, which might be nice to look at but hard
202 * to compute with downstream.
204 vtkSetMacro(GenerateTriangles, bool);
205 vtkGetMacro(GenerateTriangles, bool);
206 vtkBooleanMacro(GenerateTriangles, bool);
211 * Set/get the desired precision for the output types. See the documentation
212 * for the vtkAlgorithm::Precision enum for an explanation of the available
213 * precision settings.
215 void SetOutputPointsPrecision(int precision);
216 int GetOutputPointsPrecision() const;
220 vtkMyContourFilter();
221 ~vtkMyContourFilter() override;
223 void ReportReferences(vtkGarbageCollector*) override;
225 int RequestData(vtkInformation* request,
226 vtkInformationVector** inputVector,
227 vtkInformationVector* outputVector) override;
228 int RequestUpdateExtent(vtkInformation*,
229 vtkInformationVector**,
230 vtkInformationVector*) override;
231 int FillInputPortInformation(int port, vtkInformation *info) override;
233 vtkContourValues *ContourValues;
235 bool ComputeGradients;
237 vtkIncrementalPointLocator *Locator;
239 vtkScalarTree *ScalarTree;
240 int OutputPointsPrecision;
241 bool GenerateTriangles;
243 vtkSynchronizedTemplates2D *SynchronizedTemplates2D;
244 vtkSynchronizedTemplates3D *SynchronizedTemplates3D;
245 vtkGridSynchronizedTemplates3D *GridSynchronizedTemplates;
246 vtkRectilinearSynchronizedTemplates *RectilinearSynchronizedTemplates;
247 vtkCallbackCommand *InternalProgressCallbackCommand;
249 static void InternalProgressCallbackFunction(vtkObject *caller,
255 vtkMyContourFilter(const vtkMyContourFilter&) = delete;
256 void operator=(const vtkMyContourFilter&) = delete;
260 * Set a particular contour value at contour number i. The index i ranges
261 * between 0<=i<NumberOfContours.
263 inline void vtkMyContourFilter::SetValue(int i, double value)
264 {this->ContourValues->SetValue(i,value);}
267 * Get the ith contour value.
269 inline double vtkMyContourFilter::GetValue(int i)
270 {return this->ContourValues->GetValue(i);}
273 * Get a pointer to an array of contour values. There will be
274 * GetNumberOfContours() values in the list.
276 inline double *vtkMyContourFilter::GetValues()
277 {return this->ContourValues->GetValues();}
280 * Fill a supplied list with contour values. There will be
281 * GetNumberOfContours() values in the list. Make sure you allocate
282 * enough memory to hold the list.
284 inline void vtkMyContourFilter::GetValues(double *contourValues)
285 {this->ContourValues->GetValues(contourValues);}
288 * Set the number of contours to place into the list. You only really
289 * need to use this method to reduce list size. The method SetValue()
290 * will automatically increase list size as needed.
292 inline void vtkMyContourFilter::SetNumberOfContours(int number)
293 {this->ContourValues->SetNumberOfContours(number);}
296 * Get the number of contours in the list of contour values.
298 inline int vtkMyContourFilter::GetNumberOfContours()
299 {return this->ContourValues->GetNumberOfContours();}
302 * Generate numContours equally spaced contour values between specified
303 * range. Contour values will include min/max range values.
305 inline void vtkMyContourFilter::GenerateValues(int numContours, double range[2])
306 {this->ContourValues->GenerateValues(numContours, range);}
309 * Generate numContours equally spaced contour values between specified
310 * range. Contour values will include min/max range values.
312 inline void vtkMyContourFilter::GenerateValues(int numContours, double
313 rangeStart, double rangeEnd)
314 {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}