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

Common/vtkVoidArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkVoidArray.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00041 #ifndef __vtkVoidArray_h
00042 #define __vtkVoidArray_h
00043 
00044 #include "vtkDataArray.h"
00045 
00046 class VTK_COMMON_EXPORT vtkVoidArray : public vtkDataArray
00047 {
00048 public:
00049   static vtkVoidArray *New();
00050 
00051   vtkTypeRevisionMacro(vtkVoidArray,vtkDataArray);
00052   void PrintSelf(ostream& os, vtkIndent indent);
00053 
00056   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00057 
00059   void Initialize();
00060 
00062   int GetDataType() {return VTK_VOID;};
00063   
00065   int GetDataTypeSize() { return sizeof(void*); }
00066   
00068   void SetNumberOfTuples(const vtkIdType number);
00069 
00071   float *GetTuple(const vtkIdType i);
00072 
00074 
00075   void GetTuple(const vtkIdType i, float * tuple);
00076   void GetTuple(const vtkIdType i, double * tuple);
00078 
00080 
00081   void SetTuple(const vtkIdType i, const float * tuple);
00082   void SetTuple(const vtkIdType i, const double * tuple);
00084 
00086 
00088   void InsertTuple(const vtkIdType i, const float * tuple);
00089   void InsertTuple(const vtkIdType i, const double * tuple);
00091 
00093 
00095   vtkIdType InsertNextTuple(const float * tuple);
00096   vtkIdType InsertNextTuple(const double * tuple);
00098 
00100   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
00101 
00103   virtual void Resize(vtkIdType numTuples);
00104 
00106   void* GetValue(const vtkIdType id) {return this->Array[id];};
00107 
00111   void SetNumberOfValues(const vtkIdType number);
00112 
00115   void SetValue(const vtkIdType id, void *value);
00116 
00118   void InsertValue(const vtkIdType id, void* p);
00119 
00122   vtkIdType InsertNextValue(void* v);
00123 
00125 
00127   void** GetPointer(const vtkIdType id) {return this->Array + id;}
00128   void *GetVoidPointer(const vtkIdType id) {return this->GetPointer(id);};
00130 
00134   void** WritePointer(const vtkIdType id, const vtkIdType number);
00135   
00137   void DeepCopy(vtkDataArray *da);
00138   
00139 
00140 protected:
00141   vtkVoidArray();
00142   ~vtkVoidArray();
00143 
00144   void** Array;  // pointer to data
00145   void** ResizeAndExtend(const vtkIdType sz);  // function to resize data
00146 
00147   int TupleSize; //used for data conversion
00148   float *Tuple;
00149 private:
00150   vtkVoidArray(const vtkVoidArray&);  // Not implemented.
00151   void operator=(const vtkVoidArray&);  // Not implemented.
00152 };
00153 
00154 
00155 inline void vtkVoidArray::SetNumberOfValues(const vtkIdType number) 
00156 {
00157   this->Allocate(number);
00158   this->MaxId = number - 1;
00159 }
00160 
00161 inline void vtkVoidArray::SetValue(const vtkIdType id, void *value) 
00162 {
00163   this->Array[id] = value;
00164 }
00165 
00166 inline void** vtkVoidArray::WritePointer(const vtkIdType id,
00167                                          const vtkIdType number) 
00168 {
00169   vtkIdType newSize=id+number;
00170   if ( newSize > this->Size )
00171     {
00172     this->ResizeAndExtend(newSize);
00173     }
00174   if ( (--newSize) > this->MaxId )
00175     {
00176     this->MaxId = newSize;
00177     }
00178   return this->Array + id;
00179 }
00180 
00181 inline void vtkVoidArray::InsertValue(const vtkIdType id, void* p)
00182 {
00183   if ( id >= this->Size )
00184     {
00185     this->ResizeAndExtend(id+1);
00186     }
00187   this->Array[id] = p;
00188   if ( id > this->MaxId )
00189     {
00190     this->MaxId = id;
00191     }
00192 }
00193 
00194 inline vtkIdType vtkVoidArray::InsertNextValue(void* p)
00195 {
00196   this->InsertValue (++this->MaxId,p);
00197   return this->MaxId;
00198 }
00199 
00200 
00201 #endif