Viskores  1.0
DataSetBuilderCurvilinear.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_DataSetBuilderCurvilinear_h
19 #define viskores_cont_DataSetBuilderCurvilinear_h
20 
23 #include <viskores/cont/DataSet.h>
24 
25 namespace viskores
26 {
27 namespace cont
28 {
29 
30 class VISKORES_CONT_EXPORT DataSetBuilderCurvilinear
31 {
32 public:
35 
36  template <typename T>
37  VISKORES_CONT static viskores::cont::DataSet Create(const std::vector<T>& xVals,
38  const std::string& coordsNm = "coords")
39  {
40  VISKORES_ASSERT(xVals.size() > 0);
41 
42  std::vector<T> yVals(xVals.size(), 0), zVals(xVals.size(), 0);
43  viskores::Id dim = static_cast<viskores::Id>(xVals.size());
44  auto coords = viskores::cont::make_ArrayHandleSOA<viskores::Vec<T, 3>>({ xVals, yVals, zVals });
45 
46  return DataSetBuilderCurvilinear::Create(coords, { dim, 0, 0 }, 1, coordsNm);
47  }
48 
49  template <typename T>
50  VISKORES_CONT static viskores::cont::DataSet Create(const std::vector<T>& xVals,
51  const std::vector<T>& yVals,
52  const viskores::Id2& dims,
53  const std::string& coordsNm = "coords")
54  {
55  VISKORES_ASSERT(xVals.size() > 0 && xVals.size() == yVals.size());
56 
57  std::vector<T> zVals(xVals.size(), 0);
58  auto coords = viskores::cont::make_ArrayHandleSOA<viskores::Vec<T, 3>>({ xVals, yVals, zVals });
59 
60  return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
61  }
62 
63  template <typename T>
64  VISKORES_CONT static viskores::cont::DataSet Create(const std::vector<T>& xVals,
65  const std::vector<T>& yVals,
66  const std::vector<T>& zVals,
67  const viskores::Id3& dims,
68  const std::string& coordsNm = "coords")
69  {
70  VISKORES_ASSERT(xVals.size() > 0 && xVals.size() == yVals.size());
71  VISKORES_ASSERT(xVals.size() == zVals.size());
72 
73  auto coords = viskores::cont::make_ArrayHandleSOA<viskores::Vec<T, 3>>({ xVals, yVals, zVals });
74 
75  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
76  }
77 
78  template <typename T>
80  const std::vector<viskores::Vec<T, 3>>& points,
81  const viskores::Id3& dims,
82  const std::string& coordsNm = "coords")
83  {
84  auto coords = viskores::cont::make_ArrayHandle(points);
85  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
86  }
87 
88  template <typename CoordsType>
89  VISKORES_CONT static viskores::cont::DataSet Create(const CoordsType& coords,
90  const viskores::Id3& dims,
91  const std::string& coordsNm = "coords")
92  {
93  return DataSetBuilderCurvilinear::Create(coords, dims, 3, coordsNm);
94  }
95 
96  template <typename CoordsType>
97  VISKORES_CONT static viskores::cont::DataSet Create(const CoordsType& coords,
98  const viskores::Id2& dims,
99  const std::string& coordsNm = "coords")
100  {
101  return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
102  }
103 
104  template <typename CoordsType>
105  VISKORES_CONT static viskores::cont::DataSet Create(const CoordsType& coords,
106  const std::string& coordsNm = "coords")
107  {
109  coords, { coords.GetNumberOfValues(), 0, 0 }, 1, coordsNm);
110  }
111 
112 private:
113  template <typename CoordsType>
114  VISKORES_CONT static viskores::cont::DataSet Create(const CoordsType& coords,
115  const viskores::Id3& dims,
116  const viskores::Id& cellSetDim,
117  const std::string& coordsNm = "coords")
118  {
121 
122  if (cellSetDim == 3)
123  {
124  VISKORES_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] >= 1);
125  VISKORES_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1] * dims[2]);
126 
128  cellSet.SetPointDimensions(dims);
129  ds.SetCellSet(cellSet);
130  }
131  else if (cellSetDim == 2)
132  {
133  VISKORES_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] == 0);
134  VISKORES_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1]);
135 
137  cellSet.SetPointDimensions({ dims[0], dims[1] });
138  ds.SetCellSet(cellSet);
139  }
140  else if (cellSetDim == 1)
141  {
142  VISKORES_ASSERT(dims[0] >= 1 && dims[1] == 0 && dims[2] == 0);
143  VISKORES_ASSERT(coords.GetNumberOfValues() == dims[0]);
144 
146  cellSet.SetPointDimensions(dims[0]);
147  ds.SetCellSet(cellSet);
148  }
149  else
150  throw viskores::cont::ErrorBadValue("Unsupported CellSetStructured dimension.");
151 
152  return ds;
153  }
154 };
155 
156 } // namespace cont
157 } // namespace viskores
158 
159 #endif //viskores_cont_DataSetBuilderCurvilinear_h
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::cont::DataSetBuilderCurvilinear
Definition: DataSetBuilderCurvilinear.h:30
viskores::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:38
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.
ArrayHandleSOA.h
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
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const CoordsType &coords, const viskores::Id3 &dims, const viskores::Id &cellSetDim, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:114
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const CoordsType &coords, const viskores::Id2 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:97
viskores::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:40
viskores::cont::ErrorBadValue
This class is thrown when a Viskores function or method encounters an invalid value that inhibits pro...
Definition: ErrorBadValue.h:33
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const std::vector< viskores::Vec< T, 3 >> &points, const viskores::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:79
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const std::vector< T > &xVals, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:37
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const CoordsType &coords, const viskores::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:89
viskores::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Set the dimensions of the structured array of points.
Definition: CellSetStructured.h:66
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const CoordsType &coords, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:105
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< T > &yVals, const viskores::Id2 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:50
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::Id, 2 >
viskores::cont::DataSetBuilderCurvilinear::Create
static viskores::cont::DataSet Create(const std::vector< T > &xVals, const std::vector< T > &yVals, const std::vector< T > &zVals, const viskores::Id3 &dims, const std::string &coordsNm="coords")
Definition: DataSetBuilderCurvilinear.h:64
DataSet.h
viskores::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:415