VTK
dox/Common/Core/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 "vtkCommonCoreModule.h" // For export macro
00027 #include "vtkDataArray.h"
00028 
00029 template <class T>
00030 class vtkDataArrayTemplateLookup;
00031 
00032 template <class T>
00033 class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate: public vtkDataArray
00034 {
00035 public:
00036   typedef vtkDataArray Superclass;
00037   void PrintSelf(ostream& os, vtkIndent indent);
00038 
00041   int Allocate(vtkIdType sz, vtkIdType ext=1000);
00042 
00044   void Initialize();
00045 
00047   int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
00048 
00050   void SetNumberOfTuples(vtkIdType number);
00051 
00057   virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00058 
00062   virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00063 
00067   virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
00068 
00071   double* GetTuple(vtkIdType i);
00072 
00074 
00075   void GetTuple(vtkIdType i, double* tuple);
00076   void GetTupleValue(vtkIdType i, T* tuple);
00078 
00080 
00081   void SetTuple(vtkIdType i, const float* tuple);
00082   void SetTuple(vtkIdType i, const double* tuple);
00083   void SetTupleValue(vtkIdType i, const T* tuple);
00085 
00087 
00089   void InsertTuple(vtkIdType i, const float* tuple);
00090   void InsertTuple(vtkIdType i, const double* tuple);
00091   void InsertTupleValue(vtkIdType i, const T* tuple);
00093 
00095 
00097   vtkIdType InsertNextTuple(const float* tuple);
00098   vtkIdType InsertNextTuple(const double* tuple);
00099   vtkIdType InsertNextTupleValue(const T* tuple);
00101 
00103 
00105   void GetValueRange(T range[2], int comp)
00106     {
00107     double doubleRange[2];
00108     this->ComputeRange(doubleRange, comp);
00109     range[0] = static_cast<T>(doubleRange[0]);
00110     range[1] = static_cast<T>(doubleRange[1]);
00111     }
00112   T *GetValueRange(int comp)
00113     {
00114     this->GetValueRange(this->ValueRange, comp);
00115     return this->ValueRange;
00116     }
00118 
00120   void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
00121 
00123   vtkIdType Capacity() { return this->Size; }
00124 
00129   virtual int Resize(vtkIdType numTuples);
00130 
00132   T GetValue(vtkIdType id) { return this->Array[id]; }
00133 
00135 
00137   void SetValue(vtkIdType id, T value)
00138     { this->Array[id] = value;};
00140 
00144   void SetNumberOfValues(vtkIdType number);
00145 
00147   void InsertValue(vtkIdType id, T f);
00148 
00150   void SetVariantValue(vtkIdType id, vtkVariant value);
00151 
00154   vtkIdType InsertNextValue(T f);
00155 
00157 
00160   virtual void RemoveTuple(vtkIdType id);
00161   virtual void RemoveFirstTuple();
00162   virtual void RemoveLastTuple();
00164 
00168   double GetComponent(vtkIdType i, int j);
00169 
00174   void SetComponent(vtkIdType i, int j, double c);
00175 
00179   virtual void InsertComponent(vtkIdType i, int j, double c);
00180 
00182 
00185   T* WritePointer(vtkIdType id, vtkIdType number);
00186   virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00187     { return this->WritePointer(id, number); }
00189 
00191 
00193   T* GetPointer(vtkIdType id) { return this->Array + id; }
00194   virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
00196 
00198 
00199   void DeepCopy(vtkDataArray* da);
00200   void DeepCopy(vtkAbstractArray* aa)
00201     { this->Superclass::DeepCopy(aa); }
00203 
00204 //BTX
00205   enum DeleteMethod
00206   {
00207     VTK_DATA_ARRAY_FREE,
00208     VTK_DATA_ARRAY_DELETE
00209   };
00210 //ETX
00211 
00213 
00222   void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
00223   void SetArray(T* array, vtkIdType size, int save)
00224     { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
00225   virtual void SetVoidArray(void* array, vtkIdType size, int save)
00226     { this->SetArray(static_cast<T*>(array), size, save); }
00227   virtual void SetVoidArray(void* array,
00228                             vtkIdType size,
00229                             int save,
00230                             int deleteMethod)
00231     {
00232       this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
00233     }
00235 
00239   virtual void ExportToVoidPointer(void *out_ptr);
00240 
00242   virtual vtkArrayIterator* NewIterator();
00243 
00245 
00246   virtual vtkIdType LookupValue(vtkVariant value);
00247   virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00248   vtkIdType LookupValue(T value);
00249   void LookupValue(T value, vtkIdList* ids);
00251 
00258   virtual void DataChanged();
00259 
00263   virtual void DataElementChanged(vtkIdType id);
00264 
00268   virtual void ClearLookup();
00269 
00270 protected:
00271   vtkDataArrayTemplate(vtkIdType numComp);
00272   ~vtkDataArrayTemplate();
00273 
00274   T* Array;   // pointer to data
00275   T ValueRange[2]; // range of the data
00276   T* ResizeAndExtend(vtkIdType sz);  // function to resize data
00277   T* Realloc(vtkIdType sz);
00278 
00279   int TupleSize; //used for data conversion
00280   double* Tuple;
00281 
00282   int SaveUserArray;
00283   int DeleteMethod;
00284 
00285   virtual void ComputeScalarRange(double range[2], int comp);
00286   virtual void ComputeVectorRange(double range[2]);
00287 private:
00288   vtkDataArrayTemplate(const vtkDataArrayTemplate&);  // Not implemented.
00289   void operator=(const vtkDataArrayTemplate&);  // Not implemented.
00290 
00291   vtkDataArrayTemplateLookup<T>* Lookup;
00292   void UpdateLookup();
00293 
00294   void DeleteArray();
00295 };
00296 
00297 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
00298 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
00299    template class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate< T >
00300 #else
00301 # include "vtkDataArrayTemplateImplicit.txx"
00302 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
00303 #endif
00304 
00305 #endif // !defined(__vtkDataArrayTemplate_h)
00306 
00307 // This portion must be OUTSIDE the include blockers.  Each
00308 // vtkDataArray subclass uses this to give its instantiation of this
00309 // template a DLL interface.
00310 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
00311 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
00312 #  pragma warning (push)
00313 #  pragma warning (disable: 4091) // warning C4091: 'extern ' :
00314    // ignored on left of 'int' when no variable is declared
00315 #  pragma warning (disable: 4231) // Compiler-specific extension warning.
00316 
00317    // We need to disable warning 4910 and do an extern dllexport
00318    // anyway.  When deriving vtkCharArray and other types from an
00319    // instantiation of this template the compiler does an explicit
00320    // instantiation of the base class.  From outside the vtkCommon
00321    // library we block this using an extern dllimport instantiation.
00322    // For classes inside vtkCommon we should be able to just do an
00323    // extern instantiation, but VS 2008 complains about missing
00324    // definitions.  We cannot do an extern dllimport inside vtkCommon
00325    // since the symbols are local to the dll.  An extern dllexport
00326    // seems to be the only way to convince VS 2008 to do the right
00327    // thing, so we just disable the warning.
00328 #  pragma warning (disable: 4910) // extern and dllexport incompatible
00329 
00330    // Use an "extern explicit instantiation" to give the class a DLL
00331    // interface.  This is a compiler-specific extension.
00332    extern VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(VTK_DATA_ARRAY_TEMPLATE_TYPE);
00333 #  pragma warning (pop)
00334 # endif
00335 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
00336 #endif
00337 // VTK-HeaderTest-Exclude: vtkDataArrayTemplate.h