1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkRandomAttributeGenerator.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 vtkRandomAttributeGenerator - generate and create random data attributes 16 // .SECTION Description 17 // vtkRandomAttributeGenerator is a filter that creates random attributes 18 // including scalars, vectors, normals, tensors, texture coordinates and/or 19 // general data arrays. These attributes can be generated as point data, cell 20 // data or general field data. The generation of each component is normalized 21 // between a user-specified minimum and maximum value. 22 // 23 // This filter provides that capability to specify the data type of the 24 // attributes, the range for each of the components, and the number of 25 // components. Note, however, that this flexibility only goes so far because 26 // some attributes (e.g., normals, vectors and tensors) are fixed in the 27 // number of components, and in the case of normals and tensors, are 28 // constrained in the values that some of the components can take (i.e., 29 // normals have magnitude one, and tensors are symmetric). 30 31 // .SECTION Caveats 32 // In general this class is used for debugging or testing purposes. 33 // 34 // It is possible to generate multiple attributes simultaneously. 35 // 36 // By default, no data is generated. Make sure to enable the generation of 37 // some attributes if you want this filter to affect the output. Also note 38 // that this filter passes through input geometry, topology and attributes. 39 // Newly created attributes may replace attribute data that would have 40 // otherwise been passed through. 41 42 // .SECTION See also 43 // vtkBrownianPoints 44 45 46 #ifndef vtkRandomAttributeGenerator_h 47 #define vtkRandomAttributeGenerator_h 48 49 #include "vtkFiltersGeneralModule.h" // For export macro 50 #include "vtkPassInputTypeAlgorithm.h" 51 52 class vtkDataSet; 53 class vtkCompositeDataSet; 54 55 class VTKFILTERSGENERAL_EXPORT vtkRandomAttributeGenerator : public vtkPassInputTypeAlgorithm 56 { 57 public: 58 // Description: 59 // Create instance with minimum speed 0.0, maximum speed 1.0. 60 static vtkRandomAttributeGenerator *New(); 61 62 vtkTypeMacro(vtkRandomAttributeGenerator,vtkPassInputTypeAlgorithm); 63 void PrintSelf(ostream& os, vtkIndent indent); 64 65 // Description: 66 // Specify the type of array to create (all components of this array are of this 67 // type). This holds true for all arrays that are created. 68 vtkSetMacro(DataType,int); SetDataTypeToBit()69 void SetDataTypeToBit() {this->SetDataType(VTK_BIT);} SetDataTypeToChar()70 void SetDataTypeToChar() {this->SetDataType(VTK_CHAR);} SetDataTypeToUnsignedChar()71 void SetDataTypeToUnsignedChar() {this->SetDataType(VTK_UNSIGNED_CHAR);} SetDataTypeToShort()72 void SetDataTypeToShort() {this->SetDataType(VTK_SHORT);} SetDataTypeToUnsignedShort()73 void SetDataTypeToUnsignedShort() {this->SetDataType(VTK_UNSIGNED_SHORT);} SetDataTypeToInt()74 void SetDataTypeToInt() {this->SetDataType(VTK_INT);} SetDataTypeToUnsignedInt()75 void SetDataTypeToUnsignedInt() {this->SetDataType(VTK_UNSIGNED_INT);} SetDataTypeToLong()76 void SetDataTypeToLong() {this->SetDataType(VTK_LONG);} SetDataTypeToUnsignedLong()77 void SetDataTypeToUnsignedLong() {this->SetDataType(VTK_UNSIGNED_LONG);} SetDataTypeToFloat()78 void SetDataTypeToFloat() {this->SetDataType(VTK_FLOAT);} SetDataTypeToDouble()79 void SetDataTypeToDouble() {this->SetDataType(VTK_DOUBLE);} 80 vtkGetMacro(DataType,int); 81 82 // Description: 83 // Specify the number of components to generate. This value only applies to those 84 // attribute types that take a variable number of components. For example, a vector 85 // is only three components so the number of components is not applicable; whereas 86 // a scalar may support multiple, varying number of components. 87 vtkSetClampMacro(NumberOfComponents,int,1,VTK_INT_MAX); 88 vtkGetMacro(NumberOfComponents,int); 89 90 // Description: 91 // Set the minimum component value. This applies to all data that is generated, 92 // although normals and tensors have internal constraints that must be 93 // observed. 94 vtkSetMacro(MinimumComponentValue,double); 95 vtkGetMacro(MinimumComponentValue,double); SetComponentRange(double minimumValue,double maximumValue)96 void SetComponentRange (double minimumValue, double maximumValue) 97 { 98 this->SetMinimumComponentValue (minimumValue); 99 this->SetMaximumComponentValue (maximumValue); 100 } 101 102 // Description: 103 // Set the maximum component value. This applies to all data that is generated, 104 // although normals and tensors have internal constraints that must be 105 // observed. 106 vtkSetMacro(MaximumComponentValue,double); 107 vtkGetMacro(MaximumComponentValue,double); 108 109 // Description: 110 // Specify the number of tuples to generate. This value only applies when creating 111 // general field data. In all other cases (i.e., point data or cell data), the number 112 // of tuples is controlled by the number of points and cells, respectively. 113 vtkSetClampMacro(NumberOfTuples,vtkIdType,0,VTK_INT_MAX); 114 vtkGetMacro(NumberOfTuples,vtkIdType); 115 116 // Description: 117 // Indicate that point scalars are to be generated. Note that the specified 118 // number of components is used to create the scalar. 119 vtkSetMacro(GeneratePointScalars,int); 120 vtkGetMacro(GeneratePointScalars,int); 121 vtkBooleanMacro(GeneratePointScalars,int); 122 123 // Description: 124 // Indicate that point vectors are to be generated. Note that the 125 // number of components is always equal to three. 126 vtkSetMacro(GeneratePointVectors,int); 127 vtkGetMacro(GeneratePointVectors,int); 128 vtkBooleanMacro(GeneratePointVectors,int); 129 130 // Description: 131 // Indicate that point normals are to be generated. Note that the 132 // number of components is always equal to three. 133 vtkSetMacro(GeneratePointNormals,int); 134 vtkGetMacro(GeneratePointNormals,int); 135 vtkBooleanMacro(GeneratePointNormals,int); 136 137 // Description: 138 // Indicate that point tensors are to be generated. Note that the 139 // number of components is always equal to nine. 140 vtkSetMacro(GeneratePointTensors,int); 141 vtkGetMacro(GeneratePointTensors,int); 142 vtkBooleanMacro(GeneratePointTensors,int); 143 144 // Description: 145 // Indicate that point texture coordinates are to be generated. Note that 146 // the specified number of components is used to create the texture 147 // coordinates (but must range between one and three). 148 vtkSetMacro(GeneratePointTCoords,int); 149 vtkGetMacro(GeneratePointTCoords,int); 150 vtkBooleanMacro(GeneratePointTCoords,int); 151 152 // Description: 153 // Indicate that an arbitrary point array is to be generated. Note that the 154 // specified number of components is used to create the array. 155 vtkSetMacro(GeneratePointArray,int); 156 vtkGetMacro(GeneratePointArray,int); 157 vtkBooleanMacro(GeneratePointArray,int); 158 159 // Description: 160 // Indicate that cell scalars are to be generated. Note that the specified 161 // number of components is used to create the scalar. 162 vtkSetMacro(GenerateCellScalars,int); 163 vtkGetMacro(GenerateCellScalars,int); 164 vtkBooleanMacro(GenerateCellScalars,int); 165 166 // Description: 167 // Indicate that cell vectors are to be generated. Note that the 168 // number of components is always equal to three. 169 vtkSetMacro(GenerateCellVectors,int); 170 vtkGetMacro(GenerateCellVectors,int); 171 vtkBooleanMacro(GenerateCellVectors,int); 172 173 // Description: 174 // Indicate that cell normals are to be generated. Note that the 175 // number of components is always equal to three. 176 vtkSetMacro(GenerateCellNormals,int); 177 vtkGetMacro(GenerateCellNormals,int); 178 vtkBooleanMacro(GenerateCellNormals,int); 179 180 // Description: 181 // Indicate that cell tensors are to be generated. Note that the 182 // number of components is always equal to nine. 183 vtkSetMacro(GenerateCellTensors,int); 184 vtkGetMacro(GenerateCellTensors,int); 185 vtkBooleanMacro(GenerateCellTensors,int); 186 187 // Description: 188 // Indicate that cell texture coordinates are to be generated. Note that 189 // the specified number of components is used to create the texture 190 // coordinates (but must range between one and three). 191 vtkSetMacro(GenerateCellTCoords,int); 192 vtkGetMacro(GenerateCellTCoords,int); 193 vtkBooleanMacro(GenerateCellTCoords,int); 194 195 // Description: 196 // Indicate that an arbitrary cell array is to be generated. Note that the 197 // specified number of components is used to create the array. 198 vtkSetMacro(GenerateCellArray,int); 199 vtkGetMacro(GenerateCellArray,int); 200 vtkBooleanMacro(GenerateCellArray,int); 201 202 // Description: 203 // Indicate that an arbitrary field data array is to be generated. Note 204 // that the specified number of components is used to create the scalar. 205 vtkSetMacro(GenerateFieldArray,int); 206 vtkGetMacro(GenerateFieldArray,int); 207 vtkBooleanMacro(GenerateFieldArray,int); 208 209 // Description: 210 // Indicate that the generated attributes are 211 // constant within a block. This can be used to highlight 212 // blocks in a composite dataset. 213 vtkSetMacro(AttributesConstantPerBlock,bool); 214 vtkGetMacro(AttributesConstantPerBlock,bool); 215 vtkBooleanMacro(AttributesConstantPerBlock,bool); 216 217 218 // Description: 219 // Convenience methods for generating data: all data, all point data, or all cell data. 220 // For example, if all data is enabled, then all point, cell and field data is generated. 221 // If all point data is enabled, then point scalars, vectors, normals, tensors, tcoords, 222 // and a data array are produced. GenerateAllPointDataOn()223 void GenerateAllPointDataOn() 224 { 225 this->GeneratePointScalarsOn(); 226 this->GeneratePointVectorsOn(); 227 this->GeneratePointNormalsOn(); 228 this->GeneratePointTCoordsOn(); 229 this->GeneratePointTensorsOn(); 230 this->GeneratePointArrayOn(); 231 } GenerateAllPointDataOff()232 void GenerateAllPointDataOff() 233 { 234 this->GeneratePointScalarsOff(); 235 this->GeneratePointVectorsOff(); 236 this->GeneratePointNormalsOff(); 237 this->GeneratePointTCoordsOff(); 238 this->GeneratePointTensorsOff(); 239 this->GeneratePointArrayOff(); 240 } GenerateAllCellDataOn()241 void GenerateAllCellDataOn() 242 { 243 this->GenerateCellScalarsOn(); 244 this->GenerateCellVectorsOn(); 245 this->GenerateCellNormalsOn(); 246 this->GenerateCellTCoordsOn(); 247 this->GenerateCellTensorsOn(); 248 this->GenerateCellArrayOn(); 249 } GenerateAllCellDataOff()250 void GenerateAllCellDataOff() 251 { 252 this->GenerateCellScalarsOff(); 253 this->GenerateCellVectorsOff(); 254 this->GenerateCellNormalsOff(); 255 this->GenerateCellTCoordsOff(); 256 this->GenerateCellTensorsOff(); 257 this->GenerateCellArrayOff(); 258 } GenerateAllDataOn()259 void GenerateAllDataOn() 260 { 261 this->GenerateAllPointDataOn(); 262 this->GenerateAllCellDataOn(); 263 this->GenerateFieldArrayOn(); 264 } GenerateAllDataOff()265 void GenerateAllDataOff() 266 { 267 this->GenerateAllPointDataOff(); 268 this->GenerateAllCellDataOff(); 269 this->GenerateFieldArrayOff(); 270 } 271 272 protected: 273 vtkRandomAttributeGenerator(); ~vtkRandomAttributeGenerator()274 ~vtkRandomAttributeGenerator() {} 275 276 virtual int RequestData(vtkInformation *, vtkInformationVector **, 277 vtkInformationVector *); 278 virtual int FillInputPortInformation(int port, vtkInformation* info); 279 280 int DataType; 281 int NumberOfComponents; 282 vtkIdType NumberOfTuples; 283 double MinimumComponentValue; 284 double MaximumComponentValue; 285 286 int GeneratePointScalars; 287 int GeneratePointVectors; 288 int GeneratePointNormals; 289 int GeneratePointTCoords; 290 int GeneratePointTensors; 291 int GeneratePointArray; 292 293 int GenerateCellScalars; 294 int GenerateCellVectors; 295 int GenerateCellNormals; 296 int GenerateCellTCoords; 297 int GenerateCellTensors; 298 int GenerateCellArray; 299 300 int GenerateFieldArray; 301 bool AttributesConstantPerBlock; 302 303 // Helper functions 304 vtkDataArray *GenerateData(int dataType, vtkIdType numTuples, int numComp, 305 int minComp, int maxComp, double min, double max); 306 int RequestData(vtkDataSet *input, vtkDataSet *output); 307 int RequestData(vtkCompositeDataSet *input, vtkCompositeDataSet *output); 308 template <class T> 309 void GenerateRandomTuples(T *data, 310 vtkIdType numTuples, 311 int numComp, 312 int minComp, 313 int maxComp, 314 double min, 315 double max); 316 317 318 private: 319 vtkRandomAttributeGenerator(const vtkRandomAttributeGenerator&); // Not implemented. 320 void operator=(const vtkRandomAttributeGenerator&); // Not implemented. 321 }; 322 323 #endif 324