VTK-m  2.0
DataSetBuilderRectilinear.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_DataSetBuilderRectilinear_h
11 #define vtk_m_cont_DataSetBuilderRectilinear_h
12 
13 #include <vtkm/cont/ArrayCopy.h>
17 #include <vtkm/cont/DataSet.h>
19 
20 namespace vtkm
21 {
22 namespace cont
23 {
24 
25 class VTKM_CONT_EXPORT DataSetBuilderRectilinear
26 {
27  template <typename T, typename U>
28  VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<U>& output)
29  {
31  output);
32  }
33 
34  template <typename T, typename U>
35  VTKM_CONT static void CopyInto(const vtkm::cont::ArrayHandle<T>& input,
37  {
38  vtkm::cont::ArrayCopy(input, output);
39  }
40 
41  template <typename T, typename U>
42  VTKM_CONT static void CopyInto(const T* input, vtkm::Id len, vtkm::cont::ArrayHandle<U>& output)
43  {
46  }
47 
48 public:
49  VTKM_CONT
51 
52  //1D grids.
53  template <typename T>
54  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
55  const std::string& coordNm = "coords")
56  {
57  std::vector<T> yvals(1, 0), zvals(1, 0);
58  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
59  }
60 
61  template <typename T>
63  T* xvals,
64  const std::string& coordNm = "coords")
65  {
66  T yvals = 0, zvals = 0;
67  return DataSetBuilderRectilinear::BuildDataSet(nx, 1, 1, xvals, &yvals, &zvals, coordNm);
68  }
69 
70  template <typename T>
72  const std::string& coordNm = "coords")
73  {
74  vtkm::cont::ArrayHandle<T> yvals, zvals;
75  yvals.Allocate(1);
76  yvals.WritePortal().Set(0, 0.0);
77  zvals.Allocate(1);
78  zvals.WritePortal().Set(0, 0.0);
79  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
80  }
81 
82  //2D grids.
83  template <typename T>
84  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
85  const std::vector<T>& yvals,
86  const std::string& coordNm = "coords")
87  {
88  std::vector<T> zvals(1, 0);
89  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
90  }
91 
92  template <typename T>
94  vtkm::Id ny,
95  T* xvals,
96  T* yvals,
97  const std::string& coordNm = "coords")
98  {
99  T zvals = 0;
100  return DataSetBuilderRectilinear::BuildDataSet(nx, ny, 1, xvals, yvals, &zvals, coordNm);
101  }
102 
103  template <typename T>
105  const vtkm::cont::ArrayHandle<T>& yvals,
106  const std::string& coordNm = "coords")
107  {
109  zvals.Allocate(1);
110  zvals.WritePortal().Set(0, 0.0);
111  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
112  }
113 
114  //3D grids.
115  template <typename T>
117  vtkm::Id ny,
118  vtkm::Id nz,
119  T* xvals,
120  T* yvals,
121  T* zvals,
122  const std::string& coordNm = "coords")
123  {
124  return DataSetBuilderRectilinear::BuildDataSet(nx, ny, nz, xvals, yvals, zvals, coordNm);
125  }
126 
127  template <typename T>
128  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
129  const std::vector<T>& yvals,
130  const std::vector<T>& zvals,
131  const std::string& coordNm = "coords")
132  {
133  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
134  }
135 
136  template <typename T>
138  const vtkm::cont::ArrayHandle<T>& yvals,
139  const vtkm::cont::ArrayHandle<T>& zvals,
140  const std::string& coordNm = "coords")
141  {
142  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
143  }
144 
145 private:
146  template <typename T>
147  VTKM_CONT static vtkm::cont::DataSet BuildDataSet(const std::vector<T>& xvals,
148  const std::vector<T>& yvals,
149  const std::vector<T>& zvals,
150  const std::string& coordNm)
151  {
156 
157  return DataSetBuilderRectilinear::BuildDataSet(Xc, Yc, Zc, coordNm);
158  }
159 
160  template <typename T>
162  vtkm::Id ny,
163  vtkm::Id nz,
164  const T* xvals,
165  const T* yvals,
166  const T* zvals,
167  const std::string& coordNm)
168  {
173 
174  return DataSetBuilderRectilinear::BuildDataSet(Xc, Yc, Zc, coordNm);
175  }
176 
177  template <typename T>
181  const std::string& coordNm)
182  {
183  vtkm::cont::DataSet dataSet;
184 
185  //Convert all coordinates to floatDefault.
189  coords;
190 
195 
197  vtkm::cont::CoordinateSystem cs(coordNm, coords);
198  dataSet.AddCoordinateSystem(cs);
199 
200  // compute the dimensions of the cellset by counting the number of axes
201  // with >1 dimension
202  int ndims = 0;
203  vtkm::Id dims[3];
204  if (Xc.GetNumberOfValues() > 1)
205  {
206  dims[ndims++] = Xc.GetNumberOfValues();
207  }
208  if (Yc.GetNumberOfValues() > 1)
209  {
210  dims[ndims++] = Yc.GetNumberOfValues();
211  }
212  if (Zc.GetNumberOfValues() > 1)
213  {
214  dims[ndims++] = Zc.GetNumberOfValues();
215  }
216 
217  if (ndims == 1)
218  {
220  cellSet.SetPointDimensions(dims[0]);
221  dataSet.SetCellSet(cellSet);
222  }
223  else if (ndims == 2)
224  {
226  cellSet.SetPointDimensions(vtkm::make_Vec(dims[0], dims[1]));
227  dataSet.SetCellSet(cellSet);
228  }
229  else if (ndims == 3)
230  {
232  cellSet.SetPointDimensions(vtkm::make_Vec(dims[0], dims[1], dims[2]));
233  dataSet.SetCellSet(cellSet);
234  }
235  else
236  {
237  throw vtkm::cont::ErrorBadValue("Invalid cell set dimension");
238  }
239 
240  return dataSet;
241  }
242 };
243 
244 } // namespace cont
245 } // namespace vtkm
246 
247 #endif //vtk_m_cont_DataSetBuilderRectilinear_h
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::make_ArrayHandle
VTKM_CONT 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:217
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static VTKM_CONT void CopyInto(const std::vector< T > &input, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:28
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle< T > &xvals, const vtkm::cont::ArrayHandle< T > &yvals, const vtkm::cont::ArrayHandle< T > &zvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:137
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static VTKM_CONT void CopyInto(const T *input, vtkm::Id len, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:42
vtkm::cont::CellSetStructured
Definition: CastAndCall.h:32
ArrayPortalToIterators.h
vtkm::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:326
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::cont::DataSetBuilderRectilinear::BuildDataSet
static VTKM_CONT vtkm::cont::DataSet BuildDataSet(const vtkm::cont::ArrayHandle< T > &X, const vtkm::cont::ArrayHandle< T > &Y, const vtkm::cont::ArrayHandle< T > &Z, const std::string &coordNm)
Definition: DataSetBuilderRectilinear.h:178
vtkm::cont::DataSetBuilderRectilinear::BuildDataSet
static VTKM_CONT vtkm::cont::DataSet BuildDataSet(const std::vector< T > &xvals, const std::vector< T > &yvals, const std::vector< T > &zvals, const std::string &coordNm)
Definition: DataSetBuilderRectilinear.h:147
CoordinateSystem.h
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle< T > &xvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:71
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(vtkm::Id nx, vtkm::Id ny, T *xvals, T *yvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:93
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:54
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayCopy.h
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle< T > &xvals, const vtkm::cont::ArrayHandle< T > &yvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:104
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::vector< T > &yvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:84
X
#define X
Definition: ClipTables.h:2430
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static VTKM_CONT void CopyInto(const vtkm::cont::ArrayHandle< T > &input, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:35
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::cont::DataSetBuilderRectilinear
Definition: DataSetBuilderRectilinear.h:25
DeviceAdapterSerial.h
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz, T *xvals, T *yvals, T *zvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:116
ArrayHandleCartesianProduct.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandle::WritePortal
VTKM_CONT WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:435
vtkm::make_Vec
constexpr VTKM_EXEC_CONT vtkm::Vec< T, vtkm::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1212
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(vtkm::Id nx, T *xvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:62
vtkm::cont::DataSetBuilderRectilinear::Create
static VTKM_CONT vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::vector< T > &yvals, const std::vector< T > &zvals, const std::string &coordNm="coords")
Definition: DataSetBuilderRectilinear.h:128
vtkm::CopyFlag::Off
@ Off
vtkm::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Definition: CellSetStructured.h:49
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::DataSet::AddCoordinateSystem
VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem &cs)
Adds the given CoordinateSystem to the DataSet.
vtkm::cont::DataSet::SetCellSet
VTKM_CONT void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:355
vtkm::cont::DataSetBuilderRectilinear::BuildDataSet
static VTKM_CONT vtkm::cont::DataSet BuildDataSet(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz, const T *xvals, const T *yvals, const T *zvals, const std::string &coordNm)
Definition: DataSetBuilderRectilinear.h:161
vtkm::cont::make_ArrayHandleCartesianProduct
VTKM_CONT vtkm::cont::ArrayHandleCartesianProduct< FirstHandleType, SecondHandleType, ThirdHandleType > make_ArrayHandleCartesianProduct(const FirstHandleType &first, const SecondHandleType &second, const ThirdHandleType &third)
A convenience function for creating an ArrayHandleCartesianProduct.
Definition: ArrayHandleCartesianProduct.h:384
DataSet.h