VTK: IO/XML/vtkXMLOffsetsManager.h Source File

| VTK 9.3.1

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