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