ThresholdPoints first attempt

This commit is contained in:
Patricia Kroll Fasel - 090207 2017-03-07 14:03:22 -07:00
parent 57f5881538
commit dee28a3089
9 changed files with 818 additions and 0 deletions

@ -41,6 +41,7 @@ set(headers
ResultDataSet.h
ResultField.h
Threshold.h
ThresholdPoints.h
VectorMagnitude.h
VertexClustering.h
)
@ -61,6 +62,7 @@ set(header_template_sources
PointAverage.hxx
PointElevation.hxx
Threshold.hxx
ThresholdPoints.hxx
VectorMagnitude.hxx
VertexClustering.hxx
)

@ -0,0 +1,84 @@
//============================================================================
// 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_ThresholdPoints_h
#define vtk_m_filter_ThresholdPoints_h
#include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/ThresholdPoints.h>
namespace vtkm {
namespace filter {
class ThresholdPoints : public vtkm::filter::FilterDataSetWithField<ThresholdPoints>
{
public:
VTKM_CONT
ThresholdPoints();
VTKM_CONT
void SetLowerThreshold(vtkm::Float64 value){ this->LowerValue = value; }
VTKM_CONT
void SetUpperThreshold(vtkm::Float64 value){ this->UpperValue = value; }
VTKM_CONT
vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; }
VTKM_CONT
vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; }
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
vtkm::filter::ResultDataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
//Map a new field onto the resulting dataset after running the filter
//this call is only valid
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
bool DoMapField(vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
double LowerValue;
double UpperValue;
};
template<>
class FilterTraits<ThresholdPoints>
{ //currently the threshold filter only works on scalar data.
public:
typedef TypeListTagScalarAll InputFieldTypeList;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/ThresholdPoints.hxx>
#endif // vtk_m_filter_ThresholdPoints_h

@ -0,0 +1,176 @@
//============================================================================
// 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 <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace
{
// Predicate for values less than minimum
class ValuesBelow
{
public:
VTKM_CONT
ValuesBelow(const vtkm::Float32& thresholdValue) :
ThresholdValue(thresholdValue)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value <= static_cast<T>(this->ThresholdValue);
}
private:
vtkm::Float32 ThresholdValue;
};
// Predicate for values greater than maximum
class ValuesAbove
{
public:
VTKM_CONT
ValuesAbove(const vtkm::Float32& thresholdValue) :
ThresholdValue(thresholdValue)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value >= static_cast<T>(this->ThresholdValue);
}
private:
vtkm::Float32 ThresholdValue;
};
// Predicate for values between minimum and maximum
class ValuesBetween
{
public:
VTKM_CONT
ValuesBetween(const vtkm::Float64& lower,
const vtkm::Float64& upper) :
Lower(lower),
Upper(upper)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) &&
value <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
}
namespace vtkm {
namespace filter {
//-----------------------------------------------------------------------------
inline VTKM_CONT
ThresholdPoints::ThresholdPoints():
vtkm::filter::FilterDataSetWithField<ThresholdPoints>(),
LowerValue(0),
UpperValue(0)
{
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
vtkm::filter::ResultDataSet ThresholdPoints::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& device)
{
//get the cells and coordinates of the dataset
const vtkm::cont::DynamicCellSet& cells =
input.GetCellSet(this->GetActiveCellSetIndex());
if (fieldMeta.IsPointField() == false)
{
//todo: we need to mark this as a failure of input, not a failure of the algorithm
return vtkm::filter::ResultDataSet();
}
ValuesBetween predicate( this->GetLowerThreshold(), this->GetUpperThreshold() );
// output dataset
vtkm::cont::DataSet output;
vtkm::cont::CellSetSingleType<> outCellSet;
// output data set gets cell set from the worklet
vtkm::worklet::ThresholdPoints worklet;
outCellSet = worklet.Run(vtkm::filter::ApplyPolicy(cells, policy),
field,
predicate,
device);
output.AddCellSet(outCellSet);
// add input dataset coordinates to the output dataset
output.AddCoordinateSystem(
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()) );
return vtkm::filter::ResultDataSet(output);
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
bool ThresholdPoints::DoMapField(
vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter&)
{
// point data is copied as is because it was not collapsed
if(fieldMeta.IsPointField())
{
result.GetDataSet().AddField(fieldMeta.AsField(input));
return true;
}
// cell data does not apply
return false;
}
}
}

@ -31,6 +31,7 @@ set(unit_tests
UnitTestPointAverageFilter.cxx
UnitTestPointElevationFilter.cxx
UnitTestThresholdFilter.cxx
UnitTestThresholdPointsFilter.cxx
UnitTestVectorMagnitudeFilter.cxx
UnitTestVertexClusteringFilter.cxx
)

