1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkParametricFunctionSource.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   vtkParametricFunctionSource
17  * @brief   tessellate parametric functions
18  *
19  * This class tessellates parametric functions. The user must specify how
20  * many points in the parametric coordinate directions are required (i.e.,
21  * the resolution), and the mode to use to generate scalars.
22  *
23  * @par Thanks:
24  * Andrew Maclean andrew.amaclean@gmail.com for creating and contributing
25  * the class.
26  *
27  * @sa
28  * vtkParametricFunction
29  *
30  * @sa
31  * Implementation of parametrics for 1D lines:
32  * vtkParametricSpline
33  *
34  * @sa
35  * Subclasses of vtkParametricFunction implementing non-orentable surfaces:
36  * vtkParametricBoy vtkParametricCrossCap vtkParametricFigure8Klein
37  * vtkParametricKlein vtkParametricMobius vtkParametricRoman
38  *
39  * @sa
40  * Subclasses of vtkParametricFunction implementing orientable surfaces:
41  * vtkParametricConicSpiral vtkParametricDini vtkParametricEllipsoid
42  * vtkParametricEnneper vtkParametricRandomHills vtkParametricSuperEllipsoid
43  * vtkParametricSuperToroid vtkParametricTorus
44  *
45  */
46 
47 #ifndef vtkParametricFunctionSource_h
48 #define vtkParametricFunctionSource_h
49 
50 #include "vtkFiltersSourcesModule.h" // For export macro
51 #include "vtkPolyDataAlgorithm.h"
52 
53 class vtkCellArray;
54 class vtkParametricFunction;
55 
56 class VTKFILTERSSOURCES_EXPORT vtkParametricFunctionSource : public vtkPolyDataAlgorithm
57 {
58 public:
59   vtkTypeMacro(vtkParametricFunctionSource, vtkPolyDataAlgorithm);
60   void PrintSelf(ostream& os, vtkIndent indent) override;
61 
62   /**
63    * Create a new instance with (50,50,50) points in the (u-v-w) directions.
64    */
65   static vtkParametricFunctionSource* New();
66 
67   ///@{
68   /**
69    * Specify the parametric function to use to generate the tessellation.
70    */
71   virtual void SetParametricFunction(vtkParametricFunction*);
72   vtkGetObjectMacro(ParametricFunction, vtkParametricFunction);
73   ///@}
74 
75   ///@{
76   /**
77    * Set/Get the number of subdivisions / tessellations in the u parametric
78    * direction. Note that the number of tessellant points in the u
79    * direction is the UResolution + 1.
80    */
81   vtkSetClampMacro(UResolution, int, 2, VTK_INT_MAX);
82   vtkGetMacro(UResolution, int);
83   ///@}
84 
85   ///@{
86   /**
87    * Set/Get the number of subdivisions / tessellations in the v parametric
88    * direction. Note that the number of tessellant points in the v
89    * direction is the VResolution + 1.
90    */
91   vtkSetClampMacro(VResolution, int, 2, VTK_INT_MAX);
92   vtkGetMacro(VResolution, int);
93   ///@}
94 
95   ///@{
96   /**
97    * Set/Get the number of subdivisions / tessellations in the w parametric
98    * direction. Note that the number of tessellant points in the w
99    * direction is the WResolution + 1.
100    */
101   vtkSetClampMacro(WResolution, int, 2, VTK_INT_MAX);
102   vtkGetMacro(WResolution, int);
103   ///@}
104 
105   ///@{
106   /**
107    * Set/Get the generation of texture coordinates. This is off by
108    * default.
109    * Note that this is only applicable to parametric surfaces
110    * whose parametric dimension is 2.
111    * Note that texturing may fail in some cases.
112    */
113   vtkBooleanMacro(GenerateTextureCoordinates, vtkTypeBool);
114   vtkSetClampMacro(GenerateTextureCoordinates, vtkTypeBool, 0, 1);
115   vtkGetMacro(GenerateTextureCoordinates, vtkTypeBool);
116   ///@}
117 
118   ///@{
119   /**
120    * Set/Get the generation of normals. This is on by
121    * default.
122    * Note that this is only applicable to parametric surfaces
123    * whose parametric dimension is 2.
124    */
125   vtkBooleanMacro(GenerateNormals, vtkTypeBool);
126   vtkSetClampMacro(GenerateNormals, vtkTypeBool, 0, 1);
127   vtkGetMacro(GenerateNormals, vtkTypeBool);
128   ///@}
129 
130   /**
131    * Enumerate the supported scalar generation modes.<br>
132    * SCALAR_NONE - Scalars are not generated (default).<br>
133    * SCALAR_U - The scalar is set to the u-value.<br>
134    * SCALAR_V - The scalar is set to the v-value.<br>
135    * SCALAR_U0 - The scalar is set to 1 if
136    * u = (u_max - u_min)/2 = u_avg, 0 otherwise.<br>
137    * SCALAR_V0 - The scalar is set to 1 if
138    * v = (v_max - v_min)/2 = v_avg, 0 otherwise.<br>
139    * SCALAR_U0V0 - The scalar is
140    * set to 1 if u == u_avg, 2 if v == v_avg,
141    * 3 if u = u_avg && v = v_avg, 0 otherwise.<br>
142    * SCALAR_MODULUS - The scalar is set to (sqrt(u*u+v*v)),
143    * this is measured relative to (u_avg,v_avg).<br>
144    * SCALAR_PHASE - The scalar is set to (atan2(v,u))
145    * (in degrees, 0 to 360),
146    * this is measured relative to (u_avg,v_avg).<br>
147    * SCALAR_QUADRANT - The scalar is set to 1, 2, 3 or 4.
148    * depending upon the quadrant of the point (u,v).<br>
149    * SCALAR_X - The scalar is set to the x-value.<br>
150    * SCALAR_Y - The scalar is set to the y-value.<br>
151    * SCALAR_Z - The scalar is set to the z-value.<br>
152    * SCALAR_DISTANCE - The scalar is set to (sqrt(x*x+y*y+z*z)).
153    * I.e. distance from the origin.<br>
154    * SCALAR_USER_DEFINED - The scalar is set to the value
155    * returned from EvaluateScalar().<br>
156    */
157   enum SCALAR_MODE
158   {
159     SCALAR_NONE = 0,
160     SCALAR_U,
161     SCALAR_V,
162     SCALAR_U0,
163     SCALAR_V0,
164     SCALAR_U0V0,
165     SCALAR_MODULUS,
166     SCALAR_PHASE,
167     SCALAR_QUADRANT,
168     SCALAR_X,
169     SCALAR_Y,
170     SCALAR_Z,
171     SCALAR_DISTANCE,
172     SCALAR_FUNCTION_DEFINED
173   };
174 
175   ///@{
176   /**
177    * Get/Set the mode used for the scalar data.
178    * See SCALAR_MODE for a description of the types of scalars generated.
179    */
180   vtkSetClampMacro(ScalarMode, int, SCALAR_NONE, SCALAR_FUNCTION_DEFINED);
181   vtkGetMacro(ScalarMode, int);
SetScalarModeToNone(void)182   void SetScalarModeToNone(void) { this->SetScalarMode(SCALAR_NONE); }
SetScalarModeToU(void)183   void SetScalarModeToU(void) { this->SetScalarMode(SCALAR_U); }
SetScalarModeToV(void)184   void SetScalarModeToV(void) { this->SetScalarMode(SCALAR_V); }
SetScalarModeToU0(void)185   void SetScalarModeToU0(void) { this->SetScalarMode(SCALAR_U0); }
SetScalarModeToV0(void)186   void SetScalarModeToV0(void) { this->SetScalarMode(SCALAR_V0); }
SetScalarModeToU0V0(void)187   void SetScalarModeToU0V0(void) { this->SetScalarMode(SCALAR_U0V0); }
SetScalarModeToModulus(void)188   void SetScalarModeToModulus(void) { this->SetScalarMode(SCALAR_MODULUS); }
SetScalarModeToPhase(void)189   void SetScalarModeToPhase(void) { this->SetScalarMode(SCALAR_PHASE); }
SetScalarModeToQuadrant(void)190   void SetScalarModeToQuadrant(void) { this->SetScalarMode(SCALAR_QUADRANT); }
SetScalarModeToX(void)191   void SetScalarModeToX(void) { this->SetScalarMode(SCALAR_X); }
SetScalarModeToY(void)192   void SetScalarModeToY(void) { this->SetScalarMode(SCALAR_Y); }
SetScalarModeToZ(void)193   void SetScalarModeToZ(void) { this->SetScalarMode(SCALAR_Z); }
SetScalarModeToDistance(void)194   void SetScalarModeToDistance(void) { this->SetScalarMode(SCALAR_DISTANCE); }
SetScalarModeToFunctionDefined(void)195   void SetScalarModeToFunctionDefined(void) { this->SetScalarMode(SCALAR_FUNCTION_DEFINED); }
196   ///@}
197 
198   /**
199    * Return the MTime also considering the parametric function.
200    */
201   vtkMTimeType GetMTime() override;
202 
203   ///@{
204   /**
205    * Set/get the desired precision for the output points.
206    * See the documentation for the vtkAlgorithm::Precision enum for an
207    * explanation of the available precision settings.
208    */
209   vtkSetMacro(OutputPointsPrecision, int);
210   vtkGetMacro(OutputPointsPrecision, int);
211   ///@}
212 
213 protected:
214   vtkParametricFunctionSource();
215   ~vtkParametricFunctionSource() override;
216 
217   // Usual data generation method
218   int RequestData(
219     vtkInformation* info, vtkInformationVector** input, vtkInformationVector* output) override;
220 
221   // Variables
222   vtkParametricFunction* ParametricFunction;
223 
224   int UResolution;
225   int VResolution;
226   int WResolution;
227   vtkTypeBool GenerateTextureCoordinates;
228   vtkTypeBool GenerateNormals;
229   int ScalarMode;
230   int OutputPointsPrecision;
231 
232 private:
233   // Create output depending on function dimension
234   void Produce1DOutput(vtkInformationVector* output);
235   void Produce2DOutput(vtkInformationVector* output);
236 
237   /**
238    * Generate triangles from an ordered set of points.
239 
240    * Given a parametrization f(u,v)->(x,y,z), this function generates
241    * a vtkCellAarray of point IDs over the range MinimumU <= u < MaximumU
242    * and MinimumV <= v < MaximumV.
243 
244    * Before using this function, ensure that: UResolution,
245    * VResolution, MinimumU, MaximumU, MinimumV, MaximumV, JoinU, JoinV,
246    * TwistU, TwistV, ordering are set appropriately for the parametric function.
247    */
248   void MakeTriangles(vtkCellArray* strips, int PtsU, int PtsV);
249 
250   vtkParametricFunctionSource(const vtkParametricFunctionSource&) = delete;
251   void operator=(const vtkParametricFunctionSource&) = delete;
252 };
253 
254 #endif
255