2015-11-16 19:21:07 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-11-16 19:21:07 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
2019-08-18 01:10:57 +00:00
|
|
|
#ifndef vtk_m_worklet_Contour_h
|
|
|
|
#define vtk_m_worklet_Contour_h
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2015-11-16 19:21:07 +00:00
|
|
|
#include <vtkm/cont/ArrayHandlePermutation.h>
|
2020-03-11 21:27:54 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2020-02-24 22:37:04 +00:00
|
|
|
#include <vtkm/worklet/contour/CommonState.h>
|
|
|
|
#include <vtkm/worklet/contour/FieldPropagation.h>
|
2020-03-11 21:27:54 +00:00
|
|
|
#include <vtkm/worklet/contour/FlyingEdges.h>
|
2020-02-24 22:37:04 +00:00
|
|
|
#include <vtkm/worklet/contour/MarchingCells.h>
|
2015-11-16 19:21:07 +00:00
|
|
|
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2016-07-20 16:40:03 +00:00
|
|
|
|
2020-03-11 21:27:54 +00:00
|
|
|
|
|
|
|
namespace contour
|
|
|
|
{
|
|
|
|
struct DeduceCoordType
|
|
|
|
{
|
|
|
|
template <typename CoordinateType, typename CellSetType, typename... Args>
|
|
|
|
void operator()(const CoordinateType& coords,
|
|
|
|
const CellSetType& cells,
|
|
|
|
vtkm::cont::CellSetSingleType<>& result,
|
|
|
|
Args&&... args) const
|
|
|
|
{
|
|
|
|
result = marching_cells::execute(cells, coords, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2020-07-09 18:56:23 +00:00
|
|
|
void operator()(
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagUniformPoints>& coords,
|
|
|
|
const vtkm::cont::CellSetStructured<3>& cells,
|
|
|
|
vtkm::cont::CellSetSingleType<>& result,
|
|
|
|
Args&&... args) const
|
2020-03-11 21:27:54 +00:00
|
|
|
{
|
|
|
|
result = flying_edges::execute(cells, coords, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeduceCellType
|
|
|
|
{
|
|
|
|
template <typename CellSetType, typename CoordinateType, typename... Args>
|
|
|
|
void operator()(const CellSetType& cells, CoordinateType&& coordinateSystem, Args&&... args) const
|
|
|
|
{
|
|
|
|
vtkm::cont::CastAndCall(
|
|
|
|
coordinateSystem, contour::DeduceCoordType{}, cells, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:37:04 +00:00
|
|
|
/// \brief Compute the isosurface of a given 3D data set, supports all
|
|
|
|
/// linear cell types
|
2019-08-18 01:10:57 +00:00
|
|
|
class Contour
|
2015-11-16 19:21:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2019-08-18 01:10:57 +00:00
|
|
|
Contour(bool mergeDuplicates = true)
|
2020-02-24 22:37:04 +00:00
|
|
|
: SharedState(mergeDuplicates)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2019-07-26 01:28:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id2> GetInterpolationEdgeIds() const
|
|
|
|
{
|
2020-02-24 22:37:04 +00:00
|
|
|
return this->SharedState.InterpolationEdgeIds;
|
2019-07-26 01:28:38 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2020-02-24 22:37:04 +00:00
|
|
|
void SetMergeDuplicatePoints(bool merge) { this->SharedState.MergeDuplicatePoints = merge; }
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2020-02-24 22:37:04 +00:00
|
|
|
bool GetMergeDuplicatePoints() const { return this->SharedState.MergeDuplicatePoints; }
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2020-02-06 21:58:59 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> GetCellIdMap() const { return this->SharedState.CellIdMap; }
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ValueType,
|
|
|
|
typename CellSetType,
|
|
|
|
typename CoordinateSystem,
|
|
|
|
typename StorageTagField,
|
|
|
|
typename CoordinateType,
|
2018-08-30 15:53:18 +00:00
|
|
|
typename StorageTagVertices>
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(
|
2020-03-16 20:29:59 +00:00
|
|
|
const std::vector<ValueType>& isovalues,
|
2017-05-26 17:53:28 +00:00
|
|
|
const CellSetType& cells,
|
2017-05-18 14:29:41 +00:00
|
|
|
const CoordinateSystem& coordinateSystem,
|
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
|
2020-02-24 22:37:04 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagVertices>& vertices)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2020-02-24 22:37:04 +00:00
|
|
|
this->SharedState.GenerateNormals = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>> normals;
|
2020-02-24 22:37:04 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellSetSingleType<> outputCells;
|
|
|
|
vtkm::cont::CastAndCall(cells,
|
2020-03-11 21:27:54 +00:00
|
|
|
contour::DeduceCellType{},
|
|
|
|
coordinateSystem,
|
2020-02-24 22:37:04 +00:00
|
|
|
outputCells,
|
|
|
|
isovalues,
|
|
|
|
input,
|
|
|
|
vertices,
|
2020-03-11 21:27:54 +00:00
|
|
|
normals,
|
|
|
|
this->SharedState);
|
2020-02-24 22:37:04 +00:00
|
|
|
return outputCells;
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ValueType,
|
|
|
|
typename CellSetType,
|
|
|
|
typename CoordinateSystem,
|
|
|
|
typename StorageTagField,
|
|
|
|
typename CoordinateType,
|
|
|
|
typename StorageTagVertices,
|
2018-08-30 15:53:18 +00:00
|
|
|
typename StorageTagNormals>
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(
|
2020-03-16 20:29:59 +00:00
|
|
|
const std::vector<ValueType>& isovalues,
|
2017-05-26 17:53:28 +00:00
|
|
|
const CellSetType& cells,
|
2017-05-18 14:29:41 +00:00
|
|
|
const CoordinateSystem& coordinateSystem,
|
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
|
2020-02-24 22:37:04 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagVertices>& vertices,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagNormals>& normals)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2020-02-24 22:37:04 +00:00
|
|
|
this->SharedState.GenerateNormals = true;
|
|
|
|
|
|
|
|
vtkm::cont::CellSetSingleType<> outputCells;
|
|
|
|
vtkm::cont::CastAndCall(cells,
|
2020-03-11 21:27:54 +00:00
|
|
|
contour::DeduceCellType{},
|
|
|
|
coordinateSystem,
|
2020-02-24 22:37:04 +00:00
|
|
|
outputCells,
|
|
|
|
isovalues,
|
|
|
|
input,
|
|
|
|
vertices,
|
2020-03-11 21:27:54 +00:00
|
|
|
normals,
|
|
|
|
this->SharedState);
|
2020-02-24 22:37:04 +00:00
|
|
|
return outputCells;
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename ValueType, typename StorageType>
|
2017-06-06 17:01:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> ProcessPointField(
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageType>& input) const
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2020-02-24 22:37:04 +00:00
|
|
|
|
2019-08-18 01:10:57 +00:00
|
|
|
using vtkm::worklet::contour::MapPointField;
|
2020-02-24 22:37:04 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<MapPointField> applyFieldDispatcher;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-06-06 17:01:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> output;
|
2020-02-24 22:37:04 +00:00
|
|
|
applyFieldDispatcher.Invoke(this->SharedState.InterpolationEdgeIds,
|
|
|
|
this->SharedState.InterpolationWeights,
|
|
|
|
input,
|
|
|
|
output);
|
|
|
|
|
2017-06-06 17:01:45 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename ValueType, typename StorageType>
|
2017-06-06 17:01:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageType>& in) const
|
2017-06-06 17:01:45 +00:00
|
|
|
{
|
|
|
|
// Use a temporary permutation array to simplify the mapping:
|
2020-02-24 22:37:04 +00:00
|
|
|
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->SharedState.CellIdMap, in);
|
2017-06-06 17:01:45 +00:00
|
|
|
|
|
|
|
// Copy into an array with default storage:
|
|
|
|
vtkm::cont::ArrayHandle<ValueType> result;
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::ArrayCopy(tmp, result);
|
2017-06-06 17:01:45 +00:00
|
|
|
|
|
|
|
return result;
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2015-11-16 19:21:07 +00:00
|
|
|
|
2017-06-08 21:02:55 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2020-02-24 22:37:04 +00:00
|
|
|
void ReleaseCellMapArrays() { this->SharedState.CellIdMap.ReleaseResources(); }
|
2017-06-08 21:02:55 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
private:
|
2020-02-24 22:37:04 +00:00
|
|
|
vtkm::worklet::contour::CommonState SharedState;
|
2015-11-16 19:21:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
2019-08-18 01:10:57 +00:00
|
|
|
#endif // vtk_m_worklet_Contour_h
|