VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkDataSetAttributes.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00049 #ifndef __vtkDataSetAttributes_h 00050 #define __vtkDataSetAttributes_h 00051 00052 #include "vtkCommonDataModelModule.h" // For export macro 00053 #include "vtkFieldData.h" 00054 00055 class vtkLookupTable; 00056 00057 class VTKCOMMONDATAMODEL_EXPORT vtkDataSetAttributes : public vtkFieldData 00058 { 00059 public: 00061 static vtkDataSetAttributes *New(); 00062 00063 vtkTypeMacro(vtkDataSetAttributes,vtkFieldData); 00064 void PrintSelf(ostream& os, vtkIndent indent); 00065 00068 virtual void Initialize(); 00069 00072 virtual void Update() {} 00073 00074 // -- shallow and deep copy ----------------------------------------------- 00075 00078 virtual void DeepCopy(vtkFieldData *pd); 00079 00082 virtual void ShallowCopy(vtkFieldData *pd); 00083 00084 // -- attribute types ----------------------------------------------------- 00085 //BTX 00086 // Always keep NUM_ATTRIBUTES as the last entry 00087 enum AttributeTypes 00088 { 00089 SCALARS=0, 00090 VECTORS=1, 00091 NORMALS=2, 00092 TCOORDS=3, 00093 TENSORS=4, 00094 GLOBALIDS=5, 00095 PEDIGREEIDS=6, 00096 EDGEFLAG=7, 00097 NUM_ATTRIBUTES 00098 }; 00099 00100 enum AttributeLimitTypes 00101 { 00102 MAX, 00103 EXACT, 00104 NOLIMIT 00105 }; 00106 //ETX 00107 00109 00110 int SetScalars(vtkDataArray* da); 00111 int SetActiveScalars(const char* name); 00112 vtkDataArray* GetScalars(); 00114 00116 00117 int SetVectors(vtkDataArray* da); 00118 int SetActiveVectors(const char* name); 00119 vtkDataArray* GetVectors(); 00121 00123 00124 int SetNormals(vtkDataArray* da); 00125 int SetActiveNormals(const char* name); 00126 vtkDataArray* GetNormals(); 00128 00130 00131 int SetTCoords(vtkDataArray* da); 00132 int SetActiveTCoords(const char* name); 00133 vtkDataArray* GetTCoords(); 00135 00137 00138 int SetTensors(vtkDataArray* da); 00139 int SetActiveTensors(const char* name); 00140 vtkDataArray* GetTensors(); 00142 00144 00145 int SetGlobalIds(vtkDataArray* da); 00146 int SetActiveGlobalIds(const char* name); 00147 vtkDataArray* GetGlobalIds(); 00149 00151 00152 int SetPedigreeIds(vtkAbstractArray* da); 00153 int SetActivePedigreeIds(const char* name); 00154 vtkAbstractArray* GetPedigreeIds(); 00156 00158 00161 vtkDataArray* GetScalars(const char* name); 00162 vtkDataArray* GetVectors(const char* name); 00163 vtkDataArray* GetNormals(const char* name); 00164 vtkDataArray* GetTCoords(const char* name); 00165 vtkDataArray* GetTensors(const char* name); 00166 vtkDataArray* GetGlobalIds(const char* name); 00167 vtkAbstractArray* GetPedigreeIds(const char* name); 00169 00177 int SetActiveAttribute(const char* name, int attributeType); 00178 00180 int SetActiveAttribute(int index, int attributeType); 00181 00184 void GetAttributeIndices(int* indexArray); 00185 00190 int IsArrayAnAttribute(int idx); 00191 00196 vtkDataArray* GetAttribute(int attributeType); 00197 00203 vtkAbstractArray* GetAbstractAttribute(int attributeType); 00204 00206 00207 virtual void RemoveArray(const char *name); 00208 virtual void RemoveArray(int index); 00210 00211 00213 00215 static const char* GetAttributeTypeAsString(int attributeType); 00216 static const char* GetLongAttributeTypeAsString(int attributeType); 00218 00219 // -- attribute copy properties ------------------------------------------ 00220 00221 //BTX 00222 enum AttributeCopyOperations 00223 { 00224 COPYTUPLE=0, 00225 INTERPOLATE=1, 00226 PASSDATA=2, 00227 ALLCOPY //all of the above 00228 }; 00229 //ETX 00230 00235 void SetCopyAttribute (int index, int value, int ctype=ALLCOPY); 00236 00238 00249 void SetCopyScalars(int i, int ctype=ALLCOPY); 00250 int GetCopyScalars(int ctype=ALLCOPY); 00251 vtkBooleanMacro(CopyScalars, int); 00253 00255 00266 void SetCopyVectors(int i, int ctype=ALLCOPY); 00267 int GetCopyVectors(int ctype=ALLCOPY); 00268 vtkBooleanMacro(CopyVectors, int); 00270 00272 00283 void SetCopyNormals(int i, int ctype=ALLCOPY); 00284 int GetCopyNormals(int ctype=ALLCOPY); 00285 vtkBooleanMacro(CopyNormals, int); 00287 00289 00300 void SetCopyTCoords(int i, int ctype=ALLCOPY); 00301 int GetCopyTCoords(int ctype=ALLCOPY); 00302 vtkBooleanMacro(CopyTCoords, int); 00304 00306 00317 void SetCopyTensors(int i, int ctype=ALLCOPY); 00318 int GetCopyTensors(int ctype=ALLCOPY); 00319 vtkBooleanMacro(CopyTensors, int); 00321 00323 00334 void SetCopyGlobalIds(int i, int ctype=ALLCOPY); 00335 int GetCopyGlobalIds(int ctype=ALLCOPY); 00336 vtkBooleanMacro(CopyGlobalIds, int); 00338 00340 00351 void SetCopyPedigreeIds(int i, int ctype=ALLCOPY); 00352 int GetCopyPedigreeIds(int ctype=ALLCOPY); 00353 vtkBooleanMacro(CopyPedigreeIds, int); 00355 00367 virtual void CopyAllOn(int ctype=ALLCOPY); 00368 00380 virtual void CopyAllOff(int ctype=ALLCOPY); 00381 00382 // -- passthrough operations ---------------------------------------------- 00383 00391 virtual void PassData(vtkFieldData* fd); 00392 00393 // -- copytuple operations ------------------------------------------------ 00394 00396 00404 void CopyAllocate(vtkDataSetAttributes* pd, vtkIdType sze=0, 00405 vtkIdType ext=1000) 00406 { 00407 this->CopyAllocate(pd, sze, ext, 0); 00408 } 00409 void CopyAllocate(vtkDataSetAttributes* pd, vtkIdType sze, 00410 vtkIdType ext, int shallowCopyArrays); 00412 00414 00416 void CopyStructuredData(vtkDataSetAttributes *inDsa, 00417 const int *inExt, const int *outExt); 00419 00427 void CopyData(vtkDataSetAttributes *fromPd, vtkIdType fromId, vtkIdType toId); 00428 00429 00431 00435 void CopyTuple(vtkAbstractArray *fromData, vtkAbstractArray *toData, 00436 vtkIdType fromId, vtkIdType toId); 00438 00439 00440 // -- interpolate operations ---------------------------------------------- 00441 00443 00448 void InterpolateAllocate(vtkDataSetAttributes* pd, vtkIdType sze=0, 00449 vtkIdType ext=1000) 00450 { 00451 this->InterpolateAllocate(pd, sze, ext, 0); 00452 } 00453 void InterpolateAllocate(vtkDataSetAttributes* pd, vtkIdType sze, 00454 vtkIdType ext, int shallowCopyArrays); 00456 00458 00463 void InterpolatePoint(vtkDataSetAttributes *fromPd, vtkIdType toId, 00464 vtkIdList *ids, double *weights); 00466 00468 00475 void InterpolateEdge(vtkDataSetAttributes *fromPd, vtkIdType toId, 00476 vtkIdType p1, vtkIdType p2, double t); 00478 00480 00490 void InterpolateTime(vtkDataSetAttributes *from1, 00491 vtkDataSetAttributes *from2, 00492 vtkIdType id, double t); 00494 00495 //BTX 00496 class FieldList; 00497 00498 // field list copy operations ------------------------------------------ 00499 00501 00503 void CopyAllocate(vtkDataSetAttributes::FieldList& list, vtkIdType sze=0, 00504 vtkIdType ext=1000); 00506 00508 00512 void CopyData(vtkDataSetAttributes::FieldList& list, 00513 vtkDataSetAttributes* dsa, int idx, vtkIdType fromId, 00514 vtkIdType toId); 00516 00518 00523 void InterpolateAllocate(vtkDataSetAttributes::FieldList& list, vtkIdType sze=0, 00524 vtkIdType ext=1000); 00526 00528 00532 void InterpolatePoint( 00533 vtkDataSetAttributes::FieldList& list, 00534 vtkDataSetAttributes *fromPd, 00535 int idx, vtkIdType toId, 00536 vtkIdList *ids, double *weights); 00538 00539 friend class vtkDataSetAttributes::FieldList; 00540 //ETX 00541 00542 //BTX 00543 protected: 00544 vtkDataSetAttributes(); 00545 ~vtkDataSetAttributes(); 00546 00547 void InternalCopyAllocate(vtkDataSetAttributes* pd, 00548 int ctype, 00549 vtkIdType sze=0, 00550 vtkIdType ext=1000, 00551 int shallowCopyArrays=0); 00552 00553 void InternalCopyAllocate( 00554 vtkDataSetAttributes::FieldList& list, 00555 int ctype, 00556 vtkIdType sze, vtkIdType ext); 00557 00559 virtual void InitializeFields(); 00560 00561 int AttributeIndices[NUM_ATTRIBUTES]; //index to attribute array in field data 00562 int CopyAttributeFlags[ALLCOPY][NUM_ATTRIBUTES]; //copy flag for attribute data 00563 00564 vtkFieldData::BasicIterator RequiredArrays; 00565 00566 int* TargetIndices; 00567 00568 static const int NumberOfAttributeComponents[NUM_ATTRIBUTES]; 00569 static const int AttributeLimits[NUM_ATTRIBUTES]; 00570 static const char AttributeNames[NUM_ATTRIBUTES][12]; 00571 static const char LongAttributeNames[NUM_ATTRIBUTES][35]; 00572 00573 private: 00574 int SetAttribute(vtkAbstractArray* da, int attributeType); 00575 static int CheckNumberOfComponents(vtkAbstractArray* da, int attributeType); 00576 00577 vtkFieldData::BasicIterator ComputeRequiredArrays(vtkDataSetAttributes* pd, int ctype); 00578 00579 private: 00580 vtkDataSetAttributes(const vtkDataSetAttributes&); // Not implemented. 00581 void operator=(const vtkDataSetAttributes&); // Not implemented. 00582 00583 public: 00584 // This public class is used to perform set operations, other misc. 00585 // operations on fields. For example, vtkAppendFilter uses it to 00586 // determine which attributes the input datasets share in common. 00587 class vtkInternalComponentNames; 00588 class VTKCOMMONDATAMODEL_EXPORT FieldList 00589 { 00590 public: 00591 FieldList(int numInputs); 00592 ~FieldList(); 00593 void PrintSelf(ostream &os, vtkIndent indent); 00594 00595 void InitializeFieldList(vtkDataSetAttributes* dsa); 00596 void IntersectFieldList(vtkDataSetAttributes* dsa); 00597 00602 void UnionFieldList(vtkDataSetAttributes* dsa); 00603 00604 //Determine whether data is available 00605 int IsAttributePresent(int attrType); //true/false attributes specified 00606 00607 // Accessor methods. 00608 int GetNumberOfFields() { return this->NumberOfFields; } 00609 int GetFieldIndex(int i) { return this->FieldIndices[i]; } 00610 const char* GetFieldName(int i) { return this->Fields[i]; } 00611 int GetFieldComponents(int i) { return this->FieldComponents[i]; } 00612 int GetDSAIndex(int index, int i) { return this->DSAIndices[index][i]; } 00613 00614 friend class vtkDataSetAttributes; 00615 00616 protected: 00617 FieldList(const FieldList&) {} //prevent these methods from being used 00618 void operator=(const FieldList&) {} 00619 00620 void SetFieldIndex(int i, int index) 00621 { this->FieldIndices[i] = index; } 00622 private: 00623 void SetField(int index, vtkAbstractArray *da); 00624 void RemoveField(const char *name); 00625 void ClearFields(); 00626 void GrowBy(unsigned int delta); 00627 00628 int NumberOfFields; //the number of fields (including five named attributes) 00629 // These keep track of what is common across datasets. The first 00630 // six items are always named attributes. 00631 char** Fields; // the names of the fields 00632 int *FieldTypes; // the types of the fields 00633 int *FieldComponents; // the number of components in field 00634 int *FieldIndices; // output data array index 00635 vtkLookupTable **LUT; // luts associated with each array 00636 vtkInformation **FieldInformation; // Information map associated with each array 00637 00638 vtkInternalComponentNames **FieldComponentsNames; // the name for each component in the field 00639 00640 vtkIdType NumberOfTuples; // a running total of values 00641 00642 //For every vtkDataSetAttributes that are processed, keep track of the 00643 //indices into various things. The indices are organized so that the 00644 //first NUM_ATTRIBUTES refer to attributes, the next refer to the 00645 //non-attribute fields, for a total of NUM_ATTRIBUTES + NumberOfFields. 00646 //CurrentInput is the current input being processed. 00647 int **DSAIndices; 00648 int NumberOfDSAIndices; 00649 int CurrentInput; 00650 00651 }; 00652 //ETX 00653 }; 00654 00655 #endif 00656 00657