VTK
dox/Common/vtkDataArrayTemplate.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkDataArrayTemplate.h
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 VTK_COMMON_EXPORT 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 
00104   void GetValueRange(T range[2], int comp) {
00105     this->ComputeRange(comp);
00106     range[0] = this->ValueRange[0];
00107     range[1] = this->ValueRange[1]; }
00108   T *GetValueRange(int comp) {
00109     this->ComputeRange(comp);
00110     return this->ValueRange; }
00112 
00114   void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
00115 
00117   vtkIdType Capacity() { return this->Size; }
00118 
00123   virtual int Resize(vtkIdType numTuples);
00124 
00126   T GetValue(vtkIdType id) { return this->Array[id]; }
00127 
00129 
00131   void SetValue(vtkIdType id, T value)
00132     { this->Array[id] = value;};
00134 
00138   void SetNumberOfValues(vtkIdType number);
00139 
00141   void InsertValue(vtkIdType id, T f);
00142 
00144   void SetVariantValue(vtkIdType id, vtkVariant value);
00145 
00148   vtkIdType InsertNextValue(T f);
00149 
00151 
00154   virtual void RemoveTuple(vtkIdType id);
00155   virtual void RemoveFirstTuple();
00156   virtual void RemoveLastTuple();
00158 
00162   double GetComponent(vtkIdType i, int j);
00163 
00168   void SetComponent(vtkIdType i, int j, double c);
00169 
00173   virtual void InsertComponent(vtkIdType i, int j, double c);
00174 
00176 
00179   T* WritePointer(vtkIdType id, vtkIdType number);
00180   virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00181     { return this->WritePointer(id, number); }
00183 
00185 
00187   T* GetPointer(vtkIdType id) { return this->Array + id; }
00188   virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
00190 
00192 
00193   void DeepCopy(vtkDataArray* da);
00194   void DeepCopy(vtkAbstractArray* aa)
00195     { this->Superclass::DeepCopy(aa); }
00197 
00198 //BTX
00199   enum DeleteMethod
00200   {
00201     VTK_DATA_ARRAY_FREE,
00202     VTK_DATA_ARRAY_DELETE
00203   };
00204 //ETX
00205 
00207 
00216   void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
00217   void SetArray(T* array, vtkIdType size, int save)
00218     { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
00219   virtual void SetVoidArray(void* array, vtkIdType size, int save)
00220     { this->SetArray(static_cast<T*>(array), size, save); }
00221   virtual void SetVoidArray(void* array,
00222                             vtkIdType size,
00223                             int save,
00224                             int deleteMethod)
00225     {
00226       this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
00227     }
00229 
00233   virtual void ExportToVoidPointer(void *out_ptr);
00234 
00236   virtual vtkArrayIterator* NewIterator();
00237   
00239 
00240   virtual vtkIdType LookupValue(vtkVariant value);
00241   virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00242   vtkIdType LookupValue(T value);
00243   void LookupValue(T value, vtkIdList* ids);
00245 
00252   virtual void DataChanged();
00253 
00257   virtual void DataElementChanged(vtkIdType id);
00258 
00262   virtual void ClearLookup();
00263 
00264 protected:
00265   vtkDataArrayTemplate(vtkIdType numComp);
00266   ~vtkDataArrayTemplate();
00267 
00268   T* Array;   // pointer to data
00269   T ValueRange[2]; // range of the data
00270   T* ResizeAndExtend(vtkIdType sz);  // function to resize data
00271   T* Realloc(vtkIdType sz);
00272 
00273   int TupleSize; //used for data conversion
00274   double* Tuple;
00275 
00276   int SaveUserArray;
00277   int DeleteMethod;
00278 
00279   virtual void ComputeScalarRange(int comp);
00280   virtual void ComputeVectorRange();
00281 private:
00282   vtkDataArrayTemplate(const vtkDataArrayTemplate&);  // Not implemented.
00283   void operator=(const vtkDataArrayTemplate&);  // Not implemented.
00284 
00285   vtkDataArrayTemplateLookup<T>* Lookup;
00286   void UpdateLookup();
00287 
00288   void DeleteArray();
00289 };
00290 
00291 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
00292 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
00293    template class VTK_COMMON_EXPORT vtkDataArrayTemplate< T >
00294 #else
00295 # include "vtkDataArrayTemplateImplicit.txx"
00296 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
00297 #endif
00298 
00299 #endif // !defined(__vtkDataArrayTemplate_h)
00300 
00301 // This portion must be OUTSIDE the include blockers.  Each
00302 // vtkDataArray subclass uses this to give its instantiation of this
00303 // template a DLL interface.
00304 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
00305 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
00306 #  pragma warning (push)
00307 #  pragma warning (disable: 4091) // warning C4091: 'extern ' :
00308    // ignored on left of 'int' when no variable is declared
00309 #  pragma warning (disable: 4231) // Compiler-specific extension warning.
00310 
00311    // We need to disable warning 4910 and do an extern dllexport
00312    // anyway.  When deriving vtkCharArray and other types from an
00313    // instantiation of this template the compiler does an explicit
00314    // instantiation of the base class.  From outside the vtkCommon
00315    // library we block this using an extern dllimport instantiation.
00316    // For classes inside vtkCommon we should be able to just do an
00317    // extern instantiation, but VS 2008 complains about missing
00318    // definitions.  We cannot do an extern dllimport inside vtkCommon
00319    // since the symbols are local to the dll.  An extern dllexport
00320    // seems to be the only way to convince VS 2008 to do the right
00321    // thing, so we just disable the warning.
00322 #  pragma warning (disable: 4910) // extern and dllexport incompatible
00323 
00324    // Use an "extern explicit instantiation" to give the class a DLL
00325    // interface.  This is a compiler-specific extension.
00326    extern VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(VTK_DATA_ARRAY_TEMPLATE_TYPE);
00327 #  pragma warning (pop)
00328 # endif
00329 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
00330 #endif