VTK
dox/Common/vtkDenseArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkDenseArray.h
00005   
00006 -------------------------------------------------------------------------
00007   Copyright 2008 Sandia Corporation.
00008   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009   the U.S. Government retains certain rights in this software.
00010 -------------------------------------------------------------------------
00011 
00012   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00013   All rights reserved.
00014   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018      PURPOSE.  See the above copyright notice for more information.
00019 
00020 =========================================================================*/
00021 
00051 #ifndef __vtkDenseArray_h
00052 #define __vtkDenseArray_h
00053 
00054 #include "vtkArrayCoordinates.h"
00055 #include "vtkObjectFactory.h"
00056 #include "vtkTypedArray.h"
00057 #include "vtkTypeTemplate.h"
00058 
00059 template<typename T>
00060 class vtkDenseArray :
00061   public vtkTypeTemplate<vtkDenseArray<T>, vtkTypedArray<T> >
00062 {
00063 public:
00064   static vtkDenseArray<T>* New();
00065   void PrintSelf(ostream &os, vtkIndent indent);
00066   
00067   // vtkArray API
00068   bool IsDense();
00069   const vtkArrayExtents& GetExtents();
00070   vtkIdType GetNonNullSize();
00071   void GetCoordinatesN(const vtkIdType n, vtkArrayCoordinates& coordinates);
00072   vtkArray* DeepCopy();
00073 
00074   // vtkTypedArray API
00075   const T& GetValue(vtkIdType i);
00076   const T& GetValue(vtkIdType i, vtkIdType j);
00077   const T& GetValue(vtkIdType i, vtkIdType j, vtkIdType k);
00078   const T& GetValue(const vtkArrayCoordinates& coordinates);
00079   const T& GetValueN(const vtkIdType n);
00080   void SetValue(vtkIdType i, const T& value);
00081   void SetValue(vtkIdType i, vtkIdType j, const T& value);
00082   void SetValue(vtkIdType i, vtkIdType j, vtkIdType k, const T& value);
00083   void SetValue(const vtkArrayCoordinates& coordinates, const T& value);
00084   void SetValueN(const vtkIdType n, const T& value);
00085 
00086   // vtkDenseArray API
00087 
00089 
00092   class MemoryBlock
00093   {
00094   public:
00095     virtual ~MemoryBlock();
00096     // Description:
00097     // Returns a pointer to the block of memory to be used for storage.
00098     virtual T* GetAddress() = 0;
00099   };
00101 
00103 
00106   class HeapMemoryBlock :
00107     public MemoryBlock
00108   {
00109   public:
00110     HeapMemoryBlock(const vtkArrayExtents& extents);
00111     virtual ~HeapMemoryBlock();
00112     virtual T* GetAddress();
00114 
00115   private:
00116     T* Storage;
00117   };
00118 
00120 
00122   class StaticMemoryBlock :
00123     public MemoryBlock
00124   {
00125   public:
00126     StaticMemoryBlock(T* const storage);
00127     virtual T* GetAddress();
00129 
00130   private:
00131     T* Storage;
00132   };
00133 
00147   void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
00148 
00150   void Fill(const T& value);
00151 
00154   T& operator[](const vtkArrayCoordinates& coordinates);
00155 
00158   const T* GetStorage() const;
00159   
00162   T* GetStorage();
00163 
00164 protected:
00165   vtkDenseArray();
00166   ~vtkDenseArray();
00167 
00168 private:
00169   vtkDenseArray(const vtkDenseArray&); // Not implemented
00170   void operator=(const vtkDenseArray&); // Not implemented
00171 
00172   void InternalResize(const vtkArrayExtents& extents);
00173   void InternalSetDimensionLabel(vtkIdType i, const vtkStdString& label);
00174   vtkStdString InternalGetDimensionLabel(vtkIdType i);
00175   inline vtkIdType MapCoordinates(vtkIdType i);
00176   inline vtkIdType MapCoordinates(vtkIdType i, vtkIdType j);
00177   inline vtkIdType MapCoordinates(vtkIdType i, vtkIdType j, vtkIdType k);
00178   inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
00179 
00180   void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
00181 
00182   typedef vtkDenseArray<T> ThisT;
00183 
00185   vtkArrayExtents Extents;
00186   
00188   vtkstd::vector<vtkStdString> DimensionLabels;
00189 
00191   MemoryBlock* Storage;
00192   
00194 
00196   T* Begin;
00197   T* End;
00199 
00201 
00202   vtkstd::vector<vtkIdType> Offsets;
00203   // Description:
00204   // Stores the stride along each array dimension (used for fast lookups).
00205   vtkstd::vector<vtkIdType> Strides;
00207 };
00208 
00209 #include "vtkDenseArray.txx"
00210 
00211 #endif
00212