VTK-m  2.2
CellLocatorChooser.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_CellLocatorChooser_h
11 #define vtk_m_cont_CellLocatorChooser_h
12 
13 #include <vtkm/cont/CastAndCall.h>
18 #include <vtkm/cont/DataSet.h>
19 
20 namespace vtkm
21 {
22 namespace cont
23 {
24 
25 namespace detail
26 {
27 
28 template <typename CellSetType, typename CoordinateSystemArrayType>
29 struct CellLocatorChooserImpl
30 {
32 };
33 
35 
36 template <>
37 struct CellLocatorChooserImpl<vtkm::cont::CellSetStructured<3>, UniformArray>
38 {
40 };
41 
42 using RectilinearArray =
46 
47 template <>
48 struct CellLocatorChooserImpl<vtkm::cont::CellSetStructured<3>, RectilinearArray>
49 {
51 };
52 
53 } // namespace detail
54 
62 template <typename CellSetType, typename CoordinateSystemArrayType>
63 using CellLocatorChooser =
65 
66 namespace detail
67 {
68 
69 struct CastAndCallCellLocatorChooserFunctor
70 {
71  template <typename CellLocatorType, typename Functor, typename... Args>
72  void CallFunctorWithLocator(const vtkm::cont::UnknownCellSet& cellSet,
73  const vtkm::cont::CoordinateSystem& coordinateSystem,
74  Functor&& functor,
75  Args&&... args) const
76  {
77  CellLocatorType locator;
78  locator.SetCellSet(cellSet);
79  locator.SetCoordinates(coordinateSystem);
80 
81  functor(locator, std::forward<Args>(args)...);
82  }
83 
84  template <typename CellSetType, typename Functor, typename... Args>
85  void operator()(const CellSetType& cellSet,
86  const vtkm::cont::CoordinateSystem& coordinateSystem,
87  Functor&& functor,
88  Args&&... args) const
89  {
90  this->CallFunctorWithLocator<vtkm::cont::CellLocatorTwoLevel>(
91  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
92  }
93 
94  template <typename Functor, typename... Args>
95  void operator()(const vtkm::cont::CellSetStructured<3>& cellSet,
96  const vtkm::cont::CoordinateSystem& coordinateSystem,
97  Functor&& functor,
98  Args&&... args) const
99  {
100  auto coordArray = coordinateSystem.GetData();
101  if (coordArray.IsType<detail::UniformArray>())
102  {
103  this->CallFunctorWithLocator<vtkm::cont::CellLocatorUniformGrid>(
104  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
105  }
106  else if (coordArray.IsType<detail::RectilinearArray>())
107  {
108  this->CallFunctorWithLocator<vtkm::cont::CellLocatorRectilinearGrid>(
109  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
110  }
111  else
112  {
113  this->CallFunctorWithLocator<vtkm::cont::CellLocatorTwoLevel>(
114  cellSet, coordinateSystem, std::forward<Functor>(functor), std::forward<Args>(args)...);
115  }
116  }
117 };
118 
119 } // namespace detail
120 
129 template <typename CellSetType, typename Functor, typename... Args>
130 VTKM_CONT void CastAndCallCellLocatorChooser(const CellSetType& cellSet,
131  const vtkm::cont::CoordinateSystem& coordinateSystem,
132  Functor&& functor,
133  Args&&... args)
134 {
135  vtkm::cont::CastAndCall(cellSet,
136  detail::CastAndCallCellLocatorChooserFunctor{},
137  coordinateSystem,
138  std::forward<Functor>(functor),
139  std::forward<Args>(args)...);
140 }
141 
149 template <typename Functor, typename... Args>
151  Functor&& functor,
152  Args&&... args)
153 {
155  dataSet.GetCoordinateSystem(),
156  std::forward<Functor>(functor),
157  std::forward<Args>(args)...);
158 }
159 
160 }
161 } // namespace vtkm::cont
162 
163 #endif //vtk_m_cont_CellLocatorChooser_h
vtkm::cont::DataSet::GetCellSet
const vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:403
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::cont::CellLocatorRectilinearGrid
Definition: cont/CellLocatorRectilinearGrid.h:22
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
vtkm::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:334
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
CellLocatorUniformGrid.h
vtkm::cont::CastAndCallCellLocatorChooser
void CastAndCallCellLocatorChooser(const CellSetType &cellSet, const vtkm::cont::CoordinateSystem &coordinateSystem, Functor &&functor, Args &&... args)
Calls a functor with the appropriate type of CellLocator.
Definition: CellLocatorChooser.h:130
vtkm::cont::CoordinateSystem
Manages a coordinate system for a DataSet.
Definition: CoordinateSystem.h:30
vtkm::cont::CellLocatorChooser
typename detail::CellLocatorChooserImpl< CellSetType, CoordinateSystemArrayType >::type CellLocatorChooser
A template to select an appropriate CellLocator based on CellSet type.
Definition: CellLocatorChooser.h:64
CastAndCall.h
CellLocatorTwoLevel.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::CellLocatorBase::SetCellSet
void SetCellSet(const vtkm::cont::UnknownCellSet &cellSet)
Specify the CellSet defining the structure of the cells being searched.
Definition: CellLocatorBase.h:49
vtkm::cont::CoordinateSystem::GetData
vtkm::cont::UncertainArrayHandle< vtkm::TypeListFieldVec3, ::vtkm::cont::StorageListCommon > GetData() const
CellLocatorRectilinearGrid.h
vtkm::cont::ArrayHandleUniformPointCoordinates
ArrayHandleUniformPointCoordinates is a specialization of ArrayHandle.
Definition: ArrayHandleUniformPointCoordinates.h:45
vtkm::cont::CellLocatorUniformGrid
Definition: cont/CellLocatorUniformGrid.h:22
vtkm::cont::DataSet::GetCoordinateSystem
vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index=0) const
CellSetStructured.h
vtkm::cont::CellLocatorTwoLevel
A locator that uses 2 nested levels of grids.
Definition: cont/CellLocatorTwoLevel.h:43
DataSet.h