@ -0,0 +1,174 @@
//============================================================================
// 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 <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/ThresholdPoints.h>
using vtkm::cont::testing::MakeTestDataSet;
namespace {
class TestingThresholdPoints
{
public:
void TestRegular2D() const
{
std::cout << "Testing threshold on 2D regular dataset" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
vtkm::filter::ThresholdPoints thresholdPoints;
vtkm::filter::ResultDataSet result;
thresholdPoints.SetLowerThreshold(40.0);
thresholdPoints.SetUpperThreshold(71.1);
result = thresholdPoints.Execute(dataset, dataset.GetField("pointvar"));
thresholdPoints.MapFieldOntoOutput(result, dataset.GetField("pointvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1,
"Wrong number of fields in the output dataset");
VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), 11),
"Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = output.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(12) == 50.0f,
"Wrong point field data");
}
/*
void TestRegular3D() const
{
std::cout << "Testing threshold on 3D regular dataset" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0();
vtkm::filter::Threshold threshold;
vtkm::filter::ResultDataSet result;
threshold.SetLowerThreshold(20.1);
threshold.SetUpperThreshold(20.1);
result = threshold.Execute(dataset, std::string("pointvar"));
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1,
"Wrong number of fields in the output dataset");
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;
OutCellFieldArrayHandleType cellFieldArray;
output.GetField("cellvar").GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f &&
cellFieldArray.GetPortalConstControl().Get(1) == 100.2f,
"Wrong cell field data");
}
*/
/*
void TestExplicit3D() const
{
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1();
vtkm::filter::Threshold threshold;
vtkm::filter::ResultDataSet result;
threshold.SetLowerThreshold(20.1);
threshold.SetUpperThreshold(20.1);
result = threshold.Execute(dataset, std::string("pointvar"));
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1,
"Wrong number of fields in the output dataset");
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;
OutCellFieldArrayHandleType cellFieldArray;
output.GetField("cellvar").GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f &&
cellFieldArray.GetPortalConstControl().Get(1) == 100.2f,
"Wrong cell field data");
}
*/
/*
void TestExplicit3DZeroResults() const
{
std::cout << "Testing threshold on 3D explicit dataset with empty results" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1();
vtkm::filter::Threshold threshold;
vtkm::filter::ResultDataSet result;
threshold.SetLowerThreshold(500.1);
threshold.SetUpperThreshold(500.1);
result = threshold.Execute(dataset, std::string("pointvar"));
VTKM_TEST_ASSERT(result.IsValid(), "threshold algorithm should return true");
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1,
"Wrong number of fields in the output dataset");
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;
OutCellFieldArrayHandleType cellFieldArray;
output.GetField("cellvar").GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 0, "field should be empty");
}
*/
void operator()() const
{
this->TestRegular2D();
//this->TestRegular3D();
//this->TestExplicit3D();
//this->TestExplicit3DZeroResults();
}
};
}
int UnitTestThresholdPointsFilter(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestingThresholdPoints());
}

