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

Common/vtkIntArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkIntArray.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 =========================================================================*/
00045 #ifndef __vtkIntArray_h
00046 #define __vtkIntArray_h
00047 
00048 #include "vtkDataArray.h"
00049 
00050 class VTK_COMMON_EXPORT vtkIntArray : public vtkDataArray
00051 {
00052 public:
00053   static vtkIntArray *New();
00054 
00055   vtkTypeRevisionMacro(vtkIntArray,vtkDataArray);
00056   void PrintSelf(ostream& os, vtkIndent indent);
00057 
00060   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00061   
00063   void Initialize();
00064 
00066 
00067   int GetDataType() 
00068     {return VTK_INT;}
00070 
00072   int GetDataTypeSize() { return sizeof(int); }
00073 
00075 
00076   void Squeeze() 
00077     {this->ResizeAndExtend (this->MaxId+1);}
00079 
00081   virtual void Resize(vtkIdType numTuples);
00082 
00084   void SetNumberOfTuples(const vtkIdType number);
00085 
00088   float *GetTuple(const vtkIdType i);
00089   
00091 
00092   void GetTuple(const vtkIdType i, float * tuple);
00093   void GetTuple(const vtkIdType i, double * tuple);
00095 
00097 
00098   void SetTuple(const vtkIdType i, const float * tuple);
00099   void SetTuple(const vtkIdType i, const double * tuple);
00101 
00103 
00105   void InsertTuple(const vtkIdType i, const float * tuple);
00106   void InsertTuple(const vtkIdType i, const double * tuple);
00108 
00110 
00112   vtkIdType InsertNextTuple(const float * tuple);
00113   vtkIdType InsertNextTuple(const double * tuple);
00115 
00117 
00118   int GetValue(const vtkIdType id) 
00119     {return this->Array[id];}
00121 
00123 
00125   void SetValue(const vtkIdType id, const int value) 
00126     {this->Array[id] = value;}
00128 
00132   void SetNumberOfValues(const vtkIdType number);
00133 
00135   void InsertValue(const vtkIdType id, const int i);
00136 
00139   vtkIdType InsertNextValue(const int i);
00140 
00144   float GetComponent(const vtkIdType i, const int j);
00145   
00150   void SetComponent(const vtkIdType i, const int j, float c);
00151   
00155   virtual void InsertComponent(const vtkIdType i, const int j, float c);
00156 
00158 
00160   int *GetPointer(const vtkIdType id) 
00161     {return this->Array + id;}
00162   void *GetVoidPointer(const vtkIdType id) 
00163     {return (void *)this->GetPointer(id);}
00165 
00169   int *WritePointer(const vtkIdType id, const vtkIdType number);
00170 
00172   void DeepCopy(vtkDataArray *ia);
00173 
00175 
00181   void SetArray(int* array, vtkIdType size, int save);
00182   void SetVoidArray(void *array,vtkIdType size, int save) 
00183     {this->SetArray((int*)array, size, save);};
00185 
00186 protected:
00187   vtkIntArray(vtkIdType numComp=1);
00188   ~vtkIntArray();
00189 
00190   int *Array;   // pointer to data
00191   int *ResizeAndExtend(const vtkIdType sz);  // function to resize data
00192 
00193   int TupleSize; //used for data conversion
00194   float *Tuple;
00195 
00196   int SaveUserArray;
00197 private:
00198   vtkIntArray(const vtkIntArray&);  // Not implemented.
00199   void operator=(const vtkIntArray&);  // Not implemented.
00200 };
00201 
00202 
00203 inline void vtkIntArray::SetNumberOfValues(const vtkIdType number) 
00204 {
00205   this->Allocate(number);
00206   this->MaxId = number - 1;
00207 }
00208 
00209 inline int *vtkIntArray::WritePointer(const vtkIdType id,
00210                                       const vtkIdType number)
00211 {
00212   vtkIdType newSize=id+number;
00213   if ( newSize > this->Size )
00214     {
00215     this->ResizeAndExtend(newSize);
00216     }
00217   if ( (--newSize) > this->MaxId )
00218     {
00219     this->MaxId = newSize;
00220     }
00221   return this->Array + id;
00222 }
00223 
00224 inline void vtkIntArray::InsertValue(const vtkIdType id, const int i)
00225 {
00226   if ( id >= this->Size )
00227     {
00228     this->ResizeAndExtend(id+1);
00229     }
00230   this->Array[id] = i;
00231   if ( id > this->MaxId )
00232     {
00233     this->MaxId = id;
00234     }
00235 }
00236 
00237 inline vtkIdType vtkIntArray::InsertNextValue(const int i)
00238 {
00239   this->InsertValue (++this->MaxId,i); 
00240   return this->MaxId;
00241 }
00242 
00243 
00244 #endif