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