migrate ExtractGeometry

This commit is contained in:
Li-Ta Lo 2022-01-09 13:06:47 -07:00 committed by Kenneth Moreland
parent be309097c0
commit e3703b09cf
14 changed files with 165 additions and 428 deletions

@ -48,7 +48,6 @@ set(common_headers
set(common_header_template_sources
CellAverage.hxx
CellMeasures.hxx
ExtractGeometry.hxx
ExtractStructured.hxx
FilterDataSet.hxx
FilterDataSetWithField.hxx
@ -62,7 +61,6 @@ set(common_header_template_sources
set(common_sources_device
CellAverage.cxx
ExtractGeometry.cxx
ExtractStructured.cxx
PointAverage.cxx
Threshold.cxx

@ -1,60 +0,0 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_ExtractGeometry_cxx
#include <vtkm/filter/ExtractGeometry.h>
#include <vtkm/filter/ExtractGeometry.hxx>
#include <vtkm/filter/MapFieldPermutation.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
ExtractGeometry::ExtractGeometry()
: vtkm::filter::FilterDataSet<ExtractGeometry>()
, ExtractInside(true)
, ExtractBoundaryCells(false)
, ExtractOnlyBoundaryCells(false)
{
}
bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
{
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
vtkm::cont::ArrayHandle<vtkm::Id> permutation = this->Worklet.GetValidCellIds();
return vtkm::filter::MapFieldPermutation(field, permutation, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute(
const vtkm::cont::DataSet& inData,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault> policy);
}
} // namespace vtkm::filter

@ -7,105 +7,34 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_ExtractGeometry_h
#define vtk_m_filter_ExtractGeometry_h
#include <vtkm/filter/vtkm_filter_common_export.h>
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractGeometry.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
namespace vtkm
{
namespace filter
{
/// \brief Extract a subset of geometry based on an implicit function
///
/// Extracts from its input geometry all cells that are either
/// completely inside or outside of a specified implicit function. Any type of
/// data can be input to this filter.
///
/// To use this filter you must specify an implicit function. You must also
/// specify whether to extract cells laying inside or outside of the implicit
/// function. (The inside of an implicit function is the negative values
/// region.) An option exists to extract cells that are neither inside or
/// outside (i.e., boundary).
///
/// This differs from Clip in that Clip will subdivide boundary cells into new
/// cells, while this filter will not, producing a more 'crinkly' output.
///
class VTKM_FILTER_COMMON_EXPORT ExtractGeometry
: public vtkm::filter::FilterDataSet<ExtractGeometry>
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/entity_extraction/ExtractGeometry.h instead of vtkm/filter/ExtractGeometry.h.")
inline void ExtractGeometry_deprecated() {}
inline void ExtractGeometry_deprecated_warning()
{
public:
//currently the ExtractGeometry filter only works on scalar data.
using SupportedTypes = TypeListScalarAll;
ExtractGeometry_deprecated();
}
VTKM_CONT ExtractGeometry();
// Set the volume of interest to extract
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; }
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT
bool GetExtractInside() { return this->ExtractInside; }
VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT
void ExtractInsideOn() { this->ExtractInside = true; }
VTKM_CONT
void ExtractInsideOff() { this->ExtractInside = false; }
VTKM_CONT
bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; }
VTKM_CONT
void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; }
VTKM_CONT
void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; }
VTKM_CONT
void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; }
VTKM_CONT
bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; }
VTKM_CONT
void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; }
template <typename DerivedPolicy>
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
return this->MapFieldOntoOutput(result, field);
}
private:
bool ExtractInside;
bool ExtractBoundaryCells;
bool ExtractOnlyBoundaryCells;
vtkm::ImplicitFunctionGeneral Function;
vtkm::worklet::ExtractGeometry Worklet;
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::ExtractGeometry.") ExtractGeometry
: public vtkm::filter::entity_extraction::ExtractGeometry
{
using entity_extraction::ExtractGeometry::ExtractGeometry;
};
#ifndef vtkm_filter_ExtractGeometry_cxx
extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute(
const vtkm::cont::DataSet&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
}
} // namespace vtkm::filter
#endif // vtk_m_filter_ExtractGeometry_h
#endif //vtk_m_filter_ExtractGeometry_h

