VTK-m  2.0
RemoveDegenerateCells.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_worklet_RemoveDegeneratePolygons_h
11 #define vtk_m_worklet_RemoveDegeneratePolygons_h
12 
14 
15 #include <vtkm/cont/ArrayCopy.h>
20 
22 
23 #include <vtkm/CellTraits.h>
24 
25 #include <vtkm/exec/CellFace.h>
26 
27 namespace vtkm
28 {
29 namespace worklet
30 {
31 
33 {
35  {
36  using ControlSignature = void(CellSetIn, FieldOutCell);
37  using ExecutionSignature = _2(CellShape, PointIndices);
38  using InputDomain = _1;
39 
40  template <vtkm::IdComponent dimensionality, typename CellShapeTag, typename PointVecType>
42  CellShapeTag,
43  PointVecType&& pointIds) const
44  {
45  const vtkm::IdComponent numPoints = pointIds.GetNumberOfComponents();
46  vtkm::IdComponent numUnduplicatedPoints = 0;
47  for (vtkm::IdComponent localPointId = 0; localPointId < numPoints; ++localPointId)
48  {
49  ++numUnduplicatedPoints;
50  if (numUnduplicatedPoints >= dimensionality + 1)
51  {
52  return true;
53  }
54  while (((localPointId < numPoints - 1) &&
55  (pointIds[localPointId] == pointIds[localPointId + 1])) ||
56  ((localPointId == numPoints - 1) && (pointIds[localPointId] == pointIds[0])))
57  {
58  // Skip over any repeated points. Assume any repeated points are adjacent.
59  ++localPointId;
60  }
61  }
62  return false;
63  }
64 
65  template <typename CellShapeTag, typename PointVecType>
67  CellShapeTag,
68  PointVecType&&)
69  {
70  return true;
71  }
72 
73  template <typename CellShapeTag, typename PointVecType>
75  CellShapeTag shape,
76  PointVecType&& pointIds)
77  {
78  const vtkm::IdComponent numFaces = vtkm::exec::CellFaceNumberOfFaces(shape, *this);
79  vtkm::Id numValidFaces = 0;
80  for (vtkm::IdComponent faceId = 0; faceId < numFaces; ++faceId)
81  {
82  if (this->CheckForDimensionality(
83  vtkm::CellTopologicalDimensionsTag<2>(), vtkm::CellShapeTagPolygon(), pointIds))
84  {
85  ++numValidFaces;
86  if (numValidFaces > 2)
87  {
88  return true;
89  }
90  }
91  }
92  return false;
93  }
94 
95  template <typename CellShapeTag, typename PointIdVec>
96  VTKM_EXEC bool operator()(CellShapeTag shape, const PointIdVec& pointIds) const
97  {
98  using Traits = vtkm::CellTraits<CellShapeTag>;
99  return this->CheckForDimensionality(
100  typename Traits::TopologicalDimensionsTag(), shape, pointIds);
101  }
102 
103  template <typename PointIdVec>
104  VTKM_EXEC bool operator()(vtkm::CellShapeTagGeneric shape, PointIdVec&& pointIds) const
105  {
106  bool passCell = true;
107  switch (shape.Id)
108  {
109  vtkmGenericCellShapeMacro(passCell = (*this)(CellShapeTag(), pointIds));
110  default:
111  // Raise an error for unknown cell type? Pass if we don't know.
112  passCell = true;
113  }
114  return passCell;
115  }
116  };
117 
118  template <typename CellSetType>
119  vtkm::cont::CellSetExplicit<> Run(const CellSetType& cellSet)
120  {
123  dispatcher.Invoke(cellSet, passFlags);
124 
128  vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()), passFlags, this->ValidCellIds);
129 
130  vtkm::cont::CellSetPermutation<CellSetType> permutation(this->ValidCellIds, cellSet);
132  vtkm::worklet::CellDeepCopy::Run(permutation, output);
133  return output;
134  }
135 
136  template <typename CellSetList>
138  {
140  cellSet.CastAndCall([&](const auto& concrete) { output = this->Run(concrete); });
141 
142  return output;
143  }
144 
146 
147 private:
149 };
150 }
151 }
152 
153 #endif //vtk_m_worklet_RemoveDegeneratePolygons_h
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< bool >
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::operator()
VTKM_EXEC bool operator()(CellShapeTag shape, const PointIdVec &pointIds) const
Definition: RemoveDegenerateCells.h:96
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::InputDomain
_1 InputDomain
Definition: RemoveDegenerateCells.h:38
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::CheckForDimensionality
VTKM_EXEC bool CheckForDimensionality(vtkm::CellTopologicalDimensionsTag< 0 >, CellShapeTag, PointVecType &&)
Definition: RemoveDegenerateCells.h:66
vtkm::cont::CellSetPermutation
Definition: CastAndCall.h:38
CellSetExplicit.h
vtkm::cont::make_ArrayHandleCounting
VTKM_CONT vtkm::cont::ArrayHandleCounting< CountingValueType > make_ArrayHandleCounting(CountingValueType start, CountingValueType step, vtkm::Id length)
A convenience function for creating an ArrayHandleCounting.
Definition: ArrayHandleCounting.h:151
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::CheckForDimensionality
VTKM_EXEC bool CheckForDimensionality(vtkm::CellTopologicalDimensionsTag< dimensionality >, CellShapeTag, PointVecType &&pointIds) const
Definition: RemoveDegenerateCells.h:41
vtkm::cont::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:38
CellFace.h
UncertainCellSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
IncidentElementIndices PointIndices
Definition: WorkletMapTopology.h:269
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayCopy.h
CellDeepCopy.h
vtkmGenericCellShapeMacro
#define vtkmGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:230
vtkm::worklet::RemoveDegenerateCells
Definition: RemoveDegenerateCells.h:32
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::ExecutionSignature
_2(CellShape, PointIndices) ExecutionSignature
Definition: RemoveDegenerateCells.h:37
vtkm::CellTopologicalDimensionsTag
vtkm::CellTraits::TopologyDimensionType is typedef to this with the template parameter set to TOPOLOG...
Definition: CellTraits.h:23
vtkm::worklet::RemoveDegenerateCells::GetValidCellIds
vtkm::cont::ArrayHandle< vtkm::Id > GetValidCellIds() const
Definition: RemoveDegenerateCells.h:145
vtkm::worklet::DispatcherMapTopology
Dispatcher for worklets that inherit from WorkletMapTopology.
Definition: DispatcherMapTopology.h:31
ArrayHandleIndex.h
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
vtkm::worklet::RemoveDegenerateCells::ValidCellIds
vtkm::cont::ArrayHandle< vtkm::Id > ValidCellIds
Definition: RemoveDegenerateCells.h:148
vtkm::cont::Algorithm::CopyIf
static VTKM_CONT void CopyIf(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:435
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates
Definition: RemoveDegenerateCells.h:34
vtkm::cont::UncertainCellSet::CastAndCall
VTKM_CONT void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying cell set type.
Definition: UncertainCellSet.h:81
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::operator()
VTKM_EXEC bool operator()(vtkm::CellShapeTagGeneric shape, PointIdVec &&pointIds) const
Definition: RemoveDegenerateCells.h:104
vtkm::worklet::RemoveDegenerateCells::Run
vtkm::cont::CellSetExplicit Run(const CellSetType &cellSet)
Definition: RemoveDegenerateCells.h:119
CellSetPermutation.h
vtkm::worklet::RemoveDegenerateCells::Run
vtkm::cont::CellSetExplicit Run(const vtkm::cont::UncertainCellSet< CellSetList > &cellSet)
Definition: RemoveDegenerateCells.h:137
vtkm::worklet::CellDeepCopy::Run
static VTKM_CONT void Run(const InCellSetType &inCellSet, vtkm::cont::CellSetExplicit< ShapeStorage, ConnectivityStorage, OffsetsStorage > &outCellSet, vtkm::Id numberOfPoints)
Definition: CellDeepCopy.h:68
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
vtkm::cont::CellSetExplicit
Definition: CastAndCall.h:36
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::CheckForDimensionality
VTKM_EXEC bool CheckForDimensionality(vtkm::CellTopologicalDimensionsTag< 3 >, CellShapeTag shape, PointVecType &&pointIds)
Definition: RemoveDegenerateCells.h:74
CellTraits.h
vtkm::worklet::RemoveDegenerateCells::IdentifyDegenerates::ControlSignature
void(CellSetIn, FieldOutCell) ControlSignature
Definition: RemoveDegenerateCells.h:36
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:152
DispatcherMapTopology.h
vtkm::CellTraits
Information about a cell based on its tag.
Definition: CellTraits.h:46
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:54
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263