Viskores  1.0
CellLocatorChooser.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_CellLocatorChooser_h
19 #define viskores_cont_CellLocatorChooser_h
20 
26 #include <viskores/cont/DataSet.h>
27 
28 namespace viskores
29 {
30 namespace cont
31 {
32 
33 namespace detail
34 {
35 
36 template <typename CellSetType, typename CoordinateSystemArrayType>
37 struct CellLocatorChooserImpl
38 {
40 };
41 
43 
44 template <>
45 struct CellLocatorChooserImpl<viskores::cont::CellSetStructured<3>, UniformArray>
46 {
48 };
49 
50 using RectilinearArray =
54 
55 template <>
56 struct CellLocatorChooserImpl<viskores::cont::CellSetStructured<3>, RectilinearArray>
57 {
59 };
60 
61 } // namespace detail
62 
70 template <typename CellSetType, typename CoordinateSystemArrayType>
71 using CellLocatorChooser =
73 
74 namespace detail
75 {
76 
77 struct CastAndCallCellLocatorChooserFunctor
78 {
79  template <typename CellLocatorType, typename Functor, typename... Args>
80  void CallFunctorWithLocator(const viskores::cont::UnknownCellSet& cellSet,
81  const viskores::cont::CoordinateSystem& coordinateSystem,
82  Functor&& functor,
83  Args&&... args) const
84  {
85  CellLocatorType locator;
86  locator.SetCellSet(cellSet);
87  locator.SetCoordinates(coordinateSystem);
88 
89  functor(locator, std::forward<Args>(args)...);
90  }
91 
92  template <typename CellSetType, typename Functor, typename... Args>
93  void operator()(const CellSetType& cellSet,
94  const viskores::cont::CoordinateSystem& coordinateSystem,
95  Functor&& functor,
96  Args&&... args) const
97  {
98  this->CallFunctorWithLocator<viskores::cont::CellLocatorTwoLevel>(
99  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
100  }
101 
102  template <typename Functor, typename... Args>
103  void operator()(const viskores::cont::CellSetStructured<3>& cellSet,
104  const viskores::cont::CoordinateSystem& coordinateSystem,
105  Functor&& functor,
106  Args&&... args) const
107  {
108  auto coordArray = coordinateSystem.GetData();
109  if (coordArray.IsType<detail::UniformArray>())
110  {
111  this->CallFunctorWithLocator<viskores::cont::CellLocatorUniformGrid>(
112  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
113  }
114  else if (coordArray.IsType<detail::RectilinearArray>())
115  {
116  this->CallFunctorWithLocator<viskores::cont::CellLocatorRectilinearGrid>(
117  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
118  }
119  else
120  {
121  this->CallFunctorWithLocator<viskores::cont::CellLocatorTwoLevel>(
122  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
123  }
124  }
125 };
126 
127 } // namespace detail
128 
137 template <typename CellSetType, typename Functor, typename... Args>
139  const CellSetType& cellSet,
140  const viskores::cont::CoordinateSystem& coordinateSystem,
141  Functor&& functor,
142  Args&&... args)
143 {
145  detail::CastAndCallCellLocatorChooserFunctor{},
146  coordinateSystem,
147  std::forward<Functor>(functor),
148  std::forward<Args>(args)...);
149 }
150 
158 template <typename Functor, typename... Args>
160  Functor&& functor,
161  Args&&... args)
162 {
164  dataSet.GetCoordinateSystem(),
165  std::forward<Functor>(functor),
166  std::forward<Args>(args)...);
167 }
168 
169 }
170 } // namespace viskores::cont
171 
172 #endif //viskores_cont_CellLocatorChooser_h
viskores::cont::DataSet::GetCoordinateSystem
viskores::cont::CoordinateSystem GetCoordinateSystem(viskores::Id index=0) const
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:55
viskores::cont::CellLocatorBase::SetCellSet
void SetCellSet(const viskores::cont::UnknownCellSet &cellSet)
Specify the CellSet defining the structure of the cells being searched.
Definition: CellLocatorBase.h:56
viskores::cont::CellLocatorChooser
typename detail::CellLocatorChooserImpl< CellSetType, CoordinateSystemArrayType >::type CellLocatorChooser
A template to select an appropriate CellLocator based on CellSet type.
Definition: CellLocatorChooser.h:72
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
CellLocatorUniformGrid.h
viskores::cont::ArrayHandleUniformPointCoordinates
ArrayHandleUniformPointCoordinates is a specialization of ArrayHandle.
Definition: ArrayHandleUniformPointCoordinates.h:53
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
CastAndCall.h
CellLocatorTwoLevel.h
viskores::cont::CellLocatorUniformGrid
A cell locator optimized for finding cells in a uniform grid.
Definition: cont/CellLocatorUniformGrid.h:38
viskores::cont::CoordinateSystem::GetData
viskores::cont::UncertainArrayHandle< viskores::TypeListFieldVec3, ::viskores::cont::StorageListCommon > GetData() const
viskores::cont::CellLocatorTwoLevel
A locator that uses 2 nested levels of grids.
Definition: cont/CellLocatorTwoLevel.h:52
viskores::cont::CastAndCallCellLocatorChooser
void CastAndCallCellLocatorChooser(const CellSetType &cellSet, const viskores::cont::CoordinateSystem &coordinateSystem, Functor &&functor, Args &&... args)
Calls a functor with the appropriate type of CellLocator.
Definition: CellLocatorChooser.h:138
viskores::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:40
viskores::cont::DataSet::GetCellSet
const viskores::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:422
viskores::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:56
CellLocatorRectilinearGrid.h
CellSetStructured.h
viskores::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:345
viskores::cont::CellLocatorRectilinearGrid
A cell locator optimized for finding cells in a rectilinear grid.
Definition: cont/CellLocatorRectilinearGrid.h:36
DataSet.h