Viskores  1.0
DataSetBuilderExplicit.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_DataSetBuilderExplicit_h
19 #define viskores_cont_DataSetBuilderExplicit_h
20 
26 #include <viskores/cont/DataSet.h>
27 
28 namespace viskores
29 {
30 namespace cont
31 {
32 
33 //Coordinates builder??
34 
35 class VISKORES_CONT_EXPORT DataSetBuilderExplicit
36 {
37 public:
40 
59  template <typename T>
61  const std::vector<T>& xVals,
62  const std::vector<viskores::UInt8>& shapes,
63  const std::vector<viskores::IdComponent>& numIndices,
64  const std::vector<viskores::Id>& connectivity,
65  const std::string& coordsNm = "coords")
66  {
67  std::vector<T> yVals(xVals.size(), 0), zVals(xVals.size(), 0);
69  xVals, yVals, zVals, shapes, numIndices, connectivity, coordsNm);
70  }
71 
91  template <typename T>
93  const std::vector<T>& xVals,
94  const std::vector<T>& yVals,
95  const std::vector<viskores::UInt8>& shapes,
96  const std::vector<viskores::IdComponent>& numIndices,
97  const std::vector<viskores::Id>& connectivity,
98  const std::string& coordsNm = "coords")
99  {
100  std::vector<T> zVals(xVals.size(), 0);
102  xVals, yVals, zVals, shapes, numIndices, connectivity, coordsNm);
103  }
104 
125  template <typename T>
127  const std::vector<T>& xVals,
128  const std::vector<T>& yVals,
129  const std::vector<T>& zVals,
130  const std::vector<viskores::UInt8>& shapes,
131  const std::vector<viskores::IdComponent>& numIndices,
132  const std::vector<viskores::Id>& connectivity,
133  const std::string& coordsNm = "coords");
134 
153  template <typename T>
155  const std::vector<viskores::Vec<T, 3>>& coords,
156  const std::vector<viskores::UInt8>& shapes,
157  const std::vector<viskores::IdComponent>& numIndices,
158  const std::vector<viskores::Id>& connectivity,
159  const std::string& coordsNm = "coords");
160 
180  template <typename T>
185  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
186  const std::string& coordsNm = "coords")
187  {
188  auto offsets = viskores::cont::ConvertNumComponentsToOffsets(numIndices);
189  return DataSetBuilderExplicit::BuildDataSet(coords, shapes, offsets, connectivity, coordsNm);
190  }
191 
213  template <typename T, typename CellShapeTag>
215  const std::vector<viskores::Vec<T, 3>>& coords,
216  CellShapeTag tag,
217  viskores::IdComponent numberOfPointsPerCell,
218  const std::vector<viskores::Id>& connectivity,
219  const std::string& coordsNm = "coords");
220 
242  template <typename T, typename CellShapeTag>
245  CellShapeTag tag,
246  viskores::IdComponent numberOfPointsPerCell,
247  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
248  const std::string& coordsNm = "coords")
249  {
251  coords, tag, numberOfPointsPerCell, connectivity, coordsNm);
252  }
253 
254 private:
255  template <typename T>
256  VISKORES_CONT static viskores::cont::DataSet BuildDataSet(
260  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
261  const std::string& coordsNm);
262 
263  template <typename T, typename CellShapeTag>
264  VISKORES_CONT static viskores::cont::DataSet BuildDataSet(
266  CellShapeTag tag,
267  viskores::IdComponent numberOfPointsPerCell,
268  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
269  const std::string& coordsNm);
270 };
271 
272 template <typename T>
274  const std::vector<T>& xVals,
275  const std::vector<T>& yVals,
276  const std::vector<T>& zVals,
277  const std::vector<viskores::UInt8>& shapes,
278  const std::vector<viskores::IdComponent>& numIndices,
279  const std::vector<viskores::Id>& connectivity,
280  const std::string& coordsNm)
281 {
282  VISKORES_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0);
283 
285  coordsArray.Allocate(static_cast<viskores::Id>(xVals.size()));
286  auto coordsPortal = coordsArray.WritePortal();
287  for (std::size_t index = 0; index < xVals.size(); ++index)
288  {
289  coordsPortal.Set(static_cast<viskores::Id>(index),
290  viskores::make_Vec(static_cast<viskores::FloatDefault>(xVals[index]),
291  static_cast<viskores::FloatDefault>(yVals[index]),
292  static_cast<viskores::FloatDefault>(zVals[index])));
293  }
294 
295  auto shapesArray = viskores::cont::make_ArrayHandle(shapes, viskores::CopyFlag::On);
296  auto connArray = viskores::cont::make_ArrayHandle(connectivity, viskores::CopyFlag::On);
297 
300 
302  coordsArray, shapesArray, offsetsArray, connArray, coordsNm);
303 }
304 
305 template <typename T>
307  const std::vector<viskores::Vec<T, 3>>& coords,
308  const std::vector<viskores::UInt8>& shapes,
309  const std::vector<viskores::IdComponent>& numIndices,
310  const std::vector<viskores::Id>& connectivity,
311  const std::string& coordsNm)
312 {
313  auto coordsArray = viskores::cont::make_ArrayHandle(coords, viskores::CopyFlag::On);
314  auto shapesArray = viskores::cont::make_ArrayHandle(shapes, viskores::CopyFlag::On);
315  auto connArray = viskores::cont::make_ArrayHandle(connectivity, viskores::CopyFlag::On);
316 
319 
321  coordsArray, shapesArray, offsetsArray, connArray, coordsNm);
322 }
323 
324 template <typename T>
329  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
330  const std::string& coordsNm)
331 {
332  viskores::cont::DataSet dataSet;
333 
334  dataSet.AddCoordinateSystem(viskores::cont::CoordinateSystem(coordsNm, coords));
335  viskores::Id nPts = static_cast<viskores::Id>(coords.GetNumberOfValues());
337 
338  cellSet.Fill(nPts, shapes, connectivity, offsets);
339  dataSet.SetCellSet(cellSet);
340 
341  return dataSet;
342 }
343 
344 template <typename T, typename CellShapeTag>
346  const std::vector<viskores::Vec<T, 3>>& coords,
347  CellShapeTag tag,
348  viskores::IdComponent numberOfPointsPerCell,
349  const std::vector<viskores::Id>& connectivity,
350  const std::string& coordsNm)
351 {
352  auto coordsArray = viskores::cont::make_ArrayHandle(coords, viskores::CopyFlag::On);
353  auto connArray = viskores::cont::make_ArrayHandle(connectivity, viskores::CopyFlag::On);
354 
356  coordsArray, tag, numberOfPointsPerCell, connArray, coordsNm);
357 }
358 
359 template <typename T, typename CellShapeTag>
362  CellShapeTag tag,
363  viskores::IdComponent numberOfPointsPerCell,
364  const viskores::cont::ArrayHandle<viskores::Id>& connectivity,
365  const std::string& coordsNm)
366 {
367  (void)tag; //C4100 false positive workaround
368  viskores::cont::DataSet dataSet;
369 
370  dataSet.AddCoordinateSystem(viskores::cont::CoordinateSystem(coordsNm, coords));
372 
373  cellSet.Fill(coords.GetNumberOfValues(), tag.Id, numberOfPointsPerCell, connectivity);
374  dataSet.SetCellSet(cellSet);
375 
376  return dataSet;
377 }
378 
382 class VISKORES_CONT_EXPORT DataSetBuilderExplicitIterative
383 {
384 public:
386 
393  VISKORES_CONT void Begin(const std::string& coordName = "coords");
394 
399  VISKORES_CONT viskores::Id AddPoint(const viskores::Vec3f& pt);
400 
405  template <typename T>
407  {
408  return AddPoint(static_cast<viskores::Vec3f>(pt));
409  }
410 
418  const viskores::FloatDefault& y,
419  const viskores::FloatDefault& z = 0);
420 
427  template <typename T>
428  VISKORES_CONT viskores::Id AddPoint(const T& x, const T& y, const T& z = 0)
429  {
430  return AddPoint(static_cast<viskores::FloatDefault>(x),
431  static_cast<viskores::FloatDefault>(y),
432  static_cast<viskores::FloatDefault>(z));
433  }
434 
440  VISKORES_CONT void AddCell(const viskores::UInt8& shape, const std::vector<viskores::Id>& conn);
441 
448  VISKORES_CONT void AddCell(const viskores::UInt8& shape,
449  const viskores::Id* conn,
450  const viskores::IdComponent& n);
451 
458  VISKORES_CONT void AddCell(viskores::UInt8 shape);
459 
463  VISKORES_CONT void AddCellPoint(viskores::Id pointIndex);
464 
470 
471 private:
472  std::string coordNm;
473 
474  std::vector<viskores::Vec3f> points;
475  std::vector<viskores::UInt8> shapes;
476  std::vector<viskores::IdComponent> numIdx;
477  std::vector<viskores::Id> connectivity;
478 };
479 }
480 }
481 
482 #endif //viskores_cont_DataSetBuilderExplicit_h
viskores::cont::DataSetBuilderExplicitIterative::coordNm
std::string coordNm
Definition: DataSetBuilderExplicit.h:472
viskores::cont::DataSetBuilderExplicitIterative
Helper class to build a DataSet by iteratively adding points and cells.
Definition: DataSetBuilderExplicit.h:382
viskores::CopyFlag::Off
@ Off
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
ArrayHandleCast.h
viskores::cont::DataSetBuilderExplicit::DataSetBuilderExplicit
DataSetBuilderExplicit()
Definition: DataSetBuilderExplicit.h:39
ArrayPortalToIterators.h
viskores::cont::DataSetBuilderExplicitIterative::AddPoint
viskores::Id AddPoint(const viskores::Vec< T, 3 > &pt)
Add a point to the DataSet.
Definition: DataSetBuilderExplicit.h:406
ArrayHandleCompositeVector.h
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:38
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
CoordinateSystem.h
viskores::Vec< T, 3 >
Definition: Types.h:1025
viskores::cont::DataSet::AddCoordinateSystem
viskores::IdComponent AddCoordinateSystem(const viskores::cont::CoordinateSystem &cs)
Adds the given CoordinateSystem to the DataSet.
viskores::cont::DataSetBuilderExplicit::Create
static viskores::cont::DataSet Create(const viskores::cont::ArrayHandle< viskores::Vec< T, 3 >> &coords, const viskores::cont::ArrayHandle< viskores::UInt8 > &shapes, const viskores::cont::ArrayHandle< viskores::IdComponent > &numIndices, const viskores::cont::ArrayHandle< viskores::Id > &connectivity, const std::string &coordsNm="coords")
Create a 3D DataSet with arbitrary cell connectivity.
Definition: DataSetBuilderExplicit.h:181
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::cont::DataSetBuilderExplicitIterative::AddPoint
viskores::Id AddPoint(const T &x, const T &y, const T &z=0)
Add a point to the DataSet.
Definition: DataSetBuilderExplicit.h:428
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::CopyFlag::On
@ On
viskores::cont::DataSetBuilderExplicitIterative::shapes
std::vector< viskores::UInt8 > shapes
Definition: DataSetBuilderExplicit.h:475
viskores::cont::DataSetBuilderExplicit::BuildDataSet
static viskores::cont::DataSet BuildDataSet(const viskores::cont::ArrayHandle< viskores::Vec< T, 3 >> &coords, const viskores::cont::ArrayHandle< viskores::UInt8 > &shapes, const viskores::cont::ArrayHandle< viskores::Id > &offsets, const viskores::cont::ArrayHandle< viskores::Id > &connectivity, const std::string &coordsNm)
Definition: DataSetBuilderExplicit.h:325
viskores::cont::ArrayHandle::Allocate
void Allocate(viskores::Id numberOfValues, viskores::CopyFlag preserve, viskores::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:504
viskores::cont::CellSetExplicit
Defines an irregular collection of cells.
Definition: CastAndCall.h:44
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::cont::CellSetExplicit::Fill
void Fill(viskores::Id numPoints, const viskores::cont::ArrayHandle< viskores::UInt8, ShapesStorageTag > &cellTypes, const viskores::cont::ArrayHandle< viskores::Id, ConnectivityStorageTag > &connectivity, const viskores::cont::ArrayHandle< viskores::Id, OffsetsStorageTag > &offsets)
Set all the cells of the mesh.
viskores::cont::ConvertNumComponentsToOffsets
void ConvertNumComponentsToOffsets(const viskores::cont::UnknownArrayHandle &numComponentsArray, viskores::cont::ArrayHandle< viskores::Id > &offsetsArray, viskores::Id &componentsArraySize, viskores::cont::DeviceAdapterId device=viskores::cont::DeviceAdapterTagAny{})
ConvertNumComponentsToOffsets takes an array of Vec sizes (i.e.
viskores::cont::ArrayHandle::WritePortal
WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:468
viskores::make_Vec
constexpr viskores::Vec< T, viskores::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1262
viskores::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:177
ConvertNumComponentsToOffsets.h
viskores::cont::DataSetBuilderExplicitIterative::connectivity
std::vector< viskores::Id > connectivity
Definition: DataSetBuilderExplicit.h:477
viskores::cont::DataSetBuilderExplicit::Create
static viskores::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< viskores::UInt8 > &shapes, const std::vector< viskores::IdComponent > &numIndices, const std::vector< viskores::Id > &connectivity, const std::string &coordsNm="coords")
Create a 1D DataSet with arbitrary cell connectivity.
Definition: DataSetBuilderExplicit.h:60
viskores::FloatDefault
viskores::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:244
viskores::cont::CellSetSingleType::Fill
void Fill(viskores::Id numPoints, viskores::UInt8 shapeId, viskores::IdComponent numberOfPointsPerCell, const viskores::cont::ArrayHandle< viskores::Id, ConnectivityStorageTag > &connectivity)
Set all the cells of the mesh.
Definition: CellSetSingleType.h:211
viskores::cont::DataSetBuilderExplicit::Create
static viskores::cont::DataSet Create(const viskores::cont::ArrayHandle< viskores::Vec< T, 3 >> &coords, CellShapeTag tag, viskores::IdComponent numberOfPointsPerCell, const viskores::cont::ArrayHandle< viskores::Id > &connectivity, const std::string &coordsNm="coords")
Create a 3D DataSet with arbitrary cell connectivity for a single cell type.
Definition: DataSetBuilderExplicit.h:243
viskores::cont::DataSetBuilderExplicitIterative::numIdx
std::vector< viskores::IdComponent > numIdx
Definition: DataSetBuilderExplicit.h:476
viskores::cont::CellSetSingleType
An explicit cell set with all cells of the same shape.
Definition: CastAndCall.h:42
viskores::cont::DataSetBuilderExplicit::Create
static viskores::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< T > &yVals, const std::vector< viskores::UInt8 > &shapes, const std::vector< viskores::IdComponent > &numIndices, const std::vector< viskores::Id > &connectivity, const std::string &coordsNm="coords")
Create a 2D DataSet with arbitrary cell connectivity.
Definition: DataSetBuilderExplicit.h:92
viskores::cont::make_ArrayHandle
viskores::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, viskores::Id numberOfValues, viskores::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:285
viskores::Vec< viskores::FloatDefault, 3 >
DataSet.h
viskores::cont::DataSetBuilderExplicitIterative::points
std::vector< viskores::Vec3f > points
Definition: DataSetBuilderExplicit.h:474
viskores::cont::DataSetBuilderExplicit
Definition: DataSetBuilderExplicit.h:35
viskores::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:415