DataSetBuilderExplicit.h 13.9 KB
Newer Older
Dave Pugmire's avatar
Dave Pugmire committed
1
2
3
4
5
6
7
8
//============================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
9
//  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
Dave Pugmire's avatar
Dave Pugmire committed
10
11
12
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
Dave Pugmire's avatar
Dave Pugmire committed
14
15
16
17
18
19
20
21
22
//  the U.S. Government retains certain rights in this software.
//
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//============================================================================
#ifndef vtk_m_cont_DataSetBuilderExplicit_h
#define vtk_m_cont_DataSetBuilderExplicit_h

23
#include <vtkm/cont/ArrayHandleCompositeVector.h>
24
25
26
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
Dave Pugmire's avatar
Dave Pugmire committed
27

28
29
30
31
namespace vtkm
{
namespace cont
{
Dave Pugmire's avatar
Dave Pugmire committed
32
33
34
35

//Coordinates builder??
//Need a singlecellset handler.

36
class VTKM_CONT_EXPORT DataSetBuilderExplicit
Dave Pugmire's avatar
Dave Pugmire committed
37
{
38
39
  template <typename T>
  VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<T>& output)
40
  {
41
42
    output.Allocate(static_cast<vtkm::Id>(input.size()));
    std::copy(input.begin(), input.end(), ArrayPortalToIteratorBegin(output.GetPortalControl()));
43
  }
44

Dave Pugmire's avatar
Dave Pugmire committed
45
public:
46
  VTKM_CONT
47
48
49
50
51
52
  DataSetBuilderExplicit() {}

  //Single cell explicits.
  //TODO

  //Zoo explicit cell
53
54
55
56
57
58
59
  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
                                              const std::vector<vtkm::UInt8>& shapes,
                                              const std::vector<vtkm::IdComponent>& numIndices,
                                              const std::vector<vtkm::Id>& connectivity,
                                              const std::string& coordsNm = "coords",
                                              const std::string& cellNm = "cells")
60
  {
61
    std::vector<T> yVals(xVals.size(), 0), zVals(xVals.size(), 0);
62
63
    return DataSetBuilderExplicit::Create(
      xVals, yVals, zVals, shapes, numIndices, connectivity, coordsNm, cellNm);
64
  }
65
66
67
68
69
70
71
72
73

  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
                                              const std::vector<T>& yVals,
                                              const std::vector<vtkm::UInt8>& shapes,
                                              const std::vector<vtkm::IdComponent>& numIndices,
                                              const std::vector<vtkm::Id>& connectivity,
                                              const std::string& coordsNm = "coords",
                                              const std::string& cellNm = "cells")
74
  {
75
    std::vector<T> zVals(xVals.size(), 0);
76
77
    return DataSetBuilderExplicit::Create(
      xVals, yVals, zVals, shapes, numIndices, connectivity, coordsNm, cellNm);
78
79
  }

80
  template <typename T>
81
82
83
84
85
86
87
88
  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<T>& xVals,
                                              const std::vector<T>& yVals,
                                              const std::vector<T>& zVals,
                                              const std::vector<vtkm::UInt8>& shapes,
                                              const std::vector<vtkm::IdComponent>& numIndices,
                                              const std::vector<vtkm::Id>& connectivity,
                                              const std::string& coordsNm = "coords",
                                              const std::string& cellNm = "cells");
89
90
91

  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet Create(
92
93
94
95
    const vtkm::cont::ArrayHandle<T>& xVals,
    const vtkm::cont::ArrayHandle<T>& yVals,
    const vtkm::cont::ArrayHandle<T>& zVals,
    const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
96
    const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
97
98
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm = "coords",
99
    const std::string& cellNm = "cells")
100
  {
101
102
    return DataSetBuilderExplicit::BuildDataSet(
      xVals, yVals, zVals, shapes, numIndices, connectivity, coordsNm, cellNm);
103
104
  }

105
106
107
108
109
110
111
112
113
114
115
116
117
  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<vtkm::Vec<T, 3>>& coords,
                                              const std::vector<vtkm::UInt8>& shapes,
                                              const std::vector<vtkm::IdComponent>& numIndices,
                                              const std::vector<vtkm::Id>& connectivity,
                                              const std::string& coordsNm = "coords",
                                              const std::string& cellNm = "cells");

  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet Create(
    const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
    const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
    const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
118
119
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm = "coords",
120
    const std::string& cellNm = "cells")
121
  {
122
123
    return DataSetBuilderExplicit::BuildDataSet(
      coords, shapes, numIndices, connectivity, coordsNm, cellNm);
124
125
  }

126
127
128
129
130
131
132
133
134
135
  template <typename T, typename CellShapeTag>
  VTKM_CONT static vtkm::cont::DataSet Create(const std::vector<vtkm::Vec<T, 3>>& coords,
                                              CellShapeTag tag,
                                              vtkm::IdComponent numberOfPointsPerCell,
                                              const std::vector<vtkm::Id>& connectivity,
                                              const std::string& coordsNm = "coords",
                                              const std::string& cellNm = "cells");

  template <typename T, typename CellShapeTag>
  VTKM_CONT static vtkm::cont::DataSet Create(
136
137
138
139
140
141
    const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
    CellShapeTag tag,
    vtkm::IdComponent numberOfPointsPerCell,
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm = "coords",
    const std::string& cellNm = "cells")
