From 1b256281f4c8310e33db27143743c373f8257a55 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 16 Mar 2020 16:29:59 -0400 Subject: [PATCH] Convert contour worklet to expect isovalues to a std::vector This reduces an ugly component of the Contour API --- vtkm/filter/Contour.hxx | 11 +++-------- vtkm/worklet/Contour.h | 8 ++------ vtkm/worklet/contour/FlyingEdges.h | 5 ++--- vtkm/worklet/contour/MarchingCells.h | 12 +++++------- vtkm/worklet/testing/UnitTestContour.cxx | 14 ++++++-------- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/vtkm/filter/Contour.hxx b/vtkm/filter/Contour.hxx index ae5495803..1a3532730 100644 --- a/vtkm/filter/Contour.hxx +++ b/vtkm/filter/Contour.hxx @@ -97,8 +97,7 @@ inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute( : !this->ComputeFastNormalsForUnstructured; if (this->GenerateNormals && generateHighQualityNormals) { - outputCells = this->Worklet.Run(&ivalues[0], - static_cast(ivalues.size()), + outputCells = this->Worklet.Run(ivalues, vtkm::filter::ApplyPolicyCellSet(cells, policy), coords.GetData(), field, @@ -107,12 +106,8 @@ inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute( } else { - outputCells = this->Worklet.Run(&ivalues[0], - static_cast(ivalues.size()), - vtkm::filter::ApplyPolicyCellSet(cells, policy), - coords.GetData(), - field, - vertices); + outputCells = this->Worklet.Run( + ivalues, vtkm::filter::ApplyPolicyCellSet(cells, policy), coords.GetData(), field, vertices); } if (this->GenerateNormals) diff --git a/vtkm/worklet/Contour.h b/vtkm/worklet/Contour.h index eb41754f9..0e13588f1 100644 --- a/vtkm/worklet/Contour.h +++ b/vtkm/worklet/Contour.h @@ -92,8 +92,7 @@ public: typename CoordinateType, typename StorageTagVertices> vtkm::cont::CellSetSingleType<> Run( - const ValueType* const isovalues, - const vtkm::Id numIsoValues, + const std::vector& isovalues, const CellSetType& cells, const CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, @@ -108,7 +107,6 @@ public: coordinateSystem, outputCells, isovalues, - numIsoValues, input, vertices, normals, @@ -125,8 +123,7 @@ public: typename StorageTagVertices, typename StorageTagNormals> vtkm::cont::CellSetSingleType<> Run( - const ValueType* const isovalues, - const vtkm::Id numIsoValues, + const std::vector& isovalues, const CellSetType& cells, const CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, @@ -141,7 +138,6 @@ public: coordinateSystem, outputCells, isovalues, - numIsoValues, input, vertices, normals, diff --git a/vtkm/worklet/contour/FlyingEdges.h b/vtkm/worklet/contour/FlyingEdges.h index 80d4502b9..835b2d137 100644 --- a/vtkm/worklet/contour/FlyingEdges.h +++ b/vtkm/worklet/contour/FlyingEdges.h @@ -86,8 +86,7 @@ template execute( const vtkm::cont::CellSetStructured<3>& cells, const vtkm::cont::ArrayHandleUniformPointCoordinates& coordinateSystem, - const ValueType* isovalues, - const vtkm::Id numIsoValues, + const std::vector& isovalues, const vtkm::cont::ArrayHandle& inputField, vtkm::cont::ArrayHandle, StorageTagVertices>& points, vtkm::cont::ArrayHandle, StorageTagNormals>& normals, @@ -127,7 +126,7 @@ vtkm::cont::CellSetSingleType<> execute( sharedState.CellIdMap.Shrink(0); vtkm::cont::ArrayHandle triangle_topology; - for (vtkm::Id i = 0; i < numIsoValues; ++i) + for (std::size_t i = 0; i < isovalues.size(); ++i) { ValueType isoval = isovalues[i]; diff --git a/vtkm/worklet/contour/MarchingCells.h b/vtkm/worklet/contour/MarchingCells.h index 0c6fbd060..c91164479 100644 --- a/vtkm/worklet/contour/MarchingCells.h +++ b/vtkm/worklet/contour/MarchingCells.h @@ -608,8 +608,7 @@ template execute( const CellSetType& cells, const CoordinateSystem& coordinateSystem, - const ValueType* isovalues, - const vtkm::Id numIsoValues, + const std::vector& isovalues, const vtkm::cont::ArrayHandle& inputField, vtkm::cont::ArrayHandle, StorageTagVertices>& vertices, vtkm::cont::ArrayHandle, StorageTagNormals>& normals, @@ -626,8 +625,7 @@ vtkm::cont::CellSetSingleType<> execute( // Setup the invoker vtkm::cont::Invoker invoker; - vtkm::cont::ArrayHandle isoValuesHandle = - vtkm::cont::make_ArrayHandle(isovalues, numIsoValues); + vtkm::cont::ArrayHandle isoValuesHandle = vtkm::cont::make_ArrayHandle(isovalues); // Call the ClassifyCell functor to compute the Marching Cubes case numbers // for each cell, and the number of vertices to be generated @@ -664,7 +662,7 @@ vtkm::cont::CellSetSingleType<> execute( triTable); } - if (numIsoValues <= 1 || !sharedState.MergeDuplicatePoints) + if (isovalues.size() <= 1 || !sharedState.MergeDuplicatePoints) { //release memory early that we are not going to need again contourIds.ReleaseResources(); } @@ -676,7 +674,7 @@ vtkm::cont::CellSetSingleType<> execute( // are updated. That is because MergeDuplicates will internally update // the InterpolationWeights and InterpolationOriginCellIds arrays to be the correct for the // output. But for InterpolationEdgeIds we need to do it manually once done - if (numIsoValues == 1) + if (isovalues.size() == 1) { marching_cells::MergeDuplicates(invoker, sharedState.InterpolationEdgeIds, //keys @@ -685,7 +683,7 @@ vtkm::cont::CellSetSingleType<> execute( originalCellIdsForPoints, //values connectivity); // computed using lower bounds } - else if (numIsoValues > 1) + else { marching_cells::MergeDuplicates( invoker, diff --git a/vtkm/worklet/testing/UnitTestContour.cxx b/vtkm/worklet/testing/UnitTestContour.cxx index 7dd49f6cc..d00c03e95 100644 --- a/vtkm/worklet/testing/UnitTestContour.cxx +++ b/vtkm/worklet/testing/UnitTestContour.cxx @@ -199,13 +199,12 @@ void TestContourUniformGrid() vtkm::worklet::Contour isosurfaceFilter; isosurfaceFilter.SetMergeDuplicatePoints(false); - vtkm::Float32 contourValue = 0.5f; + std::vector contourValue{ 0.5f }; vtkm::cont::ArrayHandle verticesArray; vtkm::cont::ArrayHandle normalsArray; vtkm::cont::ArrayHandle scalarsArray; - auto result = isosurfaceFilter.Run(&contourValue, - 1, + auto result = isosurfaceFilter.Run(contourValue, cellSet, dataSet.GetCoordinateSystem(), pointFieldArray, @@ -248,7 +247,7 @@ void TestContourExplicit() DataSetGenerator dataSetGenerator; vtkm::IdComponent Dimension = 10; - vtkm::Float32 contourValue = vtkm::Float32(.45); + std::vector contourValue{ 0.45f }; vtkm::cont::DataSet dataSet = dataSetGenerator.Make3DRadiantDataSet(Dimension); @@ -265,7 +264,7 @@ void TestContourExplicit() Contour.SetMergeDuplicatePoints(false); auto result = Contour.Run( - &contourValue, 1, cellSet, dataSet.GetCoordinateSystem(), contourArray, vertices, normals); + contourValue, cellSet, dataSet.GetCoordinateSystem(), contourArray, vertices, normals); DataHandle scalars; @@ -322,7 +321,7 @@ void TestContourClipped() vtkm::cont::ArrayHandle cellFieldArray; clipped.GetField("cellvar").GetData().CopyTo(cellFieldArray); - vtkm::Float32 contourValue = 0.5f; + std::vector contourValue{ 0.5f }; vtkm::cont::ArrayHandle verticesArray; vtkm::cont::ArrayHandle normalsArray; vtkm::cont::ArrayHandle scalarsArray; @@ -330,8 +329,7 @@ void TestContourClipped() vtkm::worklet::Contour isosurfaceFilter; isosurfaceFilter.SetMergeDuplicatePoints(false); - auto result = isosurfaceFilter.Run(&contourValue, - 1, + auto result = isosurfaceFilter.Run(contourValue, cellSet, clipped.GetCoordinateSystem(), pointFieldArray,