From 9f0c99920c38f2c6729fc2d860d61b088bb706f7 Mon Sep 17 00:00:00 2001 From: Patricia Kroll Fasel - 090207 Date: Tue, 21 Mar 2017 15:14:35 -0600 Subject: [PATCH] Add filters and tests for ExtractPoints and ExtractGeometry, by id only. --- vtkm/filter/CMakeLists.txt | 6 + vtkm/filter/ExtractGeometry.h | 90 +++++++++ vtkm/filter/ExtractGeometry.hxx | 178 ++++++++++++++++++ vtkm/filter/ExtractPoints.h | 90 +++++++++ vtkm/filter/ExtractPoints.hxx | 166 ++++++++++++++++ vtkm/filter/ThresholdPoints.hxx | 2 +- vtkm/filter/testing/CMakeLists.txt | 2 + .../testing/UnitTestExtractGeometryFilter.cxx | 75 ++++++++ .../testing/UnitTestExtractPointsFilter.cxx | 75 ++++++++ .../testing/UnitTestThresholdPointsFilter.cxx | 5 +- vtkm/worklet/CMakeLists.txt | 2 + vtkm/worklet/ExtractGeometry.h | 91 +-------- vtkm/worklet/ExtractPoints.h | 133 +++++++++++++ vtkm/worklet/ThresholdPoints.h | 2 +- vtkm/worklet/testing/CMakeLists.txt | 3 +- ...tCells.cxx => UnitTestExtractGeometry.cxx} | 48 ++--- .../worklet/testing/UnitTestExtractPoints.cxx | 52 +++-- 17 files changed, 876 insertions(+), 144 deletions(-) create mode 100644 vtkm/filter/ExtractGeometry.h create mode 100644 vtkm/filter/ExtractGeometry.hxx create mode 100644 vtkm/filter/ExtractPoints.h create mode 100644 vtkm/filter/ExtractPoints.hxx create mode 100644 vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx create mode 100644 vtkm/filter/testing/UnitTestExtractPointsFilter.cxx create mode 100644 vtkm/worklet/ExtractPoints.h rename vtkm/worklet/testing/{UnitTestExtractCells.cxx => UnitTestExtractGeometry.cxx} (89%) diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 84fff1a07..ef7d2025d 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -24,6 +24,8 @@ set(headers Clip.h ContourTreeUniform.h ExternalFaces.h + ExtractGeometry.h + ExtractPoints.h FieldMetadata.h FilterCell.h FilterDataSet.h @@ -33,6 +35,7 @@ set(headers Gradient.h Histogram.h MarchingCubes.h + #Mask.h MaskPoints.h PointAverage.h PointElevation.h @@ -53,6 +56,8 @@ set(header_template_sources Clip.hxx ContourTreeUniform.hxx ExternalFaces.hxx + ExtractGeometry.hxx + ExtractPoints.hxx FilterCell.hxx FilterDataSet.hxx FilterDataSetWithField.hxx @@ -60,6 +65,7 @@ set(header_template_sources Gradient.hxx Histogram.hxx MarchingCubes.hxx + #Mask.hxx MaskPoints.hxx PointAverage.hxx PointElevation.hxx diff --git a/vtkm/filter/ExtractGeometry.h b/vtkm/filter/ExtractGeometry.h new file mode 100644 index 000000000..4cb3c6eab --- /dev/null +++ b/vtkm/filter/ExtractGeometry.h @@ -0,0 +1,90 @@ +//============================================================================ +// 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 vtk_m_filter_ExtractGeometry_h +#define vtk_m_filter_ExtractGeometry_h + +#include +#include +#include +#include + +namespace vtkm { +namespace filter { + +class ExtractGeometry : public vtkm::filter::FilterDataSet +{ +public: + VTKM_CONT + ExtractGeometry(); + + // When CompactPoints is set, instead of copying the points and point fields + // from the input, the filter will create new compact fields without the unused elements + VTKM_CONT + bool GetCompactPoints() const { return this->CompactPoints; } + VTKM_CONT + void SetCompactPoints(bool value) { this->CompactPoints = value; } + + // Set the list of point ids to extract + VTKM_CONT + vtkm::cont::ArrayHandle GetCellIds() const { return this->CellIds; } + VTKM_CONT + void SetCellIds(vtkm::cont::ArrayHandle &cellIds); + + // Set the volume of interest to extract +/* + VTKM_CONT + vtkm::ImplicitFunction GetVolumeOfInterest() const { return this->VolumeOfInterest; } + VTKM_CONT + void SetVolumeOfInterest(vtkm::ImplicitFunction &implicitFunction); +*/ + + template + VTKM_CONT + vtkm::filter::ResultDataSet DoExecute(const vtkm::cont::DataSet& input, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& tag); + + //Map a new field onto the resulting dataset after running the filter + template + VTKM_CONT + bool DoMapField(vtkm::filter::ResultDataSet& result, + const vtkm::cont::ArrayHandle& input, + const vtkm::filter::FieldMetadata& fieldMeta, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& tag); + + +private: + int ExtractType; + vtkm::cont::ArrayHandle CellIds; + //vtkm::ImplicitFunction VolumeOfInterest; + + bool CompactPoints; + vtkm::filter::CleanGrid Compactor; +}; + +} +} // namespace vtkm::filter + + +#include + +#endif // vtk_m_filter_ExtractGeometry_h diff --git a/vtkm/filter/ExtractGeometry.hxx b/vtkm/filter/ExtractGeometry.hxx new file mode 100644 index 000000000..1caa8cbcf --- /dev/null +++ b/vtkm/filter/ExtractGeometry.hxx @@ -0,0 +1,178 @@ +//============================================================================ +// 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. +//============================================================================ + +namespace +{ +class AddPermutationCellSet +{ + vtkm::cont::DataSet* Output; + vtkm::cont::ArrayHandle* ValidIds; +public: + AddPermutationCellSet(vtkm::cont::DataSet& data, + vtkm::cont::ArrayHandle& validIds): + Output(&data), + ValidIds(&validIds) + { } + + template + void operator()(const CellSetType& cellset ) const + { + typedef vtkm::cont::CellSetPermutation PermutationCellSetType; + + PermutationCellSetType permCellSet(*this->ValidIds, cellset, + cellset.GetName()); + + this->Output->AddCellSet(permCellSet); + } +}; +} + +namespace vtkm { +namespace filter { + +const int BY_IDS = 0; +const int BY_VOI = 1; + +//----------------------------------------------------------------------------- +inline VTKM_CONT +void ExtractGeometry::SetCellIds(vtkm::cont::ArrayHandle &cellIds) +{ + this->CellIds = cellIds; + this->ExtractType = BY_IDS; +} + +/* +inline VTKM_CONT +void ExtractGeometry::SetVolumeOfInterest(vtkm::ImplicitFunction &implicitFunction) +{ + this->VolumeOfInterest = implicitFunction; + this->ExtractType = BY_VOI; +} +*/ + +//----------------------------------------------------------------------------- +inline VTKM_CONT +ExtractGeometry::ExtractGeometry(): + vtkm::filter::FilterDataSet(), + CellIds(), + CompactPoints(false) +{ +} + +//----------------------------------------------------------------------------- +template +inline VTKM_CONT +vtkm::filter::ResultDataSet ExtractGeometry::DoExecute( + const vtkm::cont::DataSet& input, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& device) +{ + // extract the input cell set and coordinates + const vtkm::cont::DynamicCellSet& cells = + input.GetCellSet(this->GetActiveCellSetIndex()); +/* + const vtkm::cont::CoordinateSystem& coords = + input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); +*/ + + switch (this->ExtractType) + { + case BY_IDS: + { + break; + } + case BY_VOI: + { +/* + vtkm::cont::ArrayHandle passFlags; + + // Worklet output will be a boolean passFlag array + typedef vtkm::worklet::ExtractGeometry::ExtractCellsByVOI ExtractCellsWorklet; + ExtractCellsWorklet worklet(implicitFunction); + DispatcherMapTopology dispatcher(worklet); + dispatcher.Invoke(cellSet, + coordinates, + passFlags); + + vtkm::cont::ArrayHandleCounting indices = + vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); + vtkm::cont::DeviceAdapterAlgorithm + ::CopyIf(indices, passFlags, this->ValidCellIds); +*/ + break; + } + default: + break; + } + + // create the output dataset + vtkm::cont::DataSet output; + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + + AddPermutationCellSet addCellSet(output, this->CellIds); + vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(cells, policy), + addCellSet); + + return output; +} + +//----------------------------------------------------------------------------- +template +inline VTKM_CONT +bool ExtractGeometry::DoMapField( + vtkm::filter::ResultDataSet& result, + const vtkm::cont::ArrayHandle& input, + const vtkm::filter::FieldMetadata& fieldMeta, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter&) +{ + // point data is copied as is because it was not collapsed + if(fieldMeta.IsPointField()) + { + result.GetDataSet().AddField(fieldMeta.AsField(input)); + return true; + } + + if(fieldMeta.IsCellField()) + { + //todo: We need to generate a new output policy that replaces + //the original storage tag with a new storage tag where everything is + //wrapped in ArrayHandlePermutation. + typedef vtkm::cont::ArrayHandlePermutation< + vtkm::cont::ArrayHandle, + vtkm::cont::ArrayHandle > PermutationType; + + PermutationType permutation = + vtkm::cont::make_ArrayHandlePermutation(this->CellIds, input); + + result.GetDataSet().AddField( fieldMeta.AsField(permutation) ); + return true; + } + + // cell data does not apply + return false; +} + +} +} diff --git a/vtkm/filter/ExtractPoints.h b/vtkm/filter/ExtractPoints.h new file mode 100644 index 000000000..e060e06f0 --- /dev/null +++ b/vtkm/filter/ExtractPoints.h @@ -0,0 +1,90 @@ +//============================================================================ +// 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 vtk_m_filter_ExtractPoints_h +#define vtk_m_filter_ExtractPoints_h + +#include +#include +#include +#include + +namespace vtkm { +namespace filter { + +class ExtractPoints : public vtkm::filter::FilterDataSet +{ +public: + VTKM_CONT + ExtractPoints(); + + // When CompactPoints is set, instead of copying the points and point fields + // from the input, the filter will create new compact fields without the unused elements + VTKM_CONT + bool GetCompactPoints() const { return this->CompactPoints; } + VTKM_CONT + void SetCompactPoints(bool value) { this->CompactPoints = value; } + + // Set the list of point ids to extract + VTKM_CONT + vtkm::cont::ArrayHandle GetPointIds() const { return this->PointIds; } + VTKM_CONT + void SetPointIds(vtkm::cont::ArrayHandle &pointIds); + + // Set the volume of interest to extract +/* + VTKM_CONT + vtkm::ImplicitFunction GetVolumeOfInterest() const { return this->VolumeOfInterest; } + VTKM_CONT + void SetVolumeOfInterest(vtkm::ImplicitFunction &implicitFunction); +*/ + + template + VTKM_CONT + vtkm::filter::ResultDataSet DoExecute(const vtkm::cont::DataSet& input, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& tag); + + //Map a new field onto the resulting dataset after running the filter + template + VTKM_CONT + bool DoMapField(vtkm::filter::ResultDataSet& result, + const vtkm::cont::ArrayHandle& input, + const vtkm::filter::FieldMetadata& fieldMeta, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& tag); + + +private: + int ExtractType; + vtkm::cont::ArrayHandle PointIds; + //vtkm::ImplicitFunction VolumeOfInterest; + + bool CompactPoints; + vtkm::filter::CleanGrid Compactor; +}; + +} +} // namespace vtkm::filter + + +#include + +#endif // vtk_m_filter_ExtractPoints_h diff --git a/vtkm/filter/ExtractPoints.hxx b/vtkm/filter/ExtractPoints.hxx new file mode 100644 index 000000000..d60b884ae --- /dev/null +++ b/vtkm/filter/ExtractPoints.hxx @@ -0,0 +1,166 @@ +//============================================================================ +// 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. +//============================================================================ + +namespace +{ + +// Needed to CompactPoints +template +struct CellSetSingleTypePolicy : public BasePolicy +{ + using AllCellSetList = vtkm::cont::CellSetListTagUnstructured; +}; + +template +inline vtkm::filter::PolicyBase> +GetCellSetSingleTypePolicy(const vtkm::filter::PolicyBase&) +{ + return vtkm::filter::PolicyBase>(); +} + +} + +namespace vtkm { +namespace filter { + +const int BY_IDS = 0; +const int BY_VOI = 1; + +//----------------------------------------------------------------------------- +inline VTKM_CONT +void ExtractPoints::SetPointIds(vtkm::cont::ArrayHandle &pointIds) +{ + this->PointIds = pointIds; + this->ExtractType = BY_IDS; +} + +/* +inline VTKM_CONT +void ExtractPoints::SetVolumeOfInterest(vtkm::ImplicitFunction &implicitFunction) +{ + this->VolumeOfInterest = implicitFunction; + this->ExtractType = BY_VOI; +} +*/ + +//----------------------------------------------------------------------------- +inline VTKM_CONT +ExtractPoints::ExtractPoints(): + vtkm::filter::FilterDataSet(), + CompactPoints(false) +{ +} + +//----------------------------------------------------------------------------- +template +inline VTKM_CONT +vtkm::filter::ResultDataSet ExtractPoints::DoExecute( + const vtkm::cont::DataSet& input, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter& device) +{ + // extract the input cell set and coordinates + const vtkm::cont::DynamicCellSet& cells = + input.GetCellSet(this->GetActiveCellSetIndex()); +/* + const vtkm::cont::CoordinateSystem& coords = + input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); +*/ + + // run the worklet on the cell set + vtkm::cont::CellSetSingleType<> outCellSet(cells.GetName()); + vtkm::worklet::ExtractPoints worklet; + + switch (this->ExtractType) + { + case BY_IDS: + { + outCellSet = worklet.Run(vtkm::filter::ApplyPolicy(cells, policy), + this->PointIds, + device); + break; + } + case BY_VOI: + { +/* + outCellSet = worklet.Run(vtkm::filter::ApplyPolicy(cells, policy), + vtkm::filter::ApplyPolicy(coords, policy), + this->implicitFunction, + device); +*/ + break; + } + default: + break; + } + + // create the output dataset + vtkm::cont::DataSet output; + output.AddCellSet(outCellSet); + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + + // compact the unused points in the output dataset + if (this->CompactPoints) + { + this->Compactor.SetCompactPointFields(true); + return this->Compactor.DoExecute(output, + GetCellSetSingleTypePolicy(policy), + DeviceAdapter()); + } + else + { + return vtkm::filter::ResultDataSet(output); + } +} + +//----------------------------------------------------------------------------- +template +inline VTKM_CONT +bool ExtractPoints::DoMapField( + vtkm::filter::ResultDataSet& result, + const vtkm::cont::ArrayHandle& input, + const vtkm::filter::FieldMetadata& fieldMeta, + const vtkm::filter::PolicyBase& policy, + const DeviceAdapter&) +{ + // point data is copied as is because it was not collapsed + if(fieldMeta.IsPointField()) + { + if (this->CompactPoints) + { + return this->Compactor.DoMapField(result, input, fieldMeta, policy, DeviceAdapter()); + } + else + { + result.GetDataSet().AddField(fieldMeta.AsField(input)); + return true; + } + } + + // cell data does not apply + return false; +} + +} +} diff --git a/vtkm/filter/ThresholdPoints.hxx b/vtkm/filter/ThresholdPoints.hxx index 7c925c86a..9554c7f1e 100644 --- a/vtkm/filter/ThresholdPoints.hxx +++ b/vtkm/filter/ThresholdPoints.hxx @@ -110,7 +110,7 @@ ThresholdPoints::ThresholdPoints(): LowerValue(0), UpperValue(0), ThresholdType(THRESHOLD_BETWEEN), - CompactPoints(true) + CompactPoints(false) { } diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 9e7f69414..c06d19419 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -24,6 +24,8 @@ set(unit_tests UnitTestClipFilter.cxx UnitTestContourTreeUniformFilter.cxx UnitTestExternalFacesFilter.cxx + UnitTestExtractGeometryFilter.cxx + UnitTestExtractPointsFilter.cxx UnitTestFieldMetadata.cxx UnitTestGradient.cxx UnitTestHistogramFilter.cxx diff --git a/vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx b/vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx new file mode 100644 index 000000000..af22b4e87 --- /dev/null +++ b/vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx @@ -0,0 +1,75 @@ +//============================================================================ +// 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. +//============================================================================ + +#include +#include + +#include + +using vtkm::cont::testing::MakeTestDataSet; + +namespace { + + +class TestingExtractGeometry +{ +public: + void TestUniformById() const + { + std::cout << "Testing extract points structured by id:" << std::endl; + vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); + vtkm::filter::ResultDataSet result; + + // Cells to extract + const int nCells = 5; + vtkm::Id cellids[nCells] = {0, 4, 5, 10, 15}; + vtkm::cont::ArrayHandle cellIds = + vtkm::cont::make_ArrayHandle(cellids, nCells); + + // Setup and run filter to extract by point ids + vtkm::filter::ExtractGeometry extractGeometry; + extractGeometry.SetCellIds(cellIds); + extractGeometry.SetCompactPoints(true); + + result = extractGeometry.Execute(dataset); + + // Only point data can be transferred to result + for (vtkm::IdComponent i = 0; i < dataset.GetNumberOfFields(); ++i) + { + extractGeometry.MapFieldOntoOutput(result, dataset.GetField(i)); + } + + vtkm::cont::DataSet output = result.GetDataSet(); + VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), nCells), + "Wrong result for ExtractGeometry"); + } + + void operator()() const + { + this->TestUniformById(); + } +}; + +} + +int UnitTestExtractGeometryFilter(int, char *[]) +{ + return vtkm::cont::testing::Testing::Run(TestingExtractGeometry()); +} diff --git a/vtkm/filter/testing/UnitTestExtractPointsFilter.cxx b/vtkm/filter/testing/UnitTestExtractPointsFilter.cxx new file mode 100644 index 000000000..fd57e22f4 --- /dev/null +++ b/vtkm/filter/testing/UnitTestExtractPointsFilter.cxx @@ -0,0 +1,75 @@ +//============================================================================ +// 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. +//============================================================================ + +#include +#include + +#include + +using vtkm::cont::testing::MakeTestDataSet; + +namespace { + + +class TestingExtractPoints +{ +public: + void TestUniformById() const + { + std::cout << "Testing extract points structured by id:" << std::endl; + vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); + vtkm::filter::ResultDataSet result; + + // Points to extract + const int nPoints = 13; + vtkm::Id pointids[nPoints] = {0, 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 75, 100}; + vtkm::cont::ArrayHandle pointIds = + vtkm::cont::make_ArrayHandle(pointids, nPoints); + + // Setup and run filter to extract by point ids + vtkm::filter::ExtractPoints extractPoints; + extractPoints.SetPointIds(pointIds); + extractPoints.SetCompactPoints(true); + + result = extractPoints.Execute(dataset); + + // Only point data can be transferred to result + for (vtkm::IdComponent i = 0; i < dataset.GetNumberOfFields(); ++i) + { + extractPoints.MapFieldOntoOutput(result, dataset.GetField(i)); + } + + vtkm::cont::DataSet output = result.GetDataSet(); + VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), nPoints), + "Wrong result for ExtractPoints"); + } + + void operator()() const + { + this->TestUniformById(); + } +}; + +} + +int UnitTestExtractPointsFilter(int, char *[]) +{ + return vtkm::cont::testing::Testing::Run(TestingExtractPoints()); +} diff --git a/vtkm/filter/testing/UnitTestThresholdPointsFilter.cxx b/vtkm/filter/testing/UnitTestThresholdPointsFilter.cxx index a83744080..34aa69b3e 100644 --- a/vtkm/filter/testing/UnitTestThresholdPointsFilter.cxx +++ b/vtkm/filter/testing/UnitTestThresholdPointsFilter.cxx @@ -39,7 +39,6 @@ public: vtkm::filter::ThresholdPoints thresholdPoints; thresholdPoints.SetThresholdBetween(40.0f, 71.0f); - thresholdPoints.SetCompactPoints(false); result = thresholdPoints.Execute(dataset, dataset.GetField("pointvar")); @@ -66,6 +65,8 @@ public: vtkm::filter::ThresholdPoints thresholdPoints; thresholdPoints.SetThresholdAbove(1.0f); + thresholdPoints.SetCompactPoints(true); + result = thresholdPoints.Execute(dataset, std::string("pointvar")); thresholdPoints.MapFieldOntoOutput(result, dataset.GetField("pointvar") ); @@ -91,6 +92,8 @@ public: vtkm::filter::ThresholdPoints thresholdPoints; thresholdPoints.SetThresholdBelow(50.0); + thresholdPoints.SetCompactPoints(true); + result = thresholdPoints.Execute(dataset, std::string("pointvar")); thresholdPoints.MapFieldOntoOutput(result, dataset.GetField("pointvar") ); diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 03c28f2c7..79ddbf0bb 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -30,6 +30,7 @@ set(headers DispatcherStreamingMapField.h ExternalFaces.h ExtractGeometry.h + ExtractPoints.h FieldHistogram.h FieldStatistics.h Gradient.h @@ -38,6 +39,7 @@ set(headers Magnitude.h MarchingCubes.h MarchingCubesDataTables.h + Mask.h MaskPoints.h PointAverage.h PointElevation.h diff --git a/vtkm/worklet/ExtractGeometry.h b/vtkm/worklet/ExtractGeometry.h index 09e68a686..9048b0adb 100644 --- a/vtkm/worklet/ExtractGeometry.h +++ b/vtkm/worklet/ExtractGeometry.h @@ -40,34 +40,6 @@ class ExtractGeometry public: struct BoolType : vtkm::ListTagBase {}; - //////////////////////////////////////////////////////////////////////////////////// - // Worklet to identify points within volume of interest - template - class ExtractPointsByVOI : public vtkm::worklet::WorkletMapField - { - public: - typedef void ControlSignature(FieldIn coordinates, - FieldOut passFlags); - typedef _2 ExecutionSignature(_1); - - VTKM_CONT - ExtractPointsByVOI(const ImplicitFunction &function) : - Function(function) {} - - VTKM_CONT - bool operator()(const vtkm::Vec &coordinate) const - { - bool pass = true; - vtkm::Float64 value = this->Function.Value(coordinate); - if (value > 0) - pass = false; - return pass; - } - - private: - ImplicitFunction Function; - }; - //////////////////////////////////////////////////////////////////////////////////// // Worklet to identify cells within volume of interest template @@ -106,69 +78,11 @@ public: ImplicitFunction Function; }; - //////////////////////////////////////////////////////////////////////////////////// - // Extract points by id creates new cellset of vertex cells - template - vtkm::cont::CellSetSingleType<> RunExtractPoints( - const CellSetType &cellSet, - const vtkm::cont::ArrayHandle &pointIds, - const vtkm::cont::CoordinateSystem &coordinates, - DeviceAdapter device) - { - typedef typename vtkm::cont::DeviceAdapterAlgorithm DeviceAlgorithm; - DeviceAlgorithm::Copy(pointIds, this->ValidPointIds); - - // Make CellSetSingleType with VERTEX at each point id - vtkm::cont::CellSetSingleType< > outCellSet("cells"); - outCellSet.Fill(this->ValidPointIds.GetNumberOfValues(), - vtkm::CellShapeTagVertex::Id, - 1, - this->ValidPointIds); - - return outCellSet; - } - - //////////////////////////////////////////////////////////////////////////////////// - // Extract points by implicit function - template - vtkm::cont::CellSetSingleType<> RunExtractPoints( - const CellSetType &cellSet, - const ImplicitFunction &implicitFunction, - const vtkm::cont::CoordinateSystem &coordinates, - DeviceAdapter device) - { - typedef typename vtkm::cont::DeviceAdapterAlgorithm DeviceAlgorithm; - - vtkm::cont::ArrayHandle passFlags; - - // Worklet output will be a boolean passFlag array - typedef ExtractPointsByVOI ExtractPointsWorklet; - ExtractPointsWorklet worklet(implicitFunction); - DispatcherMapField dispatcher(worklet); - dispatcher.Invoke(coordinates, passFlags); - - vtkm::cont::ArrayHandleCounting indices = - vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); - DeviceAlgorithm::CopyIf(indices, passFlags, this->ValidPointIds); - - // Make CellSetSingleType with VERTEX at each point id - vtkm::cont::CellSetSingleType< > outCellSet("cells"); - outCellSet.Fill(this->ValidPointIds.GetNumberOfValues(), - vtkm::CellShapeTagVertex::Id, - 1, - this->ValidPointIds); - - return outCellSet; - } - //////////////////////////////////////////////////////////////////////////////////// // Extract cells by ids permutes input data template - vtkm::cont::CellSetPermutation RunExtractCells( + vtkm::cont::CellSetPermutation Run( CellSetType &cellSet, const vtkm::cont::ArrayHandle &cellIds, DeviceAdapter device) @@ -186,7 +100,7 @@ public: template - vtkm::cont::CellSetPermutation RunExtractCells( + vtkm::cont::CellSetPermutation Run( CellSetType &cellSet, const ImplicitFunction &implicitFunction, const vtkm::cont::CoordinateSystem &coordinates, @@ -250,7 +164,6 @@ public: private: vtkm::cont::ArrayHandle ValidCellIds; - vtkm::cont::ArrayHandle ValidPointIds; }; } diff --git a/vtkm/worklet/ExtractPoints.h b/vtkm/worklet/ExtractPoints.h new file mode 100644 index 000000000..6f39b29a2 --- /dev/null +++ b/vtkm/worklet/ExtractPoints.h @@ -0,0 +1,133 @@ +//============================================================================ +// 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_ExtractPoints_h +#define vtkm_m_worklet_ExtractPoints_h + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace vtkm { +namespace worklet { + +class ExtractPoints +{ +public: + struct BoolType : vtkm::ListTagBase {}; + + //////////////////////////////////////////////////////////////////////////////////// + // Worklet to identify points within volume of interest + template + class ExtractPointsByVOI : public vtkm::worklet::WorkletMapField + { + public: + typedef void ControlSignature(FieldIn coordinates, + FieldOut passFlags); + typedef _2 ExecutionSignature(_1); + + VTKM_CONT + ExtractPointsByVOI(const ImplicitFunction &function) : + Function(function) {} + + VTKM_CONT + bool operator()(const vtkm::Vec &coordinate) const + { + bool pass = true; + vtkm::Float64 value = this->Function.Value(coordinate); + if (value > 0) + pass = false; + return pass; + } + + private: + ImplicitFunction Function; + }; + + //////////////////////////////////////////////////////////////////////////////////// + // Extract points by id creates new cellset of vertex cells + template + vtkm::cont::CellSetSingleType<> Run( + const CellSetType &cellSet, + const vtkm::cont::ArrayHandle &pointIds, + DeviceAdapter device) + { + typedef typename vtkm::cont::DeviceAdapterAlgorithm DeviceAlgorithm; + DeviceAlgorithm::Copy(pointIds, this->ValidPointIds); + + // Make CellSetSingleType with VERTEX at each point id + vtkm::cont::CellSetSingleType< > outCellSet(cellSet.GetName()); + outCellSet.Fill(cellSet.GetNumberOfPoints(), + vtkm::CellShapeTagVertex::Id, + 1, + this->ValidPointIds); + + return outCellSet; + } + + //////////////////////////////////////////////////////////////////////////////////// + // Extract points by implicit function + template + vtkm::cont::CellSetSingleType<> Run( + const CellSetType &cellSet, + const vtkm::cont::CoordinateSystem &coordinates, + const ImplicitFunction &implicitFunction, + DeviceAdapter device) + { + typedef typename vtkm::cont::DeviceAdapterAlgorithm DeviceAlgorithm; + + vtkm::cont::ArrayHandle passFlags; + + // Worklet output will be a boolean passFlag array + typedef ExtractPointsByVOI ExtractPointsWorklet; + ExtractPointsWorklet worklet(implicitFunction); + DispatcherMapField dispatcher(worklet); + dispatcher.Invoke(coordinates, passFlags); + + vtkm::cont::ArrayHandleCounting indices = + vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); + DeviceAlgorithm::CopyIf(indices, passFlags, this->ValidPointIds); + + // Make CellSetSingleType with VERTEX at each point id + vtkm::cont::CellSetSingleType< > outCellSet(cellSet.GetName()); + outCellSet.Fill(cellSet.GetNumberOfPoints(), + vtkm::CellShapeTagVertex::Id, + 1, + this->ValidPointIds); + + return outCellSet; + } + +private: + vtkm::cont::ArrayHandle ValidPointIds; +}; + +} +} // namespace vtkm::worklet + +#endif // vtkm_m_worklet_ExtractPoints_h diff --git a/vtkm/worklet/ThresholdPoints.h b/vtkm/worklet/ThresholdPoints.h index 446d66f31..3845757c3 100644 --- a/vtkm/worklet/ThresholdPoints.h +++ b/vtkm/worklet/ThresholdPoints.h @@ -95,7 +95,7 @@ public: vtkm::cont::ArrayHandle pointIds = PointScatter.GetOutputToInputMap(); // Make CellSetSingleType with VERTEX at each point id - vtkm::cont::CellSetSingleType< > outCellSet("cells"); + vtkm::cont::CellSetSingleType< > outCellSet(cellSet.GetName()); outCellSet.Fill(numberOfInputPoints, vtkm::CellShapeTagVertex::Id, 1, diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index a3c8998e9..3d115fcaf 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -25,13 +25,14 @@ set(unit_tests UnitTestClipping.cxx UnitTestContourTreeUniform.cxx UnitTestExternalFaces.cxx - UnitTestExtractCells.cxx + UnitTestExtractGeometry.cxx UnitTestExtractPoints.cxx UnitTestFieldHistogram.cxx UnitTestFieldStatistics.cxx UnitTestKeys.cxx UnitTestMagnitude.cxx UnitTestMarchingCubes.cxx + UnitTestMask.cxx UnitTestMaskPoints.cxx UnitTestPointElevation.cxx UnitTestPointGradient.cxx diff --git a/vtkm/worklet/testing/UnitTestExtractCells.cxx b/vtkm/worklet/testing/UnitTestExtractGeometry.cxx similarity index 89% rename from vtkm/worklet/testing/UnitTestExtractCells.cxx rename to vtkm/worklet/testing/UnitTestExtractGeometry.cxx index e362d5c6d..96c102ec1 100644 --- a/vtkm/worklet/testing/UnitTestExtractCells.cxx +++ b/vtkm/worklet/testing/UnitTestExtractGeometry.cxx @@ -33,7 +33,7 @@ using vtkm::cont::testing::MakeTestDataSet; template -class TestingExtractCells +class TestingExtractGeometry { public: ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -61,9 +61,9 @@ public: // Output data set with cell set containing extracted cells and all points vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - cellIds, - DeviceAdapter()); + extractGeometry.Run(cellSet, + cellIds, + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -100,10 +100,10 @@ public: // Output data set with cell set containing extracted cells and all points vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - box, - dataset.GetCoordinateSystem("coordinates"), - DeviceAdapter()); + extractGeometry.Run(cellSet, + box, + dataset.GetCoordinateSystem("coordinates"), + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -141,9 +141,9 @@ public: // Output data set permutation of with only extracted cells vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - cellIds, - DeviceAdapter()); + extractGeometry.Run(cellSet, + cellIds, + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -181,9 +181,9 @@ public: // Output data set with cell set containing extracted cells and all points vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - cellIds, - DeviceAdapter()); + extractGeometry.Run(cellSet, + cellIds, + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -220,10 +220,10 @@ public: // Output data set with cell set containing extracted points vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - box, - dataset.GetCoordinateSystem("coords"), - DeviceAdapter()); + extractGeometry.Run(cellSet, + box, + dataset.GetCoordinateSystem("coords"), + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -260,10 +260,10 @@ public: // Output data set with cell set containing extracted cells vtkm::worklet::ExtractGeometry extractGeometry; OutCellSetType outCellSet = - extractGeometry.RunExtractCells(cellSet, - sphere, - dataset.GetCoordinateSystem("coords"), - DeviceAdapter()); + extractGeometry.Run(cellSet, + sphere, + dataset.GetCoordinateSystem("coords"), + DeviceAdapter()); vtkm::cont::Field cellField = extractGeometry.ProcessCellField(dataset.GetField("cellvar")); @@ -287,8 +287,8 @@ public: } }; -int UnitTestExtractCells(int, char *[]) +int UnitTestExtractGeometry(int, char *[]) { return vtkm::cont::testing::Testing::Run( - TestingExtractCells()); + TestingExtractGeometry()); } diff --git a/vtkm/worklet/testing/UnitTestExtractPoints.cxx b/vtkm/worklet/testing/UnitTestExtractPoints.cxx index 7b20e608a..ef71d8f0f 100644 --- a/vtkm/worklet/testing/UnitTestExtractPoints.cxx +++ b/vtkm/worklet/testing/UnitTestExtractPoints.cxx @@ -18,7 +18,7 @@ // this software. //============================================================================ -#include +#include #include #include @@ -46,7 +46,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); // Points to extract - const int nPoints = 18; + const int nPoints = 13; vtkm::Id pointids[nPoints] = {0, 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 75, 100}; vtkm::cont::ArrayHandle pointIds = vtkm::cont::make_ArrayHandle(pointids, nPoints); @@ -56,12 +56,11 @@ public: outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0)); // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; + vtkm::worklet::ExtractPoints extractPoints; OutCellSetType outCellSet = - extractGeometry.RunExtractPoints(dataset.GetCellSet(0), - pointIds, - dataset.GetCoordinateSystem("coords"), - DeviceAdapter()); + extractPoints.Run(dataset.GetCellSet(0), + pointIds, + DeviceAdapter()); outDataSet.AddCellSet(outCellSet); VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nPoints), "Wrong result for ExtractPoints"); @@ -86,12 +85,12 @@ public: outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0)); // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; + vtkm::worklet::ExtractPoints extractPoints; OutCellSetType outCellSet = - extractGeometry.RunExtractPoints(dataset.GetCellSet(0), - box, - dataset.GetCoordinateSystem("coords"), - DeviceAdapter()); + extractPoints.Run(dataset.GetCellSet(0), + dataset.GetCoordinateSystem("coords"), + box, + DeviceAdapter()); outDataSet.AddCellSet(outCellSet); VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractPoints"); @@ -116,12 +115,12 @@ public: outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0)); // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; + vtkm::worklet::ExtractPoints extractPoints; OutCellSetType outCellSet = - extractGeometry.RunExtractPoints(dataset.GetCellSet(0), - sphere, - dataset.GetCoordinateSystem("coords"), - DeviceAdapter()); + extractPoints.Run(dataset.GetCellSet(0), + dataset.GetCoordinateSystem("coords"), + sphere, + DeviceAdapter()); outDataSet.AddCellSet(outCellSet); VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractPoints"); @@ -146,12 +145,12 @@ public: outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0)); // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; + vtkm::worklet::ExtractPoints extractPoints; OutCellSetType outCellSet = - extractGeometry.RunExtractPoints(dataset.GetCellSet(0), - box, - dataset.GetCoordinateSystem("coordinates"), - DeviceAdapter()); + extractPoints.Run(dataset.GetCellSet(0), + dataset.GetCoordinateSystem("coordinates"), + box, + DeviceAdapter()); outDataSet.AddCellSet(outCellSet); VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractPoints"); @@ -178,12 +177,11 @@ public: outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0)); // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; + vtkm::worklet::ExtractPoints extractPoints; OutCellSetType outCellSet = - extractGeometry.RunExtractPoints(dataset.GetCellSet(0), - pointIds, - dataset.GetCoordinateSystem("coordinates"), - DeviceAdapter()); + extractPoints.Run(dataset.GetCellSet(0), + pointIds, + DeviceAdapter()); outDataSet.AddCellSet(outCellSet); VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nPoints), "Wrong result for ExtractPoints");