Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkOffsetsManagerArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkOffsetsManagerArray.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 =========================================================================*/
00039 #ifndef vtkOffsetsManager_DoNotInclude
00040 #error "do not include unless you know what you are doing"
00041 #endif
00042 
00043 #ifndef __vtkOffsetsManagerArray_h
00044 #define __vtkOffsetsManagerArray_h
00045 
00046 #include "vtkSystemIncludes.h"
00047 #include <vtkstd/vector>
00048 #include <assert.h>
00049 
00050 //----------------------------------------------------------------------------
00051 class OffsetsManager
00052 {
00053 public:
00054   // Construct with default (unsigned long)-1  MTime
00055   OffsetsManager()
00056     {
00057     this->LastMTime = (unsigned long)-1; //almost invalid state
00058     }
00059   ~OffsetsManager()
00060     {
00061     }
00062   void Allocate(int numTimeStep)
00063     {
00064     assert( numTimeStep > 0);
00065     this->Positions.resize(numTimeStep);
00066     this->OffsetValues.resize(numTimeStep);
00067     }
00068   unsigned long &GetPosition(unsigned int t)
00069     {
00070     assert( t < this->Positions.size());
00071     return this->Positions[t];
00072     }
00073   unsigned long &GetOffsetValue(unsigned int t)
00074     {
00075     assert( t < this->OffsetValues.size());
00076     return this->OffsetValues[t];
00077     }
00078   unsigned long &GetLastMTime()
00079     {
00080     return this->LastMTime;
00081     }
00082 private:
00083   unsigned long LastMTime; // Previously written dataarray mtime 
00084   vtkstd::vector<unsigned long> Positions; // Position in the stream to write the offset
00085   vtkstd::vector<unsigned long> OffsetValues;    // Value of offset
00086 };
00087 
00088 //----------------------------------------------------------------------------
00089 class OffsetsManagerGroup
00090 {
00091 public:
00092   // This is kind of a hack since we need to consider both the case of Points with
00093   // only one array over time and PointData with possibly multiple array over time
00094   // therefore we need to use a OffsetsManagerGroup for representing offset from
00095   // Points but OffsetsManagerArray for PointData. In both case the toplevel structure
00096   // is a container of Pieces...
00097   OffsetsManager &GetPiece(unsigned int index)
00098     {
00099     assert( index < this->Internals.size());
00100     OffsetsManager &e = this->Internals[index];
00101     return e;
00102     }
00103   // GetElement should be used when manipulating a OffsetsManagerArray
00104   OffsetsManager &GetElement(unsigned int index)
00105     {
00106     // commenting the following out, this is an heisenbug which only appears on gcc
00107     // when exporting GLIBCPP_NEW=1. If you try to print the value or run through gdb
00108     // it desepears
00109     //assert( index < this->Internals.size());
00110     OffsetsManager &e = this->Internals[index];
00111     return e;
00112     }
00113   unsigned int GetNumberOfElements()
00114     {
00115     return this->Internals.size();
00116     }
00117   void Allocate(int numElements)
00118     {
00119     assert(numElements >= 0); //allow 0 for empty FieldData
00120     this->Internals.resize(numElements);
00121     }
00122   void Allocate(int numElements, int numTimeSteps)
00123     {
00124     assert(numElements > 0);
00125     assert(numTimeSteps > 0);
00126     this->Internals.resize(numElements);
00127     for(int i=0; i<numElements; i++)
00128       {
00129       this->Internals[i].Allocate(numTimeSteps);
00130       }
00131     }
00132 private:
00133   vtkstd::vector<OffsetsManager> Internals;
00134 };
00135 
00136 //----------------------------------------------------------------------------
00137 class OffsetsManagerArray
00138 {
00139 public:
00140   OffsetsManagerGroup &GetPiece(unsigned int index)
00141     {
00142     assert( index < this->Internals.size());
00143     return this->Internals[index];
00144     }
00145   void Allocate(int numPieces)
00146     {
00147     assert(numPieces > 0);
00148     // Force re-initialization of values.
00149     this->Internals.resize(0);
00150     this->Internals.resize(numPieces);
00151     }
00152   void Allocate(int numPieces, int numElements, int numTimeSteps)
00153     {
00154     assert(numPieces > 0);
00155     assert(numElements > 0);
00156     assert(numTimeSteps > 0);
00157 
00158     // Force re-initialization of values.
00159     this->Internals.resize(0);
00160     this->Internals.resize(numPieces);
00161     for(int i=0; i<numPieces; i++)
00162       {
00163       this->Internals[i].Allocate(numElements, numTimeSteps);
00164       }
00165     }
00166 private:
00167   vtkstd::vector<OffsetsManagerGroup> Internals;
00168 };
00169 
00170 #endif

Generated on Mon Jan 21 23:07:31 2008 for VTK by  doxygen 1.4.3-20050530