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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00054 #ifndef __vtkCharArray_h
00055 #define __vtkCharArray_h
00056 
00057 #include "vtkDataArray.h"
00058 
00059 class VTK_COMMON_EXPORT vtkCharArray : public vtkDataArray
00060 {
00061 public:
00062   static vtkCharArray *New();
00063 
00064   vtkTypeMacro(vtkCharArray,vtkDataArray);
00065   void PrintSelf(ostream& os, vtkIndent indent);
00066 
00069   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00070 
00072   void Initialize();
00073 
00075   vtkDataArray *MakeObject();
00076   
00078   int GetDataType() {return VTK_CHAR;};
00079 
00082   void SetNumberOfTuples(const vtkIdType number);
00083 
00086   float *GetTuple(const vtkIdType i);
00087 
00089 
00090   void GetTuple(const vtkIdType i, float * tuple);
00091   void GetTuple(const vtkIdType i, double * tuple);
00093 
00095 
00096   void SetTuple(const vtkIdType i, const float * tuple);
00097   void SetTuple(const vtkIdType i, const double * tuple);
00099 
00101 
00103   void InsertTuple(const vtkIdType i, const float * tuple);
00104   void InsertTuple(const vtkIdType i, const double * tuple);
00106 
00108 
00110   vtkIdType InsertNextTuple(const float * tuple);
00111   vtkIdType InsertNextTuple(const double * tuple);
00113 
00115   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00116 
00118   virtual void Resize(vtkIdType numTuples);
00119 
00123   float GetComponent(const vtkIdType i, const int j);
00124 
00129   void SetComponent(const vtkIdType i, const int j, const float c);
00130 
00134   void InsertComponent(const vtkIdType i, const int j, const float c);
00135 
00137   char GetValue(const vtkIdType id) {return this->Array[id];};
00138 
00140 
00142   void SetValue(const vtkIdType id, const char value)
00143     { this->Array[id] = value;}
00145 
00149   void SetNumberOfValues(const vtkIdType number);
00150 
00154   char *WritePointer(const vtkIdType id, const vtkIdType number);
00155 
00157   void InsertValue(const vtkIdType id, const char c);
00158 
00161   vtkIdType InsertNextValue(const char c);
00162 
00164 
00166   void *GetVoidPointer(const vtkIdType id)
00167     {return (void *)this->GetPointer(id);};
00168   char *GetPointer(const vtkIdType id) {return this->Array + id;}
00170 
00172   void DeepCopy(vtkDataArray *ia);
00173 
00175 
00181   void SetArray(char* array, vtkIdType size, int save);
00182   void SetVoidArray(void *array, vtkIdType size, int save) 
00183     {this->SetArray((char*)array, size, save);};
00185 
00186 protected:
00187   vtkCharArray(vtkIdType numComp=1);
00188   ~vtkCharArray();
00189 
00190   char *Array;    // pointer to data
00191   char *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   vtkCharArray(const vtkCharArray&);  // Not implemented.
00199   void operator=(const vtkCharArray&);  // Not implemented.
00200 };
00201 
00202 
00203 // Specify the number of values for this object to hold. Does an
00204 // allocation as well as setting the MaxId ivar. Used in conjunction with
00205 // SetValue() method for fast insertion.
00206 inline void vtkCharArray::SetNumberOfValues(const vtkIdType number) 
00207 {
00208   this->Allocate(number);
00209   this->MaxId = number - 1;
00210 }
00211 
00212 
00213 // Get the address of a particular data index. Make sure data is allocated
00214 // for the number of items requested. Set MaxId according to the number of
00215 // data values requested.
00216 inline char *vtkCharArray::WritePointer(const vtkIdType id,
00217                                         const vtkIdType number) 
00218 {
00219   vtkIdType newSize=id+number;
00220   if ( newSize > this->Size )
00221     {
00222     this->ResizeAndExtend(newSize);
00223     }
00224   if ( (--newSize) > this->MaxId )
00225     {
00226     this->MaxId = newSize;
00227     }
00228   return this->Array + id;
00229 }
00230 
00231 inline void vtkCharArray::InsertValue(const vtkIdType id, const char c)
00232 {
00233   if ( id >= this->Size )
00234     {
00235     this->ResizeAndExtend(id+1);
00236     }
00237   this->Array[id] = c;
00238   if ( id > this->MaxId )
00239     {
00240     this->MaxId = id;
00241     }
00242 }
00243 
00244 inline vtkIdType vtkCharArray::InsertNextValue(const char c)
00245 {
00246   this->InsertValue (++this->MaxId,c); 
00247   return this->MaxId;
00248 }
00249 
00250 
00251 #endif

Generated on Thu Mar 28 14:19:14 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001