142
  {
143
144
    return DataSetBuilderExplicit::BuildDataSet(
      coords, tag, numberOfPointsPerCell, connectivity, coordsNm, cellNm);
145
  }
146

147
private:
148
149
  template <typename T>
  static vtkm::cont::DataSet BuildDataSet(
150
151
152
153
    const vtkm::cont::ArrayHandle<T>& X,
    const vtkm::cont::ArrayHandle<T>& Y,
    const vtkm::cont::ArrayHandle<T>& Z,
    const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
154
    const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
155
156
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm,
157
158
159
160
161
162
163
    const std::string& cellNm);

  template <typename T>
  VTKM_CONT static vtkm::cont::DataSet BuildDataSet(
    const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
    const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
    const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
164
165
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm,
166
167
168
169
    const std::string& cellNm);

  template <typename T, typename CellShapeTag>
  VTKM_CONT static vtkm::cont::DataSet BuildDataSet(
170
171
172
173
174
175
    const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
    CellShapeTag tag,
    vtkm::IdComponent numberOfPointsPerCell,
    const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
    const std::string& coordsNm,
    const std::string& cellNm);
176
};
dpugmire's avatar
dpugmire committed
177

178
179
template <typename T>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
180
181
182
183
184
185
186
187
  const std::vector<T>& xVals,
  const std::vector<T>& yVals,
  const std::vector<T>& zVals,
  const std::vector<vtkm::UInt8>& shapes,
  const std::vector<vtkm::IdComponent>& numIndices,
  const std::vector<vtkm::Id>& connectivity,
  const std::string& coordsNm,
  const std::string& cellNm)
Dave Pugmire's avatar
Dave Pugmire committed
188
{
189
  VTKM_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0);
190
191

  vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
192
193
194
  DataSetBuilderExplicit::CopyInto(xVals, Xc);
  DataSetBuilderExplicit::CopyInto(yVals, Yc);
  DataSetBuilderExplicit::CopyInto(zVals, Zc);
195
196
197
198

  vtkm::cont::ArrayHandle<vtkm::UInt8> Sc;
  vtkm::cont::ArrayHandle<vtkm::IdComponent> Nc;
  vtkm::cont::ArrayHandle<vtkm::Id> Cc;
199
200
201
  DataSetBuilderExplicit::CopyInto(shapes, Sc);
  DataSetBuilderExplicit::CopyInto(numIndices, Nc);
  DataSetBuilderExplicit::CopyInto(connectivity, Cc);
202

203
  return DataSetBuilderExplicit::BuildDataSet(Xc, Yc, Zc, Sc, Nc, Cc, coordsNm, cellNm);
Dave Pugmire's avatar
Dave Pugmire committed
204
205
}

206
207
template <typename T>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(
208
209
210
211
  const vtkm::cont::ArrayHandle<T>& X,
  const vtkm::cont::ArrayHandle<T>& Y,
  const vtkm::cont::ArrayHandle<T>& Z,
  const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
212
  const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
213
214
  const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
  const std::string& coordsNm,
215
  const std::string& cellNm)
Dave Pugmire's avatar
Dave Pugmire committed
216
{
217
  VTKM_ASSERT(X.GetNumberOfValues() == Y.GetNumberOfValues() &&
218
219
              Y.GetNumberOfValues() == Z.GetNumberOfValues() && X.GetNumberOfValues() > 0 &&
              shapes.GetNumberOfValues() == numIndices.GetNumberOfValues());
220
221
222

  vtkm::cont::DataSet dataSet;
  dataSet.AddCoordinateSystem(
223
    vtkm::cont::CoordinateSystem(coordsNm, make_ArrayHandleCompositeVector(X, Y, Z)));
224
  vtkm::Id nPts = X.GetNumberOfValues();
225
  vtkm::cont::CellSetExplicit<> cellSet(cellNm);
226

227
  cellSet.Fill(nPts, shapes, numIndices, connectivity);
228
229
230
  dataSet.AddCellSet(cellSet);

  return dataSet;
Dave Pugmire's avatar
Dave Pugmire committed
231
232
}

233
234
template <typename T>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
235
236
237
238
239
240
  const std::vector<vtkm::Vec<T, 3>>& coords,
  const std::vector<vtkm::UInt8>& shapes,
  const std::vector<vtkm::IdComponent>& numIndices,
  const std::vector<vtkm::Id>& connectivity,
  const std::string& coordsNm,
  const std::string& cellNm)
