VTK-m  2.2
FieldCollection.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_internal_FieldCollection_h
11 #define vtk_m_cont_internal_FieldCollection_h
12 
13 #include <set>
14 #include <vtkm/cont/Field.h>
15 
16 namespace vtkm
17 {
18 namespace cont
19 {
20 namespace internal
21 {
22 
23 class VTKM_CONT_EXPORT FieldCollection
24 {
25 public:
26  VTKM_CONT
27  FieldCollection(std::initializer_list<vtkm::cont::Field::Association> validAssoc)
28  {
29  auto it = this->ValidAssoc.begin();
30  for (const auto& item : validAssoc)
31  it = this->ValidAssoc.insert(it, item);
32  }
33 
34  VTKM_CONT
35  FieldCollection(std::set<vtkm::cont::Field::Association>&& validAssoc)
36  : ValidAssoc(std::move(validAssoc))
37  {
38  }
39 
40  VTKM_CONT
41  void Clear() { this->Fields.clear(); }
42 
43  VTKM_CONT
44  vtkm::IdComponent GetNumberOfFields() const
45  {
46  return static_cast<vtkm::IdComponent>(this->Fields.size());
47  }
48 
49  VTKM_CONT void AddField(const Field& field);
50 
51  VTKM_CONT
52  const vtkm::cont::Field& GetField(vtkm::Id index) const;
53 
54  VTKM_CONT
55  vtkm::cont::Field& GetField(vtkm::Id index);
56 
57  VTKM_CONT
58  bool HasField(const std::string& name,
60  {
61  return (this->GetFieldIndex(name, assoc) != -1);
62  }
63 
64  VTKM_CONT
65  vtkm::Id GetFieldIndex(
66  const std::string& name,
68 
69  VTKM_CONT
70  const vtkm::cont::Field& GetField(
71  const std::string& name,
73 
74  VTKM_CONT
75  vtkm::cont::Field& GetField(
76  const std::string& name,
78 
79 private:
80  struct FieldCompare
81  {
82  using Key = std::pair<std::string, vtkm::cont::Field::Association>;
83 
84  template <typename T>
85  bool operator()(const T& a, const T& b) const
86  {
87  if (a.first == b.first)
88  return a.second < b.second && a.second != vtkm::cont::Field::Association::Any &&
90 
91  return a.first < b.first;
92  }
93  };
94 
95  std::map<FieldCompare::Key, vtkm::cont::Field, FieldCompare> Fields;
96  std::set<vtkm::cont::Field::Association> ValidAssoc;
97 };
98 
99 }
100 }
101 } // namespace vtkm::cont::internal
102 
103 #endif //vtk_m_cont_internal_FieldCollection_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:38
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_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
#define VTKM_CONT
Definition: ExportMacros.h:57
Field.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227