2016-05-13 18:26:59 +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).
|
2016-05-13 18:26:59 +00:00
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-05-13 18:26:59 +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_TriangulateStructured_h
|
|
|
|
#define vtk_m_worklet_TriangulateStructured_h
|
2016-05-13 18:26:59 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleGroupVec.h>
|
|
|
|
#include <vtkm/cont/CellSetSingleType.h>
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
|
|
|
#include <vtkm/cont/DynamicArrayHandle.h>
|
2017-01-09 21:15:32 +00:00
|
|
|
#include <vtkm/cont/ErrorBadValue.h>
|
2016-05-13 18:26:59 +00:00
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
#include <vtkm/worklet/ScatterUniform.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2016-05-13 18:26:59 +00:00
|
|
|
|
|
|
|
/// \brief Compute the triangulate cells for a uniform grid data set
|
|
|
|
template <typename DeviceAdapter>
|
2017-03-23 17:58:00 +00:00
|
|
|
class TriangulateStructured
|
2016-05-13 18:26:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-03-23 17:58:00 +00:00
|
|
|
TriangulateStructured() {}
|
2016-05-13 18:26:59 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Worklet to turn quads into triangles
|
|
|
|
// Vertices remain the same and each cell is processed with needing topology
|
|
|
|
//
|
|
|
|
class TriangulateCell : public vtkm::worklet::WorkletMapPointToCell
|
|
|
|
{
|
|
|
|
public:
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef void ControlSignature(CellSetIn cellset, FieldOutCell<> connectivityOut);
|
2016-05-13 18:26:59 +00:00
|
|
|
typedef void ExecutionSignature(PointIndices, _2, VisitIndex);
|
2018-02-22 13:29:13 +00:00
|
|
|
using InputDomain = _1;
|
2016-05-13 18:26:59 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using ScatterType = vtkm::worklet::ScatterUniform;
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ScatterType GetScatter() const { return ScatterType(2); }
|
2016-05-13 18:26:59 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
TriangulateCell() {}
|
2016-05-13 18:26:59 +00:00
|
|
|
|
|
|
|
// Each quad cell produces 2 triangle cells
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ConnectivityInVec, typename ConnectivityOutVec>
|
|
|
|
VTKM_EXEC void operator()(const ConnectivityInVec& connectivityIn,
|
|
|
|
ConnectivityOutVec& connectivityOut,
|
|
|
|
vtkm::IdComponent visitIndex) const
|
2016-05-13 18:26:59 +00:00
|
|
|
{
|
2017-12-05 18:42:03 +00:00
|
|
|
const static vtkm::IdComponent StructuredTriangleIndices[2][3] = { { 0, 1, 2 }, { 0, 2, 3 } };
|
|
|
|
|
|
|
|
connectivityOut[0] = connectivityIn[StructuredTriangleIndices[visitIndex][0]];
|
|
|
|
connectivityOut[1] = connectivityIn[StructuredTriangleIndices[visitIndex][1]];
|
|
|
|
connectivityOut[2] = connectivityIn[StructuredTriangleIndices[visitIndex][2]];
|
2016-05-13 18:26:59 +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)
|
2017-03-24 22:34:53 +00:00
|
|
|
|
2016-05-13 18:26:59 +00:00
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using DeviceAlgorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
2016-05-13 18:26:59 +00:00
|
|
|
|
2017-03-24 22:34:53 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
|
2016-05-13 18:26:59 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<TriangulateCell, DeviceAdapter> dispatcher;
|
|
|
|
dispatcher.Invoke(cellSet, vtkm::cont::make_ArrayHandleGroupVec<3>(connectivity));
|
2016-05-13 18:26:59 +00:00
|
|
|
|
2017-03-24 22:34:53 +00:00
|
|
|
// Fill in array of output cells per input cell
|
|
|
|
DeviceAlgorithm::Copy(
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(2, cellSet.GetNumberOfCells()),
|
|
|
|
outCellsPerCell);
|
2017-03-24 22:34:53 +00:00
|
|
|
|
2016-05-13 18:26:59 +00:00
|
|
|
// Add cells to output cellset
|
2017-05-18 14:29:41 +00:00
|
|
|
outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTriangle::Id, 3, connectivity);
|
2017-03-23 17:58:00 +00:00
|
|
|
return outCellSet;
|
2016-05-13 18:26:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
#endif // vtk_m_worklet_TriangulateStructured_h
|