Dave Pugmire's avatar
Dave Pugmire committed
241
{
242
  vtkm::cont::ArrayHandle<Vec<T, 3>> coordsArray;
243
  DataSetBuilderExplicit::CopyInto(coords, coordsArray);
244

245
246
247
  vtkm::cont::ArrayHandle<vtkm::UInt8> Sc;
  vtkm::cont::ArrayHandle<vtkm::IdComponent> Nc;
  vtkm::cont::ArrayHandle<vtkm::Id> Cc;
248
249
250
  DataSetBuilderExplicit::CopyInto(shapes, Sc);
  DataSetBuilderExplicit::CopyInto(numIndices, Nc);
  DataSetBuilderExplicit::CopyInto(connectivity, Cc);
251

252
  return DataSetBuilderExplicit::Create(coordsArray, Sc, Nc, Cc, coordsNm, cellNm);
253
}
254

255
256
257
258
259
template <typename T>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(
  const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
  const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
  const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
260
261
  const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
  const std::string& coordsNm,
262
  const std::string& cellNm)
263
{
264
  vtkm::cont::DataSet dataSet;
265

266
  dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm, coords));
267
  vtkm::Id nPts = static_cast<vtkm::Id>(coords.GetNumberOfValues());
268
  vtkm::cont::CellSetExplicit<> cellSet(cellNm);
269

270
  cellSet.Fill(nPts, shapes, numIndices, connectivity);
271
  dataSet.AddCellSet(cellSet);
272

273
  return dataSet;
Dave Pugmire's avatar
Dave Pugmire committed
274
275
}

276
277
template <typename T, typename CellShapeTag>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
278
279
280
281
282
283
  const std::vector<vtkm::Vec<T, 3>>& coords,
  CellShapeTag tag,
  vtkm::IdComponent numberOfPointsPerCell,
  const std::vector<vtkm::Id>& connectivity,
  const std::string& coordsNm,
  const std::string& cellNm)
284
{
285
  vtkm::cont::ArrayHandle<Vec<T, 3>> coordsArray;
286
  DataSetBuilderExplicit::CopyInto(coords, coordsArray);
287

288
  vtkm::cont::ArrayHandle<vtkm::Id> Cc;
289
  DataSetBuilderExplicit::CopyInto(connectivity, Cc);
290

291
292
  return DataSetBuilderExplicit::Create(
    coordsArray, tag, numberOfPointsPerCell, Cc, coordsNm, cellNm);
293
294
}

295
296
template <typename T, typename CellShapeTag>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(
297
298
299
300
301
302
  const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
  CellShapeTag tag,
  vtkm::IdComponent numberOfPointsPerCell,
  const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
  const std::string& coordsNm,
  const std::string& cellNm)
303
{
304
  (void)tag; //C4100 false positive workaround
305
  vtkm::cont::DataSet dataSet;
306

307
  dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm, coords));
308
  vtkm::cont::CellSetSingleType<> cellSet(cellNm);
309

310
  cellSet.Fill(coords.GetNumberOfValues(), tag.Id, numberOfPointsPerCell, connectivity);
311
  dataSet.AddCellSet(cellSet);
312

313
  return dataSet;
314
315
}

316
class VTKM_CONT_EXPORT DataSetBuilderExplicitIterative
317
318
{
public:
319
  VTKM_CONT
320
  DataSetBuilderExplicitIterative();
321

322
  VTKM_CONT
323
  void Begin(const std::string& coordName = "coords", const std::string& cellName = "cells");
324
325

  //Define points.
326
  VTKM_CONT
327
328
  vtkm::cont::DataSet Create();

329
  VTKM_CONT
330
  vtkm::Id AddPoint(const vtkm::Vec<vtkm::Float32, 3>& pt);
331

332
  VTKM_CONT
333
  vtkm::Id AddPoint(const vtkm::Float32& x, const vtkm::Float32& y, const vtkm::Float32& z = 0);
334

335
336
  template <typename T>
  VTKM_CONT vtkm::Id AddPoint(const T& x, const T& y, const T& z = 0)
337
  {
338
339
    return AddPoint(
      static_cast<vtkm::Float32>(x), static_cast<vtkm::Float32>(y), static_cast<vtkm::Float32>(z));
340
341
  }

342
343
  template <typename T>
  VTKM_CONT vtkm::Id AddPoint(const vtkm::Vec<T, 3>& pt)
344
  {
345
    return AddPoint(static_cast<vtkm::Vec<vtkm::Float32, 3>>(pt));
346
347
348
  }

  //Define cells.
349
  VTKM_CONT
350
  void AddCell(vtkm::UInt8 shape);
351

352
  VTKM_CONT
353
  void AddCell(const vtkm::UInt8& shape, const std::vector<vtkm::Id>& conn);
354

355
  VTKM_CONT
356
  void AddCell(const vtkm::UInt8& shape, const vtkm::Id* conn, const vtkm::IdComponent& n);
357

358
  VTKM_CONT
359
  void AddCellPoint(vtkm::Id pointIndex);
360

361
private:
362
  std::string coordNm, cellNm;
363

364
  std::vector<vtkm::Vec<vtkm::Float32, 3>> points;
365
366
367
  std::vector<vtkm::UInt8> shapes;
  std::vector<vtkm::IdComponent> numIdx;
  std::vector<vtkm::Id> connectivity;
368
};
Dave Pugmire's avatar
Dave Pugmire committed
369
370
371
372
}
}

#endif //vtk_m_cont_DataSetBuilderExplicit_h