Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Common/vtkFieldData.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkFieldData.h,v $
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 "vtkDataArray.h" // Needed for inline methods
00051 
00052 class vtkIdList;
00053 
00054 class VTK_COMMON_EXPORT vtkFieldData : public vtkObject
00055 {
00056 public:
00057   static vtkFieldData *New();
00058 
00059   vtkTypeRevisionMacro(vtkFieldData,vtkObject);
00060   void PrintSelf(ostream& os, vtkIndent indent);
00061 
00064   virtual void Initialize();
00065 
00067   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00068 
00071   void CopyStructure(vtkFieldData*);
00072 
00079   void AllocateArrays(int num);
00080 
00084   int GetNumberOfArrays();
00085 
00088   int AddArray(vtkDataArray *array);
00089 
00091 
00092   virtual void RemoveArray(const char *name)
00093     {
00094       int i;
00095       this->GetArray(name, i);
00096       this->RemoveArray(i);
00097     }
00099 
00102   vtkDataArray *GetArray(int i);
00103 
00106   vtkDataArray *GetArray(const char *arrayName, int &index);
00107 
00108   // Return the array with the name given. Returns NULL is array not found.
00109   vtkDataArray *GetArray(const char *arrayName);
00110 
00112 
00114   const char* GetArrayName(int i)
00115     {
00116     vtkDataArray* da = this->GetArray(i);
00117     if (da)
00118       {
00119       return da->GetName();
00120       }
00121     else
00122       {
00123       return 0;
00124       }
00125     }
00127 
00130   virtual void PassData(vtkFieldData* fd);
00131 
00133 
00138   void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
00139   void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
00141 
00147   virtual void CopyAllOn();
00148 
00154   virtual void CopyAllOff();
00155 
00157   virtual void DeepCopy(vtkFieldData *da);
00158 
00160   virtual void ShallowCopy(vtkFieldData *da);
00161 
00164   void Squeeze();
00165 
00168   void Reset();
00169 
00174   virtual unsigned long GetActualMemorySize();
00175 
00177   unsigned long int GetMTime();
00178   
00186   void GetField(vtkIdList *ptId, vtkFieldData *f);
00187 
00196   int GetArrayContainingComponent(int i, int& arrayComp);
00197 
00204   int GetNumberOfComponents();
00205 
00213   vtkIdType GetNumberOfTuples();
00214 
00220   void SetNumberOfTuples(const vtkIdType number);
00221 
00228   double *GetTuple(const vtkIdType i);
00229 
00236   void GetTuple(const vtkIdType i, double * tuple);
00237 
00244   void SetTuple(const vtkIdType i, const double * tuple);
00245 
00252   void InsertTuple(const vtkIdType i, const double * tuple);
00253 
00260   vtkIdType InsertNextTuple(const double * tuple);
00261 
00267   double GetComponent(const vtkIdType i, const int j);
00268 
00276   void SetComponent(const vtkIdType i, const int j, const double c);
00277   
00285   void InsertComponent(const vtkIdType i, const int j, const double c);
00286 
00287 protected:
00288 
00289   vtkFieldData();
00290   ~vtkFieldData();
00291 
00292   int NumberOfArrays;
00293   int NumberOfActiveArrays;
00294   vtkDataArray **Data;
00295 
00296   int TupleSize; //used for type conversion
00297   double *Tuple;
00298 
00300   void SetArray(int i, vtkDataArray *array);
00301 
00302   virtual void RemoveArray(int index);
00303 
00305   virtual void InitializeFields();
00306 
00307 //BTX
00308 
00309   struct CopyFieldFlag
00310   {
00311     char* ArrayName;
00312     int IsCopied;
00313   };
00314 
00315   CopyFieldFlag* CopyFieldFlags; //the names of fields not to be copied
00316   int NumberOfFieldFlags; //the number of fields not to be copied
00317   void CopyFieldOnOff(const char* name, int onOff);
00318   void ClearFieldFlags();
00319   int FindFlag(const char* field);
00320   int GetFlag(const char* field);
00321   void CopyFlags(const vtkFieldData* source);
00322   int DoCopyAllOn;
00323   int DoCopyAllOff;
00324 
00325 
00326 private:
00327   vtkFieldData(const vtkFieldData&);  // Not implemented.
00328   void operator=(const vtkFieldData&);  // Not implemented.
00329 
00330 public:
00331 
00332   class VTK_COMMON_EXPORT BasicIterator
00333   {
00334   public:
00335     BasicIterator();
00336     BasicIterator(const BasicIterator& source);
00337     BasicIterator(const int* list, unsigned int listSize);
00338     BasicIterator& operator=(const BasicIterator& source);
00339     virtual ~BasicIterator();
00340 
00341     int GetListSize() const
00342       {
00343         return this->ListSize;
00344       }
00345     int GetCurrentIndex()
00346       {
00347         return this->List[this->Position];
00348       }
00349     int BeginIndex()
00350       {
00351         this->Position = -1;
00352         return this->NextIndex();
00353       }
00354     int End() const
00355       {
00356         return (this->Position >= this->ListSize);
00357       }
00358     int NextIndex()
00359       {
00360         this->Position++;
00361         return (this->End() ? -1 : this->List[this->Position]);
00362       }
00363     
00364   protected:
00365 
00366     int* List;
00367     int ListSize;
00368     int Position;
00369   };
00370 
00371   class VTK_COMMON_EXPORT Iterator : public BasicIterator
00372   {
00373   public:
00374 
00375     Iterator(const Iterator& source);
00376     Iterator& operator=(const Iterator& source);
00377     virtual ~Iterator();
00378     Iterator(vtkFieldData* dsa, const int* list=0, 
00379              unsigned int listSize=0);
00380 
00381     vtkDataArray* Begin()
00382       {
00383         this->Position = -1;
00384         return this->Next();
00385       }
00386 
00387     vtkDataArray* Next()
00388       {
00389         this->Position++;
00390         return (this->End() ? 0 : 
00391                 Fields->GetArray(this->List[this->Position]));
00392       }
00393 
00394     void DetachFieldData();
00395 
00396   protected:
00397     vtkFieldData* Fields;
00398     int Detached;
00399   };
00400 
00401 
00402 //ETX
00403 
00404 };
00405 
00406 
00407 #endif