Merge topic 'triangulate-single-cell-type'

4239d13b3 Make triangulate implementation more general
1bd70d9c2 Enable triangulation on CellSetSingleType

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2572
This commit is contained in:
Kenneth Moreland 2021-09-09 12:11:05 +00:00 committed by Kitware Robot
commit 3309fe1760
5 changed files with 60 additions and 151 deletions

@ -75,6 +75,11 @@ public:
throw vtkm::cont::ErrorBadType("CellSetStructured<2> can't be tetrahedralized");
}
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<1>&)
{
throw vtkm::cont::ErrorBadType("CellSetStructured<1> can't be tetrahedralized");
}
// Using the saved input to output cells, expand cell data
template <typename T, typename StorageType>
vtkm::cont::ArrayHandle<T> ProcessCellField(

@ -74,6 +74,11 @@ public:
throw vtkm::cont::ErrorBadType("CellSetStructured<3> can't be triangulated");
}
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<1>&)
{
throw vtkm::cont::ErrorBadType("CellSetStructured<1> can't be tetrahedralized");
}
// Using the saved input to output cells, expand cell data
template <typename ValueType, typename StorageType>
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(

@ -81,9 +81,6 @@ class TriangulateTablesExecutionObject
{
public:
using PortalType = TriangulateArrayHandle::ReadPortalType;
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
TriangulateTablesExecutionObject() {}
VTKM_CONT
TriangulateTablesExecutionObject(const TriangulateArrayHandle& counts,
@ -136,46 +133,16 @@ private:
PortalType Indices;
};
class TriangulateTablesExecutionObjectFactory : public vtkm::cont::ExecutionObjectBase
class TriangulateTables : public vtkm::cont::ExecutionObjectBase
{
public:
VTKM_CONT TriangulateTablesExecutionObject PrepareForExecution(vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const
{
if (BasicImpl)
{
return TriangulateTablesExecutionObject();
}
return TriangulateTablesExecutionObject(
this->Counts, this->Offsets, this->Indices, device, token);
}
VTKM_CONT
TriangulateTablesExecutionObjectFactory()
: BasicImpl(true)
{
}
VTKM_CONT
TriangulateTablesExecutionObjectFactory(const TriangulateArrayHandle& counts,
const TriangulateArrayHandle& offsets,
const TriangulateArrayHandle& indices)
: BasicImpl(false)
, Counts(counts)
, Offsets(offsets)
, Indices(indices)
{
}
private:
bool BasicImpl;
TriangulateArrayHandle Counts;
TriangulateArrayHandle Offsets;
TriangulateArrayHandle Indices;
};
class TriangulateTables
{
public:
VTKM_CONT
TriangulateTables()
: Counts(vtkm::cont::make_ArrayHandle(vtkm::worklet::internal::TriangleCountData,
@ -190,12 +157,6 @@ public:
{
}
vtkm::worklet::internal::TriangulateTablesExecutionObjectFactory PrepareForInput() const
{
return vtkm::worklet::internal::TriangulateTablesExecutionObjectFactory(
this->Counts, this->Offsets, this->Indices);
}
private:
TriangulateArrayHandle Counts;
TriangulateArrayHandle Offsets;
@ -298,9 +259,6 @@ public:
{
return *this;
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
TetrahedralizeTablesExecutionObject() {}
VTKM_CONT
TetrahedralizeTablesExecutionObject(const TriangulateArrayHandle& counts,
@ -338,45 +296,7 @@ private:
PortalType Indices;
};
class TetrahedralizeTablesExecutionObjectFactory : public vtkm::cont::ExecutionObjectBase
{
public:
VTKM_CONT TetrahedralizeTablesExecutionObject
PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) const
{
if (BasicImpl)
{
return TetrahedralizeTablesExecutionObject();
}
return TetrahedralizeTablesExecutionObject(
this->Counts, this->Offsets, this->Indices, device, token);
}
VTKM_CONT
TetrahedralizeTablesExecutionObjectFactory()
: BasicImpl(true)
{
}
VTKM_CONT
TetrahedralizeTablesExecutionObjectFactory(const TriangulateArrayHandle& counts,
const TriangulateArrayHandle& offsets,
const TriangulateArrayHandle& indices)
: BasicImpl(false)
, Counts(counts)
, Offsets(offsets)
, Indices(indices)
{
}
private:
bool BasicImpl;
TriangulateArrayHandle Counts;
TriangulateArrayHandle Offsets;
TriangulateArrayHandle Indices;
};
class TetrahedralizeTables
class TetrahedralizeTables : public vtkm::cont::ExecutionObjectBase
{
public:
VTKM_CONT
@ -393,10 +313,11 @@ public:
{
}
vtkm::worklet::internal::TetrahedralizeTablesExecutionObjectFactory PrepareForInput() const
VTKM_CONT TetrahedralizeTablesExecutionObject
PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) const
{
return vtkm::worklet::internal::TetrahedralizeTablesExecutionObjectFactory(
this->Counts, this->Offsets, this->Indices);
return TetrahedralizeTablesExecutionObject(
this->Counts, this->Offsets, this->Indices, device, token);
}
private:
@ -404,6 +325,7 @@ private:
TriangulateArrayHandle Offsets;
TriangulateArrayHandle Indices;
};
}
}
}

@ -39,21 +39,22 @@ public:
//
// Worklet to count the number of tetrahedra generated per cell
//
class TetrahedraPerCell : public vtkm::worklet::WorkletMapField
class TetrahedraPerCell : public vtkm::worklet::WorkletVisitCellsWithPoints
{
public:
using ControlSignature = void(FieldIn shapes, ExecObject tables, FieldOut tetrahedronCount);
using ExecutionSignature = _3(_1, _2);
using ControlSignature = void(CellSetIn cells, ExecObject tables, FieldOut tetrahedronCount);
using ExecutionSignature = _3(CellShape, _2);
using InputDomain = _1;
VTKM_CONT
TetrahedraPerCell() {}
template <typename CellShapeTag>
VTKM_EXEC vtkm::IdComponent operator()(
vtkm::UInt8 shape,
CellShapeTag shape,
const vtkm::worklet::internal::TetrahedralizeTablesExecutionObject& tables) const
{
return tables.GetCount(vtkm::CellShapeTagGeneric(shape));
return tables.GetCount(shape);
}
};
@ -96,23 +97,12 @@ public:
};
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(
const CellSetType& vtkmNotUsed(cellSet),
vtkm::cont::ArrayHandle<vtkm::IdComponent>& vtkmNotUsed(outCellsPerCell))
{
return vtkm::cont::CellSetSingleType<>();
}
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetExplicit<>& cellSet,
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent>& outCellsPerCell)
{
vtkm::cont::CellSetSingleType<> outCellSet;
// Input topology
auto inShapes =
cellSet.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
auto inNumIndices =
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
vtkm::cont::Invoker invoke;
// Output topology
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
@ -120,14 +110,14 @@ public:
vtkm::worklet::internal::TetrahedralizeTables tables;
// Determine the number of output cells each input cell will generate
vtkm::worklet::DispatcherMapField<TetrahedraPerCell> tetPerCellDispatcher;
tetPerCellDispatcher.Invoke(inShapes, tables.PrepareForInput(), outCellsPerCell);
invoke(TetrahedraPerCell{}, cellSet, tables, outCellsPerCell);
// Build new cells
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell> tetrahedralizeDispatcher(
TetrahedralizeCell::MakeScatter(outCellsPerCell));
tetrahedralizeDispatcher.Invoke(
cellSet, tables.PrepareForInput(), vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));
invoke(TetrahedralizeCell{},
TetrahedralizeCell::MakeScatter(outCellsPerCell),
cellSet,
tables,
vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));
// Add cells to output cellset
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTetra::Id, 4, outConnectivity);

