VTK
Portals.h
Go to the documentation of this file.
1//=============================================================================
2//
3// Copyright (c) Kitware, Inc.
4// All rights reserved.
5// See LICENSE.txt for details.
6//
7// This software is distributed WITHOUT ANY WARRANTY; without even
8// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9// PURPOSE. See the above copyright notice for more information.
10//
11// Copyright 2012 Sandia Corporation.
12// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
13// the U.S. Government retains certain rights in this software.
14//
15//=============================================================================
16
17#ifndef vtkToDax_vtkPointsContainer_h
18#define vtkToDax_vtkPointsContainer_h
19
20#include "vtkCellArray.h"
21#include "vtkDataArray.h"
22#include "vtkPoints.h"
23
24#include <dax/Types.h>
25#include <dax/VectorTraits.h>
26#include <dax/cont/ArrayPortal.h>
27#include <dax/cont/internal/IteratorFromArrayPortal.h>
28#include <iterator>
29
30//this is needed so that we can properly deduce if we are a const
31//portal. and if we are a const portal properly move the const
32//to be each vaule of the dax tuple, instead of the tuple itself
33#include <boost/type_traits/remove_const.hpp>
34#include <boost/type_traits/is_const.hpp>
35#include <boost/type_traits/is_base_of.hpp>
36#include <boost/mpl/if.hpp>
37
38namespace
39{
40template<int N>
41struct fillComponents
42{
43 template<typename T, typename Tuple>
44 void operator()(T* t, const Tuple& tuple) const
45 {
46 fillComponents<N-1>()(t,tuple);
47 t[N-1]=dax::VectorTraits<Tuple>::GetComponent(tuple,N-1);
48 }
49};
50
51template<>
52struct fillComponents<1>
53 {
54 template<typename T, typename Tuple>
55 void operator()(T* t, const Tuple& tuple) const
56 {
57 t[0]=dax::VectorTraits<Tuple>::GetComponent(tuple,0);
58 }
59};
60
61template<int N>
62struct readComponents
63{
64 template<typename T, typename Tuple>
65 void operator()(const T* t, Tuple& tuple) const
66 {
67 readComponents<N-1>()(t,tuple);
68 dax::VectorTraits<Tuple>::SetComponent(tuple,N-1,t[N-1]);
69 }
70};
71
72template<>
73struct readComponents<1>
74{
75 template<typename T, typename Tuple>
76 void operator()(const T* t, Tuple& tuple) const
77 {
78 dax::VectorTraits<Tuple>::SetComponent(tuple,0,t[0]);
79 }
80};
81
82template<typename ValueType, int N>
83struct readVector
84{
85 template<typename T>
86 ValueType operator()(const T* rawArray)
87 {
88 ValueType temp;
89 readComponents<N>()(rawArray,temp);
90 return temp;
91 }
92};
93
94template<typename ValueType>
95struct readVector<ValueType,1>
96{
97 template<typename T>
98 ValueType operator()(const T* rawArray)
99 {
100 return ValueType(*rawArray);
101 }
102};
103
104
105template<typename T>
106struct ConstCorrectedType
107{
108 //get the number of components in T
109 static const int NUM_COMPONENTS = dax::VectorTraits<T>::NUM_COMPONENTS;
110 typedef typename dax::VectorTraits<T>::ComponentType ComponentType;
111
112 //on arrayPortal and PointsPortal we are generating
113 //T on the fly, so it be const T since
114 typedef typename boost::remove_const<T>::type correctConstT;
115 typedef typename boost::is_const<T>::type isConst;
117};
118
119}
120
121namespace vtkToDax
122{
123
124
125template <typename DaxValueType, typename VTKComponentType>
127{
128 static const int NUM_COMPONENTS =
129 dax::VectorTraits<DaxValueType>::NUM_COMPONENTS;
130public:
131 typedef typename ConstCorrectedType<DaxValueType>::Type ValueType;
132 typedef typename ConstCorrectedType<DaxValueType>::ComponentType ComponentType;
133
134 DAX_CONT_EXPORT vtkArrayPortal():
135 VTKData(NULL),
136 Array(NULL),
137 Size(0)
138 {
139 }
140
141 DAX_CONT_EXPORT vtkArrayPortal(vtkDataArray* array, dax::Id size):
142 VTKData(array),
143 Array(static_cast<VTKComponentType*>(array->GetVoidPointer(0))),
144 Size(size)
145 {
146 DAX_ASSERT_CONT(this->GetNumberOfValues() >= 0);
147 }
148
149
154 template<typename OtherDaxType, typename OtherVTKType>
155 DAX_CONT_EXPORT
157 VTKData(src.GetVtkData()),
158 Array(src.Array),
159 Size(src.GetNumberOfValues())
160 {
161 }
162
163 DAX_CONT_EXPORT
164 dax::Id GetNumberOfValues() const
165 {
166 return this->Size;
167 }
168
169 DAX_CONT_EXPORT
170 ValueType Get(dax::Id index) const
171 {
172 VTKComponentType *rawArray = this->Array + (index * NUM_COMPONENTS);
173 return readVector<ValueType,NUM_COMPONENTS>()(rawArray);
174 }
175
176 DAX_CONT_EXPORT
177 void Set(dax::Id index, const ValueType& value) const
178 {
179 VTKComponentType *rawArray = this->Array + (index * NUM_COMPONENTS);
180 //use template magic to auto unroll insertion
181 fillComponents<NUM_COMPONENTS>()(rawArray,value);
182 }
183
184 typedef dax::cont::internal::IteratorFromArrayPortal<vtkArrayPortal>
186 DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
187 {
188 return IteratorType(*this, 0);
189 }
190
191 DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
192 {
193 return IteratorType(*this, this->Size);
194 }
195
196 DAX_CONT_EXPORT
197 vtkDataArray *GetVtkData() const { return this->VTKData; }
198
199private:
200 vtkDataArray *VTKData;
201 VTKComponentType *Array;
202 dax::Id Size;
203
204};
205
206
207template <typename Type,
208 int NUM_COMPONENTS = dax::VectorTraits<Type>::NUM_COMPONENTS>
210{
211public:
212 typedef typename ConstCorrectedType<Type>::Type ValueType;
213 typedef typename ConstCorrectedType<Type>::ComponentType ComponentType;
214
215 DAX_CONT_EXPORT vtkPointsPortal():
216 Points(NULL),
217 Array(NULL),
218 Size(0)
219 {
220 }
221
222 DAX_CONT_EXPORT vtkPointsPortal(vtkPoints* points, dax::Id size):
223 Points(points),
224 Array(static_cast<ComponentType*>(points->GetVoidPointer(0))),
225 Size(size)
226 {
227 DAX_ASSERT_CONT(this->GetNumberOfValues() >= 0);
228 }
229
234 template<typename OtherType>
235 DAX_CONT_EXPORT
237 Points(src.GetVtkData()),
238 Array(static_cast<ComponentType*>(src.GetVtkData()->GetVoidPointer(0))),
239 Size(src.GetNumberOfValues())
240 {
241 }
242
243 DAX_CONT_EXPORT
244 dax::Id GetNumberOfValues() const
245 {
246 return this->Size;
247 }
248
249 DAX_CONT_EXPORT
250 ValueType Get(dax::Id index) const
251 {
252 return ValueType(this->Array+(index*NUM_COMPONENTS));
253 }
254
255 DAX_CONT_EXPORT
256 void Set(dax::Id index, const ValueType& value) const
257 {
258 ComponentType *rawArray = this->Array + (index * NUM_COMPONENTS);
259 //use template magic to auto unroll insertion
260 fillComponents<NUM_COMPONENTS>()(rawArray,value);
261 }
262
263 typedef dax::cont::internal::IteratorFromArrayPortal<vtkPointsPortal>
265 DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
266 {
267 return IteratorType(*this, 0);
268 }
269
270 DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
271 {
272 return IteratorType(*this, this->Size);
273 }
274
275 vtkPoints* GetVtkData() const { return Points; }
276
277private:
278 vtkPoints* Points;
279 ComponentType *Array;
280 dax::Id Size;
281
282};
283
284//A topology portal goal is to make the vtkCellArray for a continous cell type
285//look like a dax topology layout. This means that we skip over the elements
286//in the vtkCellArray that state how many number of points are in each cell
287//so for example a vtkCellArray of triangles is stored like:
288// 3, 0, 2, 1, 3, 0, 3, 1,
289//and we want it to be in Dax:
290// 0, 2, 1, 0, 3, 1
291
292template<typename T, int PointsPerCell>
294{
295public:
296 typedef T ValueType;
297 DAX_CONT_EXPORT vtkTopologyPortal():
298 CellArray(NULL),
299 RawCells(NULL),
300 Size(0)
301 {
302 }
303
304 //numOfEntries should be the length of the cell topology array as far
305 //as dax is concerned.
306 DAX_CONT_EXPORT vtkTopologyPortal(vtkCellArray* cells, dax::Id daxTopoLen):
307 CellArray(cells),
308 RawCells(cells->GetPointer()),
309 Size(daxTopoLen)
310 {
311 DAX_ASSERT_CONT(this->GetNumberOfValues() >= 0);
312 DAX_ASSERT_CONT(this->CellArray->GetNumberOfConnectivityEntries() >=
313 daxTopoLen + (daxTopoLen/PointsPerCell));
314 }
315
320 template<typename OtherType>
321 DAX_CONT_EXPORT
323 CellArray(src.GetVtkData()),
324 RawCells(src.GetVtkData()->GetPointer()),
325 Size(src.GetNumberOfValues())
326 {
327 }
328
329 DAX_CONT_EXPORT
330 dax::Id GetNumberOfValues() const{
331 return this->Size;
332 }
333
334
335 DAX_CONT_EXPORT
336 ValueType Get(dax::Id index) const{
337 return this->RawCells[1 + index + (index/PointsPerCell) ];
338 }
339
340 DAX_CONT_EXPORT
341 void Set(dax::Id index, const ValueType& value) const{
342 this->RawCells[1 + index + index/PointsPerCell]=value;
343 }
344
345 typedef dax::cont::internal::IteratorFromArrayPortal<vtkTopologyPortal>
347 DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
348 {
349 return IteratorType(*this, 0);
350 }
351
352 DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
353 {
354 return IteratorType(*this, this->Size);
355 }
356
357 vtkCellArray* GetVtkData() const { return CellArray; }
358
359private:
360 vtkCellArray *CellArray;
361 vtkIdType *RawCells;
362 dax::Id Size;
363
364};
365
366}
367
368
369
370#endif // vtkToDax_vtkPointsContainer_h
object to represent cell connectivity
Definition: vtkCellArray.h:51
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:130
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
represent and manipulate 3D points
Definition: vtkPoints.h:40
DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
Definition: Portals.h:191
DAX_CONT_EXPORT vtkArrayPortal(const vtkArrayPortal< OtherDaxType, OtherVTKType > &src)
Copy constructor for any other vtkArrayPortal with an iterator type that can be copied to this iterat...
Definition: Portals.h:156
DAX_CONT_EXPORT ValueType Get(dax::Id index) const
Definition: Portals.h:170
DAX_CONT_EXPORT void Set(dax::Id index, const ValueType &value) const
Definition: Portals.h:177
ConstCorrectedType< DaxValueType >::ComponentType ComponentType
Definition: Portals.h:132
dax::cont::internal::IteratorFromArrayPortal< vtkArrayPortal > IteratorType
Definition: Portals.h:185
DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
Definition: Portals.h:186
DAX_CONT_EXPORT vtkArrayPortal()
Definition: Portals.h:134
DAX_CONT_EXPORT dax::Id GetNumberOfValues() const
Definition: Portals.h:164
ConstCorrectedType< DaxValueType >::Type ValueType
Definition: Portals.h:131
DAX_CONT_EXPORT vtkArrayPortal(vtkDataArray *array, dax::Id size)
Definition: Portals.h:141
DAX_CONT_EXPORT vtkDataArray * GetVtkData() const
Definition: Portals.h:197
DAX_CONT_EXPORT ValueType Get(dax::Id index) const
Definition: Portals.h:250
ConstCorrectedType< Type >::Type ValueType
Definition: Portals.h:212
DAX_CONT_EXPORT vtkPointsPortal(const vtkPointsPortal< OtherType > &src)
Copy constructor for any other vtkArrayPortal with an iterator type that can be copied to this iterat...
Definition: Portals.h:236
vtkPoints * GetVtkData() const
Definition: Portals.h:275
DAX_CONT_EXPORT vtkPointsPortal(vtkPoints *points, dax::Id size)
Definition: Portals.h:222
DAX_CONT_EXPORT dax::Id GetNumberOfValues() const
Definition: Portals.h:244
DAX_CONT_EXPORT vtkPointsPortal()
Definition: Portals.h:215
DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
Definition: Portals.h:265
DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
Definition: Portals.h:270
ConstCorrectedType< Type >::ComponentType ComponentType
Definition: Portals.h:213
DAX_CONT_EXPORT void Set(dax::Id index, const ValueType &value) const
Definition: Portals.h:256
dax::cont::internal::IteratorFromArrayPortal< vtkPointsPortal > IteratorType
Definition: Portals.h:264
DAX_CONT_EXPORT vtkTopologyPortal(vtkCellArray *cells, dax::Id daxTopoLen)
Definition: Portals.h:306
dax::cont::internal::IteratorFromArrayPortal< vtkTopologyPortal > IteratorType
Definition: Portals.h:346
DAX_CONT_EXPORT dax::Id GetNumberOfValues() const
Definition: Portals.h:330
DAX_CONT_EXPORT IteratorType GetIteratorEnd() const
Definition: Portals.h:352
vtkCellArray * GetVtkData() const
Definition: Portals.h:357
DAX_CONT_EXPORT vtkTopologyPortal(const vtkTopologyPortal< OtherType, PointsPerCell > &src)
Copy constructor for any other vtkArrayPortal with an iterator type that can be copied to this iterat...
Definition: Portals.h:322
DAX_CONT_EXPORT IteratorType GetIteratorBegin() const
Definition: Portals.h:347
DAX_CONT_EXPORT ValueType Get(dax::Id index) const
Definition: Portals.h:336
DAX_CONT_EXPORT void Set(dax::Id index, const ValueType &value) const
Definition: Portals.h:341
DAX_CONT_EXPORT vtkTopologyPortal()
Definition: Portals.h:297
@ points
Definition: vtkX3D.h:446
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ size
Definition: vtkX3D.h:253
@ index
Definition: vtkX3D.h:246
int vtkIdType
Definition: vtkType.h:287