VTK  9.1.0
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 <cassert>
51#include <vector>
52
53//----------------------------------------------------------------------------
55{
56public:
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 }
90 vtkMTimeType& GetLastMTime() { return this->LastMTime; }
91
92private:
93 vtkMTimeType LastMTime; // Previously written dataarray mtime
94 // at some point these vectors could become a vector of map <string,ul>
95 // where the string is the name of the offset, but that would be pretty fat
96 // and slow, but if another couple offsets are added then we should
97 // consider doing it
98 // Position in the stream to write the offset
99 std::vector<vtkTypeInt64> Positions;
100 std::vector<vtkTypeInt64> RangeMinPositions; // Where is this
101 std::vector<vtkTypeInt64> RangeMaxPositions; // Whee is this
102
103 std::vector<vtkTypeInt64> OffsetValues; // Value of offset
104};
105
106//----------------------------------------------------------------------------
108{
109public:
110 // This is kind of a hack since we need to consider both the case of Points
111 // with only one array over time and PointData with possibly multiple array
112 // over time therefore we need to use a OffsetsManagerGroup for
113 // representing offset from Points but OffsetsManagerArray for
114 // PointData. In both case the toplevel structure is a container of
115 // Pieces...
117 {
118 assert(index < this->Internals.size());
119 OffsetsManager& e = this->Internals[index];
120 return e;
121 }
122 // GetElement should be used when manipulating a OffsetsManagerArray
124 {
125 // commenting the following out, this is an heisenbug which only appears
126 // on gcc when exporting GLIBCPP_NEW=1. If you try to print the value or
127 // run through gdb it desepears //assert( index <
128 // this->Internals.size());
129 OffsetsManager& e = this->Internals[index];
130 return e;
131 }
132 unsigned int GetNumberOfElements() { return static_cast<unsigned int>(this->Internals.size()); }
133 void Allocate(int numElements)
134 {
135 assert(numElements >= 0); // allow 0 for empty FieldData
136 this->Internals.resize(numElements);
137 }
138 void Allocate(int numElements, int numTimeSteps)
139 {
140 assert(numElements >= 0); // allow 0 for empty FieldData
141 assert(numTimeSteps > 0);
142 this->Internals.resize(numElements);
143 for (int i = 0; i < numElements; i++)
144 {
145 this->Internals[i].Allocate(numTimeSteps);
146 }
147 }
148
149private:
150 std::vector<OffsetsManager> Internals;
151};
152
153//----------------------------------------------------------------------------
155{
156public:
158 {
159 assert(index < this->Internals.size());
160 return this->Internals[index];
161 }
162 void Allocate(int numPieces)
163 {
164 assert(numPieces > 0);
165 // Force re-initialization of values.
166 this->Internals.resize(0);
167 this->Internals.resize(numPieces);
168 }
169 void Allocate(int numPieces, int numElements, int numTimeSteps)
170 {
171 assert(numPieces > 0);
172 assert(numElements > 0);
173 assert(numTimeSteps > 0);
174
175 // Force re-initialization of values.
176 this->Internals.resize(0);
177 this->Internals.resize(numPieces);
178 for (int i = 0; i < numPieces; i++)
179 {
180 this->Internals[i].Allocate(numElements, numTimeSteps);
181 }
182 }
183
184private:
185 std::vector<OffsetsManagerGroup> Internals;
186};
187
188#endif
189// VTK-HeaderTest-Exclude: vtkXMLOffsetsManager.h
void Allocate(int numPieces)
OffsetsManagerGroup & GetPiece(unsigned int index)
void Allocate(int numPieces, int numElements, int numTimeSteps)
OffsetsManager & GetPiece(unsigned int index)
void Allocate(int numElements)
unsigned int GetNumberOfElements()
OffsetsManager & GetElement(unsigned int index)
void Allocate(int numElements, int numTimeSteps)
Helper class due to PIMPL excess.
void Allocate(int numTimeStep)
vtkTypeInt64 & GetPosition(unsigned int t)
vtkTypeInt64 & GetRangeMaxPosition(unsigned int t)
vtkTypeInt64 & GetOffsetValue(unsigned int t)
vtkMTimeType & GetLastMTime()
vtkTypeInt64 & GetRangeMinPosition(unsigned int t)
@ index
Definition: vtkX3D.h:252
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287