Viskores  1.0
CellLocatorMultiplexer.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_exec_CellLocatorMultiplexer_h
19 #define viskores_exec_CellLocatorMultiplexer_h
20 
21 #include <viskores/ErrorCode.h>
22 #include <viskores/TypeList.h>
23 
24 #include <viskores/exec/Variant.h>
25 
26 namespace viskores
27 {
28 namespace exec
29 {
30 
31 namespace detail
32 {
33 
34 struct FindCellFunctor
35 {
36  template <typename Locator>
37  VISKORES_EXEC viskores::ErrorCode operator()(Locator&& locator,
38  const viskores::Vec3f& point,
39  viskores::Id& cellId,
40  viskores::Vec3f& parametric) const
41  {
42  return locator.FindCell(point, cellId, parametric);
43  }
44 
45  template <typename Locator, typename LastCell>
46  VISKORES_EXEC viskores::ErrorCode operator()(Locator&& locator,
47  const viskores::Vec3f& point,
48  viskores::Id& cellId,
49  viskores::Vec3f& parametric,
50  LastCell& lastCell) const
51  {
52  using ConcreteLastCell = typename std::decay_t<Locator>::LastCell;
53  if (!lastCell.template IsType<ConcreteLastCell>())
54  {
55  lastCell = ConcreteLastCell{};
56  }
57  return locator.FindCell(point, cellId, parametric, lastCell.template Get<ConcreteLastCell>());
58  }
59 };
60 
61 } // namespace detail
62 
63 template <typename... LocatorTypes>
64 class VISKORES_ALWAYS_EXPORT CellLocatorMultiplexer
65 {
66  viskores::exec::Variant<LocatorTypes...> Locators;
67 
68 public:
69  CellLocatorMultiplexer() = default;
70 
71  using LastCell = viskores::exec::Variant<typename LocatorTypes::LastCell...>;
72 
73  template <typename Locator>
74  VISKORES_CONT CellLocatorMultiplexer(const Locator& locator)
75  : Locators(locator)
76  {
77  }
78 
80  viskores::Id& cellId,
81  viskores::Vec3f& parametric) const
82  {
83  return this->Locators.CastAndCall(detail::FindCellFunctor{}, point, cellId, parametric);
84  }
85 
87  viskores::Id& cellId,
88  viskores::Vec3f& parametric,
89  LastCell& lastCell) const
90  {
91  return this->Locators.CastAndCall(
92  detail::FindCellFunctor{}, point, cellId, parametric, lastCell);
93  }
94 };
95 
96 }
97 } // namespace viskores::exec
98 
99 #endif //viskores_exec_CellLocatorMultiplexer_h
Variant.h
viskores::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:36
viskores::exec::CellLocatorMultiplexer::Locators
viskores::exec::Variant< LocatorTypes... > Locators
Definition: CellLocatorMultiplexer.h:66
viskores::exec::CellLocatorMultiplexer::FindCell
viskores::ErrorCode FindCell(const viskores::Vec3f &point, viskores::Id &cellId, viskores::Vec3f &parametric) const
Definition: CellLocatorMultiplexer.h:79
ErrorCode.h
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
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
TypeList.h
viskores::exec::CellLocatorMultiplexer::CellLocatorMultiplexer
CellLocatorMultiplexer(const Locator &locator)
Definition: CellLocatorMultiplexer.h:74
viskores::exec::CellLocatorMultiplexer
Definition: CellLocatorMultiplexer.h:64
viskores::exec::CellLocatorMultiplexer::FindCell
viskores::ErrorCode FindCell(const viskores::Vec3f &point, viskores::Id &cellId, viskores::Vec3f &parametric, LastCell &lastCell) const
Definition: CellLocatorMultiplexer.h:86
viskores::Vec< viskores::FloatDefault, 3 >
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
viskores::exec::CellLocatorMultiplexer::LastCell
viskores::exec::Variant< typename LocatorTypes::LastCell... > LastCell
Definition: CellLocatorMultiplexer.h:71