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

vtkShortArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkShortArray.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 =========================================================================*/
00030 #ifndef __vtkShortArray_h
00031 #define __vtkShortArray_h
00032 
00033 #include "vtkDataArray.h"
00034 
00035 class VTK_COMMON_EXPORT vtkShortArray : public vtkDataArray
00036 {
00037 public:
00038   static vtkShortArray *New();
00039 
00040   vtkTypeRevisionMacro(vtkShortArray,vtkDataArray);
00041   void PrintSelf(ostream& os, vtkIndent indent);
00042 
00045   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00046 
00048   void Initialize();
00049 
00051   int GetDataType() {return VTK_SHORT;};
00052 
00054   int GetDataTypeSize() { return sizeof(short); }
00055   
00057   void SetNumberOfTuples(const vtkIdType number);
00058 
00061   float *GetTuple(const vtkIdType i);
00062 
00064 
00065   void GetTuple(const vtkIdType i, float * tuple);
00066   void GetTuple(const vtkIdType i, double * tuple);
00068 
00070 
00071   void SetTuple(const vtkIdType i, const float * tuple);
00072   void SetTuple(const vtkIdType i, const double * tuple);
00074   
00076 
00078   void InsertTuple(const vtkIdType i, const float * tuple);
00079   void InsertTuple(const vtkIdType i, const double * tuple);
00081 
00083 
00085   vtkIdType InsertNextTuple(const float * tuple);
00086   vtkIdType InsertNextTuple(const double * tuple);
00088 
00090   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
00091 
00093   virtual void Resize(vtkIdType numTuples);
00094 
00098   float GetComponent(const vtkIdType i, const int j);
00099   
00104   void SetComponent(const vtkIdType i, const int j, float c);
00105   
00109   void InsertComponent(const vtkIdType i, const int j, float c);
00110 
00112   short GetValue(const vtkIdType id) {return this->Array[id];};
00113 
00115 
00117   void SetValue(const vtkIdType id, const short value)
00118     {this->Array[id] = value;};
00120 
00124   void SetNumberOfValues(const vtkIdType number);
00125 
00127   void InsertValue(const vtkIdType id, const short i);
00128 
00131   vtkIdType InsertNextValue(const short);
00132 
00136   short *WritePointer(const vtkIdType id, const vtkIdType number);
00137 
00139 
00141   void *GetVoidPointer(const vtkIdType id)
00142     {return (void *)this->GetPointer(id);};
00143   short *GetPointer(const vtkIdType id) {return this->Array + id;}
00145 
00147   void DeepCopy(vtkDataArray *da);
00148   
00150 
00156   void SetArray(short* array, vtkIdType size, int save);
00157   void SetVoidArray(void *array, vtkIdType size, int save) 
00158     {this->SetArray((short*)array, size, save);};
00160   
00161 protected:
00162   vtkShortArray(vtkIdType numComp=1);
00163   ~vtkShortArray();
00164 
00165   short *Array;   // pointer to data
00166   short *ResizeAndExtend(const vtkIdType sz);  // function to resize data
00167 
00168   int TupleSize; //used for data conversion
00169   float *Tuple;
00170 
00171   int SaveUserArray;
00172 private:
00173   vtkShortArray(const vtkShortArray&);  // Not implemented.
00174   void operator=(const vtkShortArray&);  // Not implemented.
00175 };
00176 
00177 inline void vtkShortArray::SetNumberOfValues(const vtkIdType number) 
00178 {
00179   this->Allocate(number);
00180   this->MaxId = number - 1;
00181 }
00182 
00183 
00184 inline short *vtkShortArray::WritePointer(const vtkIdType id,
00185                                           const vtkIdType number) 
00186 {
00187   vtkIdType newSize=id+number;
00188   if ( newSize > this->Size )
00189     {
00190     this->ResizeAndExtend(newSize);
00191     }
00192   if ( (--newSize) > this->MaxId )
00193     {
00194     this->MaxId = newSize;
00195     }
00196   return this->Array + id;
00197 }
00198 
00199 inline void vtkShortArray::InsertValue(const vtkIdType id, const short i)
00200 {
00201   if ( id >= this->Size )
00202     {
00203     this->ResizeAndExtend(id+1);
00204     }
00205   this->Array[id] = i;
00206   if ( id > this->MaxId )
00207     {
00208     this->MaxId = id;
00209     }
00210 }
00211 
00212 inline vtkIdType vtkShortArray::InsertNextValue(const short i)
00213 {
00214   this->InsertValue (++this->MaxId,i); 
00215   return this->MaxId;
00216 }
00217 
00218 
00219 #endif