Viskores  1.0
DataSet.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_DataSet_h
19 #define viskores_cont_DataSet_h
20 
22 
26 #include <viskores/cont/Field.h>
30 
31 namespace viskores
32 {
33 namespace cont
34 {
35 
36 VISKORES_CONT_EXPORT VISKORES_CONT std::string& GlobalGhostCellFieldName() noexcept;
37 
38 VISKORES_CONT_EXPORT VISKORES_CONT const std::string& GetGlobalGhostCellFieldName() noexcept;
39 
40 VISKORES_CONT_EXPORT VISKORES_CONT void SetGlobalGhostCellFieldName(
41  const std::string& name) noexcept;
42 
66 class VISKORES_CONT_EXPORT DataSet
67 {
68 public:
69  DataSet() = default;
70 
71  DataSet(viskores::cont::DataSet&&) = default;
72 
73  DataSet(const viskores::cont::DataSet&) = default;
74 
75  viskores::cont::DataSet& operator=(viskores::cont::DataSet&&) = default;
76 
77  viskores::cont::DataSet& operator=(const viskores::cont::DataSet&) = default;
78 
79  VISKORES_CONT void Clear();
80 
82  VISKORES_CONT viskores::Id GetNumberOfCells() const;
83 
88  VISKORES_CONT viskores::Id GetNumberOfPoints() const;
89 
96  VISKORES_CONT void AddField(const Field& field);
97 
104  VISKORES_CONT void AddField(const std::string& name,
107 
118  {
119  return this->Fields.GetField(index);
120  }
121 
123  viskores::cont::Field& GetField(viskores::Id index) { return this->Fields.GetField(index); }
125 
127  bool HasField(
128  const std::string& name,
130  {
131  return this->Fields.HasField(name, assoc);
132  }
133 
135  bool HasCellField(const std::string& name) const
136  {
137  return (this->Fields.GetFieldIndex(name, viskores::cont::Field::Association::Cells) != -1);
138  }
139 
141  bool HasGhostCellField() const;
142 
144  const std::string& GetGhostCellFieldName() const;
145 
147  bool HasPointField(const std::string& name) const
148  {
149  return (this->Fields.GetFieldIndex(name, viskores::cont::Field::Association::Points) != -1);
150  }
151 
152 
163  const std::string& name,
165  {
166  return this->Fields.GetFieldIndex(name, assoc);
167  }
168 
176  const std::string& name,
178  {
179  return this->Fields.GetField(name, assoc);
180  }
181 
182 
185  const std::string& name,
187  {
188  return this->Fields.GetField(name, assoc);
189  }
191 
198  const viskores::cont::Field& GetCellField(const std::string& name) const
199  {
200  return this->GetField(name, viskores::cont::Field::Association::Cells);
201  }
202 
204  viskores::cont::Field& GetCellField(const std::string& name)
205  {
206  return this->GetField(name, viskores::cont::Field::Association::Cells);
207  }
209 
216  viskores::cont::Field GetGhostCellField() const;
218 
225  const viskores::cont::Field& GetPointField(const std::string& name) const
226  {
227  return this->GetField(name, viskores::cont::Field::Association::Points);
228  }
229 
231  viskores::cont::Field& GetPointField(const std::string& name)
232  {
233  return this->GetField(name, viskores::cont::Field::Association::Points);
234  }
236 
245  void AddPointField(const std::string& fieldName, const viskores::cont::UnknownArrayHandle& field)
246  {
247  this->AddField(fieldName, viskores::cont::Field::Association::Points, field);
248  }
249 
250  template <typename T, typename Storage>
251  VISKORES_CONT void AddPointField(const std::string& fieldName,
253  {
254  this->AddPointField(fieldName, viskores::cont::UnknownArrayHandle{ field });
255  }
256 
257  template <typename T>
258  VISKORES_CONT void AddPointField(const std::string& fieldName, const std::vector<T>& field)
259  {
260  this->AddField(make_Field(
262  }
263 
264  template <typename T>
265  VISKORES_CONT void AddPointField(const std::string& fieldName,
266  const T* field,
267  const viskores::Id& n)
268  {
269  this->AddField(make_Field(
271  }
273 
282  void AddCellField(const std::string& fieldName, const viskores::cont::UnknownArrayHandle& field)
283  {
284  this->AddField(fieldName, viskores::cont::Field::Association::Cells, field);
285  }
286 
287  template <typename T, typename Storage>
288  VISKORES_CONT void AddCellField(const std::string& fieldName,
290  {
291  this->AddCellField(fieldName, viskores::cont::UnknownArrayHandle{ field });
292  }
293 
294  template <typename T>
295  VISKORES_CONT void AddCellField(const std::string& fieldName, const std::vector<T>& field)
296  {
297  this->AddField(make_Field(
299  }
300 
301  template <typename T>
302  VISKORES_CONT void AddCellField(const std::string& fieldName,
303  const T* field,
304  const viskores::Id& n)
305  {
306  this->AddField(make_Field(
308  }
310 
314  VISKORES_CONT void SetGhostCellFieldName(const std::string& name);
315 
319  VISKORES_CONT void SetGhostCellField(const std::string& name);
320 
331  VISKORES_CONT void SetGhostCellField(const viskores::cont::Field& field);
332  VISKORES_CONT void SetGhostCellField(const std::string& fieldName,
335 
345  VISKORES_CONT void SetGhostCellField(const viskores::cont::UnknownArrayHandle& field);
346 
347  VISKORES_DEPRECATED(2.0, "Use SetGhostCellField.")
349  void AddGhostCellField(const std::string& fieldName,
350  const viskores::cont::UnknownArrayHandle& field)
351  {
352  this->SetGhostCellField(fieldName, field);
353  }
354 
355  VISKORES_DEPRECATED(2.0, "Use SetGhostCellField.")
357  void AddGhostCellField(const viskores::cont::UnknownArrayHandle& field)
358  {
359  this->SetGhostCellField(field);
360  }
361 
362  VISKORES_DEPRECATED(2.0, "Use SetGhostCellField.")
364  void AddGhostCellField(const viskores::cont::Field& field) { this->SetGhostCellField(field); }
365 
366 
373  viskores::IdComponent AddCoordinateSystem(const viskores::cont::CoordinateSystem& cs);
374 
380  VISKORES_CONT viskores::IdComponent AddCoordinateSystem(
381  const std::string& name,
383 
390  VISKORES_CONT viskores::IdComponent AddCoordinateSystem(const std::string& pointFieldName);
391 
393  bool HasCoordinateSystem(const std::string& name) const
394  {
395  return this->GetCoordinateSystemIndex(name) >= 0;
396  }
397 
399  viskores::cont::CoordinateSystem GetCoordinateSystem(viskores::Id index = 0) const;
400 
405  viskores::IdComponent GetCoordinateSystemIndex(const std::string& name) const;
406 
407  VISKORES_CONT const std::string& GetCoordinateSystemName(viskores::Id index = 0) const;
408 
412  viskores::cont::CoordinateSystem GetCoordinateSystem(const std::string& name) const;
413 
414  template <typename CellSetType>
415  VISKORES_CONT void SetCellSet(const CellSetType& cellSet)
416  {
418  this->SetCellSetImpl(cellSet);
419  }
420 
422  const viskores::cont::UnknownCellSet& GetCellSet() const { return this->CellSet; }
423 
426 
428  viskores::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
429 
432  {
433  return static_cast<viskores::IdComponent>(this->CoordSystemNames.size());
434  }
435 
440  void CopyStructure(const viskores::cont::DataSet& source);
441 
455  VISKORES_CONT void ConvertToExpected();
456 
458  void PrintSummary(std::ostream& out) const;
459 
460 private:
461  std::vector<std::string> CoordSystemNames;
462  viskores::cont::internal::FieldCollection Fields{
466  };
467 
469  std::shared_ptr<std::string> GhostCellName;
470 
471  VISKORES_CONT void SetCellSetImpl(const viskores::cont::UnknownCellSet& cellSet);
472 };
473 
474 } // namespace cont
475 } // namespace viskores
476 
477 //=============================================================================
478 // Specializations of serialization related classes
480 namespace viskores
481 {
482 namespace cont
483 {
484 
493 template <typename... CellSetTypes>
494 struct DataSetWithCellSetTypes
495 {
496  viskores::cont::DataSet DataSet;
497 
498  DataSetWithCellSetTypes() = default;
499 
500  explicit DataSetWithCellSetTypes(const viskores::cont::DataSet& dataset)
501  : DataSet(dataset)
502  {
503  }
504 };
505 
506 template <typename... CellSetTypes>
507 struct DataSetWithCellSetTypes<viskores::List<CellSetTypes...>>
508  : DataSetWithCellSetTypes<CellSetTypes...>
509 {
510  using DataSetWithCellSetTypes<CellSetTypes...>::DataSetWithCellSetTypes;
511 };
512 
513 template <typename FieldTypeList = VISKORES_DEFAULT_TYPE_LIST,
514  typename CellSetTypesList = VISKORES_DEFAULT_CELL_SET_LIST>
515 struct VISKORES_DEPRECATED(
516  2.1,
517  "Serialize DataSet directly or use DataSetWithCellSetTypes for weird CellSets.")
518  SerializableDataSet : DataSetWithCellSetTypes<CellSetTypesList>
519 {
520  using DataSetWithCellSetTypes<CellSetTypesList>::DataSetWithCellSetTypes;
521 };
522 
523 }
524 } // viskores::cont
525 
526 namespace mangled_diy_namespace
527 {
528 
529 template <>
530 struct VISKORES_CONT_EXPORT Serialization<viskores::cont::DataSet>
531 {
532  static VISKORES_CONT void foo();
533  static VISKORES_CONT void save(BinaryBuffer& bb, const viskores::cont::DataSet& obj);
534  static VISKORES_CONT void load(BinaryBuffer& bb, viskores::cont::DataSet& obj);
535 };
536 
537 template <typename... CellSetTypes>
538 struct Serialization<viskores::cont::DataSetWithCellSetTypes<CellSetTypes...>>
539 {
540 private:
541  using Type = viskores::cont::DataSetWithCellSetTypes<CellSetTypes...>;
542 
543 public:
544  static VISKORES_CONT void save(BinaryBuffer& bb, const Type& serializable)
545  {
546  const auto& dataset = serializable.DataSet;
547 
548  viskoresdiy::save(bb, dataset.GetCellSet().ResetCellSetList(viskores::List<CellSetTypes...>{}));
549 
550  viskores::IdComponent numberOfFields = dataset.GetNumberOfFields();
551  viskoresdiy::save(bb, numberOfFields);
552  for (viskores::IdComponent i = 0; i < numberOfFields; ++i)
553  {
554  viskoresdiy::save(bb, dataset.GetField(i));
555  }
556 
557  viskores::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems();
558  viskoresdiy::save(bb, numberOfCoordinateSystems);
559  for (viskores::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
560  {
561  viskoresdiy::save(bb, dataset.GetCoordinateSystemName(i));
562  }
563  }
564 
565  static VISKORES_CONT void load(BinaryBuffer& bb, Type& serializable)
566  {
567  auto& dataset = serializable.DataSet;
568  dataset = {}; // clear
569 
570  viskores::cont::UncertainCellSet<viskores::List<CellSetTypes...>> cells;
571  viskoresdiy::load(bb, cells);
572  dataset.SetCellSet(cells);
573 
574  viskores::IdComponent numberOfFields = 0;
575  viskoresdiy::load(bb, numberOfFields);
576  for (viskores::IdComponent i = 0; i < numberOfFields; ++i)
577  {
578  viskores::cont::Field field;
579  viskoresdiy::load(bb, field);
580  dataset.AddField(field);
581  }
582 
583  viskores::IdComponent numberOfCoordinateSystems = 0;
584  viskoresdiy::load(bb, numberOfCoordinateSystems);
585  for (viskores::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
586  {
587  std::string coordName;
588  viskoresdiy::load(bb, coordName);
589  dataset.AddCoordinateSystem(coordName);
590  }
591  }
592 };
593 
594 template <typename... CellSetTypes>
595 struct Serialization<viskores::cont::DataSetWithCellSetTypes<viskores::List<CellSetTypes...>>>
596  : Serialization<viskores::cont::DataSetWithCellSetTypes<CellSetTypes...>>
597 {
598 };
599 
601 template <typename FieldTypeList, typename CellSetTypesList>
602 struct Serialization<viskores::cont::SerializableDataSet<FieldTypeList, CellSetTypesList>>
603  : Serialization<viskores::cont::DataSetWithCellSetTypes<CellSetTypesList>>
604 {
605 };
607 
608 } // diy
610 
611 #endif //viskores_cont_DataSet_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
VISKORES_IS_KNOWN_OR_UNKNOWN_CELL_SET
#define VISKORES_IS_KNOWN_OR_UNKNOWN_CELL_SET(T)
Definition: UnknownCellSet.h:325
viskores::cont::DataSet::GetCellField
viskores::cont::Field & GetCellField(const std::string &name)
Returns the first cell field that matches the provided name.
Definition: DataSet.h:204
viskores::cont::DataSet::GetNumberOfCoordinateSystems
viskores::IdComponent GetNumberOfCoordinateSystems() const
Definition: DataSet.h:431
ArrayHandle.h
viskores::cont::DataSet::GetPointField
const viskores::cont::Field & GetPointField(const std::string &name) const
Returns the first point field that matches the provided name.
Definition: DataSet.h:225
viskores::cont::DataSet::CoordSystemNames
std::vector< std::string > CoordSystemNames
Definition: DataSet.h:461
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::cont::DataSet::GetPointField
viskores::cont::Field & GetPointField(const std::string &name)
Returns the first point field that matches the provided name.
Definition: DataSet.h:231
viskores::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:46
viskores::cont::DataSet::GetCellField
const viskores::cont::Field & GetCellField(const std::string &name) const
Returns the first cell field that matches the provided name.
Definition: DataSet.h:198
FieldCollection.h
VISKORES_DEFAULT_TYPE_LIST
#define VISKORES_DEFAULT_TYPE_LIST
Definition: DefaultTypes.h:53
viskores::cont::DataSet::HasPointField
bool HasPointField(const std::string &name) const
Definition: DataSet.h:147
viskores::cont::Field::Association::Any
@ Any
Any field regardless of the association.
UnknownCellSet.h
viskores::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const viskores::cont::ArrayHandle< T, Storage > &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:288
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:38
viskores::cont::DataSet::GetField
const viskores::cont::Field & GetField(viskores::Id index) const
Retrieves a field by index.
Definition: DataSet.h:117
viskores::cont::DataSet::GetNumberOfFields
viskores::IdComponent GetNumberOfFields() const
Definition: DataSet.h:428
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
CoordinateSystem.h
viskores::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const viskores::cont::UnknownArrayHandle &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:245
viskores::cont::DataSet::GetField
viskores::cont::Field & GetField(viskores::Id index)
Retrieves a field by index.
Definition: DataSet.h:123
viskores::cont::Field::Association::Cells
@ Cells
A field that applies to cells.
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::DataSet::GetField
viskores::cont::Field & GetField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any)
Returns the field that matches the provided name and association.
Definition: DataSet.h:184
viskores::cont::GetGlobalGhostCellFieldName
const std::string & GetGlobalGhostCellFieldName() noexcept
viskores::cont::DataSet::HasCoordinateSystem
bool HasCoordinateSystem(const std::string &name) const
Definition: DataSet.h:393
viskores::List
A template used to hold a list of types.
Definition: List.h:47
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
UnknownArrayHandle.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const viskores::cont::UnknownArrayHandle &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:282
viskores::cont::DataSet::GhostCellName
std::shared_ptr< std::string > GhostCellName
Definition: DataSet.h:469
VISKORES_DEFAULT_CELL_SET_LIST
#define VISKORES_DEFAULT_CELL_SET_LIST
Definition: DefaultTypes.h:85
viskores::cont::make_Field
viskores::cont::Field make_Field(std::string name, Field::Association association, const T *data, viskores::Id size, viskores::CopyFlag copy)
Convenience functions to build fields from C style arrays and std::vector.
Definition: Field.h:266
viskores::CopyFlag::On
@ On
viskores::cont::SetGlobalGhostCellFieldName
void SetGlobalGhostCellFieldName(const std::string &name) noexcept
VISKORES_DEPRECATED
#define VISKORES_DEPRECATED(...)
Definition: Deprecated.h:156
viskores::cont::DataSet::GetCellSet
viskores::cont::UnknownCellSet & GetCellSet()
Definition: DataSet.h:425
Field.h
viskores::cont::DataSet::GetField
const viskores::cont::Field & GetField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:175
VISKORES_DEPRECATED_SUPPRESS_END
#define VISKORES_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:132
viskores::cont::DataSet::AddCellField
void AddCellField(const std::string &fieldName, const T *field, const viskores::Id &n)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:302
viskores::cont::GlobalGhostCellFieldName
std::string & GlobalGhostCellFieldName() noexcept
viskores::cont::DataSet::GetCellSet
const viskores::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:422
viskores::cont::DataSet::HasCellField
bool HasCellField(const std::string &name) const
Definition: DataSet.h:135
viskores::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:56
viskores::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:258
viskores::cont::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:46
viskores::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const T *field, const viskores::Id &n)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:265
ErrorBadValue.h
viskores::cont::Field::Association::WholeDataSet
@ WholeDataSet
A "global" field that applies to the entirety of a viskores::cont::DataSet.
viskores::cont::DataSet::GetFieldIndex
viskores::Id GetFieldIndex(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:162
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::cont::DataSet::CellSet
viskores::cont::UnknownCellSet CellSet
Definition: DataSet.h:468
viskores::cont::Field::Association::Points
@ Points
A field that applies to points.
viskores::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:39
viskores::cont::DataSet::HasField
bool HasField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any) const
Definition: DataSet.h:127
viskores::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:36
viskores::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const viskores::cont::ArrayHandle< T, Storage > &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:251
VISKORES_DEPRECATED_SUPPRESS_BEGIN
#define VISKORES_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:131
viskores::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:295
viskores::cont::DataSet::SetCellSet
void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:415
viskores_cont_export.h