Merge topic 'marching-cubes-instantiations'

db2dbbbcc Simplify MarchingCells execute method
0ee495f31 Split the compilation of ContourMarchingCells into instantiations

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3089
This commit is contained in:
Kenneth Moreland 2023-06-27 14:09:07 +00:00 committed by Kitware Robot
commit 99c548ef52
5 changed files with 161 additions and 40 deletions

@ -8,4 +8,7 @@ Although `Contour` is still the preferred option for most cases because it selec
Deprecate functions `GetComputeFastNormalsForStructured`, `SetComputeFastNormalsForStructured`, `GetComputeFastNormalsForUnstructured` and `GetComputeFastNormalsForUnstructured`, to use the more general `GetComputeFastNormals` and `SetComputeFastNormals` instead. Deprecate functions `GetComputeFastNormalsForStructured`, `SetComputeFastNormalsForStructured`, `GetComputeFastNormalsForUnstructured` and `GetComputeFastNormalsForUnstructured`, to use the more general `GetComputeFastNormals` and `SetComputeFastNormals` instead.
By default, for the `Contour` filter, `GenerateNormals` is now `true`, and `ComputeFastNormals` is `false`. By default, for the `Contour` filter, `GenerateNormals` is now `true`, and `ComputeFastNormals` is `false`.
The marching cubes version of contour still has several possible compile paths, so it can still take a bit to compile. To help manage the compile time further, the contour filter compilation is broken up even further using the instantiation build capabilities.

@ -34,6 +34,9 @@ set(contour_sources
Contour.cxx Contour.cxx
) )
vtkm_add_instantiations(contour_instantiations INSTANTIATIONS_FILE worklet/ContourMarchingCells.h)
list(APPEND contour_sources_device ${contour_instantiations})
set_source_files_properties(Contour.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) set_source_files_properties(Contour.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
vtkm_library( vtkm_library(

@ -59,12 +59,11 @@ vtkm::cont::DataSet ContourMarchingCells::DoExecute(const vtkm::cont::DataSet& i
if (this->GenerateNormals && !this->GetComputeFastNormals()) if (this->GenerateNormals && !this->GetComputeFastNormals())
{ {
outputCells = outputCells = worklet.Run(ivalues, inputCells, inputCoords, concrete, vertices, normals);
worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices, normals);
} }
else else
{ {
outputCells = worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices); outputCells = worklet.Run(ivalues, inputCells, inputCoords, concrete, vertices);
} }
}; };

