1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSynchronizedTemplates3D.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   vtkSynchronizedTemplates3D
17  * @brief   generate isosurface from structured points
18  *
19  * vtkSynchronizedTemplates3D is a 3D implementation of the synchronized
20  * template algorithm. Note that vtkContourFilter will automatically
21  * use this class when appropriate.
22  *
23  * @warning
24  * This filter is specialized to 3D images (aka volumes).
25  *
26  * @sa
27  * vtkContourFilter vtkFlyingEdges3D vtkMarchingCubes
28  * vtkSynchronizedTemplates2D vtkDiscreteFlyingEdges3D
29  */
30 
31 #ifndef vtkSynchronizedTemplates3D_h
32 #define vtkSynchronizedTemplates3D_h
33 
34 #include "vtkContourValues.h"     // Passes calls through
35 #include "vtkFiltersCoreModule.h" // For export macro
36 #include "vtkPolyDataAlgorithm.h"
37 
38 class vtkImageData;
39 
40 class VTKFILTERSCORE_EXPORT vtkSynchronizedTemplates3D : public vtkPolyDataAlgorithm
41 {
42 public:
43   static vtkSynchronizedTemplates3D* New();
44 
45   vtkTypeMacro(vtkSynchronizedTemplates3D, vtkPolyDataAlgorithm);
46   void PrintSelf(ostream& os, vtkIndent indent) override;
47 
48   /**
49    * Because we delegate to vtkContourValues
50    */
51   vtkMTimeType GetMTime() override;
52 
53   ///@{
54   /**
55    * Set/Get the computation of normals. Normal computation is fairly
56    * expensive in both time and storage. If the output data will be
57    * processed by filters that modify topology or geometry, it may be
58    * wise to turn Normals and Gradients off.
59    */
60   vtkSetMacro(ComputeNormals, vtkTypeBool);
61   vtkGetMacro(ComputeNormals, vtkTypeBool);
62   vtkBooleanMacro(ComputeNormals, vtkTypeBool);
63   ///@}
64 
65   ///@{
66   /**
67    * Set/Get the computation of gradients. Gradient computation is
68    * fairly expensive in both time and storage. Note that if
69    * ComputeNormals is on, gradients will have to be calculated, but
70    * will not be stored in the output dataset.  If the output data
71    * will be processed by filters that modify topology or geometry, it
72    * may be wise to turn Normals and Gradients off.
73    */
74   vtkSetMacro(ComputeGradients, vtkTypeBool);
75   vtkGetMacro(ComputeGradients, vtkTypeBool);
76   vtkBooleanMacro(ComputeGradients, vtkTypeBool);
77   ///@}
78 
79   ///@{
80   /**
81    * Set/Get the computation of scalars.
82    */
83   vtkSetMacro(ComputeScalars, vtkTypeBool);
84   vtkGetMacro(ComputeScalars, vtkTypeBool);
85   vtkBooleanMacro(ComputeScalars, vtkTypeBool);
86   ///@}
87 
88   ///@{
89   /**
90    * If this is enabled (by default), the output will be triangles
91    * otherwise, the output will be the intersection polygons
92    */
93   vtkSetMacro(GenerateTriangles, vtkTypeBool);
94   vtkGetMacro(GenerateTriangles, vtkTypeBool);
95   vtkBooleanMacro(GenerateTriangles, vtkTypeBool);
96   ///@}
97 
98   /**
99    * Set a particular contour value at contour number i. The index i ranges
100    * between 0<=i<NumberOfContours.
101    */
SetValue(int i,double value)102   void SetValue(int i, double value) { this->ContourValues->SetValue(i, value); }
103 
104   /**
105    * Get the ith contour value.
106    */
GetValue(int i)107   double GetValue(int i) { return this->ContourValues->GetValue(i); }
108 
109   /**
110    * Get a pointer to an array of contour values. There will be
111    * GetNumberOfContours() values in the list.
112    */
GetValues()113   double* GetValues() { return this->ContourValues->GetValues(); }
114 
115   /**
116    * Fill a supplied list with contour values. There will be
117    * GetNumberOfContours() values in the list. Make sure you allocate
118    * enough memory to hold the list.
119    */
GetValues(double * contourValues)120   void GetValues(double* contourValues) { this->ContourValues->GetValues(contourValues); }
121 
122   /**
123    * Set the number of contours to place into the list. You only really
124    * need to use this method to reduce list size. The method SetValue()
125    * will automatically increase list size as needed.
126    */
SetNumberOfContours(int number)127   void SetNumberOfContours(int number) { this->ContourValues->SetNumberOfContours(number); }
128 
129   /**
130    * Get the number of contours in the list of contour values.
131    */
GetNumberOfContours()132   vtkIdType GetNumberOfContours() { return this->ContourValues->GetNumberOfContours(); }
133 
134   /**
135    * Generate numContours equally spaced contour values between specified
136    * range. Contour values will include min/max range values.
137    */
GenerateValues(int numContours,double range[2])138   void GenerateValues(int numContours, double range[2])
139   {
140     this->ContourValues->GenerateValues(numContours, range);
141   }
142 
143   /**
144    * Generate numContours equally spaced contour values between specified
145    * range. Contour values will include min/max range values.
146    */
GenerateValues(int numContours,double rangeStart,double rangeEnd)147   void GenerateValues(int numContours, double rangeStart, double rangeEnd)
148   {
149     this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);
150   }
151 
152   void ThreadedExecute(
153     vtkImageData* data, vtkInformation* inInfo, vtkInformation* outInfo, vtkDataArray* inScalars);
154 
155   ///@{
156   /**
157    * Determines the chunk size for streaming.  This filter will act like a
158    * collector: ask for many input pieces, but generate one output.  Limit is
159    * in KBytes
160    */
161   void SetInputMemoryLimit(unsigned long limit);
162   unsigned long GetInputMemoryLimit();
163   ///@}
164 
165   ///@{
166   /**
167    * Set/get which component of the scalar array to contour on; defaults to 0.
168    */
169   vtkSetMacro(ArrayComponent, int);
170   vtkGetMacro(ArrayComponent, int);
171   ///@}
172 
173 protected:
174   vtkSynchronizedTemplates3D();
175   ~vtkSynchronizedTemplates3D() override;
176 
177   vtkTypeBool ComputeNormals;
178   vtkTypeBool ComputeGradients;
179   vtkTypeBool ComputeScalars;
180   vtkContourValues* ContourValues;
181 
182   int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
183   int RequestUpdateExtent(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
184   int FillInputPortInformation(int port, vtkInformation* info) override;
185 
186   int ArrayComponent;
187 
188   vtkTypeBool GenerateTriangles;
189 
190 private:
191   vtkSynchronizedTemplates3D(const vtkSynchronizedTemplates3D&) = delete;
192   void operator=(const vtkSynchronizedTemplates3D&) = delete;
193 };
194 
195 // template table.
196 
197 extern int VTKFILTERSCORE_EXPORT VTK_SYNCHRONIZED_TEMPLATES_3D_TABLE_1[];
198 extern int VTKFILTERSCORE_EXPORT VTK_SYNCHRONIZED_TEMPLATES_3D_TABLE_2[];
199 
200 #endif
201