@ -9,12 +9,14 @@
##============================================================================
set(entity_extraction_headers
ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h
MaskPoints.h
ThresholdPoints.h
)
set(entity_extraction_sources_device
ExternalFaces.cxx
ExtractGeometry.cxx
ExtractPoints.cxx
MaskPoints.cxx
ThresholdPoints.cxx

@ -1,4 +1,5 @@
//============================================================================
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
@ -7,18 +8,15 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_ExtractGeometry_hxx
#define vtk_m_filter_ExtractGeometry_hxx
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
#include <vtkm/filter/entity_extraction/worklet/ExtractGeometry.h>
namespace
{
struct CallWorker
{
vtkm::cont::UnknownCellSet& Output;
@ -57,41 +55,70 @@ struct CallWorker
this->ExtractOnlyBoundaryCells);
}
};
} // end anon namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input)
{
// extract the input cell set and coordinates
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::worklet::ExtractGeometry Worklet;
vtkm::cont::UnknownCellSet outCells;
CallWorker worker(outCells,
this->Worklet,
Worklet,
coords,
this->Function,
this->ExtractInside,
this->ExtractBoundaryCells,
this->ExtractOnlyBoundaryCells);
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(worker);
cells.CastAndCallForTypes<VTKM_DEFAULT_CELL_SET_LIST>(worker);
// create the output dataset
vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(outCells);
auto mapper = [&, this](auto& result, const auto& f) {
this->MapFieldOntoOutput(result, f, Worklet);
};
MapFieldsOntoOutput(input, output, mapper);
return output;
}
}
}
#endif
bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::ExtractGeometry& Worklet)
{
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
vtkm::cont::ArrayHandle<vtkm::Id> permutation = Worklet.GetValidCellIds();
return vtkm::filter::MapFieldPermutation(field, permutation, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -0,0 +1,97 @@
//============================================================================
// 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_fulter_entity_extraction_ExtractGeometry_h
#define vtk_m_fulter_entity_extraction_ExtractGeometry_h
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace worklet
{
// Forward declaration for the worklet so we don't need to include the worklet header file
// which would require user code to be compilerd by device compiler.
class ExtractGeometry;
}
namespace filter
{
namespace entity_extraction
{
/// \brief Extract a subset of geometry based on an implicit function
///
/// Extracts from its input geometry all cells that are either
/// completely inside or outside of a specified implicit function. Any type of
/// data can be input to this filter.
///
/// To use this filter you must specify an implicit function. You must also
/// specify whether to extract cells laying inside or outside of the implicit
/// function. (The inside of an implicit function is the negative values
/// region.) An option exists to extract cells that are neither inside or
/// outside (i.e., boundary).
///
/// This differs from Clip in that Clip will subdivide boundary cells into new
/// cells, while this filter will not, producing a more 'crinkly' output.
///
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractGeometry : public vtkm::filter::NewFilterField
{
public:
// Set the volume of interest to extract
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; }
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT
bool GetExtractInside() { return this->ExtractInside; }
VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT
void ExtractInsideOn() { this->ExtractInside = true; }
VTKM_CONT
void ExtractInsideOff() { this->ExtractInside = false; }
VTKM_CONT
bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; }
VTKM_CONT
void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; }
VTKM_CONT
void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; }
VTKM_CONT
void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; }
VTKM_CONT
bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; }
VTKM_CONT
void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::ExtractGeometry&);
bool ExtractInside = true;
bool ExtractBoundaryCells = false;
bool ExtractOnlyBoundaryCells = false;
vtkm::ImplicitFunctionGeneral Function;
};
}
}
} // namespace vtkm::filter
#endif // vtk_m_fulter_entity_extraction_ExtractGeometry_h

@ -10,6 +10,7 @@
set(unit_tests
UnitTestExternalFacesFilter.cxx
UnitTestExtractGeometryFilter.cxx
UnitTestExtractPointsFilter.cxx
UnitTestMaskPointsFilter.cxx
UnitTestThresholdPointsFilter.cxx

@ -11,7 +11,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/ExtractGeometry.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -32,7 +32,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(false);
@ -59,7 +59,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(false);
extractGeometry.SetExtractBoundaryCells(false);
@ -86,7 +86,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(true);
@ -112,7 +112,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(true);

@ -10,6 +10,7 @@
set(headers
ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h
MaskPoints.h
ThresholdPoints.h

@ -26,7 +26,6 @@ set(unit_tests
UnitTestCoordinateSystemTransform.cxx
UnitTestCrossProductFilter.cxx
UnitTestEntropyFilter.cxx
UnitTestExtractGeometryFilter.cxx
UnitTestExtractStructuredFilter.cxx
UnitTestFieldMetadata.cxx
UnitTestFieldSelection.cxx

@ -27,7 +27,6 @@ set(headers
DispatcherPointNeighborhood.h
DispatcherReduceByKey.h
DotProduct.h
ExtractGeometry.h
ExtractStructured.h
FieldEntropy.h
FieldHistogram.h

@ -32,7 +32,6 @@ set(unit_tests
UnitTestCrossProduct.cxx
UnitTestDescriptiveStatistics.cxx
UnitTestDotProduct.cxx
UnitTestExtractGeometry.cxx
UnitTestExtractStructured.cxx
UnitTestFieldHistogram.cxx
UnitTestFieldStatistics.cxx

@ -1,255 +0,0 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/ExtractGeometry.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
class TestingExtractGeometry
{
public:
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestExplicitById() const
{
std::cout << "Testing extract cell explicit by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 2 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(0) == 110.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestExplicitByBox() const
{
std::cout << "Testing extract cells with implicit function (box) on explicit:" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f minPoint(0.5f, 0.0f, 0.0f);
vtkm::Vec3f maxPoint(2.0f, 2.0f, 2.0f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coordinates"),
vtkm::Box(minPoint, maxPoint),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.ReadPortal().Get(1) == 120.2f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformById2D() const
{
std::cout << "Testing extract cells structured by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 4, 5, 10, 15 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set permutation of with only extracted cells
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(1) == 4.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformById3D() const
{
std::cout << "Testing extract cells structured by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 4, 5, 10, 15 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(2) == 5.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformByBox() const
{
std::cout << "Testing extract cells with implicit function (box):" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f minPoint(1.0f, 1.0f, 1.0f);
vtkm::Vec3f maxPoint(3.0f, 3.0f, 3.0f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coords"),
vtkm::Box(minPoint, maxPoint),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
cellFieldArray.ReadPortal().Get(0) == 21.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformBySphere() const
{
std::cout << "Testing extract cells with implicit function (sphere):" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f center(2.f, 2.f, 2.f);
vtkm::FloatDefault radius(1.8f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted cells
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coords"),
vtkm::Sphere(center, radius),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
cellFieldArray.ReadPortal().Get(1) == 22.f,
"Wrong cell field data");
}
void operator()() const
{
this->TestUniformById2D();
this->TestUniformById3D();
this->TestUniformBySphere();
this->TestUniformByBox();
this->TestExplicitById();
this->TestExplicitByBox();
}
};
int UnitTestExtractGeometry(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingExtractGeometry(), argc, argv);
}