Common/vtkCharArray.h Source File

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

# Common/vtkCharArray.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program:   Visualization Toolkit
    00004   Module:    $RCSfile: vtkCharArray.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 __vtkCharArray_h
    00046 #define __vtkCharArray_h
    00047
    00048 #include "vtkDataArray.h"
    00049
    00050 class VTK_COMMON_EXPORT vtkCharArray : public vtkDataArray
    00051 {
    00052 public:
    00053   static vtkCharArray *New();
    00054
    00055   vtkTypeRevisionMacro(vtkCharArray,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   int GetDataType() {return VTK_CHAR;};
    00067
    00069   int GetDataTypeSize() { return sizeof(char); }
    00070
    00073   void SetNumberOfTuples(const vtkIdType number);
    00074
    00077   float *GetTuple(const vtkIdType i);
    00078
    00080
    00081   void GetTuple(const vtkIdType i, float * tuple);
    00082   void GetTuple(const vtkIdType i, double * tuple);
    00084
    00086
    00087   void SetTuple(const vtkIdType i, const float * tuple);
    00088   void SetTuple(const vtkIdType i, const double * tuple);
    00090
    00092
    00094   void InsertTuple(const vtkIdType i, const float * tuple);
    00095   void InsertTuple(const vtkIdType i, const double * tuple);
    00097
    00099
    00101   vtkIdType InsertNextTuple(const float * tuple);
    00102   vtkIdType InsertNextTuple(const double * tuple);
    00104
    00106   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
    00107
    00109   virtual void Resize(vtkIdType numTuples);
    00110
    00114   float GetComponent(const vtkIdType i, const int j);
    00115
    00120   void SetComponent(const vtkIdType i, const int j, float c);
    00121
    00125   void InsertComponent(const vtkIdType i, const int j, float c);
    00126
    00128   char GetValue(const vtkIdType id) {return this->Array[id];};
    00129
    00131
    00133   void SetValue(const vtkIdType id, const char value)
    00134     { this->Array[id] = value;}
    00136
    00140   void SetNumberOfValues(const vtkIdType number);
    00141
    00145   char *WritePointer(const vtkIdType id, const vtkIdType number);
    00146
    00148   void InsertValue(const vtkIdType id, const char c);
    00149
    00152   vtkIdType InsertNextValue(const char c);
    00153
    00155
    00157   void *GetVoidPointer(const vtkIdType id)
    00158     {return (void *)this->GetPointer(id);};
    00159   char *GetPointer(const vtkIdType id) {return this->Array + id;}
    00161
    00163   void DeepCopy(vtkDataArray *ia);
    00164
    00166
    00172   void SetArray(char* array, vtkIdType size, int save);
    00173   void SetVoidArray(void *array, vtkIdType size, int save)
    00174     {this->SetArray((char*)array, size, save);};
    00176
    00177 protected:
    00178   vtkCharArray(vtkIdType numComp=1);
    00179   ~vtkCharArray();
    00180
    00181   char *Array;    // pointer to data
    00182   char *ResizeAndExtend(const vtkIdType sz);  // function to resize data
    00183
    00184   int TupleSize; //used for data conversion
    00185   float *Tuple;
    00186
    00187   int SaveUserArray;
    00188 private:
    00189   vtkCharArray(const vtkCharArray&);  // Not implemented.
    00190   void operator=(const vtkCharArray&);  // Not implemented.
    00191 };
    00192
    00193
    00194 // Specify the number of values for this object to hold. Does an
    00195 // allocation as well as setting the MaxId ivar. Used in conjunction with
    00196 // SetValue() method for fast insertion.
    00197 inline void vtkCharArray::SetNumberOfValues(const vtkIdType number)
    00198 {
    00199   this->Allocate(number);
    00200   this->MaxId = number - 1;
    00201 }
    00202
    00203
    00204 // Get the address of a particular data index. Make sure data is allocated
    00205 // for the number of items requested. Set MaxId according to the number of
    00206 // data values requested.
    00207 inline char *vtkCharArray::WritePointer(const vtkIdType id,
    00208                                         const vtkIdType number)
    00209 {
    00210   vtkIdType newSize=id+number;
    00211   if ( newSize > this->Size )
    00212     {
    00213     this->ResizeAndExtend(newSize);
    00214     }
    00215   if ( (--newSize) > this->MaxId )
    00216     {
    00217     this->MaxId = newSize;
    00218     }
    00219   return this->Array + id;
    00220 }
    00221
    00222 inline void vtkCharArray::InsertValue(const vtkIdType id, const char c)
    00223 {
    00224   if ( id >= this->Size )
    00225     {
    00226     this->ResizeAndExtend(id+1);
    00227     }
    00228   this->Array[id] = c;
    00229   if ( id > this->MaxId )
    00230     {
    00231     this->MaxId = id;
    00232     }
    00233 }
    00234
    00235 inline vtkIdType vtkCharArray::InsertNextValue(const char c)
    00236 {
    00237   this->InsertValue (++this->MaxId,c);
    00238   return this->MaxId;
    00239 }
    00240
    00241
    00242 #endif