VTK
dox/Common/Core/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   typedef typename vtkArray::CoordinateT CoordinateT;
00068   typedef typename vtkArray::DimensionT DimensionT;
00069   typedef typename vtkArray::SizeT SizeT;
00070 
00071   // vtkArray API
00072   bool IsDense();
00073   const vtkArrayExtents& GetExtents();
00074   SizeT GetNonNullSize();
00075   void GetCoordinatesN(const SizeT n, vtkArrayCoordinates& coordinates);
00076   vtkArray* DeepCopy();
00077 
00078   // vtkTypedArray API
00079   const T& GetValue(CoordinateT i);
00080   const T& GetValue(CoordinateT i, CoordinateT j);
00081   const T& GetValue(CoordinateT i, CoordinateT j, CoordinateT k);
00082   const T& GetValue(const vtkArrayCoordinates& coordinates);
00083   const T& GetValueN(const SizeT n);
00084   void SetValue(CoordinateT i, const T& value);
00085   void SetValue(CoordinateT i, CoordinateT j, const T& value);
00086   void SetValue(CoordinateT i, CoordinateT j, CoordinateT k, const T& value);
00087   void SetValue(const vtkArrayCoordinates& coordinates, const T& value);
00088   void SetValueN(const SizeT n, const T& value);
00089 
00090   // vtkDenseArray API
00091 
00093 
00096   class MemoryBlock
00097   {
00098   public:
00099     virtual ~MemoryBlock();
00101 
00102 
00103     virtual T* GetAddress() = 0;
00104   };
00106 
00108 
00111   class HeapMemoryBlock :
00112     public MemoryBlock
00113   {
00114   public:
00115     HeapMemoryBlock(const vtkArrayExtents& extents);
00116     virtual ~HeapMemoryBlock();
00117     virtual T* GetAddress();
00119 
00120   private:
00121     T* Storage;
00122   };
00123 
00125 
00127   class StaticMemoryBlock :
00128     public MemoryBlock
00129   {
00130   public:
00131     StaticMemoryBlock(T* const storage);
00132     virtual T* GetAddress();
00134 
00135   private:
00136     T* Storage;
00137   };
00138 
00152   void ExternalStorage(const vtkArrayExtents& extents, MemoryBlock* storage);
00153 
00155   void Fill(const T& value);
00156 
00159   T& operator[](const vtkArrayCoordinates& coordinates);
00160 
00163   const T* GetStorage() const;
00164 
00167   T* GetStorage();
00168 
00169 protected:
00170   vtkDenseArray();
00171   ~vtkDenseArray();
00172 
00173 private:
00174   vtkDenseArray(const vtkDenseArray&); // Not implemented
00175   void operator=(const vtkDenseArray&); // Not implemented
00176 
00177   void InternalResize(const vtkArrayExtents& extents);
00178   void InternalSetDimensionLabel(DimensionT i, const vtkStdString& label);
00179   vtkStdString InternalGetDimensionLabel(DimensionT i);
00180   inline vtkIdType MapCoordinates(CoordinateT i);
00181   inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j);
00182   inline vtkIdType MapCoordinates(CoordinateT i, CoordinateT j, CoordinateT k);
00183   inline vtkIdType MapCoordinates(const vtkArrayCoordinates& coordinates);
00184 
00185   void Reconfigure(const vtkArrayExtents& extents, MemoryBlock* storage);
00186 
00187   typedef vtkDenseArray<T> ThisT;
00188 
00190   vtkArrayExtents Extents;
00191 
00193   std::vector<vtkStdString> DimensionLabels;
00194 
00196   MemoryBlock* Storage;
00197 
00199 
00201   T* Begin;
00202   T* End;
00204 
00206   std::vector<vtkIdType> Offsets;
00208 
00209   std::vector<vtkIdType> Strides;
00210 };
00212 
00213 #include "vtkDenseArray.txx"
00214 
00215 #endif
00216 
00217 // VTK-HeaderTest-Exclude: vtkDenseArray.h