2018-06-05 03:04:38 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-06-05 03:04:38 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleConcatenate.h>
|
2019-03-15 18:46:25 +00:00
|
|
|
#include <vtkm/cont/CellLocatorBoundingIntervalHierarchy.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/cont/DataSetBuilderUniform.h>
|
2019-07-31 17:50:23 +00:00
|
|
|
#include <vtkm/cont/Invoker.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/cont/Timer.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2019-01-31 14:14:55 +00:00
|
|
|
#include <vtkm/exec/CellInterpolate.h>
|
|
|
|
#include <vtkm/exec/ParametricCoordinates.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/io/reader/VTKDataSetReader.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
struct CellCentroidCalculator : public vtkm::worklet::WorkletVisitCellsWithPoints
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2019-01-10 18:59:25 +00:00
|
|
|
typedef void ControlSignature(CellSetIn, FieldInPoint, FieldOut);
|
2018-06-05 03:04:38 +00:00
|
|
|
typedef _3 ExecutionSignature(_1, PointCount, _2);
|
|
|
|
|
|
|
|
template <typename CellShape, typename InputPointField>
|
|
|
|
VTKM_EXEC typename InputPointField::ComponentType operator()(
|
|
|
|
CellShape shape,
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
const InputPointField& inputPointField) const
|
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f parametricCenter = vtkm::exec::ParametricCoordinatesCenter(numPoints, shape, *this);
|
2018-06-05 03:04:38 +00:00
|
|
|
return vtkm::exec::CellInterpolate(inputPointField, parametricCenter, shape, *this);
|
|
|
|
}
|
|
|
|
}; // struct CellCentroidCalculator
|
|
|
|
|
|
|
|
struct BoundingIntervalHierarchyTester : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
2019-01-10 18:59:25 +00:00
|
|
|
typedef void ControlSignature(FieldIn, ExecObject, FieldIn, FieldOut);
|
2018-06-13 22:08:15 +00:00
|
|
|
typedef _4 ExecutionSignature(_1, _2, _3);
|
2018-06-05 03:04:38 +00:00
|
|
|
|
2018-06-13 22:08:15 +00:00
|
|
|
template <typename Point, typename BoundingIntervalHierarchyExecObject>
|
2018-06-05 03:04:38 +00:00
|
|
|
VTKM_EXEC vtkm::IdComponent operator()(const Point& point,
|
|
|
|
const BoundingIntervalHierarchyExecObject& bih,
|
|
|
|
const vtkm::Id expectedId) const
|
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f parametric;
|
2018-06-13 22:08:15 +00:00
|
|
|
vtkm::Id cellId;
|
|
|
|
bih->FindCell(point, cellId, parametric, *this);
|
2018-06-05 03:04:38 +00:00
|
|
|
return (1 - static_cast<vtkm::IdComponent>(expectedId == cellId));
|
|
|
|
}
|
|
|
|
}; // struct BoundingIntervalHierarchyTester
|
|
|
|
|
|
|
|
vtkm::cont::DataSet ConstructDataSet(vtkm::Id size)
|
|
|
|
{
|
|
|
|
return vtkm::cont::DataSetBuilderUniform().Create(vtkm::Id3(size, size, size));
|
|
|
|
}
|
|
|
|
|
2019-03-14 13:39:56 +00:00
|
|
|
void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, vtkm::IdComponent numPlanes)
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2019-01-09 16:11:49 +00:00
|
|
|
using Timer = vtkm::cont::Timer;
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet();
|
2018-06-13 22:08:15 +00:00
|
|
|
vtkm::cont::ArrayHandleVirtualCoordinates vertices = dataSet.GetCoordinateSystem().GetData();
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
std::cout << "Using numPlanes: " << numPlanes << "\n";
|
2018-06-29 17:42:17 +00:00
|
|
|
std::cout << "Building Bounding Interval Hierarchy Tree" << std::endl;
|
2018-07-12 21:34:29 +00:00
|
|
|
vtkm::cont::CellLocatorBoundingIntervalHierarchy bih =
|
|
|
|
vtkm::cont::CellLocatorBoundingIntervalHierarchy(numPlanes, 5);
|
2018-06-13 22:08:15 +00:00
|
|
|
bih.SetCellSet(cellSet);
|
2018-06-25 00:16:46 +00:00
|
|
|
bih.SetCoordinates(dataSet.GetCoordinateSystem());
|
|
|
|
bih.Update();
|
2018-06-29 17:42:17 +00:00
|
|
|
std::cout << "Built Bounding Interval Hierarchy Tree" << std::endl;
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
Timer centroidsTimer;
|
2019-01-09 16:11:49 +00:00
|
|
|
centroidsTimer.Start();
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3f> centroids;
|
2018-06-05 03:04:38 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<CellCentroidCalculator>().Invoke(
|
|
|
|
cellSet, vertices, centroids);
|
2019-01-09 16:11:49 +00:00
|
|
|
centroidsTimer.Stop();
|
|
|
|
std::cout << "Centroids calculation time: " << centroidsTimer.GetElapsedTime() << "\n";
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> expectedCellIds(0, 1, cellSet.GetNumberOfCells());
|
|
|
|
|
|
|
|
Timer interpolationTimer;
|
2019-01-09 16:11:49 +00:00
|
|
|
interpolationTimer.Start();
|
2018-06-05 03:04:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::IdComponent> results;
|
2018-06-13 22:08:15 +00:00
|
|
|
|
2018-06-05 03:04:38 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<BoundingIntervalHierarchyTester>().Invoke(
|
2018-06-13 22:08:15 +00:00
|
|
|
centroids, bih, expectedCellIds, results);
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::Id numDiffs = vtkm::cont::Algorithm::Reduce(results, 0, vtkm::Add());
|
2019-01-09 16:11:49 +00:00
|
|
|
interpolationTimer.Stop();
|
2018-06-05 03:04:38 +00:00
|
|
|
vtkm::Float64 timeDiff = interpolationTimer.GetElapsedTime();
|
|
|
|
std::cout << "No of interpolations: " << results.GetNumberOfValues() << "\n";
|
|
|
|
std::cout << "Interpolation time: " << timeDiff << "\n";
|
|
|
|
std::cout << "Average interpolation rate: "
|
|
|
|
<< (static_cast<vtkm::Float64>(results.GetNumberOfValues()) / timeDiff) << "\n";
|
|
|
|
std::cout << "No of diffs: " << numDiffs << "\n";
|
2018-06-24 00:49:57 +00:00
|
|
|
VTKM_TEST_ASSERT(numDiffs == 0, "Calculated cell Ids not the same as expected cell Ids");
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 13:39:56 +00:00
|
|
|
void RunTest()
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2019-04-17 20:16:08 +00:00
|
|
|
//If this test is run on a machine that already has heavy
|
|
|
|
//cpu usage it will fail, so we limit the number of threads
|
|
|
|
//to avoid the test timing out
|
|
|
|
#ifdef VTKM_ENABLE_OPENMP
|
|
|
|
omp_set_num_threads(std::min(4, omp_get_max_threads()));
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 13:39:56 +00:00
|
|
|
TestBoundingIntervalHierarchy(ConstructDataSet(16), 3);
|
|
|
|
TestBoundingIntervalHierarchy(ConstructDataSet(16), 4);
|
|
|
|
TestBoundingIntervalHierarchy(ConstructDataSet(16), 6);
|
|
|
|
TestBoundingIntervalHierarchy(ConstructDataSet(16), 9);
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestBoundingIntervalHierarchy(int argc, char* argv[])
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2019-03-14 13:39:56 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(RunTest, argc, argv);
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|