VTK-m  2.2
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 
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 
61  template <typename T>
62  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
63  const std::string& coordNm = "coords")
64  {
65  std::vector<T> yvals(1, 0), zvals(1, 0);
66  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
67  }
68 
79  template <typename T>
81  T* xvals,
82  const std::string& coordNm = "coords")
83  {
84  T yvals = 0, zvals = 0;
85  return DataSetBuilderRectilinear::BuildDataSet(nx, 1, 1, xvals, &yvals, &zvals, coordNm);
86  }
87 
98  template <typename T>
100  const std::string& coordNm = "coords")
101  {
102  vtkm::cont::ArrayHandle<T> yvals, zvals;
103  yvals.Allocate(1);
104  yvals.WritePortal().Set(0, 0.0);
105  zvals.Allocate(1);
106  zvals.WritePortal().Set(0, 0.0);
107  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
108  }
109 
120  template <typename T>
121  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
122  const std::vector<T>& yvals,
123  const std::string& coordNm = "coords")
124  {
125  std::vector<T> zvals(1, 0);
126  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
127  }
128 
141  template <typename T>
143  vtkm::Id ny,
144  T* xvals,
145  T* yvals,
146  const std::string& coordNm = "coords")
147  {
148  T zvals = 0;
149  return DataSetBuilderRectilinear::BuildDataSet(nx, ny, 1, xvals, yvals, &zvals, coordNm);
150  }
151 
163  template <typename T>
165  const vtkm::cont::ArrayHandle<T>& yvals,
166  const std::string& coordNm = "coords")
167  {
169  zvals.Allocate(1);
170  zvals.WritePortal().Set(0, 0.0);
171  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
172  }
173 
188  template <typename T>
190  vtkm::Id ny,
191  vtkm::Id nz,
192  T* xvals,
193  T* yvals,
194  T* zvals,
195  const std::string& coordNm = "coords")
196  {
197  return DataSetBuilderRectilinear::BuildDataSet(nx, ny, nz, xvals, yvals, zvals, coordNm);
198  }
199 
211  template <typename T>
212  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xvals,
213  const std::vector<T>& yvals,
214  const std::vector<T>& zvals,
215  const std::string& coordNm = "coords")
216  {
217  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
218  }
219 
232  template <typename T>
234  const vtkm::cont::ArrayHandle<T>& yvals,
235  const vtkm::cont::ArrayHandle<T>& zvals,
236  const std::string& coordNm = "coords")
237  {
238  return DataSetBuilderRectilinear::BuildDataSet(xvals, yvals, zvals, coordNm);
239  }
240 
241 private:
242  template <typename T>
243  VTKM_CONT static vtkm::cont::DataSet BuildDataSet(const std::vector<T>& xvals,
244  const std::vector<T>& yvals,
245  const std::vector<T>& zvals,
246  const std::string& coordNm)
247  {
252 
253  return DataSetBuilderRectilinear::BuildDataSet(Xc, Yc, Zc, coordNm);
254  }
255 
256  template <typename T>
258  vtkm::Id ny,
259  vtkm::Id nz,
260  const T* xvals,
261  const T* yvals,
262  const T* zvals,
263  const std::string& coordNm)
264  {
269 
270  return DataSetBuilderRectilinear::BuildDataSet(Xc, Yc, Zc, coordNm);
271  }
272 
273  template <typename T>
277  const std::string& coordNm)
278  {
279  vtkm::cont::DataSet dataSet;
280 
281  //Convert all coordinates to floatDefault.
285  coords;
286 
291 
293  vtkm::cont::CoordinateSystem cs(coordNm, coords);
294  dataSet.AddCoordinateSystem(cs);
295 
296  // compute the dimensions of the cellset by counting the number of axes
297  // with >1 dimension
298  int ndims = 0;
299  vtkm::Id dims[3];
300  if (Xc.GetNumberOfValues() > 1)
301  {
302  dims[ndims++] = Xc.GetNumberOfValues();
303  }
304  if (Yc.GetNumberOfValues() > 1)
305  {
306  dims[ndims++] = Yc.GetNumberOfValues();
307  }
308  if (Zc.GetNumberOfValues() > 1)
309  {
310  dims[ndims++] = Zc.GetNumberOfValues();
311  }
312 
313  if (ndims == 1)
314  {
316  cellSet.SetPointDimensions(dims[0]);
317  dataSet.SetCellSet(cellSet);
318  }
319  else if (ndims == 2)
320  {
322  cellSet.SetPointDimensions(vtkm::make_Vec(dims[0], dims[1]));
323  dataSet.SetCellSet(cellSet);
324  }
325  else if (ndims == 3)
326  {
328  cellSet.SetPointDimensions(vtkm::make_Vec(dims[0], dims[1], dims[2]));
329  dataSet.SetCellSet(cellSet);
330  }
331  else
332  {
333  throw vtkm::cont::ErrorBadValue("Invalid cell set dimension");
334  }
335 
336  return dataSet;
337  }
338 };
339 
340 } // namespace cont
341 } // namespace vtkm
342 
343 #endif //vtk_m_cont_DataSetBuilderRectilinear_h
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(vtkm::Id nx, T *xvals, const std::string &coordNm="coords")
Create a 1D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:80
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::vector< T > &yvals, const std::vector< T > &zvals, const std::string &coordNm="coords")
Create a 3D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:212
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::vector< T > &yvals, const std::string &coordNm="coords")
Create a 2D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:121
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(const std::vector< T > &xvals, const std::string &coordNm="coords")
Create a 1D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:62
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::make_Vec
constexpr 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:1253
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
ArrayPortalToIterators.h
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static void CopyInto(const std::vector< T > &input, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:28
vtkm::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:396
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static void CopyInto(const T *input, vtkm::Id len, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:42
vtkm::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:334
vtkm::cont::DataSetBuilderRectilinear::Create
static 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")
Create a 3D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:233
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::cont::ArrayHandle::GetNumberOfValues
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:468
vtkm::cont::make_ArrayHandleCartesianProduct
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:393
vtkm::cont::DataSetBuilderRectilinear::BuildDataSet
static 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:243
CoordinateSystem.h
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(vtkm::Id nx, vtkm::Id ny, T *xvals, T *yvals, const std::string &coordNm="coords")
Create a 2D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:142
ArrayCopy.h
vtkm::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:30
vtkm::cont::DataSetBuilderRectilinear::BuildDataSet
static 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:257
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz, T *xvals, T *yvals, T *zvals, const std::string &coordNm="coords")
Create a 3D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:189
vtkm::cont::DataSetBuilderRectilinear::CopyInto
static void CopyInto(const vtkm::cont::ArrayHandle< T > &input, vtkm::cont::ArrayHandle< U > &output)
Definition: DataSetBuilderRectilinear.h:35
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:120
vtkm::cont::DataSetBuilderRectilinear
Definition: DataSetBuilderRectilinear.h:25
DeviceAdapterSerial.h
ArrayHandleCartesianProduct.h
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::DataSetBuilderRectilinear::BuildDataSet
static 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:274
vtkm::cont::DataSet::AddCoordinateSystem
vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem &cs)
Adds the given CoordinateSystem to the DataSet.
vtkm::CopyFlag::Off
@ Off
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::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle< T > &xvals, const std::string &coordNm="coords")
Create a 1D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:99
vtkm::cont::ArrayHandle::Allocate
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:490
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::ArrayHandle::WritePortal
WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:454
DataSet.h
vtkm::cont::DataSetBuilderRectilinear::Create
static vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle< T > &xvals, const vtkm::cont::ArrayHandle< T > &yvals, const std::string &coordNm="coords")
Create a 2D retilinear DataSet.
Definition: DataSetBuilderRectilinear.h:164