dox/Common/vtkDataArrayTemplate.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDataArrayTemplate.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00023 #ifndef __vtkDataArrayTemplate_h
00024 #define __vtkDataArrayTemplate_h
00025 
00026 #include "vtkDataArray.h"
00027 
00028 template <class T>
00029 class vtkDataArrayTemplateLookup;
00030 
00031 template <class T>
00032 class vtkDataArrayTemplate: public vtkDataArray
00033 {
00034 public:
00035   typedef vtkDataArray Superclass;
00036   void PrintSelf(ostream& os, vtkIndent indent);
00037 
00040   int Allocate(vtkIdType sz, vtkIdType ext=1000);
00041 
00043   void Initialize();
00044 
00046   int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
00047 
00049   void SetNumberOfTuples(vtkIdType number);
00050 
00056   virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00057 
00061   virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00062 
00066   virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
00067   
00070   double* GetTuple(vtkIdType i);
00071 
00073 
00074   void GetTuple(vtkIdType i, double* tuple);
00075   void GetTupleValue(vtkIdType i, T* tuple);
00077 
00079 
00080   void SetTuple(vtkIdType i, const float* tuple);
00081   void SetTuple(vtkIdType i, const double* tuple);
00082   void SetTupleValue(vtkIdType i, const T* tuple);
00084 
00086 
00088   void InsertTuple(vtkIdType i, const float* tuple);
00089   void InsertTuple(vtkIdType i, const double* tuple);
00090   void InsertTupleValue(vtkIdType i, const T* tuple);
00092 
00094 
00096   vtkIdType InsertNextTuple(const float* tuple);
00097   vtkIdType InsertNextTuple(const double* tuple);
00098   vtkIdType InsertNextTupleValue(const T* tuple);
00100 
00102   void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
00103 
00105   vtkIdType Capacity() { return this->Size; }
00106 
00108   virtual int Resize(vtkIdType numTuples);
00109 
00111   T GetValue(vtkIdType id) { return this->Array[id]; }
00112 
00114 
00116   void SetValue(vtkIdType id, T value)
00117     { this->Array[id] = value;};
00119 
00123   void SetNumberOfValues(vtkIdType number);
00124 
00126   void InsertValue(vtkIdType id, T f);
00127 
00129   void InsertVariantValue(vtkIdType id, vtkVariant value);
00130 
00133   vtkIdType InsertNextValue(T f);
00134 
00136 
00139   virtual void RemoveTuple(vtkIdType id);
00140   virtual void RemoveFirstTuple();
00141   virtual void RemoveLastTuple();
00143 
00147   double GetComponent(vtkIdType i, int j);
00148 
00153   void SetComponent(vtkIdType i, int j, double c);
00154 
00158   virtual void InsertComponent(vtkIdType i, int j, double c);
00159 
00161 
00164   T* WritePointer(vtkIdType id, vtkIdType number);
00165   virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00166     { return this->WritePointer(id, number); }
00168 
00170 
00172   T* GetPointer(vtkIdType id) { return this->Array + id; }
00173   virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
00175 
00177 
00178   void DeepCopy(vtkDataArray* da);
00179   void DeepCopy(vtkAbstractArray* aa)
00180     { this->Superclass::DeepCopy(aa); }
00182 
00183 //BTX
00184   enum DeleteMethod
00185   {
00186     VTK_DATA_ARRAY_FREE,
00187     VTK_DATA_ARRAY_DELETE
00188   };
00189 //ETX
00190 
00192 
00201   void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
00202   void SetArray(T* array, vtkIdType size, int save)
00203     { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
00204   virtual void SetVoidArray(void* array, vtkIdType size, int save)
00205     { this->SetArray(static_cast<T*>(array), size, save); }
00206   virtual void SetVoidArray(void* array, 
00207                             vtkIdType size, 
00208                             int save, 
00209                             int deleteMethod)
00210     { 
00211       this->SetArray(static_cast<T*>(array), size, save, deleteMethod); 
00212     }
00214 
00218   virtual void ExportToVoidPointer(void *out_ptr);
00219 
00221   virtual void ComputeRange(int comp);
00222 
00224   virtual vtkArrayIterator* NewIterator();
00225   
00226   //BTX
00228 
00229   virtual vtkIdType LookupValue(vtkVariant value);
00230   virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00231   //ETX
00232   vtkIdType LookupValue(T value);
00233   void LookupValue(T value, vtkIdList* ids);
00235   
00242   virtual void DataChanged();
00243   
00247   virtual void DataElementChanged(vtkIdType id);
00248 
00252   virtual void ClearLookup();
00253   
00254 protected:
00255   vtkDataArrayTemplate(vtkIdType numComp);
00256   ~vtkDataArrayTemplate();
00257 
00258   T* Array;   // pointer to data
00259   T* ResizeAndExtend(vtkIdType sz);  // function to resize data
00260   T* Realloc(vtkIdType sz);
00261   
00262   int TupleSize; //used for data conversion
00263   double* Tuple;
00264 
00265   int SaveUserArray;
00266   int DeleteMethod;
00267 
00268   void ComputeScalarRange(int comp);
00269   void ComputeVectorRange();
00270 private:
00271   vtkDataArrayTemplate(const vtkDataArrayTemplate&);  // Not implemented.
00272   void operator=(const vtkDataArrayTemplate&);  // Not implemented.
00273 
00274   vtkDataArrayTemplateLookup<T>* Lookup;
00275   void UpdateLookup();
00276 
00277   void DeleteArray();
00278 };
00279 
00280 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
00281 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
00282    template class VTK_COMMON_EXPORT vtkDataArrayTemplate< T >
00283 #else
00284 # include "vtkDataArrayTemplateImplicit.txx"
00285 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
00286 #endif
00287 
00288 #endif // !defined(__vtkDataArrayTemplate_h)
00289 
00290 // This portion must be OUTSIDE the include blockers.  Each
00291 // vtkDataArray subclass uses this to give its instantiation of this
00292 // template a DLL interface.
00293 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
00294 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
00295 #  pragma warning (push)
00296 #  pragma warning (disable: 4091) // warning C4091: 'extern ' : 
00297    // ignored on left of 'int' when no variable is declared
00298 #  pragma warning (disable: 4231) // Compiler-specific extension warning.
00299 
00300    // We need to disable warning 4910 and do an extern dllexport
00301    // anyway.  When deriving vtkCharArray and other types from an
00302    // instantiation of this template the compiler does an explicit
00303    // instantiation of the base class.  From outside the vtkCommon
00304    // library we block this using an extern dllimport instantiation.
00305    // For classes inside vtkCommon we should be able to just do an
00306    // extern instantiation, but VS 2008 complains about missing
00307    // definitions.  We cannot do an extern dllimport inside vtkCommon
00308    // since the symbols are local to the dll.  An extern dllexport
00309    // seems to be the only way to convince VS 2008 to do the right
00310    // thing, so we just disable the warning.
00311 #  pragma warning (disable: 4910) // extern and dllexport incompatible
00312 
00313    // Use an "extern explicit instantiation" to give the class a DLL
00314    // interface.  This is a compiler-specific extension.
00315    extern VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(VTK_DATA_ARRAY_TEMPLATE_TYPE);
00316 #  pragma warning (pop)
00317 # endif
00318 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
00319 #endif

Generated on Thu Aug 28 14:31:03 2008 for VTK by  doxygen 1.4.7