2017-03-07 21:03:22 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-03-07 21:03:22 +00:00
|
|
|
// 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/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>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
// Predicate for values less than minimum
|
|
|
|
class ValuesBelow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValuesBelow(const vtkm::FloatDefault& value)
|
|
|
|
: Value(value)
|
|
|
|
{
|
|
|
|
}
|
2017-03-07 21:03:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ScalarType>
|
|
|
|
VTKM_EXEC bool operator()(const ScalarType& value) const
|
2017-03-07 21:03:22 +00:00
|
|
|
{
|
2017-03-29 20:04:58 +00:00
|
|
|
return static_cast<vtkm::FloatDefault>(value) <= this->Value;
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-29 20:04:58 +00:00
|
|
|
vtkm::FloatDefault Value;
|
2017-03-07 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Predicate for values greater than maximum
|
|
|
|
class ValuesAbove
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValuesAbove(const vtkm::FloatDefault& value)
|
|
|
|
: Value(value)
|
|
|
|
{
|
|
|
|
}
|
2017-03-07 21:03:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ScalarType>
|
|
|
|
VTKM_EXEC bool operator()(const ScalarType& value) const
|
2017-03-07 21:03:22 +00:00
|
|
|
{
|
2017-03-29 20:04:58 +00:00
|
|
|
return static_cast<vtkm::FloatDefault>(value) >= this->Value;
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-29 20:04:58 +00:00
|
|
|
vtkm::FloatDefault Value;
|
2017-03-07 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Predicate for values between minimum and maximum
|
|
|
|
class ValuesBetween
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValuesBetween(const vtkm::FloatDefault& lower, const vtkm::FloatDefault& upper)
|
|
|
|
: Lower(lower)
|
|
|
|
, Upper(upper)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ScalarType>
|
|
|
|
VTKM_EXEC bool operator()(const ScalarType& value) const
|
2017-03-07 21:03:22 +00:00
|
|
|
{
|
2017-03-29 20:04:58 +00:00
|
|
|
return static_cast<vtkm::FloatDefault>(value) >= this->Lower &&
|
2017-05-18 14:29:41 +00:00
|
|
|
static_cast<vtkm::FloatDefault>(value) <= this->Upper;
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-28 22:07:56 +00:00
|
|
|
vtkm::FloatDefault Lower;
|
|
|
|
vtkm::FloatDefault Upper;
|
2017-03-07 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using vtkm::cont::testing::MakeTestDataSet;
|
|
|
|
|
|
|
|
class TestingThresholdPoints
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void TestUniform2D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing threshold on 2D uniform dataset" << std::endl;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using OutCellSetType = vtkm::cont::CellSetSingleType<>;
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
|
|
|
|
|
|
|
|
// Output dataset contains input coordinate system and point data
|
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
|
2017-03-29 20:04:58 +00:00
|
|
|
outDataSet.AddField(dataset.GetField("pointvar"));
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
// Output dataset gets new cell set of points that meet threshold predicate
|
|
|
|
vtkm::worklet::ThresholdPoints threshold;
|
|
|
|
OutCellSetType outCellSet;
|
2019-12-05 17:55:57 +00:00
|
|
|
outCellSet =
|
|
|
|
threshold.Run(dataset.GetCellSet(),
|
2021-01-25 17:36:56 +00:00
|
|
|
dataset.GetField("pointvar")
|
|
|
|
.GetData()
|
|
|
|
.ResetTypes(vtkm::TypeListFieldScalar{}, VTKM_DEFAULT_STORAGE_LIST{}),
|
2019-12-05 17:55:57 +00:00
|
|
|
ValuesBetween(40.0f, 71.0f));
|
2019-08-13 17:08:54 +00:00
|
|
|
outDataSet.SetCellSet(outCellSet);
|
2017-03-07 21:03:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11),
|
|
|
|
"Wrong result for ThresholdPoints");
|
2017-03-29 20:04:58 +00:00
|
|
|
|
|
|
|
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
|
2021-01-25 17:36:56 +00:00
|
|
|
pointField.GetData().AsArrayHandle(pointFieldArray);
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(pointFieldArray.ReadPortal().Get(12) == 50.0f, "Wrong point field data");
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestUniform3D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing threshold on 3D uniform dataset" << std::endl;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using OutCellSetType = vtkm::cont::CellSetSingleType<>;
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
|
|
|
|
|
|
|
// Output dataset contains input coordinate system and point data
|
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
|
2017-03-29 20:04:58 +00:00
|
|
|
outDataSet.AddField(dataset.GetField("pointvar"));
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
// Output dataset gets new cell set of points that meet threshold predicate
|
|
|
|
vtkm::worklet::ThresholdPoints threshold;
|
|
|
|
OutCellSetType outCellSet;
|
2019-12-05 17:55:57 +00:00
|
|
|
outCellSet =
|
|
|
|
threshold.Run(dataset.GetCellSet(),
|
2021-01-25 17:36:56 +00:00
|
|
|
dataset.GetField("pointvar")
|
|
|
|
.GetData()
|
|
|
|
.ResetTypes(vtkm::TypeListFieldScalar{}, VTKM_DEFAULT_STORAGE_LIST{}),
|
2019-12-05 17:55:57 +00:00
|
|
|
ValuesAbove(1.0f));
|
2019-08-13 17:08:54 +00:00
|
|
|
outDataSet.SetCellSet(outCellSet);
|
2017-03-07 21:03:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27),
|
|
|
|
"Wrong result for ThresholdPoints");
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestExplicit3D() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using OutCellSetType = vtkm::cont::CellSetSingleType<>;
|
2017-03-07 21:03:22 +00:00
|
|
|
|
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
|
|
|
|
|
|
|
|
// Output dataset contains input coordinate system and point data
|
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
|
|
|
|
|
|
|
|
// Output dataset gets new cell set of points that meet threshold predicate
|
|
|
|
vtkm::worklet::ThresholdPoints threshold;
|
|
|
|
OutCellSetType outCellSet;
|
2019-12-05 17:55:57 +00:00
|
|
|
outCellSet =
|
|
|
|
threshold.Run(dataset.GetCellSet(),
|
2021-01-25 17:36:56 +00:00
|
|
|
dataset.GetField("pointvar")
|
|
|
|
.GetData()
|
|
|
|
.ResetTypes(vtkm::TypeListFieldScalar{}, VTKM_DEFAULT_STORAGE_LIST{}),
|
2019-12-05 17:55:57 +00:00
|
|
|
ValuesBelow(50.0f));
|
2019-08-13 17:08:54 +00:00
|
|
|
outDataSet.SetCellSet(outCellSet);
|
2017-03-07 21:03:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 6),
|
|
|
|
"Wrong result for ThresholdPoints");
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()() const
|
|
|
|
{
|
|
|
|
this->TestUniform2D();
|
|
|
|
this->TestUniform3D();
|
|
|
|
this->TestExplicit3D();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestThresholdPoints(int argc, char* argv[])
|
2017-03-07 21:03:22 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestingThresholdPoints(), argc, argv);
|
2017-03-07 21:03:22 +00:00
|
|
|
}
|