VTK-m  2.0
MeshQualityWorklet.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 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2018 UT-Battelle, LLC.
11 // Copyright 2018 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-NA0003525 with NTESS,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 #ifndef vtk_m_filter_mesh_info_worklet_MeshQualityWorklet_h
21 #define vtk_m_filter_mesh_info_worklet_MeshQualityWorklet_h
22 
24 
25 #include <vtkm/cont/DataSet.h>
26 #include <vtkm/cont/Field.h>
28 
29 #include <vtkm/ErrorCode.h>
30 #include <vtkm/TypeList.h>
31 
32 namespace
33 {
34 
41 template <typename Derived>
42 struct MeshQualityWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
43 {
44  using ControlSignature = void(CellSetIn cellset,
45  FieldInPoint pointCoords,
46  FieldOutCell metricOut);
47  using ExecutionSignature = void(CellShape, PointCount, _2, _3);
48 
49 
50  template <typename CellShapeType, typename PointCoordVecType, typename OutType>
51  VTKM_EXEC void operator()(CellShapeType shape,
52  const vtkm::IdComponent& numPoints,
53  const PointCoordVecType& pts,
54  OutType& metricValue) const
55  {
56  vtkm::UInt8 thisId = shape.Id;
57  if (shape.Id == vtkm::CELL_SHAPE_POLYGON)
58  {
59  if (numPoints == 3)
61  else if (numPoints == 4)
62  thisId = vtkm::CELL_SHAPE_QUAD;
63  }
64 
65  const Derived* self = reinterpret_cast<const Derived*>(this);
67  switch (thisId)
68  {
69  vtkmGenericCellShapeMacro(metricValue = self->template ComputeMetric<OutType>(
70  numPoints, pts, CellShapeTag{}, errorCode));
71  default:
73  metricValue = OutType(0.0);
74  }
75 
76  if (errorCode != vtkm::ErrorCode::Success)
77  {
78  this->RaiseError(vtkm::ErrorString(errorCode));
79  }
80  }
81 
83  const vtkm::cont::Field& field) const
84  {
85  if (!field.IsPointField())
86  {
87  throw vtkm::cont::ErrorBadValue("Active field for MeshQuality must be point coordinates. "
88  "But the active field is not a point field.");
89  }
90 
92  vtkm::cont::Invoker invoke;
93 
94  auto resolveType = [&](const auto& concrete) {
95  using T = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
97  invoke(*reinterpret_cast<const Derived*>(this), input.GetCellSet(), concrete, result);
98  outArray = result;
99  };
100  field.GetData()
102  resolveType);
103 
104  return outArray;
105  }
106 };
107 
108 } // anonymous namespace
109 
110 #endif //vtk_m_filter_mesh_info_worklet_MeshQualityWorklet_h
vtkm::cont::Field::IsPointField
VTKM_CONT bool IsPointField() const
Definition: cont/Field.h:67
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::cont::UnknownArrayHandle::CastAndCallForTypesWithFloatFallback
VTKM_CONT void CastAndCallForTypesWithFloatFallback(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type with a float cast fallback.
Definition: UnknownArrayHandle.h:1051
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::ErrorCode::Success
@ Success
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
vtkm::cont::DataSet
Definition: DataSet.h:34
ErrorCode.h
vtkm::cont::Field::GetData
const vtkm::cont::UnknownArrayHandle & GetData() const
vtkmGenericCellShapeMacro
#define vtkmGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:230
UnknownArrayHandle.h
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: cont/Field.h:31
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
TypeList.h
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::CELL_SHAPE_TRIANGLE
@ CELL_SHAPE_TRIANGLE
Definition: CellShape.h:41
vtkm::ErrorCode::CellNotFound
@ CellNotFound
vtkm::TypeListFieldVec3
vtkm::List< vtkm::Vec3f_32, vtkm::Vec3f_64 > TypeListFieldVec3
A list containing types for values for fields with three dimensional vectors.
Definition: TypeList.h:57
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
Field.h
vtkm::ErrorString
const VTKM_EXEC_CONT char * ErrorString(vtkm::ErrorCode code) noexcept
Definition: ErrorCode.h:40
WorkletMapTopology.h
vtkm::CELL_SHAPE_POLYGON
@ CELL_SHAPE_POLYGON
Definition: CellShape.h:43
vtkm::cont::DataSet::GetCellSet
const VTKM_CONT vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:362
DataSet.h
vtkm::exec::FunctorBase::RaiseError
VTKM_EXEC void RaiseError(const char *message) const
Definition: FunctorBase.h:40
vtkm::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
Definition: CellShape.h:45