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 =========================================================================*/
41 #ifndef vtkXMLOffsetsManager_DoNotInclude
42 #error "do not include unless you know what you are doing"
43 #endif
44 
45 #ifndef vtkXMLOffsetsManager_h
46 #define vtkXMLOffsetsManager_h
47 
48 #include "vtkSystemIncludes.h"
49 #include <vector>
50 #include <cassert>
51 
52 //----------------------------------------------------------------------------
54 {
55 public:
56  // Construct with default (unsigned long)-1 MTime
58  {
59  this->LastMTime = static_cast<unsigned long>(-1); //almost invalid state
60  }
61  void Allocate(int numTimeStep)
62  {
63  assert( numTimeStep > 0);
64  this->Positions.resize(numTimeStep);
65  this->RangeMinPositions.resize(numTimeStep);
66  this->RangeMaxPositions.resize(numTimeStep);
67  this->OffsetValues.resize(numTimeStep);
68  }
69  vtkTypeInt64 &GetPosition(unsigned int t)
70  {
71  assert( t < this->Positions.size());
72  return this->Positions[t];
73  }
74  vtkTypeInt64 &GetRangeMinPosition(unsigned int t)
75  {
76  assert( t < this->RangeMinPositions.size());
77  return this->RangeMinPositions[t];
78  }
79  vtkTypeInt64 &GetRangeMaxPosition(unsigned int t)
80  {
81  assert( t < this->RangeMaxPositions.size());
82  return this->RangeMaxPositions[t];
83  }
84  vtkTypeInt64 &GetOffsetValue(unsigned int t)
85  {
86  assert( t < this->OffsetValues.size());
87  return this->OffsetValues[t];
88  }
89  unsigned long &GetLastMTime()
90  {
91  return this->LastMTime;
92  }
93 private:
94  unsigned long LastMTime; // Previously written dataarray mtime
95  // at some point these vectors could become a vector of map <string,ul>
96  // where the string is the name of the offset, but that would be pretty fat
97  // and slow, but if another couple offsets are added then we should
98  // consider doing it
99  // Position in the stream to write the offset
100  std::vector<vtkTypeInt64> Positions;
101  std::vector<vtkTypeInt64> RangeMinPositions; // Where is this
102  std::vector<vtkTypeInt64> RangeMaxPositions; // Whee is this
103 
104  std::vector<vtkTypeInt64> OffsetValues; // Value of offset
105 };
106 
107 //----------------------------------------------------------------------------
109 {
110 public:
111  // This is kind of a hack since we need to consider both the case of Points
112  // with only one array over time and PointData with possibly multiple array
113  // over time therefore we need to use a OffsetsManagerGroup for
114  // representing offset from Points but OffsetsManagerArray for
115  // PointData. In both case the toplevel structure is a container of
116  // Pieces...
118  {
119  assert( index < this->Internals.size());
120  OffsetsManager &e = this->Internals[index];
121  return e;
122  }
123  // GetElement should be used when manipulating a OffsetsManagerArray
125  {
126  // commenting the following out, this is an heisenbug which only appears
127  // on gcc when exporting GLIBCPP_NEW=1. If you try to print the value or
128  // run through gdb it desepears //assert( index <
129  // this->Internals.size());
130  OffsetsManager &e = this->Internals[index];
131  return e;
132  }
133  unsigned int GetNumberOfElements()
134  {
135  return static_cast<unsigned int>(this->Internals.size());
136  }
137  void Allocate(int numElements)
138  {
139  assert(numElements >= 0); //allow 0 for empty FieldData
140  this->Internals.resize(numElements);
141  }
142  void Allocate(int numElements, int numTimeSteps)
143  {
144  assert(numElements > 0);
145  assert(numTimeSteps > 0);
146  this->Internals.resize(numElements);
147  for(int i=0; i<numElements; i++)
148  {
149  this->Internals[i].Allocate(numTimeSteps);
150  }
151  }
152 private:
153  std::vector<OffsetsManager> Internals;
154 };
155 
156 //----------------------------------------------------------------------------
158 {
159 public:
161  {
162  assert( index < this->Internals.size());
163  return this->Internals[index];
164  }
165  void Allocate(int numPieces)
166  {
167  assert(numPieces > 0);
168  // Force re-initialization of values.
169  this->Internals.resize(0);
170  this->Internals.resize(numPieces);
171  }
172  void Allocate(int numPieces, int numElements, int numTimeSteps)
173  {
174  assert(numPieces > 0);
175  assert(numElements > 0);
176  assert(numTimeSteps > 0);
177 
178  // Force re-initialization of values.
179  this->Internals.resize(0);
180  this->Internals.resize(numPieces);
181  for(int i=0; i<numPieces; i++)
182  {
183  this->Internals[i].Allocate(numElements, numTimeSteps);
184  }
185  }
186 private:
187  std::vector<OffsetsManagerGroup> Internals;
188 };
189 
190 #endif
191 // VTK-HeaderTest-Exclude: vtkXMLOffsetsManager.h
OffsetsManagerGroup & GetPiece(unsigned int index)
void Allocate(int numTimeStep)
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)
unsigned long & GetLastMTime()
void Allocate(int numPieces, int numElements, int numTimeSteps)
OffsetsManager & GetElement(unsigned int index)