@ -47,6 +47,7 @@ set(headers
TetrahedralizeExplicitGrid.h
TetrahedralizeUniformGrid.h
Threshold.h
ThresholdPoints.h
TriangulateExplicitGrid.h
TriangulateUniformGrid.h
VertexClustering.h

@ -0,0 +1,121 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 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_Threshold_h
#define vtkm_m_worklet_Threshold_h
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/cont/Field.h>
namespace vtkm {
namespace worklet {
// Threshold points on predicate producing CellSetSingleType<VERTEX> with
// resulting subset of points
class ThresholdPoints : public vtkm::worklet::WorkletMapPointToCell
{
public:
struct BoolType : vtkm::ListTagBase<bool> { };
template <typename UnaryPredicate>
class ThresholdPointField : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<> scalars,
FieldOut<IdComponentType> mask);
typedef _2 ExecutionSignature(_1);
VTKM_CONT
ThresholdPointField() : Predicate() { }
VTKM_CONT
explicit ThresholdPointField(const UnaryPredicate &predicate)
: Predicate(predicate)
{ }
template<typename ScalarType>
VTKM_EXEC
vtkm::IdComponent operator()(const ScalarType &scalar) const
{
bool pass = this->Predicate(scalar);
vtkm::IdComponent mask = 0;
if (pass == true)
mask = 1;
std::cout << "scalar " << scalar << " mask " << mask << std::endl;
return mask;
}
private:
UnaryPredicate Predicate;
};
template <typename CellSetType,
typename UnaryPredicate,
typename ValueType,
typename StorageType,
typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(
const CellSetType &cellSet,
const vtkm::cont::ArrayHandle<ValueType, StorageType>& fieldArray,
const UnaryPredicate &predicate,
DeviceAdapter device)
{
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
vtkm::cont::ArrayHandle<vtkm::IdComponent> MaskArray;
DeviceAlgorithm::Copy(vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(0, cellSet.GetNumberOfPoints()),
MaskArray);
// Worklet output will be a boolean passFlag array
typedef ThresholdPointField<UnaryPredicate> ThresholdWorklet;
ThresholdWorklet worklet(predicate);
DispatcherMapField<ThresholdWorklet, DeviceAdapter> dispatcher(worklet);
dispatcher.Invoke(fieldArray, MaskArray);
vtkm::worklet::ScatterCounting PointScatter(MaskArray, DeviceAdapter(), true);
vtkm::cont::ArrayHandle<vtkm::Id> pointIds = PointScatter.GetOutputToInputMap();
std::cout << "Point ids that meet threshold" << std::endl;
printSummary_ArrayHandle(pointIds, std::cout);
// Make CellSetSingleType with VERTEX at each point id
vtkm::cont::CellSetSingleType< > outCellSet("cells");
vtkm::Id numberOfVertices = pointIds.GetNumberOfValues();
std::cout << "Number of vertices in output " << numberOfVertices << std::endl;
outCellSet.Fill(numberOfVertices,
vtkm::CellShapeTagVertex::Id,
1,
pointIds);
std::cout << "Fill vertices with cell set" << std::endl;
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_ThresholdPoints_h

@ -40,6 +40,7 @@ set(unit_tests
UnitTestTetrahedralizeExplicitGrid.cxx
UnitTestTetrahedralizeUniformGrid.cxx
UnitTestThreshold.cxx
UnitTestThresholdPoints.cxx
UnitTestWorkletMapField.cxx
UnitTestWorkletMapFieldExecArg.cxx
UnitTestWorkletMapFieldWholeArray.cxx

@ -0,0 +1,258 @@
//============================================================================
// 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 <vtkm/worklet/ThresholdPoints.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/CellSet.h>
#include <algorithm>
#include <iostream>
#include <vector>
namespace {
// Predicate for values less than minimum
class ValuesBelow
{
public:
VTKM_CONT
ValuesBelow(const vtkm::Float32& thresholdValue) :
ThresholdValue(thresholdValue)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value <= static_cast<T>(this->ThresholdValue);
}
private:
vtkm::Float32 ThresholdValue;
};
// Predicate for values greater than maximum
class ValuesAbove
{
public:
VTKM_CONT
ValuesAbove(const vtkm::Float32& thresholdValue) :
ThresholdValue(thresholdValue)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value >= static_cast<T>(this->ThresholdValue);
}
private:
vtkm::Float32 ThresholdValue;
};
// Predicate for values between minimum and maximum
class ValuesBetween
{
public:
VTKM_CONT
ValuesBetween(const vtkm::Float64& lower,
const vtkm::Float64& upper) :
Lower(lower),
Upper(upper)
{ }
template<typename T>
VTKM_EXEC
bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) &&
value <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
using vtkm::cont::testing::MakeTestDataSet;
template <typename DeviceAdapter>
class TestingThresholdPoints
{
public:
void TestUniform2D() const
{
std::cout << "Testing threshold on 2D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<2> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
fieldArray,
ValuesBetween(40.0f, 71.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
std::cout << "Number of output vertex cells " << outCellSet.GetNumberOfCells() << std::endl;
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(12) == 50.0f,
"Wrong point field data");
}
void TestUniform3D() const
{
std::cout << "Testing threshold on 3D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
fieldArray,
ValuesAbove(1.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
std::cout << "Number of output vertex cells " << outCellSet.GetNumberOfCells() << std::endl;
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(31) == 99.0f,
"Wrong point field data");
}
void TestExplicit3D() const
{
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
fieldArray,
ValuesBelow(50.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
std::cout << "Number of output vertex cells " << outCellSet.GetNumberOfCells() << std::endl;
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 6), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(3) == 40.2f,
"Wrong point field data");
}
void operator()() const
{
this->TestUniform2D();
this->TestUniform3D();
this->TestExplicit3D();
}
};
}
int UnitTestThresholdPoints(int, char *[])
{
return vtkm::cont::testing::Testing::Run(
TestingThresholdPoints<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>());
}