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