VTK
vtkXMLOffsetsManager.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkXMLOffsetsManager.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
42 #ifndef vtkXMLOffsetsManager_DoNotInclude
43 #error "do not include unless you know what you are doing"
44 #endif
45 
46 #ifndef vtkXMLOffsetsManager_h
47 #define vtkXMLOffsetsManager_h
48 
49 #include "vtkSystemIncludes.h"
50 #include <vector>
51 #include <cassert>
52 
53 //----------------------------------------------------------------------------
55 {
56 public:
57  // Construct with default (vtkMTimeType)-1 MTime
59  {
60  this->LastMTime = static_cast<vtkMTimeType>(-1); //almost invalid state
61  }
62  void Allocate(int numTimeStep)
63  {
64  assert( numTimeStep > 0);
65  this->Positions.resize(numTimeStep);
66  this->RangeMinPositions.resize(numTimeStep);
67  this->RangeMaxPositions.resize(numTimeStep);
68  this->OffsetValues.resize(numTimeStep);
69  }
70  vtkTypeInt64 &GetPosition(unsigned int t)
71  {
72  assert( t < this->Positions.size());
73  return this->Positions[t];
74  }
75  vtkTypeInt64 &GetRangeMinPosition(unsigned int t)
76  {
77  assert( t < this->RangeMinPositions.size());
78  return this->RangeMinPositions[t];
79  }
80  vtkTypeInt64 &GetRangeMaxPosition(unsigned int t)
81  {
82  assert( t < this->RangeMaxPositions.size());
83  return this->RangeMaxPositions[t];
84  }
85  vtkTypeInt64 &GetOffsetValue(unsigned int t)
86  {
87  assert( t < this->OffsetValues.size());
88  return this->OffsetValues[t];
89  }
91  {
92  return this->LastMTime;
93  }
94 private:
95  vtkMTimeType LastMTime; // Previously written dataarray mtime
96  // at some point these vectors could become a vector of map <string,ul>
97  // where the string is the name of the offset, but that would be pretty fat
98  // and slow, but if another couple offsets are added then we should
99  // consider doing it
100  // Position in the stream to write the offset
101  std::vector<vtkTypeInt64> Positions;
102  std::vector<vtkTypeInt64> RangeMinPositions; // Where is this
103  std::vector<vtkTypeInt64> RangeMaxPositions; // Whee is this
104 
105  std::vector<vtkTypeInt64> OffsetValues; // Value of offset
106 };
107 
108 //----------------------------------------------------------------------------
110 {
111 public:
112  // This is kind of a hack since we need to consider both the case of Points
113  // with only one array over time and PointData with possibly multiple array
114  // over time therefore we need to use a OffsetsManagerGroup for
115  // representing offset from Points but OffsetsManagerArray for
116  // PointData. In both case the toplevel structure is a container of
117  // Pieces...
119  {
120  assert( index < this->Internals.size());
121  OffsetsManager &e = this->Internals[index];
122  return e;
123  }
124  // GetElement should be used when manipulating a OffsetsManagerArray
126  {
127  // commenting the following out, this is an heisenbug which only appears
128  // on gcc when exporting GLIBCPP_NEW=1. If you try to print the value or
129  // run through gdb it desepears //assert( index <
130  // this->Internals.size());
131  OffsetsManager &e = this->Internals[index];
132  return e;
133  }
134  unsigned int GetNumberOfElements()
135  {
136  return static_cast<unsigned int>(this->Internals.size());
137  }
138  void Allocate(int numElements)
139  {
140  assert(numElements >= 0); //allow 0 for empty FieldData
141  this->Internals.resize(numElements);
142  }
143  void Allocate(int numElements, int numTimeSteps)
144  {
145  assert(numElements > 0);
146  assert(numTimeSteps > 0);
147  this->Internals.resize(numElements);
148  for(int i=0; i<numElements; i++)
149  {
150  this->Internals[i].Allocate(numTimeSteps);
151  }
152  }
153 private:
154  std::vector<OffsetsManager> Internals;
155 };
156 
157 //----------------------------------------------------------------------------
159 {
160 public:
162  {
163  assert( index < this->Internals.size());
164  return this->Internals[index];
165  }
166  void Allocate(int numPieces)
167  {
168  assert(numPieces > 0);
169  // Force re-initialization of values.
170  this->Internals.resize(0);
171  this->Internals.resize(numPieces);
172  }
173  void Allocate(int numPieces, int numElements, int numTimeSteps)
174  {
175  assert(numPieces > 0);
176  assert(numElements > 0);
177  assert(numTimeSteps > 0);
178 
179  // Force re-initialization of values.
180  this->Internals.resize(0);
181  this->Internals.resize(numPieces);
182  for(int i=0; i<numPieces; i++)
183  {
184  this->Internals[i].Allocate(numElements, numTimeSteps);
185  }
186  }
187 private:
188  std::vector<OffsetsManagerGroup> Internals;
189 };
190 
191 #endif
192 // VTK-HeaderTest-Exclude: vtkXMLOffsetsManager.h
OffsetsManagerGroup & GetPiece(unsigned int index)
void Allocate(int numTimeStep)
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
void Allocate(int numElements)
void Allocate(int numPieces)
Helper class due to PIMPL excess.
OffsetsManager & GetPiece(unsigned int index)
vtkTypeInt64 & GetRangeMaxPosition(unsigned int t)
unsigned int GetNumberOfElements()
vtkTypeInt64 & GetRangeMinPosition(unsigned int t)
vtkTypeInt64 & GetPosition(unsigned int t)
vtkTypeInt64 & GetOffsetValue(unsigned int t)
void Allocate(int numElements, int numTimeSteps)
void Allocate(int numPieces, int numElements, int numTimeSteps)
OffsetsManager & GetElement(unsigned int index)
vtkMTimeType & GetLastMTime()