Salome HOME
initial commit from paravisaddons
[tools/paravisaddons_common.git] / src / CellDataContour / plugin / CellDataContourModule / vtkMyContourFilter.h
1 // Copyright (C) 2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 /*=========================================================================
21
22   Program:   Visualization Toolkit
23   Module:    vtkMyContourFilter.h
24
25   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
26   All rights reserved.
27   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
28
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.
32
33 =========================================================================*/
34 /**
35  * @class   vtkMyContourFilter
36  * @brief   generate isosurfaces/isolines from scalar values
37  *
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.
45  *
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().
55  *
56  * @warning
57  * For unstructured data or structured grids, normals and gradients
58  * are not computed. Use vtkPolyDataNormals to compute the surface
59  * normals.
60  *
61  * @sa
62  * vtkFlyingEdges3D vtkFlyingEdges2D vtkDiscreteFlyingEdges3D
63  * vtkDiscreteFlyingEdges2D vtkMarchingContourFilter vtkMarchingCubes
64  * vtkSliceCubes vtkMarchingSquares vtkImageMarchingCubes
65 */
66
67 #ifndef vtkMyContourFilter_h
68 #define vtkMyContourFilter_h
69
70 #include <vtkPolyDataAlgorithm.h>
71
72 #include "vtkContourValues.h" // Needed for inline methods
73
74 #include "vtkMyCellDataToPointData.h"
75
76 class vtkIncrementalPointLocator;
77 class vtkScalarTree;
78 class vtkSynchronizedTemplates2D;
79 class vtkSynchronizedTemplates3D;
80 class vtkGridSynchronizedTemplates3D;
81 class vtkRectilinearSynchronizedTemplates;
82 class vtkCallbackCommand;
83
84 class VTK_EXPORT vtkMyContourFilter : public vtkPolyDataAlgorithm
85 {
86 public:
87   vtkTypeMacro(vtkMyContourFilter,vtkPolyDataAlgorithm);
88   void PrintSelf(ostream& os, vtkIndent indent) override;
89
90   /**
91    * Construct object with initial range (0,1) and single contour value
92    * of 0.0.
93    */
94   static vtkMyContourFilter *New();
95
96   //@{
97   /**
98    * Methods to set / get contour values.
99    */
100   void SetValue(int i, double value);
101   double GetValue(int i);
102   double *GetValues();
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);
108   //@}
109
110   /**
111    * Modified GetMTime Because we delegate to vtkContourValues
112    */
113   vtkMTimeType GetMTime() override;
114
115   //@{
116   /**
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.
125    */
126   vtkSetMacro(ComputeNormals, bool);
127   vtkGetMacro(ComputeNormals, bool);
128   vtkBooleanMacro(ComputeNormals, bool);
129   //@}
130
131   //@{
132   /**
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.
139    */
140   vtkSetMacro(ComputeGradients, bool);
141   vtkGetMacro(ComputeGradients, bool);
142   vtkBooleanMacro(ComputeGradients, bool);
143   //@}
144
145   //@{
146   /**
147    * Set/Get the computation of scalars.
148    */
149   vtkSetMacro(ComputeScalars, bool);
150   vtkGetMacro(ComputeScalars, bool);
151   vtkBooleanMacro(ComputeScalars, bool);
152   //@}
153
154   //@{
155   /**
156    * Enable the use of a scalar tree to accelerate contour extraction.
157    */
158   vtkSetMacro(UseScalarTree, bool);
159   vtkGetMacro(UseScalarTree, bool);
160   vtkBooleanMacro(UseScalarTree, bool);
161   //@}
162
163   //@{
164   /**
165    * Enable the use of a scalar tree to accelerate contour extraction.
166    */
167   virtual void SetScalarTree(vtkScalarTree*);
168   vtkGetObjectMacro(ScalarTree,vtkScalarTree);
169   //@}
170
171   //@{
172   /**
173    * Set / get a spatial locator for merging points. By default,
174    * an instance of vtkMergePoints is used.
175    */
176   void SetLocator(vtkIncrementalPointLocator *locator);
177   vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
178   //@}
179
180   /**
181    * Create default locator. Used to create one when none is
182    * specified. The locator is used to merge coincident points.
183    */
184   void CreateDefaultLocator();
185
186   //@{
187   /**
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.
190    */
191   void SetArrayComponent(int);
192   int  GetArrayComponent();
193   //@}
194
195
196   //@{
197   /**
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.
203    */
204   vtkSetMacro(GenerateTriangles, bool);
205   vtkGetMacro(GenerateTriangles, bool);
206   vtkBooleanMacro(GenerateTriangles, bool);
207   //@}
208
209   //@{
210   /**
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.
214    */
215   void SetOutputPointsPrecision(int precision);
216   int GetOutputPointsPrecision() const;
217   //@}
218
219 protected:
220   vtkMyContourFilter();
221   ~vtkMyContourFilter() override;
222
223   void ReportReferences(vtkGarbageCollector*) override;
224
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;
232
233   vtkContourValues *ContourValues;
234   bool ComputeNormals;
235   bool ComputeGradients;
236   bool ComputeScalars;
237   vtkIncrementalPointLocator *Locator;
238   bool UseScalarTree;
239   vtkScalarTree *ScalarTree;
240   int OutputPointsPrecision;
241   bool GenerateTriangles;
242
243   vtkSynchronizedTemplates2D *SynchronizedTemplates2D;
244   vtkSynchronizedTemplates3D *SynchronizedTemplates3D;
245   vtkGridSynchronizedTemplates3D *GridSynchronizedTemplates;
246   vtkRectilinearSynchronizedTemplates *RectilinearSynchronizedTemplates;
247   vtkCallbackCommand *InternalProgressCallbackCommand;
248
249   static void InternalProgressCallbackFunction(vtkObject *caller,
250                                                unsigned long eid,
251                                                void *clientData,
252                                                void *callData);
253
254 private:
255   vtkMyContourFilter(const vtkMyContourFilter&) = delete;
256   void operator=(const vtkMyContourFilter&) = delete;
257 };
258
259 /**
260  * Set a particular contour value at contour number i. The index i ranges
261  * between 0<=i<NumberOfContours.
262  */
263 inline void vtkMyContourFilter::SetValue(int i, double value)
264 {this->ContourValues->SetValue(i,value);}
265
266 /**
267  * Get the ith contour value.
268  */
269 inline double vtkMyContourFilter::GetValue(int i)
270 {return this->ContourValues->GetValue(i);}
271
272 /**
273  * Get a pointer to an array of contour values. There will be
274  * GetNumberOfContours() values in the list.
275  */
276 inline double *vtkMyContourFilter::GetValues()
277 {return this->ContourValues->GetValues();}
278
279 /**
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.
283  */
284 inline void vtkMyContourFilter::GetValues(double *contourValues)
285 {this->ContourValues->GetValues(contourValues);}
286
287 /**
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.
291  */
292 inline void vtkMyContourFilter::SetNumberOfContours(int number)
293 {this->ContourValues->SetNumberOfContours(number);}
294
295 /**
296  * Get the number of contours in the list of contour values.
297  */
298 inline int vtkMyContourFilter::GetNumberOfContours()
299 {return this->ContourValues->GetNumberOfContours();}
300
301 /**
302  * Generate numContours equally spaced contour values between specified
303  * range. Contour values will include min/max range values.
304  */
305 inline void vtkMyContourFilter::GenerateValues(int numContours, double range[2])
306 {this->ContourValues->GenerateValues(numContours, range);}
307
308 /**
309  * Generate numContours equally spaced contour values between specified
310  * range. Contour values will include min/max range values.
311  */
312 inline void vtkMyContourFilter::GenerateValues(int numContours, double
313                                              rangeStart, double rangeEnd)
314 {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}
315
316
317 #endif