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