Viskores  1.0
FieldSelection.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_filter_FieldSelection_h
19 #define viskores_filter_FieldSelection_h
20 
21 #include <viskores/Pair.h>
22 #include <viskores/cont/Field.h>
23 
25 
26 #include <initializer_list>
27 #include <memory>
28 
29 namespace viskores
30 {
31 namespace filter
32 {
33 
39 class VISKORES_FILTER_CORE_EXPORT FieldSelection
40 {
41 public:
42  enum struct Mode
43  {
44  None,
45  All,
46  Select,
47  Exclude
48  };
49 
50  VISKORES_CONT FieldSelection(Mode mode = Mode::Select);
51 
56  VISKORES_CONT FieldSelection(const std::string& field, Mode mode = Mode::Select);
57 
62  VISKORES_CONT FieldSelection(const char* field, Mode mode = Mode::Select);
63 
68  VISKORES_CONT FieldSelection(const std::string& field,
70  Mode mode = Mode::Select);
71 
76  VISKORES_CONT FieldSelection(std::initializer_list<std::string> fields, Mode mode = Mode::Select);
77 
87  std::initializer_list<std::pair<std::string, viskores::cont::Field::Association>> fields,
88  Mode mode = Mode::Select);
89 
100  Mode mode = Mode::Select);
101 
104  VISKORES_CONT FieldSelection& operator=(const FieldSelection& src);
105  VISKORES_CONT FieldSelection& operator=(FieldSelection&& rhs);
106 
108 
112  bool IsFieldSelected(const viskores::cont::Field& inputField) const
113  {
114  return this->IsFieldSelected(inputField.GetName(), inputField.GetAssociation());
115  }
116 
117  VISKORES_CONT bool IsFieldSelected(
118  const std::string& name,
120 
125  {
126  this->AddField(inputField.GetName(), inputField.GetAssociation(), this->GetMode());
127  }
128 
129  VISKORES_CONT void AddField(const viskores::cont::Field& inputField, Mode mode)
130  {
131  this->AddField(inputField.GetName(), inputField.GetAssociation(), mode);
132  }
133 
135  void AddField(
136  const std::string& fieldName,
138  {
139  this->AddField(fieldName, association, this->GetMode());
140  }
141 
142  VISKORES_CONT void AddField(const std::string& fieldName, Mode mode)
143  {
144  this->AddField(fieldName, viskores::cont::Field::Association::Any, mode);
145  }
146 
147  VISKORES_CONT void AddField(const std::string& fieldName,
149  Mode mode);
151 
157  {
158  return this->GetFieldMode(inputField.GetName(), inputField.GetAssociation());
159  }
160 
161  VISKORES_CONT Mode GetFieldMode(
162  const std::string& fieldName,
165 
170  VISKORES_CONT bool HasField(const viskores::cont::Field& inputField) const
171  {
172  return this->HasField(inputField.GetName(), inputField.GetAssociation());
173  }
174 
176  const std::string& name,
178  {
179  return (this->GetFieldMode(name, association) != Mode::None);
180  }
181 
183  VISKORES_CONT void ClearFields();
184 
190  VISKORES_CONT Mode GetMode() const;
191 
202  VISKORES_CONT void SetMode(Mode val);
203 
204 private:
205  struct InternalStruct;
206  std::unique_ptr<InternalStruct> Internals;
207 };
208 
209 }
210 } // namespace viskores::filter
211 
212 #endif // viskores_filter_FieldSelection_h
viskores::filter::FieldSelection::GetFieldMode
Mode GetFieldMode(const viskores::cont::Field &inputField) const
Definition: FieldSelection.h:156
viskores::cont::Field::GetAssociation
Association GetAssociation() const
Return the association of the field.
Definition: Field.h:153
viskores::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:46
viskores::cont::Field::Association::Any
@ Any
Any field regardless of the association.
Pair.h
viskores::filter::FieldSelection::AddField
void AddField(const std::string &fieldName, Mode mode)
Definition: FieldSelection.h:142
viskores_filter_core_export.h
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::filter::FieldSelection::IsFieldSelected
bool IsFieldSelected(const viskores::cont::Field &inputField) const
Returns true if the input field should be mapped to the output dataset.
Definition: FieldSelection.h:112
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::filter::FieldSelection::HasField
bool HasField(const viskores::cont::Field &inputField) const
Returns true if the input field has been added to this selection.
Definition: FieldSelection.h:170
viskores::filter::FieldSelection::HasField
bool HasField(const std::string &name, viskores::cont::Field::Association association=viskores::cont::Field::Association::Any) const
Definition: FieldSelection.h:175
viskores::filter::FieldSelection::Mode
Mode
Definition: FieldSelection.h:42
Field.h
viskores::cont::Field::GetName
const std::string & GetName() const
Return the name of the field.
Definition: Field.h:151
viskores::Pair
A viskores::Pair is essentially the same as an STL pair object except that the methods (constructors ...
Definition: Pair.h:37
viskores::filter::FieldSelection
A FieldSelection stores information about fields to map for input dataset to output when a filter is ...
Definition: FieldSelection.h:39
viskores::filter::FieldSelection::Internals
std::unique_ptr< InternalStruct > Internals
Definition: FieldSelection.h:205
viskores::filter::FieldSelection::AddField
void AddField(const viskores::cont::Field &inputField)
Definition: FieldSelection.h:124
viskores::filter::FieldSelection::AddField
void AddField(const viskores::cont::Field &inputField, Mode mode)
Definition: FieldSelection.h:129
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::filter::FieldSelection::AddField
void AddField(const std::string &fieldName, viskores::cont::Field::Association association=viskores::cont::Field::Association::Any)
Definition: FieldSelection.h:135