VTK-m  2.1
DataSet.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_DataSet_h
11 #define vtk_m_cont_DataSet_h
12 
14 
15 #include <vtkm/cont/ArrayHandle.h>
18 #include <vtkm/cont/Field.h>
22 
23 namespace vtkm
24 {
25 namespace cont
26 {
27 
29 
30 VTKM_CONT_EXPORT VTKM_CONT const std::string& GetGlobalGhostCellFieldName() noexcept;
31 
32 VTKM_CONT_EXPORT VTKM_CONT void SetGlobalGhostCellFieldName(const std::string& name) noexcept;
33 
58 {
59 public:
60  DataSet() = default;
61 
62  DataSet(vtkm::cont::DataSet&&) = default;
63 
64  DataSet(const vtkm::cont::DataSet&) = default;
65 
66  vtkm::cont::DataSet& operator=(vtkm::cont::DataSet&&) = default;
67 
68  vtkm::cont::DataSet& operator=(const vtkm::cont::DataSet&) = default;
69 
70  VTKM_CONT void Clear();
71 
73  VTKM_CONT vtkm::Id GetNumberOfCells() const;
74 
79  VTKM_CONT vtkm::Id GetNumberOfPoints() const;
80 
87  VTKM_CONT void AddField(const Field& field);
88 
97  VTKM_CONT
98  const vtkm::cont::Field& GetField(vtkm::Id index) const { return this->Fields.GetField(index); }
99 
100  VTKM_CONT
101  vtkm::cont::Field& GetField(vtkm::Id index) { return this->Fields.GetField(index); }
103 
104  VTKM_CONT
105  bool HasField(const std::string& name,
107  {
108  return this->Fields.HasField(name, assoc);
109  }
110 
111  VTKM_CONT
112  bool HasCellField(const std::string& name) const
113  {
114  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Cells) != -1);
115  }
116 
117  VTKM_CONT
118  bool HasGhostCellField() const;
119 
120  VTKM_CONT
121  const std::string& GetGhostCellFieldName() const;
122 
123  VTKM_CONT
124  bool HasPointField(const std::string& name) const
125  {
126  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Points) != -1);
127  }
128 
129 
138  VTKM_CONT
140  const std::string& name,
142  {
143  return this->Fields.GetFieldIndex(name, assoc);
144  }
145 
151  VTKM_CONT
153  const std::string& name,
155  {
156  return this->Fields.GetField(name, assoc);
157  }
158 
159 
160  VTKM_CONT
162  const std::string& name,
164  {
165  return this->Fields.GetField(name, assoc);
166  }
168 
174  VTKM_CONT
175  const vtkm::cont::Field& GetCellField(const std::string& name) const
176  {
177  return this->GetField(name, vtkm::cont::Field::Association::Cells);
178  }
179 
180  VTKM_CONT
181  vtkm::cont::Field& GetCellField(const std::string& name)
182  {
183  return this->GetField(name, vtkm::cont::Field::Association::Cells);
184  }
186 
192  VTKM_CONT
193  vtkm::cont::Field GetGhostCellField() const;
195 
201  VTKM_CONT
202  const vtkm::cont::Field& GetPointField(const std::string& name) const
203  {
204  return this->GetField(name, vtkm::cont::Field::Association::Points);
205  }
206 
207  VTKM_CONT
208  vtkm::cont::Field& GetPointField(const std::string& name)
209  {
210  return this->GetField(name, vtkm::cont::Field::Association::Points);
211  }
213 
221  VTKM_CONT
222  void AddPointField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
223  {
224  this->AddField(make_FieldPoint(fieldName, field));
225  }
226 
227  template <typename T, typename Storage>
228  VTKM_CONT void AddPointField(const std::string& fieldName,
230  {
231  this->AddField(make_FieldPoint(fieldName, field));
232  }
233 
234  template <typename T>
235  VTKM_CONT void AddPointField(const std::string& fieldName, const std::vector<T>& field)
236  {
237  this->AddField(
239  }
240 
241  template <typename T>
242  VTKM_CONT void AddPointField(const std::string& fieldName, const T* field, const vtkm::Id& n)
243  {
244  this->AddField(
246  }
248 
256  VTKM_CONT
257  void AddCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
258  {
259  this->AddField(make_FieldCell(fieldName, field));
260  }
261 
262  template <typename T, typename Storage>
263  VTKM_CONT void AddCellField(const std::string& fieldName,
265  {
266  this->AddField(make_FieldCell(fieldName, field));
267  }
268 
269  template <typename T>
270  VTKM_CONT void AddCellField(const std::string& fieldName, const std::vector<T>& field)
271  {
272  this->AddField(
274  }
275 
276  template <typename T>
277  VTKM_CONT void AddCellField(const std::string& fieldName, const T* field, const vtkm::Id& n)
278  {
279  this->AddField(
281  }
283 
287  VTKM_CONT void SetGhostCellFieldName(const std::string& name);
288 
292  VTKM_CONT void SetGhostCellField(const std::string& name);
293 
304  VTKM_CONT void SetGhostCellField(const vtkm::cont::Field& field);
305  VTKM_CONT void SetGhostCellField(const std::string& fieldName,
306  const vtkm::cont::UnknownArrayHandle& field);
308 
318  VTKM_CONT void SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field);
319 
320  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
321  VTKM_CONT
322  void AddGhostCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
323  {
324  this->SetGhostCellField(fieldName, field);
325  }
326 
327  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
328  VTKM_CONT
329  void AddGhostCellField(const vtkm::cont::UnknownArrayHandle& field)
330  {
331  this->SetGhostCellField(field);
332  }
333 
334  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
335  VTKM_CONT
336  void AddGhostCellField(const vtkm::cont::Field& field) { this->SetGhostCellField(field); }
337 
338 
344  VTKM_CONT
345  vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs);
346 
353  VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const std::string& pointFieldName);
354 
355  VTKM_CONT
356  bool HasCoordinateSystem(const std::string& name) const
357  {
358  return this->GetCoordinateSystemIndex(name) >= 0;
359  }
360 
361  VTKM_CONT
362  vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index = 0) const;
363 
367  VTKM_CONT
368  vtkm::IdComponent GetCoordinateSystemIndex(const std::string& name) const;
369 
370  VTKM_CONT const std::string& GetCoordinateSystemName(vtkm::Id index = 0) const;
371 
374  VTKM_CONT
375  vtkm::cont::CoordinateSystem GetCoordinateSystem(const std::string& name) const;
376 
377  template <typename CellSetType>
378  VTKM_CONT void SetCellSet(const CellSetType& cellSet)
379  {
381  this->SetCellSetImpl(cellSet);
382  }
383 
384  VTKM_CONT
385  const vtkm::cont::UnknownCellSet& GetCellSet() const { return this->CellSet; }
386 
387  VTKM_CONT
389 
390  VTKM_CONT
391  vtkm::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
392 
393  VTKM_CONT
395  {
396  return static_cast<vtkm::IdComponent>(this->CoordSystemNames.size());
397  }
398 
402  VTKM_CONT
403  void CopyStructure(const vtkm::cont::DataSet& source);
404 
418  VTKM_CONT void ConvertToExpected();
419 
420  VTKM_CONT
421  void PrintSummary(std::ostream& out) const;
422 
423 private:
424  std::vector<std::string> CoordSystemNames;
425  vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::WholeDataSet,
428 
430  std::shared_ptr<std::string> GhostCellName;
431 
432  VTKM_CONT void SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet);
433 };
434 
435 } // namespace cont
436 } // namespace vtkm
437 
438 //=============================================================================
439 // Specializations of serialization related classes
441 namespace vtkm
442 {
443 namespace cont
444 {
445 
454 template <typename... CellSetTypes>
455 struct DataSetWithCellSetTypes
456 {
457  vtkm::cont::DataSet DataSet;
458 
459  DataSetWithCellSetTypes() = default;
460 
461  explicit DataSetWithCellSetTypes(const vtkm::cont::DataSet& dataset)
462  : DataSet(dataset)
463  {
464  }
465 };
466 
467 template <typename... CellSetTypes>
468 struct DataSetWithCellSetTypes<vtkm::List<CellSetTypes...>>
469  : DataSetWithCellSetTypes<CellSetTypes...>
470 {
471  using DataSetWithCellSetTypes<CellSetTypes...>::DataSetWithCellSetTypes;
472 };
473 
474 template <typename FieldTypeList = VTKM_DEFAULT_TYPE_LIST,
475  typename CellSetTypesList = VTKM_DEFAULT_CELL_SET_LIST>
476 struct VTKM_DEPRECATED(
477  2.1,
478  "Serialize DataSet directly or use DataSetWithCellSetTypes for weird CellSets.")
479  SerializableDataSet : DataSetWithCellSetTypes<CellSetTypesList>
480 {
481  using DataSetWithCellSetTypes<CellSetTypesList>::DataSetWithCellSetTypes;
482 };
483 
484 }
485 } // vtkm::cont
486 
487 namespace mangled_diy_namespace
488 {
489 
490 template <>
491 struct VTKM_CONT_EXPORT Serialization<vtkm::cont::DataSet>
492 {
493  static VTKM_CONT void foo();
494  static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::DataSet& obj);
495  static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::DataSet& obj);
496 };
497 
498 template <typename... CellSetTypes>
499 struct Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>>
500 {
501 private:
502  using Type = vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>;
503 
504 public:
505  static VTKM_CONT void save(BinaryBuffer& bb, const Type& serializable)
506  {
507  const auto& dataset = serializable.DataSet;
508 
509  vtkmdiy::save(bb, dataset.GetCellSet().ResetCellSetList(vtkm::List<CellSetTypes...>{}));
510 
511  vtkm::IdComponent numberOfFields = dataset.GetNumberOfFields();
512  vtkmdiy::save(bb, numberOfFields);
513  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
514  {
515  vtkmdiy::save(bb, dataset.GetField(i));
516  }
517 
518  vtkm::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems();
519  vtkmdiy::save(bb, numberOfCoordinateSystems);
520  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
521  {
522  vtkmdiy::save(bb, dataset.GetCoordinateSystemName(i));
523  }
524  }
525 
526  static VTKM_CONT void load(BinaryBuffer& bb, Type& serializable)
527  {
528  auto& dataset = serializable.DataSet;
529  dataset = {}; // clear
530 
531  vtkm::cont::UncertainCellSet<vtkm::List<CellSetTypes...>> cells;
532  vtkmdiy::load(bb, cells);
533  dataset.SetCellSet(cells);
534 
535  vtkm::IdComponent numberOfFields = 0;
536  vtkmdiy::load(bb, numberOfFields);
537  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
538  {
539  vtkm::cont::Field field;
540  vtkmdiy::load(bb, field);
541  dataset.AddField(field);
542  }
543 
544  vtkm::IdComponent numberOfCoordinateSystems = 0;
545  vtkmdiy::load(bb, numberOfCoordinateSystems);
546  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
547  {
548  std::string coordName;
549  vtkmdiy::load(bb, coordName);
550  dataset.AddCoordinateSystem(coordName);
551  }
552  }
553 };
554 
555 template <typename... CellSetTypes>
556 struct Serialization<vtkm::cont::DataSetWithCellSetTypes<vtkm::List<CellSetTypes...>>>
557  : Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>>
558 {
559 };
560 
562 template <typename FieldTypeList, typename CellSetTypesList>
563 struct Serialization<vtkm::cont::SerializableDataSet<FieldTypeList, CellSetTypesList>>
564  : Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypesList>>
565 {
566 };
568 
569 } // diy
571 
572 #endif //vtk_m_cont_DataSet_h
vtkm::cont::DataSet::GetCellSet
const vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:385
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
ArrayHandle.h
vtkm::cont::DataSet::GetFieldIndex
vtkm::Id GetFieldIndex(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:139
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
FieldCollection.h
VTKM_IS_KNOWN_OR_UNKNOWN_CELL_SET
#define VTKM_IS_KNOWN_OR_UNKNOWN_CELL_SET(T)
Definition: UnknownCellSet.h:313
UnknownCellSet.h
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::DataSet::HasPointField
bool HasPointField(const std::string &name) const
Definition: DataSet.h:124
vtkm::cont::DataSet::GetPointField
vtkm::cont::Field & GetPointField(const std::string &name)
Returns the first point field that matches the provided name.
Definition: DataSet.h:208
vtkm::cont::DataSet::GetField
const vtkm::cont::Field & GetField(vtkm::Id index) const
Retrieves a field by index.
Definition: DataSet.h:98
vtkm::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:38
vtkm::cont::make_Field
vtkm::cont::Field make_Field(std::string name, Field::Association association, const T *data, vtkm::Id size, vtkm::CopyFlag copy)
Convenience functions to build fields from C style arrays and std::vector.
Definition: Field.h:236
vtkm::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:378
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::cont::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:38
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::cont::Field::Association::WholeDataSet
@ WholeDataSet
A "global" field that applies to the entirety of a vtkm::cont::DataSet.
vtkm::cont::DataSet::GetPointField
const vtkm::cont::Field & GetPointField(const std::string &name) const
Returns the first point field that matches the provided name.
Definition: DataSet.h:202
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
CoordinateSystem.h
vtkm::cont::DataSet::GetCellField
vtkm::cont::Field & GetCellField(const std::string &name)
Returns the first cell field that matches the provided name.
Definition: DataSet.h:181
vtkm::cont::DataSet::HasCellField
bool HasCellField(const std::string &name) const
Definition: DataSet.h:112
vtkm::cont::DataSet::GetNumberOfCoordinateSystems
vtkm::IdComponent GetNumberOfCoordinateSystems() const
Definition: DataSet.h:394
mangled_diy_namespace
Definition: Particle.h:351
vtkm::cont::SetGlobalGhostCellFieldName
void SetGlobalGhostCellFieldName(const std::string &name) noexcept
VTKM_DEPRECATED_SUPPRESS_END
#define VTKM_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:123
vtkm::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:30
vtkm::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:263
vtkm::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const std::vector< T > &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:235
vtkm::cont::make_FieldCell
vtkm::cont::Field make_FieldCell(std::string name, const vtkm::cont::ArrayHandle< T, S > &data)
Convenience function to build cell fields from vtkm::cont::ArrayHandle.
Definition: Field.h:297
vtkm::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const std::vector< T > &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:270
vtkm::cont::DataSet::GetField
vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any)
Returns the field that matches the provided name and association.
Definition: DataSet.h:161
UnknownArrayHandle.h
vtkm::cont::DataSet::CellSet
vtkm::cont::UnknownCellSet CellSet
Definition: DataSet.h:429
vtkm::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:228
VTKM_DEFAULT_CELL_SET_LIST
#define VTKM_DEFAULT_CELL_SET_LIST
Definition: DefaultTypes.h:77
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:31
vtkm::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:277
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm::cont::Field::Association::Any
@ Any
Any field regardless of the association.
vtkm_cont_export.h
vtkm::cont::Field::Association::Points
@ Points
A field that applies to points.
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
Field.h
vtkm::cont::DataSet::HasCoordinateSystem
bool HasCoordinateSystem(const std::string &name) const
Definition: DataSet.h:356
vtkm::cont::DataSet::HasField
bool HasField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: DataSet.h:105
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:28
vtkm::cont::DataSet::GetField
const vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:152
vtkm::CopyFlag::On
@ On
VTKM_DEPRECATED_SUPPRESS_BEGIN
#define VTKM_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:122
vtkm::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const vtkm::cont::UnknownArrayHandle &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:257
vtkm::cont::DataSet::GetCellSet
vtkm::cont::UnknownCellSet & GetCellSet()
Definition: DataSet.h:388
vtkm::cont::GetGlobalGhostCellFieldName
const std::string & GetGlobalGhostCellFieldName() noexcept
vtkm::cont::GlobalGhostCellFieldName
std::string & GlobalGhostCellFieldName() noexcept
VTKM_DEFAULT_TYPE_LIST
#define VTKM_DEFAULT_TYPE_LIST
Definition: DefaultTypes.h:45
vtkm::cont::Field::Association::Cells
@ Cells
A field that applies to cells.
ErrorBadValue.h
vtkm::cont::DataSet::GhostCellName
std::shared_ptr< std::string > GhostCellName
Definition: DataSet.h:430
vtkm::List
A template used to hold a list of types.
Definition: List.h:39
vtkm::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const vtkm::cont::UnknownArrayHandle &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:222
vtkm::cont::DataSet::GetCellField
const vtkm::cont::Field & GetCellField(const std::string &name) const
Returns the first cell field that matches the provided name.
Definition: DataSet.h:175
vtkm::cont::DataSet::CoordSystemNames
std::vector< std::string > CoordSystemNames
Definition: DataSet.h:424
VTKM_DEPRECATED
#define VTKM_DEPRECATED(...)
Definition: Deprecated.h:145
vtkm::cont::make_FieldPoint
vtkm::cont::Field make_FieldPoint(std::string name, const vtkm::cont::ArrayHandle< T, S > &data)
Convenience function to build point fields from vtkm::cont::ArrayHandle.
Definition: Field.h:283
vtkm::cont::DataSet::GetField
vtkm::cont::Field & GetField(vtkm::Id index)
Retrieves a field by index.
Definition: DataSet.h:101
vtkm::cont::DataSet::GetNumberOfFields
vtkm::IdComponent GetNumberOfFields() const
Definition: DataSet.h:391
vtkm::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:242