@ -39,25 +39,23 @@ public:
//
// Worklet to count the number of triangles generated per cell
//
class TrianglesPerCell : public vtkm::worklet::WorkletMapField
class TrianglesPerCell : public vtkm::worklet::WorkletVisitCellsWithPoints
{
public:
using ControlSignature = void(FieldIn shapes,
FieldIn numPoints,
ExecObject tables,
FieldOut triangleCount);
using ExecutionSignature = _4(_1, _2, _3);
using ControlSignature = void(CellSetIn cells, ExecObject tables, FieldOut triangleCount);
using ExecutionSignature = _3(CellShape, IncidentElementCount, _2);
using InputDomain = _1;
VTKM_CONT
TrianglesPerCell() {}
template <typename CellShapeTag>
VTKM_EXEC vtkm::IdComponent operator()(
vtkm::UInt8 shape,
CellShapeTag shape,
vtkm::IdComponent numPoints,
const vtkm::worklet::internal::TriangulateTablesExecutionObject& tables) const
{
return tables.GetCount(vtkm::CellShapeTagGeneric(shape), numPoints);
return tables.GetCount(shape, numPoints);
}
};
@ -98,46 +96,35 @@ public:
}
};
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(
const CellSetType& vtkmNotUsed(cellSet),
vtkm::cont::ArrayHandle<vtkm::IdComponent>& vtkmNotUsed(outCellsPerCell))
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent>& outCellsPerCell)
{
vtkm::cont::CellSetSingleType<> outCellSet;
vtkm::cont::Invoker invoke;
// Output topology
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
vtkm::worklet::internal::TriangulateTables tables;
// Determine the number of output cells each input cell will generate
invoke(TrianglesPerCell{}, cellSet, tables, outCellsPerCell);
// Build new cells
invoke(TriangulateCell{},
TriangulateCell::MakeScatter(outCellsPerCell),
cellSet,
tables,
vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));
// Add cells to output cellset
outCellSet.Fill(
cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTriangle::Id, 3, outConnectivity);
return outCellSet;
}
};
template <>
vtkm::cont::CellSetSingleType<> TriangulateExplicit::Run(
const vtkm::cont::CellSetExplicit<>& cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent>& outCellsPerCell)
{
vtkm::cont::CellSetSingleType<> outCellSet;
// Input topology
auto inShapes =
cellSet.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
auto inNumIndices =
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
// Output topology
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
vtkm::worklet::internal::TriangulateTables tables;
// Determine the number of output cells each input cell will generate
vtkm::worklet::DispatcherMapField<TrianglesPerCell> triPerCellDispatcher;
triPerCellDispatcher.Invoke(inShapes, inNumIndices, tables.PrepareForInput(), outCellsPerCell);
// Build new cells
vtkm::worklet::DispatcherMapTopology<TriangulateCell> triangulateDispatcher(
TriangulateCell::MakeScatter(outCellsPerCell));
triangulateDispatcher.Invoke(
cellSet, tables.PrepareForInput(), vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));
// Add cells to output cellset
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTriangle::Id, 3, outConnectivity);
return outCellSet;
}
}
} // namespace vtkm::worklet