VTK-m  2.2
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 
95  VTKM_CONT void AddField(const std::string& name,
97  const vtkm::cont::UnknownArrayHandle& data);
98 
107  VTKM_CONT
108  const vtkm::cont::Field& GetField(vtkm::Id index) const { return this->Fields.GetField(index); }
109 
110  VTKM_CONT
111  vtkm::cont::Field& GetField(vtkm::Id index) { return this->Fields.GetField(index); }
113 
114  VTKM_CONT
115  bool HasField(const std::string& name,
117  {
118  return this->Fields.HasField(name, assoc);
119  }
120 
121  VTKM_CONT
122  bool HasCellField(const std::string& name) const
123  {
124  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Cells) != -1);
125  }
126 
127  VTKM_CONT
128  bool HasGhostCellField() const;
129 
130  VTKM_CONT
131  const std::string& GetGhostCellFieldName() const;
132 
133  VTKM_CONT
134  bool HasPointField(const std::string& name) const
135  {
136  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Points) != -1);
137  }
138 
139 
148  VTKM_CONT
150  const std::string& name,
152  {
153  return this->Fields.GetFieldIndex(name, assoc);
154  }
155 
161  VTKM_CONT
163  const std::string& name,
165  {
166  return this->Fields.GetField(name, assoc);
167  }
168 
169 
170  VTKM_CONT
172  const std::string& name,
174  {
175  return this->Fields.GetField(name, assoc);
176  }
178 
184  VTKM_CONT
185  const vtkm::cont::Field& GetCellField(const std::string& name) const
186  {
187  return this->GetField(name, vtkm::cont::Field::Association::Cells);
188  }
189 
190  VTKM_CONT
191  vtkm::cont::Field& GetCellField(const std::string& name)
192  {
193  return this->GetField(name, vtkm::cont::Field::Association::Cells);
194  }
196 
202  VTKM_CONT
203  vtkm::cont::Field GetGhostCellField() const;
205 
211  VTKM_CONT
212  const vtkm::cont::Field& GetPointField(const std::string& name) const
213  {
214  return this->GetField(name, vtkm::cont::Field::Association::Points);
215  }
216 
217  VTKM_CONT
218  vtkm::cont::Field& GetPointField(const std::string& name)
219  {
220  return this->GetField(name, vtkm::cont::Field::Association::Points);
221  }
223 
231  VTKM_CONT
232  void AddPointField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
233  {
234  this->AddField(fieldName, vtkm::cont::Field::Association::Points, field);
235  }
236 
237  template <typename T, typename Storage>
238  VTKM_CONT void AddPointField(const std::string& fieldName,
240  {
241  this->AddPointField(fieldName, vtkm::cont::UnknownArrayHandle{ field });
242  }
243 
244  template <typename T>
245  VTKM_CONT void AddPointField(const std::string& fieldName, const std::vector<T>& field)
246  {
247  this->AddField(
249  }
250 
251  template <typename T>
252  VTKM_CONT void AddPointField(const std::string& fieldName, const T* field, const vtkm::Id& n)
253  {
254  this->AddField(
256  }
258 
266  VTKM_CONT
267  void AddCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
268  {
269  this->AddField(fieldName, vtkm::cont::Field::Association::Cells, field);
270  }
271 
272  template <typename T, typename Storage>
273  VTKM_CONT void AddCellField(const std::string& fieldName,
275  {
276  this->AddCellField(fieldName, vtkm::cont::UnknownArrayHandle{ field });
277  }
278 
279  template <typename T>
280  VTKM_CONT void AddCellField(const std::string& fieldName, const std::vector<T>& field)
281  {
282  this->AddField(
284  }
285 
286  template <typename T>
287  VTKM_CONT void AddCellField(const std::string& fieldName, const T* field, const vtkm::Id& n)
288  {
289  this->AddField(
291  }
293 
297  VTKM_CONT void SetGhostCellFieldName(const std::string& name);
298 
302  VTKM_CONT void SetGhostCellField(const std::string& name);
303 
314  VTKM_CONT void SetGhostCellField(const vtkm::cont::Field& field);
315  VTKM_CONT void SetGhostCellField(const std::string& fieldName,
316  const vtkm::cont::UnknownArrayHandle& field);
318 
328  VTKM_CONT void SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field);
329 
330  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
331  VTKM_CONT
332  void AddGhostCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
333  {
334  this->SetGhostCellField(fieldName, field);
335  }
336 
337  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
338  VTKM_CONT
339  void AddGhostCellField(const vtkm::cont::UnknownArrayHandle& field)
340  {
341  this->SetGhostCellField(field);
342  }
343 
344  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
345  VTKM_CONT
346  void AddGhostCellField(const vtkm::cont::Field& field) { this->SetGhostCellField(field); }
347 
348 
354  VTKM_CONT
355  vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs);
356 
362  VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const std::string& name,
363  const vtkm::cont::UnknownArrayHandle& data);
364 
371  VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const std::string& pointFieldName);
372 
373  VTKM_CONT
374  bool HasCoordinateSystem(const std::string& name) const
375  {
376  return this->GetCoordinateSystemIndex(name) >= 0;
377  }
378 
379  VTKM_CONT
380  vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index = 0) const;
381 
385  VTKM_CONT
386  vtkm::IdComponent GetCoordinateSystemIndex(const std::string& name) const;
387 
388  VTKM_CONT const std::string& GetCoordinateSystemName(vtkm::Id index = 0) const;
389 
392  VTKM_CONT
393  vtkm::cont::CoordinateSystem GetCoordinateSystem(const std::string& name) const;
394 
395  template <typename CellSetType>
396  VTKM_CONT void SetCellSet(const CellSetType& cellSet)
397  {
399  this->SetCellSetImpl(cellSet);
400  }
401 
402  VTKM_CONT
403  const vtkm::cont::UnknownCellSet& GetCellSet() const { return this->CellSet; }
404 
405  VTKM_CONT
407 
408  VTKM_CONT
409  vtkm::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
410 
411  VTKM_CONT
413  {
414  return static_cast<vtkm::IdComponent>(this->CoordSystemNames.size());
415  }
416 
420  VTKM_CONT
421  void CopyStructure(const vtkm::cont::DataSet& source);
422 
436  VTKM_CONT void ConvertToExpected();
437 
438  VTKM_CONT
439  void PrintSummary(std::ostream& out) const;
440 
441 private:
442  std::vector<std::string> CoordSystemNames;
443  vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::WholeDataSet,
446 
448  std::shared_ptr<std::string> GhostCellName;
449 
450  VTKM_CONT void SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet);
451 };
452 
453 } // namespace cont
454 } // namespace vtkm
455 
456 //=============================================================================
457 // Specializations of serialization related classes
459 namespace vtkm
460 {
461 namespace cont
462 {
463 
472 template <typename... CellSetTypes>
473 struct DataSetWithCellSetTypes
474 {
475  vtkm::cont::DataSet DataSet;
476 
477  DataSetWithCellSetTypes() = default;
478 
479  explicit DataSetWithCellSetTypes(const vtkm::cont::DataSet& dataset)
480  : DataSet(dataset)
481  {
482  }
483 };
484 
485 template <typename... CellSetTypes>
486 struct DataSetWithCellSetTypes<vtkm::List<CellSetTypes...>>
487  : DataSetWithCellSetTypes<CellSetTypes...>
488 {
489  using DataSetWithCellSetTypes<CellSetTypes...>::DataSetWithCellSetTypes;
490 };
491 
492 template <typename FieldTypeList = VTKM_DEFAULT_TYPE_LIST,
493  typename CellSetTypesList = VTKM_DEFAULT_CELL_SET_LIST>
494 struct VTKM_DEPRECATED(
495  2.1,
496  "Serialize DataSet directly or use DataSetWithCellSetTypes for weird CellSets.")
497  SerializableDataSet : DataSetWithCellSetTypes<CellSetTypesList>
498 {
499  using DataSetWithCellSetTypes<CellSetTypesList>::DataSetWithCellSetTypes;
500 };
501 
502 }
503 } // vtkm::cont
504 
505 namespace mangled_diy_namespace
506 {
507 
508 template <>
509 struct VTKM_CONT_EXPORT Serialization<vtkm::cont::DataSet>
510 {
511  static VTKM_CONT void foo();
512  static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::DataSet& obj);
513  static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::DataSet& obj);
514 };
515 
516 template <typename... CellSetTypes>
517 struct Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>>
518 {
519 private:
520  using Type = vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>;
521 
522 public:
523  static VTKM_CONT void save(BinaryBuffer& bb, const Type& serializable)
524  {
525  const auto& dataset = serializable.DataSet;
526 
527  vtkmdiy::save(bb, dataset.GetCellSet().ResetCellSetList(vtkm::List<CellSetTypes...>{}));
528 
529  vtkm::IdComponent numberOfFields = dataset.GetNumberOfFields();
530  vtkmdiy::save(bb, numberOfFields);
531  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
532  {
533  vtkmdiy::save(bb, dataset.GetField(i));
534  }
535 
536  vtkm::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems();
537  vtkmdiy::save(bb, numberOfCoordinateSystems);
538  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
539  {
540  vtkmdiy::save(bb, dataset.GetCoordinateSystemName(i));
541  }
542  }
543 
544  static VTKM_CONT void load(BinaryBuffer& bb, Type& serializable)
545  {
546  auto& dataset = serializable.DataSet;
547  dataset = {}; // clear
548 
549  vtkm::cont::UncertainCellSet<vtkm::List<CellSetTypes...>> cells;
550  vtkmdiy::load(bb, cells);
551  dataset.SetCellSet(cells);
552 
553  vtkm::IdComponent numberOfFields = 0;
554  vtkmdiy::load(bb, numberOfFields);
555  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
556  {
557  vtkm::cont::Field field;
558  vtkmdiy::load(bb, field);
559  dataset.AddField(field);
560  }
561 
562  vtkm::IdComponent numberOfCoordinateSystems = 0;
563  vtkmdiy::load(bb, numberOfCoordinateSystems);
564  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
565  {
566  std::string coordName;
567  vtkmdiy::load(bb, coordName);
568  dataset.AddCoordinateSystem(coordName);
569  }
570  }
571 };
572 
573 template <typename... CellSetTypes>
574 struct Serialization<vtkm::cont::DataSetWithCellSetTypes<vtkm::List<CellSetTypes...>>>
575  : Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypes...>>
576 {
577 };
578 
580 template <typename FieldTypeList, typename CellSetTypesList>
581 struct Serialization<vtkm::cont::SerializableDataSet<FieldTypeList, CellSetTypesList>>
582  : Serialization<vtkm::cont::DataSetWithCellSetTypes<CellSetTypesList>>
583 {
584 };
586 
587 } // diy
589 
590 #endif //vtk_m_cont_DataSet_h
vtkm::cont::DataSet::GetCellSet
const vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:403
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:149
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:134
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:218
vtkm::cont::DataSet::GetField
const vtkm::cont::Field & GetField(vtkm::Id index) const
Retrieves a field by index.
Definition: DataSet.h:108
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:257
vtkm::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:396
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:212
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:191
vtkm::cont::DataSet::HasCellField
bool HasCellField(const std::string &name) const
Definition: DataSet.h:122
vtkm::cont::DataSet::GetNumberOfCoordinateSystems
vtkm::IdComponent GetNumberOfCoordinateSystems() const
Definition: DataSet.h:412
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:273
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:245
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:280
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:171
UnknownArrayHandle.h
vtkm::cont::DataSet::CellSet
vtkm::cont::UnknownCellSet CellSet
Definition: DataSet.h:447
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:238
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:287
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:374
vtkm::cont::DataSet::HasField
bool HasField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: DataSet.h:115
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:162
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:267
vtkm::cont::DataSet::GetCellSet
vtkm::cont::UnknownCellSet & GetCellSet()
Definition: DataSet.h:406
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:448
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:232
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:185
vtkm::cont::DataSet::CoordSystemNames
std::vector< std::string > CoordSystemNames
Definition: DataSet.h:442
VTKM_DEPRECATED
#define VTKM_DEPRECATED(...)
Definition: Deprecated.h:145
vtkm::cont::DataSet::GetField
vtkm::cont::Field & GetField(vtkm::Id index)
Retrieves a field by index.
Definition: DataSet.h:111
vtkm::cont::DataSet::GetNumberOfFields
vtkm::IdComponent GetNumberOfFields() const
Definition: DataSet.h:409
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:252