VTK-m  2.0
CellSampler.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_rendering_raytracing_CellSampler_h
11 #define vtk_m_rendering_raytracing_CellSampler_h
12 
13 #include <vtkm/VecVariable.h>
16 
17 #ifndef CELL_SHAPE_ZOO
18 #define CELL_SHAPE_ZOO 255
19 #endif
20 
21 #ifndef CELL_SHAPE_STRUCTURED
22 #define CELL_SHAPE_STRUCTURED 254
23 #endif
24 
25 namespace vtkm
26 {
27 namespace rendering
28 {
29 namespace raytracing
30 {
31 
32 namespace detail
33 {
34 template <typename CellTag>
35 VTKM_EXEC_CONT inline vtkm::Int32 GetNumberOfPoints(CellTag tag);
36 
37 template <>
38 VTKM_EXEC_CONT inline vtkm::Int32 GetNumberOfPoints<vtkm::CellShapeTagHexahedron>(
39  vtkm::CellShapeTagHexahedron vtkmNotUsed(tag))
40 {
41  return 8;
42 }
43 
44 template <>
45 VTKM_EXEC_CONT inline vtkm::Int32 GetNumberOfPoints<vtkm::CellShapeTagTetra>(
46  vtkm::CellShapeTagTetra vtkmNotUsed(tag))
47 {
48  return 4;
49 }
50 
51 template <>
52 VTKM_EXEC_CONT inline vtkm::Int32 GetNumberOfPoints<vtkm::CellShapeTagWedge>(
53  vtkm::CellShapeTagWedge vtkmNotUsed(tag))
54 {
55  return 6;
56 }
57 
58 template <>
59 VTKM_EXEC_CONT inline vtkm::Int32 GetNumberOfPoints<vtkm::CellShapeTagPyramid>(
60  vtkm::CellShapeTagPyramid vtkmNotUsed(tag))
61 {
62  return 5;
63 }
64 
65 template <typename P, typename S, typename CellShapeTagType>
66 VTKM_EXEC_CONT inline bool Sample(const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
67  const vtkm::Vec<S, 8>& scalars,
68  const vtkm::Vec<P, 3>& sampleLocation,
69  S& lerpedScalar,
70  const CellShapeTagType& shapeTag)
71 {
72 
73  bool validSample = true;
75  vtkm::VecVariable<S, 8> scalarVec;
76  for (vtkm::Int32 i = 0; i < GetNumberOfPoints(shapeTag); ++i)
77  {
78  pointsVec.Append(points[i]);
79  scalarVec.Append(scalars[i]);
80  }
81  vtkm::Vec<P, 3> pcoords;
82  vtkm::exec::WorldCoordinatesToParametricCoordinates(pointsVec, sampleLocation, shapeTag, pcoords);
83  P pmin, pmax;
84  pmin = vtkm::Min(vtkm::Min(pcoords[0], pcoords[1]), pcoords[2]);
85  pmax = vtkm::Max(vtkm::Max(pcoords[0], pcoords[1]), pcoords[2]);
86  if (pmin < 0.f || pmax > 1.f)
87  {
88  validSample = false;
89  }
90  vtkm::exec::CellInterpolate(scalarVec, pcoords, shapeTag, lerpedScalar);
91  return validSample;
92 }
93 
94 template <typename S, typename P, typename CellShapeTagType>
95 VTKM_EXEC_CONT inline bool Sample(const vtkm::VecAxisAlignedPointCoordinates<3>& points,
96  const vtkm::Vec<S, 8>& scalars,
97  const vtkm::Vec<P, 3>& sampleLocation,
98  S& lerpedScalar,
99  const CellShapeTagType& vtkmNotUsed(shapeTag))
100 {
101 
102  bool validSample = true;
103  vtkm::Vec<P, 3> pcoords;
104  vtkm::exec::WorldCoordinatesToParametricCoordinates(
105  points, sampleLocation, vtkm::CellShapeTagHexahedron(), pcoords);
106  P pmin, pmax;
107  pmin = vtkm::Min(vtkm::Min(pcoords[0], pcoords[1]), pcoords[2]);
108  pmax = vtkm::Max(vtkm::Max(pcoords[0], pcoords[1]), pcoords[2]);
109  if (pmin < 0.f || pmax > 1.f)
110  {
111  validSample = false;
112  }
113  vtkm::exec::CellInterpolate(scalars, pcoords, vtkm::CellShapeTagHexahedron(), lerpedScalar);
114  return validSample;
115 }
116 } // namespace detail
117 
118 //
119 // General Template: returns false if sample location is outside the cell
120 //
121 template <int CellType>
123 {
124 public:
125  template <typename P, typename S>
127  const vtkm::Vec<S, 8>& vtkmNotUsed(scalars),
128  const vtkm::Vec<P, 3>& vtkmNotUsed(sampleLocation),
129  S& vtkmNotUsed(lerpedScalar),
130  const vtkm::Int32& vtkmNotUsed(cellShape = CellType)) const
131  {
132  static_assert(CellType != CELL_SHAPE_ZOO && CellType != CELL_SHAPE_STRUCTURED &&
133  CellType != CELL_SHAPE_HEXAHEDRON && CellType != CELL_SHAPE_TETRA &&
134  CellType != CELL_SHAPE_WEDGE && CellType != CELL_SHAPE_PYRAMID,
135  "Cell Sampler: Default template. This should not happen.\n");
136  return false;
137  }
138 };
139 
140 //
141 // Zoo Sampler
142 //
143 template <>
144 class CellSampler<255>
145 {
146 public:
147  template <typename P, typename S>
148  VTKM_EXEC_CONT inline bool SampleCell(const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
149  const vtkm::Vec<S, 8>& scalars,
150  const vtkm::Vec<P, 3>& sampleLocation,
151  S& lerpedScalar,
152  const vtkm::Int32& cellShape) const
153  {
154  bool valid = false;
155  if (cellShape == CELL_SHAPE_HEXAHEDRON)
156  {
157  valid = detail::Sample(
158  points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagHexahedron());
159  }
160 
161  if (cellShape == CELL_SHAPE_TETRA)
162  {
163  valid =
164  detail::Sample(points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagTetra());
165  }
166 
167  if (cellShape == CELL_SHAPE_WEDGE)
168  {
169  valid =
170  detail::Sample(points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagWedge());
171  }
172  if (cellShape == CELL_SHAPE_PYRAMID)
173  {
174  valid =
175  detail::Sample(points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagPyramid());
176  }
177  return valid;
178  }
179 };
180 
181 //
182 // Single type hex
183 //
184 template <>
186 {
187 public:
188  template <typename P, typename S>
190  const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
191  const vtkm::Vec<S, 8>& scalars,
192  const vtkm::Vec<P, 3>& sampleLocation,
193  S& lerpedScalar,
194  const vtkm::Int32& vtkmNotUsed(cellShape = CELL_SHAPE_HEXAHEDRON)) const
195  {
196  return detail::Sample(
197  points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagHexahedron());
198  }
199 };
200 
201 //
202 // Single type hex uniform and rectilinear
203 // calls fast path for sampling
204 //
205 template <>
207 {
208 public:
209  template <typename P, typename S>
211  const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
212  const vtkm::Vec<S, 8>& scalars,
213  const vtkm::Vec<P, 3>& sampleLocation,
214  S& lerpedScalar,
215  const vtkm::Int32& vtkmNotUsed(cellShape = CELL_SHAPE_HEXAHEDRON)) const
216  {
217  vtkm::VecAxisAlignedPointCoordinates<3> rPoints(points[0], points[6] - points[0]);
218  return detail::Sample(
219  rPoints, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagHexahedron());
220  }
221 };
222 
223 //
224 // Single type pyramid
225 //
226 template <>
228 {
229 public:
230  template <typename P, typename S>
232  const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
233  const vtkm::Vec<S, 8>& scalars,
234  const vtkm::Vec<P, 3>& sampleLocation,
235  S& lerpedScalar,
236  const vtkm::Int32& vtkmNotUsed(cellShape = CELL_SHAPE_PYRAMID)) const
237  {
238  return detail::Sample(
239  points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagPyramid());
240  }
241 };
242 
243 
244 //
245 // Single type Tet
246 //
247 template <>
249 {
250 public:
251  template <typename P, typename S>
253  const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
254  const vtkm::Vec<S, 8>& scalars,
255  const vtkm::Vec<P, 3>& sampleLocation,
256  S& lerpedScalar,
257  const vtkm::Int32& vtkmNotUsed(cellShape = CELL_SHAPE_TETRA)) const
258  {
259  return detail::Sample(points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagTetra());
260  }
261 };
262 
263 //
264 // Single type Wedge
265 //
266 template <>
268 {
269 public:
270  template <typename P, typename S>
272  const vtkm::Vec<vtkm::Vec<P, 3>, 8>& points,
273  const vtkm::Vec<S, 8>& scalars,
274  const vtkm::Vec<P, 3>& sampleLocation,
275  S& lerpedScalar,
276  const vtkm::Int32& vtkmNotUsed(cellShape = CELL_SHAPE_WEDGE)) const
277  {
278  return detail::Sample(points, scalars, sampleLocation, lerpedScalar, vtkm::CellShapeTagWedge());
279  }
280 };
281 }
282 }
283 } // namespace vtkm::rendering::raytracing
284 #endif
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
Definition: CellShape.h:49
vtkm::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:78
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::rendering::raytracing::CellSampler::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &vtkmNotUsed(points), const vtkm::Vec< S, 8 > &vtkmNotUsed(scalars), const vtkm::Vec< P, 3 > &vtkmNotUsed(sampleLocation), S &vtkmNotUsed(lerpedScalar), const vtkm::Int32 &vtkmNotUsed(cellShape=CellType)) const
Definition: CellSampler.h:126
vtkm::rendering::raytracing::CellSampler< CELL_SHAPE_TETRA >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &vtkmNotUsed(cellShape=CELL_SHAPE_TETRA)) const
Definition: CellSampler.h:252
CellInterpolate.h
vtkm::VecVariable::Append
VTKM_EXEC_CONT void Append(ComponentType value)
Definition: VecVariable.h:80
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::CELL_SHAPE_TETRA
@ CELL_SHAPE_TETRA
Definition: CellShape.h:46
vtkm::exec::CellInterpolate
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const vtkm::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:56
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
Definition: CellShape.h:48
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::rendering::raytracing::CellSampler< CELL_SHAPE_PYRAMID >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &vtkmNotUsed(cellShape=CELL_SHAPE_PYRAMID)) const
Definition: CellSampler.h:231
vtkm::rendering::raytracing::CellSampler< CELL_SHAPE_STRUCTURED >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &vtkmNotUsed(cellShape=CELL_SHAPE_HEXAHEDRON)) const
Definition: CellSampler.h:210
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
VecVariable.h
vtkm::rendering::raytracing::CellSampler
Definition: CellSampler.h:122
vtkm::rendering::raytracing::CellSampler< CELL_SHAPE_HEXAHEDRON >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &vtkmNotUsed(cellShape=CELL_SHAPE_HEXAHEDRON)) const
Definition: CellSampler.h:189
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
Definition: CellShape.h:50
vtkm::rendering::raytracing::CellSampler< CELL_SHAPE_WEDGE >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &vtkmNotUsed(cellShape=CELL_SHAPE_WEDGE)) const
Definition: CellSampler.h:271
CELL_SHAPE_STRUCTURED
#define CELL_SHAPE_STRUCTURED
Definition: CellSampler.h:22
vtkm::rendering::raytracing::CellSampler< 255 >::SampleCell
VTKM_EXEC_CONT bool SampleCell(const vtkm::Vec< vtkm::Vec< P, 3 >, 8 > &points, const vtkm::Vec< S, 8 > &scalars, const vtkm::Vec< P, 3 > &sampleLocation, S &lerpedScalar, const vtkm::Int32 &cellShape) const
Definition: CellSampler.h:148
CELL_SHAPE_ZOO
#define CELL_SHAPE_ZOO
Definition: CellSampler.h:18
ParametricCoordinates.h