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