//============================================================================ // 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. //============================================================================ #ifndef vtk_m_worklet_Contour_h #define vtk_m_worklet_Contour_h #include #include #include #include #include #include #include namespace vtkm { namespace worklet { namespace contour { struct DeduceCoordType { template void operator()(const CoordinateType& coords, const CellSetType& cells, vtkm::cont::CellSetSingleType<>& result, Args&&... args) const { result = marching_cells::execute(cells, coords, std::forward(args)...); } template void operator()( const vtkm::cont::ArrayHandle& coords, const vtkm::cont::CellSetStructured<3>& cells, vtkm::cont::CellSetSingleType<>& result, Args&&... args) const { result = flying_edges::execute(cells, coords, std::forward(args)...); } }; struct DeduceCellType { template void operator()(const CellSetType& cells, CoordinateType&& coordinateSystem, Args&&... args) const { vtkm::cont::CastAndCall( coordinateSystem, contour::DeduceCoordType{}, cells, std::forward(args)...); } }; } /// \brief Compute the isosurface of a given 3D data set, supports all /// linear cell types class Contour { public: //---------------------------------------------------------------------------- Contour(bool mergeDuplicates = true) : SharedState(mergeDuplicates) { } //---------------------------------------------------------------------------- vtkm::cont::ArrayHandle GetInterpolationEdgeIds() const { return this->SharedState.InterpolationEdgeIds; } //---------------------------------------------------------------------------- void SetMergeDuplicatePoints(bool merge) { this->SharedState.MergeDuplicatePoints = merge; } //---------------------------------------------------------------------------- bool GetMergeDuplicatePoints() const { return this->SharedState.MergeDuplicatePoints; } //---------------------------------------------------------------------------- vtkm::cont::ArrayHandle GetCellIdMap() const { return this->SharedState.CellIdMap; } //---------------------------------------------------------------------------- template vtkm::cont::CellSetSingleType<> Run( const std::vector& isovalues, const CellSetType& cells, const CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, vtkm::cont::ArrayHandle, StorageTagVertices>& vertices) { this->SharedState.GenerateNormals = false; vtkm::cont::ArrayHandle> normals; vtkm::cont::CellSetSingleType<> outputCells; vtkm::cont::CastAndCall(cells, contour::DeduceCellType{}, coordinateSystem, outputCells, isovalues, input, vertices, normals, this->SharedState); return outputCells; } //---------------------------------------------------------------------------- template vtkm::cont::CellSetSingleType<> Run( const std::vector& isovalues, const CellSetType& cells, const CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, vtkm::cont::ArrayHandle, StorageTagVertices>& vertices, vtkm::cont::ArrayHandle, StorageTagNormals>& normals) { this->SharedState.GenerateNormals = true; vtkm::cont::CellSetSingleType<> outputCells; vtkm::cont::CastAndCall(cells, contour::DeduceCellType{}, coordinateSystem, outputCells, isovalues, input, vertices, normals, this->SharedState); return outputCells; } //---------------------------------------------------------------------------- template vtkm::cont::ArrayHandle ProcessPointField( const vtkm::cont::ArrayHandle& input) const { using vtkm::worklet::contour::MapPointField; vtkm::worklet::DispatcherMapField applyFieldDispatcher; vtkm::cont::ArrayHandle output; applyFieldDispatcher.Invoke(this->SharedState.InterpolationEdgeIds, this->SharedState.InterpolationWeights, input, output); return output; } //---------------------------------------------------------------------------- template vtkm::cont::ArrayHandle ProcessCellField( const vtkm::cont::ArrayHandle& in) const { // Use a temporary permutation array to simplify the mapping: auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->SharedState.CellIdMap, in); // Copy into an array with default storage: vtkm::cont::ArrayHandle result; vtkm::cont::ArrayCopy(tmp, result); return result; } //---------------------------------------------------------------------------- void ReleaseCellMapArrays() { this->SharedState.CellIdMap.ReleaseResources(); } private: vtkm::worklet::contour::CommonState SharedState; }; } } // namespace vtkm::worklet #endif // vtk_m_worklet_Contour_h