//============================================================================ // 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. // // Copyright 2014 Sandia Corporation. // Copyright 2014 UT-Battelle, LLC. // Copyright 2014 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // 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. //============================================================================ #ifndef vtkm_m_worklet_Tetrahedralize_h #define vtkm_m_worklet_Tetrahedralize_h #include #include namespace vtkm { namespace worklet { // // Distribute multiple copies of cell data depending on cells create from original // struct DistributeCellData : public vtkm::worklet::WorkletMapField { typedef void ControlSignature(FieldIn<> inIndices, FieldOut<> outIndices); typedef void ExecutionSignature(_1, _2); typedef vtkm::worklet::ScatterCounting ScatterType; VTKM_CONT ScatterType GetScatter() const { return this->Scatter; } template VTKM_CONT DistributeCellData(const CountArrayType &countArray, DeviceAdapter device) : Scatter(countArray, device) { } template VTKM_EXEC void operator()(T inputIndex, T &outputIndex) const { outputIndex = inputIndex; } private: ScatterType Scatter; }; class Tetrahedralize { public: Tetrahedralize() : OutCellsPerCell() {} // Tetrahedralize explicit data set, save number of tetra cells per input template vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet, const DeviceAdapter&) { TetrahedralizeExplicit worklet; return worklet.Run(cellSet, this->OutCellsPerCell); } // Tetrahedralize structured data set, save number of tetra cells per input template vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<3> &cellSet, const DeviceAdapter&) { TetrahedralizeStructured worklet; return worklet.Run(cellSet, this->OutCellsPerCell); } template vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<2>&, const DeviceAdapter&) { throw vtkm::cont::ErrorBadType("CellSetStructured<2> can't be tetrahedralized"); return vtkm::cont::CellSetSingleType<>(); } // Using the saved input to output cells, expand cell data template vtkm::cont::ArrayHandle ProcessField( const vtkm::cont::ArrayHandle &input, const DeviceAdapter& device) { vtkm::cont::ArrayHandle output; DistributeCellData distribute(this->OutCellsPerCell, device); vtkm::worklet::DispatcherMapField dispatcher(distribute); dispatcher.Invoke(input, output); return output; } private: vtkm::cont::ArrayHandle OutCellsPerCell; }; } } // namespace vtkm::worklet #endif // vtkm_m_worklet_Tetrahedralize_h