VTK-m  2.2
DataSetBuilderCurvilinear.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_DataSetBuilderCurvilinear_h
11 #define vtk_m_cont_DataSetBuilderCurvilinear_h
12 
15 #include <vtkm/cont/DataSet.h>
16 
17 namespace vtkm
18 {
19 namespace cont
20 {
21 
23 {
24 public:
25  VTKM_CONT
27 
28  template <typename T>
29  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
30  const std::string& coordsNm = "coords")
31  {
32  VTKM_ASSERT(xVals.size() > 0);
33 
34  std::vector<T> yVals(xVals.size(), 0), zVals(xVals.size(), 0);
35  vtkm::Id dim = static_cast<vtkm::Id>(xVals.size());
36  auto coords = vtkm::cont::make_ArrayHandleSOA<vtkm::Vec<T, 3>>({ xVals, yVals, zVals });
37 
38  return DataSetBuilderCurvilinear::Create(coords, { dim, 0, 0 }, 1, coordsNm);
39  }
40 
41  template <typename T>
42  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
43  const std::vector<T>& yVals,
44  const vtkm::Id2& dims,
45  const std::string& coordsNm = "coords")
46  {
47  VTKM_ASSERT(xVals.size() > 0 && xVals.size() == yVals.size());
48 
49  std::vector<T> zVals(xVals.size(), 0);
50  auto coords = vtkm::cont::make_ArrayHandleSOA<vtkm::Vec<T, 3>>({ xVals, yVals, zVals });
51 
52  return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
53  }
54 
55  template <typename T>
56  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
57  const std::vector<T>& yVals,
58  const std::vector<T>& zVals,
59  const vtkm::Id3& dims,
60  const std::string& coordsNm = "coords")
61  {
62  VTKM_ASSERT(xVals.size() > 0 && xVals.size() == yVals.size());
63  VTKM_ASSERT(xVals.size() == zVals.size());
64 
65  auto coords = vtkm::cont::make_ArrayHandleSOA<vtkm::Vec<T, 3>>({ xVals, yVals, zVals });
66 
67  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
68  }
69 
70  template <typename T>
71  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<vtkm::Vec<T, 3>>& points,
72  const vtkm::Id3& dims,
73  const std::string& coordsNm = "coords")
74  {
75  auto coords = vtkm::cont::make_ArrayHandle(points);
76  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
77  }
78 
79  template <typename CoordsType>
80  VTKM_CONT static vtkm::cont::DataSet Create(const CoordsType& coords,
81  const vtkm::Id3& dims,
82  const std::string& coordsNm = "coords")
83  {
84  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
85  }
86 
87  template <typename CoordsType>
88  VTKM_CONT static vtkm::cont::DataSet Create(const CoordsType& coords,
89  const vtkm::Id2& dims,
90  const std::string& coordsNm = "coords")
91  {
92  return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
93  }
94 
95  template <typename CoordsType>
96  VTKM_CONT static vtkm::cont::DataSet Create(const CoordsType& coords,
97  const std::string& coordsNm = "coords")
98  {
100  coords, { coords.GetNumberOfValues(), 0, 0 }, 1, coordsNm);
101  }
102 
103 private:
104  template <typename CoordsType>
105  VTKM_CONT static vtkm::cont::DataSet Create(const CoordsType& coords,
106  const vtkm::Id3& dims,
107  const vtkm::Id& cellSetDim,
108  const std::string& coordsNm = "coords")
109  {
112 
113  if (cellSetDim == 3)
114  {
115  VTKM_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] >= 1);
116  VTKM_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1] * dims[2]);
117 
119  cellSet.SetPointDimensions(dims);
120  ds.SetCellSet(cellSet);
121  }
122  else if (cellSetDim == 2)
123  {
124  VTKM_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] == 0);
125  VTKM_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1]);
126 
128  cellSet.SetPointDimensions({ dims[0], dims[1] });
129  ds.SetCellSet(cellSet);
130  }
131  else if (cellSetDim == 1)
132  {
133  VTKM_ASSERT(dims[0] >= 1 && dims[1] == 0 && dims[2] == 0);
134  VTKM_ASSERT(coords.GetNumberOfValues() == dims[0]);
135 
137  cellSet.SetPointDimensions(dims[0]);
138  ds.SetCellSet(cellSet);
139  }
140  else
141  throw vtkm::cont::ErrorBadValue("Unsupported CellSetStructured dimension.");
142 
143  return ds;
144  }
145 };
146 
147 } // namespace cont
148 } // namespace vtkm
149 
150 #endif //vtk_m_cont_DataSetBuilderCurvilinear_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const CoordsType &coords, const vtkm::Id3 &dims, const vtkm::Id &cellSetDim, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:105
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xVals, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:29
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< T > &yVals, const std::vector< T > &zVals, const vtkm::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:56
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
vtkm::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:396
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const CoordsType &coords, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:96
CoordinateSystem.h
vtkm::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:30
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const std::vector< vtkm::Vec< T, 3 >> &points, const vtkm::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:71
ArrayHandleSOA.h
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const CoordsType &coords, const vtkm::Id2 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:88
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const CoordsType &coords, const vtkm::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:80
vtkm::cont::DataSet::AddCoordinateSystem
vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem &cs)
Adds the given CoordinateSystem to the DataSet.
vtkm::Vec< T, 3 >
Definition: Types.h:1013
vtkm::Vec< vtkm::Id, 2 >
vtkm::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Set the dimensions of the structured array of points.
Definition: CellSetStructured.h:58
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
vtkm::cont::make_ArrayHandle
vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:270
vtkm::cont::DataSetBuilderCurvilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< T > &yVals, const vtkm::Id2 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:42
DataSet.h
vtkm::cont::DataSetBuilderCurvilinear
Definition: DataSetBuilderCurvilinear.h:22