@ -11,10 +11,19 @@
#ifndef vtk_m_worklet_ContourMarchingCells_h #ifndef vtk_m_worklet_ContourMarchingCells_h
#define vtk_m_worklet_ContourMarchingCells_h #define vtk_m_worklet_ContourMarchingCells_h
#include <vtkm/filter/contour/vtkm_filter_contour_export.h>
#include <vtkm/filter/contour/worklet/contour/CommonState.h> #include <vtkm/filter/contour/worklet/contour/CommonState.h>
#include <vtkm/filter/contour/worklet/contour/FieldPropagation.h> #include <vtkm/filter/contour/worklet/contour/FieldPropagation.h>
#include <vtkm/filter/contour/worklet/contour/MarchingCells.h> #include <vtkm/filter/contour/worklet/contour/MarchingCells.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/internal/Instantiations.h>
namespace vtkm namespace vtkm
{ {
@ -22,6 +31,7 @@ namespace worklet
{ {
namespace contour namespace contour
{ {
struct DeduceCoordType struct DeduceCoordType
{ {
template <typename CoordinateType, typename CellSetType, typename... Args> template <typename CoordinateType, typename CellSetType, typename... Args>
@ -36,15 +46,41 @@ struct DeduceCoordType
struct DeduceCellType struct DeduceCellType
{ {
template <typename CellSetType, typename CoordinateType, typename... Args> template <typename CellSetType, typename ValueType, typename StorageTagField>
void operator()(const CellSetType& cells, CoordinateType&& coordinateSystem, Args&&... args) const void operator()(const CellSetType& cells,
{ const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CastAndCall( vtkm::cont::CellSetSingleType<>& outputCells,
coordinateSystem, contour::DeduceCoordType{}, cells, std::forward<Args>(args)...); const std::vector<ValueType>& isovalues,
} const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
}; };
// Declared outside of class, non-inline so that instantiations can be exported correctly.
template <typename CellSetType, typename ValueType, typename StorageTagField>
void DeduceCellType::operator()(const CellSetType& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<ValueType>& isovalues,
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const
{
vtkm::cont::CastAndCall(coordinateSystem,
contour::DeduceCoordType{},
cells,
outputCells,
isovalues,
input,
vertices,
normals,
sharedState);
} }
} // namespace contour
/// \brief Compute the isosurface of a given 3D data set, supports all linear cell types /// \brief Compute the isosurface of a given 3D data set, supports all linear cell types
class ContourMarchingCells class ContourMarchingCells
{ {
@ -87,22 +123,18 @@ public:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void ReleaseCellMapArrays() { this->SharedState.CellIdMap.ReleaseResources(); } void ReleaseCellMapArrays() { this->SharedState.CellIdMap.ReleaseResources(); }
public:
// Filter called without normals generation // Filter called without normals generation
template <typename ValueType, template <typename ValueType, typename StorageTagField>
typename CellSetType, VTKM_CONT vtkm::cont::CellSetSingleType<> Run(
typename CoordinateSystem,
typename StorageTagField,
typename CoordinateType,
typename StorageTagVertices>
vtkm::cont::CellSetSingleType<> Run(
const std::vector<ValueType>& isovalues, const std::vector<ValueType>& isovalues,
const CellSetType& cells, const vtkm::cont::UnknownCellSet& cells,
const CoordinateSystem& coordinateSystem, const vtkm::cont::CoordinateSystem& coordinateSystem,
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input, const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagVertices>& vertices) vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices)
{ {
this->SharedState.GenerateNormals = false; this->SharedState.GenerateNormals = false;
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>> normals; vtkm::cont::ArrayHandle<vtkm::Vec3f> normals;
vtkm::cont::CellSetSingleType<> outputCells; vtkm::cont::CellSetSingleType<> outputCells;
vtkm::cont::CastAndCall(cells, vtkm::cont::CastAndCall(cells,
@ -118,20 +150,14 @@ public:
} }
// Filter called with normals generation // Filter called with normals generation
template <typename ValueType, template <typename ValueType, typename StorageTagField>
typename CellSetType, VTKM_CONT vtkm::cont::CellSetSingleType<> Run(
typename CoordinateSystem,
typename StorageTagField,
typename CoordinateType,
typename StorageTagVertices,
typename StorageTagNormals>
vtkm::cont::CellSetSingleType<> Run(
const std::vector<ValueType>& isovalues, const std::vector<ValueType>& isovalues,
const CellSetType& cells, const vtkm::cont::UnknownCellSet& cells,
const CoordinateSystem& coordinateSystem, const vtkm::cont::CoordinateSystem& coordinateSystem,
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input, const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& input,
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagVertices>& vertices, vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagNormals>& normals) vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals)
{ {
this->SharedState.GenerateNormals = true; this->SharedState.GenerateNormals = true;
@ -152,7 +178,100 @@ public:
private: private:
vtkm::worklet::contour::CommonState SharedState; vtkm::worklet::contour::CommonState SharedState;
}; };
} }
} // namespace vtkm::worklet } // namespace vtkm::worklet
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetStructured<2>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float32>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float32, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetStructured<2>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float64>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetStructured<3>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float32>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float32, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetStructured<3>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float64>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetExplicit<>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float32>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float32, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetExplicit<>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float64>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetSingleType<>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float32>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float32, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template void vtkm::worklet::contour::DeduceCellType::operator()(
const vtkm::cont::CellSetSingleType<>& cells,
const vtkm::cont::CoordinateSystem& coordinateSystem,
vtkm::cont::CellSetSingleType<>& outputCells,
const std::vector<vtkm::Float64>& isovalues,
const vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>& input,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) const;
VTKM_INSTANTIATION_END
#endif // vtk_m_worklet_ContourMarchingCells_h #endif // vtk_m_worklet_ContourMarchingCells_h

@ -30,6 +30,7 @@
#include <vtkm/worklet/ScatterPermutation.h> #include <vtkm/worklet/ScatterPermutation.h>
#include <vtkm/filter/contour/worklet/contour/CommonState.h> #include <vtkm/filter/contour/worklet/contour/CommonState.h>
#include <vtkm/filter/contour/worklet/contour/FieldPropagation.h>
#include <vtkm/filter/contour/worklet/contour/MarchingCellTables.h> #include <vtkm/filter/contour/worklet/contour/MarchingCellTables.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/PointGradient.h> #include <vtkm/filter/vector_analysis/worklet/gradient/PointGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/StructuredPointGradient.h> #include <vtkm/filter/vector_analysis/worklet/gradient/StructuredPointGradient.h>
@ -594,18 +595,14 @@ struct GenerateNormals
template <typename CellSetType, template <typename CellSetType,
typename CoordinateSystem, typename CoordinateSystem,
typename ValueType, typename ValueType,
typename StorageTagField, typename StorageTagField>
typename StorageTagVertices,
typename StorageTagNormals,
typename CoordinateType,
typename NormalType>
vtkm::cont::CellSetSingleType<> execute( vtkm::cont::CellSetSingleType<> execute(
const CellSetType& cells, const CellSetType& cells,
const CoordinateSystem& coordinateSystem, const CoordinateSystem& coordinateSystem,
const std::vector<ValueType>& isovalues, const std::vector<ValueType>& isovalues,
const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& inputField, const vtkm::cont::ArrayHandle<ValueType, StorageTagField>& inputField,
vtkm::cont::ArrayHandle<vtkm::Vec<CoordinateType, 3>, StorageTagVertices>& vertices, vtkm::cont::ArrayHandle<vtkm::Vec3f>& vertices,
vtkm::cont::ArrayHandle<vtkm::Vec<NormalType, 3>, StorageTagNormals>& normals, vtkm::cont::ArrayHandle<vtkm::Vec3f>& normals,
vtkm::worklet::contour::CommonState& sharedState) vtkm::worklet::contour::CommonState& sharedState)
{ {
using vtkm::worklet::contour::MapPointField; using vtkm::worklet::contour::MapPointField;