VTK
dox/Filtering/vtkFieldData.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkFieldData.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 =========================================================================*/
00045 #ifndef __vtkFieldData_h
00046 #define __vtkFieldData_h
00047 
00048 #include "vtkObject.h"
00049 
00050 #include "vtkAbstractArray.h" // Needed for inline methods.
00051 
00052 #ifndef VTK_LEGACY_REMOVE
00053 # include "vtkDataArray.h" // Needed for backwards compatibility.
00054 #endif
00055 
00056 class vtkIdList;
00057 
00058 class VTK_FILTERING_EXPORT vtkFieldData : public vtkObject
00059 {
00060 public:
00061   static vtkFieldData *New();
00062 
00063   vtkTypeMacro(vtkFieldData,vtkObject);
00064   void PrintSelf(ostream& os, vtkIndent indent);
00065 
00068   virtual void Initialize();
00069 
00071   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00072 
00075   void CopyStructure(vtkFieldData*);
00076 
00083   void AllocateArrays(int num);
00084 
00086 
00089   int GetNumberOfArrays()
00090     {
00091       return this->NumberOfActiveArrays;
00092     }
00094 
00097   int AddArray(vtkAbstractArray *array);
00098 
00100 
00101   virtual void RemoveArray(const char *name)
00102     {
00103       int i;
00104       this->GetAbstractArray(name, i);
00105       this->RemoveArray(i);
00106     }
00108 
00112   vtkDataArray *GetArray(int i);
00113 
00118   vtkDataArray *GetArray(const char *arrayName, int &index);
00119 
00121 
00124   vtkDataArray *GetArray(const char *arrayName)
00125     {
00126       int i;
00127       return this->GetArray(arrayName, i);
00128     }
00130 
00134   vtkAbstractArray* GetAbstractArray(int i);
00135 
00139   vtkAbstractArray* GetAbstractArray(const char* arrayName, int &index);
00140 
00142 
00144   vtkAbstractArray* GetAbstractArray(const char* arrayName)
00145     {
00146     int i;
00147     return this->GetAbstractArray(arrayName, i);
00148     }
00150   
00152 
00153   int HasArray(const char *name)
00154     {
00155       int i;
00156       vtkAbstractArray *array = this->GetAbstractArray(name, i);
00157       // assert( i == -1);
00158       return array ? 1 : 0;
00159     }
00161 
00163 
00165   const char* GetArrayName(int i)
00166     {
00167     vtkAbstractArray* da = this->GetAbstractArray(i);
00168     return da ? da->GetName() : 0;
00169     }
00171 
00174   virtual void PassData(vtkFieldData* fd);
00175 
00177 
00182   void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
00183   void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
00185 
00191   virtual void CopyAllOn(int unused=0);
00192 
00198   virtual void CopyAllOff(int unused=0);
00199 
00201   virtual void DeepCopy(vtkFieldData *da);
00202 
00204   virtual void ShallowCopy(vtkFieldData *da);
00205 
00208   void Squeeze();
00209 
00212   void Reset();
00213 
00218   virtual unsigned long GetActualMemorySize();
00219 
00221   unsigned long int GetMTime();
00222   
00230   void GetField(vtkIdList *ptId, vtkFieldData *f);
00231 
00237   int GetArrayContainingComponent(int i, int& arrayComp);
00238 
00245   int GetNumberOfComponents();
00246 
00254   vtkIdType GetNumberOfTuples();
00255 
00261   void SetNumberOfTuples(const vtkIdType number);
00262 
00266   void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
00267 
00270   void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
00271 
00275   vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
00276 
00277   // Following are LEGACY methods. Using these methods for FieldData
00278   // having arrays that are not subclasses of vtkDataArray may
00279   // yield unexpected results.
00280   
00286   VTK_LEGACY(double *GetTuple(const vtkIdType i));
00287 
00292   VTK_LEGACY(void GetTuple(const vtkIdType i, double * tuple));
00293 
00298   VTK_LEGACY(void SetTuple(const vtkIdType i, const double * tuple));
00299 
00304   VTK_LEGACY(void InsertTuple(const vtkIdType i, const double * tuple));
00305 
00310   VTK_LEGACY(vtkIdType InsertNextTuple(const double * tuple));
00311   
00316   VTK_LEGACY(double GetComponent(const vtkIdType i, const int j));
00317 
00323   VTK_LEGACY(void SetComponent(const vtkIdType i, const int j, const double c));
00324   
00326 
00331   VTK_LEGACY(void InsertComponent(const vtkIdType i, const int j, const double c));
00332 protected:
00334 
00335   vtkFieldData();
00336   ~vtkFieldData();
00337 
00338   int NumberOfArrays;
00339   int NumberOfActiveArrays;
00340   vtkAbstractArray **Data;
00341 
00343   void SetArray(int i, vtkAbstractArray *array);
00344 
00345   virtual void RemoveArray(int index);
00346 
00348   virtual void InitializeFields();
00349 
00350 //BTX
00351 
00352   struct CopyFieldFlag
00353   {
00354     char* ArrayName;
00355     int IsCopied;
00356   };
00357 
00358   CopyFieldFlag* CopyFieldFlags; //the names of fields not to be copied
00359   int NumberOfFieldFlags; //the number of fields not to be copied
00360   void CopyFieldOnOff(const char* name, int onOff);
00361   void ClearFieldFlags();
00362   int FindFlag(const char* field);
00363   int GetFlag(const char* field);
00364   void CopyFlags(const vtkFieldData* source);
00365   int DoCopyAllOn;
00366   int DoCopyAllOff;
00367 
00368 
00369 private:
00370   vtkFieldData(const vtkFieldData&);  // Not implemented.
00371   void operator=(const vtkFieldData&);  // Not implemented.
00372 
00373 #ifndef VTK_LEGACY_REMOVE
00374   // Must be removed when support for Legacy GetTuple is removed.
00375   int TupleSize; // used for type conversion in Legacy support.
00376   double* Tuple;
00377 #endif
00378 public:
00379 
00380   class VTK_FILTERING_EXPORT BasicIterator
00381   {
00382   public:
00383     BasicIterator();
00384     BasicIterator(const BasicIterator& source);
00385     BasicIterator(const int* list, unsigned int listSize);
00386     BasicIterator& operator=(const BasicIterator& source);
00387     virtual ~BasicIterator();
00388     void PrintSelf(ostream &os, vtkIndent indent);
00389 
00390     int GetListSize() const
00391       {
00392         return this->ListSize;
00393       }
00394     int GetCurrentIndex()
00395       {
00396         return this->List[this->Position];
00397       }
00398     int BeginIndex()
00399       {
00400         this->Position = -1;
00401         return this->NextIndex();
00402       }
00403     int End() const
00404       {
00405         return (this->Position >= this->ListSize);
00406       }
00407     int NextIndex()
00408       {
00409         this->Position++;
00410         return (this->End() ? -1 : this->List[this->Position]);
00411       }
00412     
00413   protected:
00414 
00415     int* List;
00416     int ListSize;
00417     int Position;
00418   };
00419 
00420   class VTK_FILTERING_EXPORT Iterator : public BasicIterator
00421   {
00422   public:
00423 
00424     Iterator(const Iterator& source);
00425     Iterator& operator=(const Iterator& source);
00426     virtual ~Iterator();
00427     Iterator(vtkFieldData* dsa, const int* list=0, 
00428              unsigned int listSize=0);
00429 
00430     vtkDataArray* Begin()
00431       {
00432         this->Position = -1;
00433         return this->Next();
00434       }
00435 
00436     vtkDataArray* Next()
00437       {
00438         this->Position++;
00439         if (this->End())
00440           {
00441           return 0;
00442           }
00443       
00444         // vtkFieldData::GetArray() can return null, which implies that
00445         // a the array at the given index in not a vtkDataArray subclass.
00446         // This iterator skips such arrays.
00447         vtkDataArray* cur =  Fields->GetArray(this->List[this->Position]);
00448         return (cur? cur : this->Next());
00449       }
00450 
00451     void DetachFieldData();
00452 
00453   protected:
00454     vtkFieldData* Fields;
00455     int Detached;
00456   };
00457 
00458 
00459 //ETX
00460 
00461 };
00462 
00463 
00464 #endif