1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkFieldDataToAttributeDataFilter.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 vtkFieldDataToAttributeDataFilter 17 * @brief map field data to dataset attribute data 18 * 19 * vtkFieldDataToAttributeDataFilter is a class that maps field data into 20 * dataset attributes. The input to this filter is any type of dataset and 21 * the output is the same dataset (geometry/topology) with new attribute data 22 * (attribute data is passed through if not replaced during filter 23 * execution). 24 * 25 * To use this filter you must specify which field data from the input 26 * dataset to use. There are three possibilities: the cell field data, the 27 * point field data, or the field data associated with the data object 28 * superclass. Then you specify which attribute data to create: either cell 29 * attribute data or point attribute data. Finally, you must define how to 30 * construct the various attribute data types (e.g., scalars, vectors, 31 * normals, etc.) from the arrays and the components of the arrays from the 32 * field data. This is done by associating components in the input field with 33 * components making up the attribute data. For example, you would specify a 34 * scalar with three components (RGB) by assigning components from the field 35 * for the R, then G, then B values of the scalars. You may also have to 36 * specify component ranges (for each R-G-B) to make sure that the number of 37 * R, G, and B values is the same. Also, you may want to normalize the 38 * components which helps distribute the data uniformly. 39 * 40 * This filter is often used in conjunction with 41 * vtkDataObjectToDataSetFilter. vtkDataObjectToDataSetFilter filter 42 * generates dataset topology and geometry and passes its input field data 43 * along to its output. Then this filter is used to generate the attribute 44 * data to go along with the dataset. 45 * 46 * @warning 47 * Make sure that the data you extract is consistent. That is, if you have N 48 * points, extract N point attributes (scalars, vectors, etc.). 49 * 50 * @sa 51 * vtkFieldData vtkDataSet vtkDataObjectToDataSetFilter 52 * vtkDataSetAttributes vtkDataArray 53 */ 54 55 #ifndef vtkFieldDataToAttributeDataFilter_h 56 #define vtkFieldDataToAttributeDataFilter_h 57 58 #include "vtkDataSetAlgorithm.h" 59 #include "vtkFiltersCoreModule.h" // For export macro 60 61 #define VTK_DATA_OBJECT_FIELD 0 62 #define VTK_POINT_DATA_FIELD 1 63 #define VTK_CELL_DATA_FIELD 2 64 65 #define VTK_CELL_DATA 0 66 #define VTK_POINT_DATA 1 67 68 class vtkDataArray; 69 class vtkDataSetAttributes; 70 class vtkFieldData; 71 72 class VTKFILTERSCORE_EXPORT vtkFieldDataToAttributeDataFilter : public vtkDataSetAlgorithm 73 { 74 public: 75 void PrintSelf(ostream& os, vtkIndent indent) override; 76 vtkTypeMacro(vtkFieldDataToAttributeDataFilter, vtkDataSetAlgorithm); 77 78 /** 79 * Construct object with input field set to the data object field, and the 80 * output attribute data set to generate point data. 81 */ 82 static vtkFieldDataToAttributeDataFilter* New(); 83 84 ///@{ 85 /** 86 * Specify which field data to use to generate the output attribute 87 * data. There are three choices: the field data associated with the 88 * vtkDataObject superclass; the point field attribute data; and the cell 89 * field attribute data. 90 */ 91 vtkSetMacro(InputField, int); 92 vtkGetMacro(InputField, int); SetInputFieldToDataObjectField()93 void SetInputFieldToDataObjectField() { this->SetInputField(VTK_DATA_OBJECT_FIELD); } SetInputFieldToPointDataField()94 void SetInputFieldToPointDataField() { this->SetInputField(VTK_POINT_DATA_FIELD); } SetInputFieldToCellDataField()95 void SetInputFieldToCellDataField() { this->SetInputField(VTK_CELL_DATA_FIELD); } 96 ///@} 97 98 ///@{ 99 /** 100 * Specify which attribute data to output: point or cell data attributes. 101 */ 102 vtkSetMacro(OutputAttributeData, int); 103 vtkGetMacro(OutputAttributeData, int); SetOutputAttributeDataToCellData()104 void SetOutputAttributeDataToCellData() { this->SetOutputAttributeData(VTK_CELL_DATA); } SetOutputAttributeDataToPointData()105 void SetOutputAttributeDataToPointData() { this->SetOutputAttributeData(VTK_POINT_DATA); } 106 ///@} 107 108 ///@{ 109 /** 110 * Define the component(s) of the field to be used for the scalar 111 * components. Note that the parameter comp must lie between (0,4). To 112 * define the field component to use you specify an array name and the 113 * component in that array. The (min,max) values are the range of data in 114 * the component you wish to extract. 115 */ 116 void SetScalarComponent( 117 int comp, const char* arrayName, int arrayComp, int min, int max, int normalize); SetScalarComponent(int comp,const char * arrayName,int arrayComp)118 void SetScalarComponent(int comp, const char* arrayName, int arrayComp) 119 { 120 this->SetScalarComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize); 121 } 122 const char* GetScalarComponentArrayName(int comp); 123 int GetScalarComponentArrayComponent(int comp); 124 int GetScalarComponentMinRange(int comp); 125 int GetScalarComponentMaxRange(int comp); 126 int GetScalarComponentNormalizeFlag(int comp); 127 ///@} 128 129 ///@{ 130 /** 131 * Define the component(s) of the field to be used for the vector 132 * components. Note that the parameter comp must lie between (0,3). To 133 * define the field component to use you specify an array name and the 134 * component in that array. The (min,max) values are the range of data in 135 * the component you wish to extract. 136 */ 137 void SetVectorComponent( 138 int comp, const char* arrayName, int arrayComp, int min, int max, int normalize); SetVectorComponent(int comp,const char * arrayName,int arrayComp)139 void SetVectorComponent(int comp, const char* arrayName, int arrayComp) 140 { 141 this->SetVectorComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize); 142 } 143 const char* GetVectorComponentArrayName(int comp); 144 int GetVectorComponentArrayComponent(int comp); 145 int GetVectorComponentMinRange(int comp); 146 int GetVectorComponentMaxRange(int comp); 147 int GetVectorComponentNormalizeFlag(int comp); 148 ///@} 149 150 ///@{ 151 /** 152 * Define the component(s) of the field to be used for the normal 153 * components. Note that the parameter comp must lie between (0,3). To 154 * define the field component to use you specify an array name and the 155 * component in that array. The (min,max) values are the range of data in 156 * the component you wish to extract. 157 */ 158 void SetNormalComponent( 159 int comp, const char* arrayName, int arrayComp, int min, int max, int normalize); SetNormalComponent(int comp,const char * arrayName,int arrayComp)160 void SetNormalComponent(int comp, const char* arrayName, int arrayComp) 161 { 162 this->SetNormalComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize); 163 } 164 const char* GetNormalComponentArrayName(int comp); 165 int GetNormalComponentArrayComponent(int comp); 166 int GetNormalComponentMinRange(int comp); 167 int GetNormalComponentMaxRange(int comp); 168 int GetNormalComponentNormalizeFlag(int comp); 169 ///@} 170 171 ///@{ 172 /** 173 * Define the components of the field to be used for the tensor 174 * components. Note that the parameter comp must lie between (0,9). To 175 * define the field component to use you specify an array name and the 176 * component in that array. The (min,max) values are the range of data in 177 * the component you wish to extract. 178 */ 179 void SetTensorComponent( 180 int comp, const char* arrayName, int arrayComp, int min, int max, int normalize); SetTensorComponent(int comp,const char * arrayName,int arrayComp)181 void SetTensorComponent(int comp, const char* arrayName, int arrayComp) 182 { 183 this->SetTensorComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize); 184 } 185 const char* GetTensorComponentArrayName(int comp); 186 int GetTensorComponentArrayComponent(int comp); 187 int GetTensorComponentMinRange(int comp); 188 int GetTensorComponentMaxRange(int comp); 189 int GetTensorComponentNormalizeFlag(int comp); 190 ///@} 191 192 ///@{ 193 /** 194 * Define the components of the field to be used for the cell texture coord 195 * components. Note that the parameter comp must lie between (0,9). To 196 * define the field component to use you specify an array name and the 197 * component in that array. The (min,max) values are the range of data in 198 * the component you wish to extract. 199 */ 200 void SetTCoordComponent( 201 int comp, const char* arrayName, int arrayComp, int min, int max, int normalize); SetTCoordComponent(int comp,const char * arrayName,int arrayComp)202 void SetTCoordComponent(int comp, const char* arrayName, int arrayComp) 203 { 204 this->SetTCoordComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize); 205 } 206 const char* GetTCoordComponentArrayName(int comp); 207 int GetTCoordComponentArrayComponent(int comp); 208 int GetTCoordComponentMinRange(int comp); 209 int GetTCoordComponentMaxRange(int comp); 210 int GetTCoordComponentNormalizeFlag(int comp); 211 ///@} 212 213 ///@{ 214 /** 215 * Set the default Normalize() flag for those methods setting a default 216 * Normalize value (e.g., SetScalarComponents). 217 */ 218 vtkSetMacro(DefaultNormalize, vtkTypeBool); 219 vtkGetMacro(DefaultNormalize, vtkTypeBool); 220 vtkBooleanMacro(DefaultNormalize, vtkTypeBool); 221 ///@} 222 223 // Helper functions, made public to support other classes 224 225 /** 226 * Given an array of names of arrays in field data, return the common type 227 * for these arrays. For example, if a vector is constructed of the three 228 * type (char,int,float), the return type is float. 229 */ 230 static int GetComponentsType(int numComp, vtkDataArray** arrays); 231 232 /** 233 * Construct a portion of a data array (the comp portion) from another data 234 * array and its component. The variables min and max control the range of 235 * the data to use from the other data array; normalize is a flag that when 236 * set will normalize the data between (0,1). 237 */ 238 static int ConstructArray(vtkDataArray* da, int comp, vtkDataArray* fieldArray, int fieldComp, 239 vtkIdType min, vtkIdType max, int normalize); 240 241 /** 242 * Return an array of a particular name from field data and do error checking. 243 */ 244 static vtkDataArray* GetFieldArray(vtkFieldData* fd, const char* name, int comp); 245 246 /** 247 * Specify an array name for one of the components. 248 */ 249 static void SetArrayName(vtkObject* self, char*& name, const char* newName); 250 251 /** 252 * Update the maximum and minimum component range values. Returns a flag 253 * indicating whether the range was updated. 254 */ 255 static int UpdateComponentRange(vtkDataArray* da, vtkIdType compRange[2]); 256 257 /** 258 * If output does not need exact extent, the I do not either. 259 */ 260 int RequestUpdateExtent(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; 261 262 protected: 263 vtkFieldDataToAttributeDataFilter(); 264 ~vtkFieldDataToAttributeDataFilter() override; 265 266 int RequestData(vtkInformation*, vtkInformationVector**, 267 vtkInformationVector*) override; // generate output data 268 269 int InputField; 270 int OutputAttributeData; 271 272 int NumberOfScalarComponents; // the number of components to fill-in 273 char* ScalarArrays[4]; // the name of the arrays used to construct the scalar 274 int ScalarArrayComponents[4]; // the components of the arrays used to construct 275 vtkIdType ScalarComponentRange[4][2]; // the range of the components to use 276 int ScalarNormalize[4]; // flags control normalization 277 278 char* VectorArrays[3]; // the name of the arrays used to construct the vectors 279 int VectorArrayComponents[3]; // the components of the arrays used to construct 280 vtkIdType VectorComponentRange[3][2]; // the range of the components to use 281 int VectorNormalize[3]; // flags control normalization 282 283 char* GhostLevelArray; // the name of the array used to construct the ghost levels 284 int GhostLevelArrayComponent; // the component of the array used to construct 285 vtkIdType GhostLevelComponentRange[2]; // the range of the components to use 286 int GhostLevelNormalize; // flags control normalization 287 288 char* NormalArrays[3]; // the name of the arrays used to construct the normals 289 int NormalArrayComponents[3]; // the components of the arrays used to construct 290 vtkIdType NormalComponentRange[3][2]; // the range of the components to use 291 int NormalNormalize[3]; // flags control normalization 292 293 char* TensorArrays[9]; // the name of the arrays used to construct the tensors 294 int TensorArrayComponents[9]; // the components of the arrays used to construct 295 vtkIdType TensorComponentRange[9][2]; // the range of the components to use 296 int TensorNormalize[9]; // flags control normalization 297 298 int NumberOfTCoordComponents; // the number of components to fill-in 299 char* TCoordArrays[3]; // the name of the arrays used to construct the tcoords 300 int TCoordArrayComponents[3]; // the components of the arrays used to construct 301 vtkIdType TCoordComponentRange[3][2]; // the range of the components to use 302 int TCoordNormalize[3]; // flags control normalization 303 304 vtkTypeBool DefaultNormalize; 305 306 void ConstructScalars(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 307 vtkIdType componentRange[4][2], char* arrays[4], int arrayComponents[4], int normalize[4], 308 int numComp); 309 void ConstructVectors(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 310 vtkIdType componentRange[3][2], char* arrays[3], int arrayComponents[3], int normalize[3]); 311 void ConstructGhostLevels(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 312 vtkIdType componentRange[2], char* array, int arrayComponent, int normalize); 313 void ConstructNormals(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 314 vtkIdType componentRange[3][2], char* arrays[3], int arrayComponents[3], int normalize[3]); 315 void ConstructTCoords(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 316 vtkIdType componentRange[3][2], char* arrays[3], int arrayComponents[3], int normalize[3], 317 int numComp); 318 void ConstructTensors(int num, vtkFieldData* fd, vtkDataSetAttributes* attr, 319 vtkIdType componentRange[9][2], char* arrays[9], int arrayComponents[9], int normalize[9]); 320 void ConstructFieldData(int num, vtkDataSetAttributes* attr); 321 322 private: 323 vtkFieldDataToAttributeDataFilter(const vtkFieldDataToAttributeDataFilter&) = delete; 324 void operator=(const vtkFieldDataToAttributeDataFilter&) = delete; 325 }; 326 327 #endif 328