1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkGenericContourFilter.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   vtkGenericContourFilter
17  * @brief   generate isocontours from input dataset
18  *
19  * vtkGenericContourFilter is a filter that takes as input any (generic)
20  * dataset and generates on output isosurfaces and/or isolines. The exact
21  * form of the output depends upon the dimensionality of the input data.
22  * Data consisting of 3D cells will generate isosurfaces, data consisting of
23  * 2D cells will generate isolines, and data with 1D or 0D cells will
24  * generate isopoints. Combinations of output type are possible if the input
25  * dimension is mixed.
26  *
27  * To use this filter you must specify one or more contour values.
28  * You can either use the method SetValue() to specify each contour
29  * value, or use GenerateValues() to generate a series of evenly
30  * spaced contours. You can use ComputeNormalsOn to compute the normals
31  * without the need of a vtkPolyDataNormals
32  *
33  * This filter has been implemented to operate on generic datasets, rather
34  * than the typical vtkDataSet (and subclasses). vtkGenericDataSet is a more
35  * complex cousin of vtkDataSet, typically consisting of nonlinear,
36  * higher-order cells. To process this type of data, generic cells are
37  * automatically tessellated into linear cells prior to isocontouring.
38  *
39  * @sa
40  * vtkContourFilter vtkGenericDataSet
41  */
42 
43 #ifndef vtkGenericContourFilter_h
44 #define vtkGenericContourFilter_h
45 
46 #include "vtkFiltersGenericModule.h" // For export macro
47 #include "vtkPolyDataAlgorithm.h"
48 
49 class vtkContourValues;
50 class vtkIncrementalPointLocator;
51 class vtkPointData;
52 class vtkCellData;
53 
54 class VTKFILTERSGENERIC_EXPORT vtkGenericContourFilter : public vtkPolyDataAlgorithm
55 {
56 public:
57   vtkTypeMacro(vtkGenericContourFilter, vtkPolyDataAlgorithm);
58 
59   void PrintSelf(ostream& os, vtkIndent indent) override;
60 
61   /**
62    * Construct object with initial range (0,1) and single contour value
63    * of 0.0.
64    */
65   static vtkGenericContourFilter* New();
66 
67   typedef double PointType[3]; // Arbitrary definition of a point
68 
69   ///@{
70   /**
71    * Methods to set / get contour values.
72    */
73   void SetValue(int i, float value);
74   double GetValue(int i);
75   double* GetValues();
76   void GetValues(double* contourValues);
77   void SetNumberOfContours(int number);
78   vtkIdType GetNumberOfContours();
79   void GenerateValues(int numContours, double range[2]);
80   void GenerateValues(int numContours, double rangeStart, double rangeEnd);
81   ///@}
82 
83   /**
84    * Modified GetMTime Because we delegate to vtkContourValues
85    */
86   vtkMTimeType GetMTime() override;
87 
88   ///@{
89   /**
90    * Set/Get the computation of normals. Normal computation is fairly
91    * expensive in both time and storage. If the output data will be
92    * processed by filters that modify topology or geometry, it may be
93    * wise to turn Normals and Gradients off.
94    */
95   vtkSetMacro(ComputeNormals, vtkTypeBool);
96   vtkGetMacro(ComputeNormals, vtkTypeBool);
97   vtkBooleanMacro(ComputeNormals, vtkTypeBool);
98   ///@}
99 
100   ///@{
101   /**
102    * Set/Get the computation of gradients. Gradient computation is
103    * fairly expensive in both time and storage. Note that if
104    * ComputeNormals is on, gradients will have to be calculated, but
105    * will not be stored in the output dataset.  If the output data
106    * will be processed by filters that modify topology or geometry, it
107    * may be wise to turn Normals and Gradients off.
108    */
109   vtkSetMacro(ComputeGradients, vtkTypeBool);
110   vtkGetMacro(ComputeGradients, vtkTypeBool);
111   vtkBooleanMacro(ComputeGradients, vtkTypeBool);
112   ///@}
113 
114   ///@{
115   /**
116    * Set/Get the computation of scalars.
117    */
118   vtkSetMacro(ComputeScalars, vtkTypeBool);
119   vtkGetMacro(ComputeScalars, vtkTypeBool);
120   vtkBooleanMacro(ComputeScalars, vtkTypeBool);
121   ///@}
122 
123   ///@{
124   /**
125    * Set / get a spatial locator for merging points. By default,
126    * an instance of vtkMergePoints is used.
127    */
128   void SetLocator(vtkIncrementalPointLocator* locator);
129   vtkGetObjectMacro(Locator, vtkIncrementalPointLocator);
130   ///@}
131 
132   /**
133    * Create default locator. Used to create one when none is
134    * specified. The locator is used to merge coincident points.
135    */
136   void CreateDefaultLocator();
137 
138   ///@{
139   /**
140    * If you want to contour by an arbitrary scalar attribute, then set its
141    * name here.
142    * By default this in nullptr and the filter will use the active scalar array.
143    */
144   vtkGetStringMacro(InputScalarsSelection);
145   virtual void SelectInputScalars(const char* fieldName);
146   ///@}
147 
148 protected:
149   vtkGenericContourFilter();
150   ~vtkGenericContourFilter() override;
151 
152   int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
153 
154   int FillInputPortInformation(int, vtkInformation*) override;
155 
156   vtkContourValues* ContourValues;
157   vtkTypeBool ComputeNormals;
158   vtkTypeBool ComputeGradients;
159   vtkTypeBool ComputeScalars;
160   vtkIncrementalPointLocator* Locator;
161 
162   char* InputScalarsSelection;
163   vtkSetStringMacro(InputScalarsSelection);
164 
165   // Used internal by vtkGenericAdaptorCell::Contour()
166   vtkPointData* InternalPD;
167   vtkPointData* SecondaryPD;
168   vtkCellData* SecondaryCD;
169 
170 private:
171   vtkGenericContourFilter(const vtkGenericContourFilter&) = delete;
172   void operator=(const vtkGenericContourFilter&) = delete;
173 };
174 #endif
175