2015-09-23 20:43:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// 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-09-20 21:33:44 +00:00
|
|
|
// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2015-11-07 11:57:16 +00:00
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
2015-09-23 20:43:27 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-09-23 20:43:27 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
#ifndef vtk_m_worklet_TetrahedralizeExplicit_h
|
|
|
|
#define vtk_m_worklet_TetrahedralizeExplicit_h
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleGroupVec.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
|
|
|
#include <vtkm/cont/DynamicArrayHandle.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
2015-11-07 11:57:16 +00:00
|
|
|
#include <vtkm/worklet/ScatterCounting.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
|
|
|
|
2015-11-07 15:15:35 +00:00
|
|
|
#include <vtkm/worklet/internal/TriangulateTables.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
/// \brief Compute the tetrahedralize cells for an explicit grid data set
|
|
|
|
template <typename DeviceAdapter>
|
2017-03-23 17:58:00 +00:00
|
|
|
class TetrahedralizeExplicit
|
2015-09-23 20:43:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-03-23 17:58:00 +00:00
|
|
|
TetrahedralizeExplicit() {}
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2015-09-24 16:56:03 +00:00
|
|
|
//
|
|
|
|
// Worklet to count the number of tetrahedra generated per cell
|
|
|
|
//
|
|
|
|
class TetrahedraPerCell : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
public:
|
2018-05-25 21:18:41 +00:00
|
|
|
using ControlSignature = void(FieldIn<> shapes, ExecObject tables, FieldOut<> tetrahedronCount);
|
|
|
|
using ExecutionSignature = _3(_1, _2);
|
2018-02-22 13:29:13 +00:00
|
|
|
using InputDomain = _1;
|
2015-09-24 16:56:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-09-24 16:56:03 +00:00
|
|
|
TetrahedraPerCell() {}
|
2015-10-22 00:09:58 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-11-07 15:15:35 +00:00
|
|
|
vtkm::IdComponent operator()(
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::UInt8 shape,
|
|
|
|
const vtkm::worklet::internal::TetrahedralizeTablesExecutionObject<DeviceAdapter>& tables)
|
|
|
|
const
|
2015-09-24 16:56:03 +00:00
|
|
|
{
|
2015-11-07 15:15:35 +00:00
|
|
|
return tables.GetCount(vtkm::CellShapeTagGeneric(shape));
|
2015-09-24 16:56:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Worklet to turn cells into tetrahedra
|
|
|
|
// Vertices remain the same and each cell is processed with needing topology
|
|
|
|
//
|
2015-10-22 00:09:58 +00:00
|
|
|
class TetrahedralizeCell : public vtkm::worklet::WorkletMapPointToCell
|
2015-09-24 16:56:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-05-25 21:18:41 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset,
|
2017-05-26 17:53:28 +00:00
|
|
|
ExecObject tables,
|
2015-11-07 11:57:16 +00:00
|
|
|
FieldOutCell<> connectivityOut);
|
2018-05-25 21:18:41 +00:00
|
|
|
using ExecutionSignature = void(CellShape, PointIndices, _2, _3, VisitIndex);
|
2018-02-22 13:29:13 +00:00
|
|
|
using InputDomain = _1;
|
2015-11-07 11:57:16 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using ScatterType = vtkm::worklet::ScatterCounting;
|
2015-09-24 16:56:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellArrayType>
|
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
|
|
|
VTKM_CONT static ScatterType MakeScatter(const CellArrayType& cellArray)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
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
|
|
|
return ScatterType(cellArray, DeviceAdapter());
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2015-09-24 16:56:03 +00:00
|
|
|
|
|
|
|
// Each cell produces tetrahedra and write result at the offset
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag, typename ConnectivityInVec, typename ConnectivityOutVec>
|
|
|
|
VTKM_EXEC void operator()(
|
2017-05-26 17:53:28 +00:00
|
|
|
CellShapeTag shape,
|
|
|
|
const ConnectivityInVec& connectivityIn,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::worklet::internal::TetrahedralizeTablesExecutionObject<DeviceAdapter>& tables,
|
2017-05-26 17:53:28 +00:00
|
|
|
ConnectivityOutVec& connectivityOut,
|
|
|
|
vtkm::IdComponent visitIndex) const
|
2015-09-24 16:56:03 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::IdComponent, 4> tetIndices = tables.GetIndices(shape, visitIndex);
|
2015-11-07 15:15:35 +00:00
|
|
|
connectivityOut[0] = connectivityIn[tetIndices[0]];
|
|
|
|
connectivityOut[1] = connectivityIn[tetIndices[1]];
|
|
|
|
connectivityOut[2] = connectivityIn[tetIndices[2]];
|
|
|
|
connectivityOut[3] = connectivityIn[tetIndices[3]];
|
2015-09-24 16:56:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-23 20:43:27 +00:00
|
|
|
{
|
2017-03-23 17:58:00 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
// Input topology
|
2017-05-18 14:29:41 +00:00
|
|
|
auto inShapes =
|
|
|
|
cellSet.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
|
|
|
auto inNumIndices =
|
|
|
|
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2015-11-07 11:57:16 +00:00
|
|
|
// Output topology
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
|
2015-09-24 16:56:03 +00:00
|
|
|
|
2016-05-13 18:26:59 +00:00
|
|
|
vtkm::worklet::internal::TetrahedralizeTables tables;
|
|
|
|
|
|
|
|
// Determine the number of output cells each input cell will generate
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<TetrahedraPerCell, DeviceAdapter> tetPerCellDispatcher;
|
2018-04-17 20:42:12 +00:00
|
|
|
tetPerCellDispatcher.Invoke(inShapes, tables.PrepareForInput(), outCellsPerCell);
|
2016-05-13 18:26:59 +00:00
|
|
|
|
|
|
|
// Build new cells
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell, DeviceAdapter>
|
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
|
|
|
tetrahedralizeDispatcher(TetrahedralizeCell::MakeScatter(outCellsPerCell));
|
2018-04-17 20:42:12 +00:00
|
|
|
tetrahedralizeDispatcher.Invoke(
|
|
|
|
cellSet, tables.PrepareForInput(), vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));
|
2015-11-07 11:57:16 +00:00
|
|
|
|
2015-09-24 16:56:03 +00:00
|
|
|
// Add cells to output cellset
|
2017-05-18 14:29:41 +00:00
|
|
|
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTetra::Id, 4, outConnectivity);
|
2017-03-23 17:58:00 +00:00
|
|
|
return outCellSet;
|
2015-09-23 20:43:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
#endif // vtk_m_worklet_TetrahedralizeExplicit_h
|