VTK-m  2.0
worklet/ExtractGeometry.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 vtkm_m_worklet_ExtractGeometry_h
11 #define vtkm_m_worklet_ExtractGeometry_h
12 
14 
15 #include <vtkm/cont/Algorithm.h>
16 #include <vtkm/cont/ArrayCopy.h>
17 #include <vtkm/cont/ArrayHandle.h>
20 #include <vtkm/cont/Invoker.h>
22 
23 #include <vtkm/ImplicitFunction.h>
24 
25 namespace vtkm
26 {
27 namespace worklet
28 {
29 
31 {
32 public:
34  // Worklet to identify cells within volume of interest
36  {
37  public:
38  using ControlSignature = void(CellSetIn cellset,
39  WholeArrayIn coordinates,
40  ExecObject implicitFunction,
41  FieldOutCell passFlags);
43 
44  VTKM_CONT
45  ExtractCellsByVOI(bool extractInside, bool extractBoundaryCells, bool extractOnlyBoundaryCells)
46  : ExtractInside(extractInside)
47  , ExtractBoundaryCells(extractBoundaryCells)
48  , ExtractOnlyBoundaryCells(extractOnlyBoundaryCells)
49  {
50  }
51 
52  template <typename ConnectivityInVec, typename InVecFieldPortalType, typename ImplicitFunction>
53  VTKM_EXEC bool operator()(vtkm::Id numIndices,
54  const ConnectivityInVec& connectivityIn,
55  const InVecFieldPortalType& coordinates,
56  const ImplicitFunction& function) const
57  {
58  // Count points inside/outside volume of interest
59  vtkm::IdComponent inCnt = 0;
60  vtkm::IdComponent outCnt = 0;
61  vtkm::Id indx;
62  for (indx = 0; indx < numIndices; indx++)
63  {
64  vtkm::Id ptId = connectivityIn[static_cast<vtkm::IdComponent>(indx)];
65  vtkm::Vec<FloatDefault, 3> coordinate = coordinates.Get(ptId);
66  vtkm::FloatDefault value = function.Value(coordinate);
67  if (value <= 0)
68  inCnt++;
69  if (value >= 0)
70  outCnt++;
71  }
72 
73  // Decide if cell is extracted
74  bool passFlag = false;
75  if (inCnt == numIndices && ExtractInside && !ExtractOnlyBoundaryCells)
76  {
77  passFlag = true;
78  }
79  else if (outCnt == numIndices && !ExtractInside && !ExtractOnlyBoundaryCells)
80  {
81  passFlag = true;
82  }
83  else if (inCnt > 0 && outCnt > 0 && (ExtractBoundaryCells || ExtractOnlyBoundaryCells))
84  {
85  passFlag = true;
86  }
87  return passFlag;
88  }
89 
90  private:
94  };
95 
97  {
100 
101  public:
104  : Output(&cellOut)
105  , ValidIds(&validIds)
106  {
107  }
108 
109  template <typename CellSetType>
110  void operator()(const CellSetType& cellset) const
111  {
112  vtkm::cont::CellSetPermutation<CellSetType> permCellSet(*this->ValidIds, cellset);
113  *this->Output = permCellSet;
114  }
115  };
116 
118  // Extract cells by ids permutes input data
119  template <typename CellSetType>
121  const vtkm::cont::ArrayHandle<vtkm::Id>& cellIds)
122  {
124 
125  vtkm::cont::ArrayCopy(cellIds, this->ValidCellIds);
126 
127  return OutputType(this->ValidCellIds, cellSet);
128  }
129 
131  // Extract cells by implicit function permutes input data
132  template <typename CellSetType, typename ImplicitFunction>
134  const vtkm::cont::CoordinateSystem& coordinates,
135  const ImplicitFunction& implicitFunction,
136  bool extractInside,
137  bool extractBoundaryCells,
138  bool extractOnlyBoundaryCells)
139  {
140  // Worklet output will be a boolean passFlag array
142 
143  ExtractCellsByVOI worklet(extractInside, extractBoundaryCells, extractOnlyBoundaryCells);
144  vtkm::cont::Invoker invoke;
145  invoke(worklet, cellSet, coordinates, implicitFunction, passFlags);
146 
149  vtkm::cont::Algorithm::CopyIf(indices, passFlags, this->ValidCellIds);
150 
151  // generate the cellset
153  }
154 
156 
157 private:
159 };
160 }
161 } // namespace vtkm::worklet
162 
163 #endif // vtkm_m_worklet_ExtractGeometry_h
vtkm::worklet::ExtractGeometry
Definition: worklet/ExtractGeometry.h:30
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ControlSignature
void(CellSetIn cellset, WholeArrayIn coordinates, ExecObject implicitFunction, FieldOutCell passFlags) ControlSignature
Definition: worklet/ExtractGeometry.h:41
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::worklet::ExtractGeometry::AddPermutationCellSet
Definition: worklet/ExtractGeometry.h:96
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::worklet::ExtractGeometry::ValidCellIds
vtkm::cont::ArrayHandle< vtkm::Id > ValidCellIds
Definition: worklet/ExtractGeometry.h:158
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ExtractCellsByVOI
VTKM_CONT ExtractCellsByVOI(bool extractInside, bool extractBoundaryCells, bool extractOnlyBoundaryCells)
Definition: worklet/ExtractGeometry.h:45
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::CellSetPermutation
Definition: CastAndCall.h:38
UnknownCellSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::PointCount
IncidentElementCount PointCount
Definition: WorkletMapTopology.h:267
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::ExtractGeometry::AddPermutationCellSet::operator()
void operator()(const CellSetType &cellset) const
Definition: worklet/ExtractGeometry.h:110
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ExtractOnlyBoundaryCells
bool ExtractOnlyBoundaryCells
Definition: worklet/ExtractGeometry.h:93
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ExtractInside
bool ExtractInside
Definition: worklet/ExtractGeometry.h:91
vtkm::worklet::ExtractGeometry::AddPermutationCellSet::Output
vtkm::cont::UnknownCellSet * Output
Definition: worklet/ExtractGeometry.h:98
Invoker.h
vtkm::worklet::ExtractGeometry::AddPermutationCellSet::AddPermutationCellSet
AddPermutationCellSet(vtkm::cont::UnknownCellSet &cellOut, vtkm::cont::ArrayHandle< vtkm::Id > &validIds)
Definition: worklet/ExtractGeometry.h:102
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
CoordinateSystem.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
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::worklet::ExtractGeometry::GetValidCellIds
vtkm::cont::ArrayHandle< vtkm::Id > GetValidCellIds() const
Definition: worklet/ExtractGeometry.h:155
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::operator()
VTKM_EXEC bool operator()(vtkm::Id numIndices, const ConnectivityInVec &connectivityIn, const InVecFieldPortalType &coordinates, const ImplicitFunction &function) const
Definition: worklet/ExtractGeometry.h:53
Algorithm.h
vtkm::cont::ArrayHandleCounting< vtkm::Id >
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::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ExtractBoundaryCells
bool ExtractBoundaryCells
Definition: worklet/ExtractGeometry.h:92
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_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI
Definition: worklet/ExtractGeometry.h:35
vtkm::worklet::ExtractGeometry::Run
vtkm::cont::CellSetPermutation< CellSetType > Run(const CellSetType &cellSet, const vtkm::cont::ArrayHandle< vtkm::Id > &cellIds)
Definition: worklet/ExtractGeometry.h:120
vtkm::worklet::ExtractGeometry::ExtractCellsByVOI::ExecutionSignature
_4(PointCount, PointIndices, _2, _3) ExecutionSignature
Definition: worklet/ExtractGeometry.h:42
vtkm::worklet::ExtractGeometry::Run
vtkm::cont::CellSetPermutation< CellSetType > Run(const CellSetType &cellSet, const vtkm::cont::CoordinateSystem &coordinates, const ImplicitFunction &implicitFunction, bool extractInside, bool extractBoundaryCells, bool extractOnlyBoundaryCells)
Definition: worklet/ExtractGeometry.h:133
ImplicitFunction.h
CellSetPermutation.h
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
WorkletMapTopology.h
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263
vtkm::worklet::ExtractGeometry::AddPermutationCellSet::ValidIds
vtkm::cont::ArrayHandle< vtkm::Id > * ValidIds
Definition: worklet/ExtractGeometry.h:99