VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkOffsetsManagerArray.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 =========================================================================*/ 00041 #ifndef vtkOffsetsManager_DoNotInclude 00042 #error "do not include unless you know what you are doing" 00043 #endif 00044 00045 #ifndef __vtkOffsetsManagerArray_h 00046 #define __vtkOffsetsManagerArray_h 00047 00048 #include "vtkSystemIncludes.h" 00049 #include <vector> 00050 #include <assert.h> 00051 00052 //---------------------------------------------------------------------------- 00053 class OffsetsManager 00054 { 00055 public: 00056 // A type used for data sizes and offsets for stream i/o. Using 00057 // vtkIdType should satisfy most users. This could be streamoff if 00058 // it is deemed portable. It could also be split into OffsetType 00059 // (streamoff) and PositionType (streampos). 00060 typedef vtkIdType OffsetType; 00061 00062 // Construct with default (unsigned long)-1 MTime 00063 OffsetsManager() 00064 { 00065 this->LastMTime = static_cast<unsigned long>(-1); //almost invalid state 00066 } 00067 ~OffsetsManager() 00068 { 00069 } 00070 void Allocate(int numTimeStep) 00071 { 00072 assert( numTimeStep > 0); 00073 this->Positions.resize(numTimeStep); 00074 this->RangeMinPositions.resize(numTimeStep); 00075 this->RangeMaxPositions.resize(numTimeStep); 00076 this->OffsetValues.resize(numTimeStep); 00077 } 00078 OffsetType &GetPosition(unsigned int t) 00079 { 00080 assert( t < this->Positions.size()); 00081 return this->Positions[t]; 00082 } 00083 OffsetType &GetRangeMinPosition(unsigned int t) 00084 { 00085 assert( t < this->RangeMinPositions.size()); 00086 return this->RangeMinPositions[t]; 00087 } 00088 OffsetType &GetRangeMaxPosition(unsigned int t) 00089 { 00090 assert( t < this->RangeMaxPositions.size()); 00091 return this->RangeMaxPositions[t]; 00092 } 00093 OffsetType &GetOffsetValue(unsigned int t) 00094 { 00095 assert( t < this->OffsetValues.size()); 00096 return this->OffsetValues[t]; 00097 } 00098 unsigned long &GetLastMTime() 00099 { 00100 return this->LastMTime; 00101 } 00102 private: 00103 unsigned long LastMTime; // Previously written dataarray mtime 00104 // at some point these vectors could become a vector of map <string,ul> 00105 // where the string is the name of the offset, but that would be pretty fat 00106 // and slow, but if another couple offsets are added then we should 00107 // consider doing it 00108 // Position in the stream to write the offset 00109 std::vector<OffsetType> Positions; 00110 std::vector<OffsetType> RangeMinPositions; // Where is this 00111 std::vector<OffsetType> RangeMaxPositions; // Whee is this 00112 00113 std::vector<OffsetType> OffsetValues; // Value of offset 00114 }; 00115 00116 //---------------------------------------------------------------------------- 00117 class OffsetsManagerGroup 00118 { 00119 public: 00120 // This is kind of a hack since we need to consider both the case of Points 00121 // with only one array over time and PointData with possibly multiple array 00122 // over time therefore we need to use a OffsetsManagerGroup for 00123 // representing offset from Points but OffsetsManagerArray for 00124 // PointData. In both case the toplevel structure is a container of 00125 // Pieces... 00126 OffsetsManager &GetPiece(unsigned int index) 00127 { 00128 assert( index < this->Internals.size()); 00129 OffsetsManager &e = this->Internals[index]; 00130 return e; 00131 } 00132 // GetElement should be used when manipulating a OffsetsManagerArray 00133 OffsetsManager &GetElement(unsigned int index) 00134 { 00135 // commenting the following out, this is an heisenbug which only appears 00136 // on gcc when exporting GLIBCPP_NEW=1. If you try to print the value or 00137 // run through gdb it desepears //assert( index < 00138 // this->Internals.size()); 00139 OffsetsManager &e = this->Internals[index]; 00140 return e; 00141 } 00142 unsigned int GetNumberOfElements() 00143 { 00144 return static_cast<unsigned int>(this->Internals.size()); 00145 } 00146 void Allocate(int numElements) 00147 { 00148 assert(numElements >= 0); //allow 0 for empty FieldData 00149 this->Internals.resize(numElements); 00150 } 00151 void Allocate(int numElements, int numTimeSteps) 00152 { 00153 assert(numElements > 0); 00154 assert(numTimeSteps > 0); 00155 this->Internals.resize(numElements); 00156 for(int i=0; i<numElements; i++) 00157 { 00158 this->Internals[i].Allocate(numTimeSteps); 00159 } 00160 } 00161 private: 00162 std::vector<OffsetsManager> Internals; 00163 }; 00164 00165 //---------------------------------------------------------------------------- 00166 class OffsetsManagerArray 00167 { 00168 public: 00169 OffsetsManagerGroup &GetPiece(unsigned int index) 00170 { 00171 assert( index < this->Internals.size()); 00172 return this->Internals[index]; 00173 } 00174 void Allocate(int numPieces) 00175 { 00176 assert(numPieces > 0); 00177 // Force re-initialization of values. 00178 this->Internals.resize(0); 00179 this->Internals.resize(numPieces); 00180 } 00181 void Allocate(int numPieces, int numElements, int numTimeSteps) 00182 { 00183 assert(numPieces > 0); 00184 assert(numElements > 0); 00185 assert(numTimeSteps > 0); 00186 00187 // Force re-initialization of values. 00188 this->Internals.resize(0); 00189 this->Internals.resize(numPieces); 00190 for(int i=0; i<numPieces; i++) 00191 { 00192 this->Internals[i].Allocate(numElements, numTimeSteps); 00193 } 00194 } 00195 private: 00196 std::vector<OffsetsManagerGroup> Internals; 00197 }; 00198 00199 #endif