2015-09-10 17:48:05 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-09-10 17:48:05 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
#ifndef vtk_m_worklet_TetrahedralizeStructured_h
|
|
|
|
#define vtk_m_worklet_TetrahedralizeStructured_h
|
2015-09-10 17:48:05 +00:00
|
|
|
|
2018-08-28 20:36:50 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2015-09-10 17:48:05 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleGroupVec.h>
|
2015-09-28 22:23:03 +00:00
|
|
|
#include <vtkm/cont/CellSetSingleType.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2017-01-09 21:15:32 +00:00
|
|
|
#include <vtkm/cont/ErrorBadValue.h>
|
2015-09-10 17:48:05 +00:00
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
#include <vtkm/worklet/ScatterUniform.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
2015-09-21 20:22:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2015-09-10 17:48:05 +00:00
|
|
|
|
2018-02-21 19:51:15 +00:00
|
|
|
namespace tetrahedralize
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Worklet to turn hexahedra into tetrahedra
|
|
|
|
// Vertices remain the same and each cell is processed with needing topology
|
|
|
|
//
|
2019-07-30 16:53:51 +00:00
|
|
|
class TetrahedralizeCell : public vtkm::worklet::WorkletVisitCellsWithPoints
|
2015-09-10 17:48:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-10 18:59:25 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset, FieldOutCell connectivityOut);
|
2018-05-25 21:18:41 +00:00
|
|
|
using ExecutionSignature = void(PointIndices, _2, ThreadIndices);
|
2018-02-21 19:51:15 +00:00
|
|
|
using InputDomain = _1;
|
|
|
|
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
using ScatterType = vtkm::worklet::ScatterUniform<5>;
|
2015-09-10 17:48:05 +00:00
|
|
|
|
2018-02-21 19:51:15 +00:00
|
|
|
// Each hexahedron cell produces five tetrahedron cells
|
|
|
|
template <typename ConnectivityInVec, typename ConnectivityOutVec, typename ThreadIndicesType>
|
|
|
|
VTKM_EXEC void operator()(const ConnectivityInVec& connectivityIn,
|
|
|
|
ConnectivityOutVec& connectivityOut,
|
|
|
|
const ThreadIndicesType threadIndices) const
|
2015-09-10 17:48:05 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::IdComponent StructuredTetrahedronIndices[2][5][4] = {
|
|
|
|
{ { 0, 1, 3, 4 }, { 1, 4, 5, 6 }, { 1, 4, 6, 3 }, { 1, 3, 6, 2 }, { 3, 6, 7, 4 } },
|
|
|
|
{ { 2, 1, 5, 0 }, { 0, 2, 3, 7 }, { 2, 5, 6, 7 }, { 0, 7, 4, 5 }, { 0, 2, 7, 5 } }
|
|
|
|
};
|
|
|
|
|
|
|
|
vtkm::Id3 inputIndex = threadIndices.GetInputIndex3D();
|
|
|
|
|
|
|
|
// Calculate the type of tetrahedron generated because it alternates
|
|
|
|
vtkm::Id indexType = (inputIndex[0] + inputIndex[1] + inputIndex[2]) % 2;
|
2015-09-10 17:48:05 +00:00
|
|
|
|
2018-02-21 19:51:15 +00:00
|
|
|
vtkm::IdComponent visitIndex = threadIndices.GetVisitIndex();
|
|
|
|
|
|
|
|
connectivityOut[0] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][0]];
|
|
|
|
connectivityOut[1] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][1]];
|
|
|
|
connectivityOut[2] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][2]];
|
|
|
|
connectivityOut[3] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][3]];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Compute the tetrahedralize cells for a uniform grid data set
|
|
|
|
class TetrahedralizeStructured
|
|
|
|
{
|
|
|
|
public:
|
2017-03-23 17:58:00 +00:00
|
|
|
template <typename CellSetType>
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::IdComponent>& outCellsPerCell)
|
2015-09-22 17:40:01 +00:00
|
|
|
{
|
2019-08-13 21:28:37 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet;
|
2015-11-07 11:57:16 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
|
2015-09-24 22:07:45 +00:00
|
|
|
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<tetrahedralize::TetrahedralizeCell> dispatcher;
|
2017-05-18 14:29:41 +00:00
|
|
|
dispatcher.Invoke(cellSet, vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity));
|
2015-09-24 22:07:45 +00:00
|
|
|
|
2017-03-24 22:34:53 +00:00
|
|
|
// Fill in array of output cells per input cell
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::cont::ArrayCopy(
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(5, cellSet.GetNumberOfCells()),
|
|
|
|
outCellsPerCell);
|
2017-03-24 22:34:53 +00:00
|
|
|
|
2015-09-24 22:07:45 +00:00
|
|
|
// Add cells to output cellset
|
2017-05-18 14:29:41 +00:00
|
|
|
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTetra::Id, 4, connectivity);
|
2017-03-23 17:58:00 +00:00
|
|
|
return outCellSet;
|
2015-09-10 17:48:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
#endif // vtk_m_worklet_TetrahedralizeStructured_h
|