diff --git a/vtkm/Bounds.h b/vtkm/Bounds.h index f12e6fa1c..8d463a031 100644 --- a/vtkm/Bounds.h +++ b/vtkm/Bounds.h @@ -50,11 +50,16 @@ struct Bounds const vtkm::Range &zRange) : X(xRange), Y(yRange), Z(zRange) { } - template + template VTKM_EXEC_CONT_EXPORT - Bounds(const T &minX, const T &maxX, - const T &minY, const T &maxY, - const T &minZ, const T &maxZ) + Bounds(const T1 &minX, const T2 &maxX, + const T3 &minY, const T4 &maxY, + const T5 &minZ, const T6 &maxZ) : X(vtkm::Range(minX, maxX)), Y(vtkm::Range(minY, maxY)), Z(vtkm::Range(minZ, maxZ)) @@ -116,6 +121,19 @@ struct Bounds this->Z.Contains(point[2])); } + /// \b Returns the center of the range. + /// + /// \c Center computes the point at the middle of the bounds. If the bounds + /// are empty, the results are undefined. + /// + VTKM_EXEC_CONT_EXPORT + vtkm::Vec Center() const + { + return vtkm::Vec(this->X.Center(), + this->Y.Center(), + this->Z.Center()); + } + /// \b Expand bounds to include a point. /// /// This version of \c Include expands the bounds just enough to include the @@ -183,4 +201,14 @@ struct Bounds } // namespace vtkm +/// Helper function for printing bounds during testing +/// +VTKM_CONT_EXPORT +std::ostream &operator<<(std::ostream &stream, const vtkm::Bounds &bounds) +{ + return stream << "{ X:" << bounds.X + << ", Y:" << bounds.Y + << ", Z:" << bounds.Z << " }"; +} + #endif //vtk_m_Bounds_h diff --git a/vtkm/Range.h b/vtkm/Range.h index 5ca811400..0dcdab73d 100644 --- a/vtkm/Range.h +++ b/vtkm/Range.h @@ -87,6 +87,42 @@ struct Range (this->Max >= static_cast(value))); } + /// \b Returns the length of the range. + /// + /// \c Length computes the distance between the min and max. If the range + /// is empty, 0 is returned. + /// + VTKM_EXEC_CONT_EXPORT + vtkm::Float64 Length() const + { + if (this->IsNonEmpty()) + { + return (this->Max - this->Min); + } + else + { + return 0.0; + } + } + + /// \b Returns the center of the range. + /// + /// \c Center computes the middle value of the range. If the range is empty, + /// NaN is returned. + /// + VTKM_EXEC_CONT_EXPORT + vtkm::Float64 Center() const + { + if (this->IsNonEmpty()) + { + return 0.5*(this->Max + this->Min); + } + else + { + return vtkm::Nan64(); + } + } + /// \b Expand range to include a value. /// /// This version of \c Include expands the range just enough to include the @@ -148,4 +184,12 @@ struct Range } // namespace vtkm +/// Helper function for printing ranges during testing +/// +VTKM_CONT_EXPORT +std::ostream &operator<<(std::ostream &stream, const vtkm::Range &range) +{ + return stream << "[" << range.Min << ".." << range.Max << "]"; +} + #endif //vtk_m_Range_h diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index 6b303da42..c0c2dd8f0 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -20,6 +20,8 @@ #ifndef vtk_m_cont_CoordinateSystem_h #define vtk_m_cont_CoordinateSystem_h +#include + #include #include #include @@ -136,10 +138,10 @@ public: template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag) const + void GetRange(vtkm::Range *range, DeviceAdapterTag) const { - this->Superclass::GetBounds( - bounds, + this->Superclass::GetRange( + range, DeviceAdapterTag(), VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(), VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); @@ -147,10 +149,10 @@ public: template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList) const + void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList) const { - this->Superclass::GetBounds( - bounds, + this->Superclass::GetRange( + range, DeviceAdapterTag(), TypeList(), VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); @@ -158,10 +160,10 @@ public: template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList, StorageList) const + void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList, StorageList) const { - this->Superclass::GetBounds( - bounds, + this->Superclass::GetRange( + range, DeviceAdapterTag(), TypeList(), StorageList()); @@ -169,9 +171,9 @@ public: template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag) const { - return this->Superclass::GetBounds( + return this->Superclass::GetRange( DeviceAdapterTag(), VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(), VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); @@ -179,10 +181,10 @@ public: template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag, - TypeList) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag, + TypeList) const { - return this->Superclass::GetBounds( + return this->Superclass::GetRange( DeviceAdapterTag(), TypeList(), VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); @@ -190,16 +192,59 @@ public: template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag, - TypeList, - StorageList) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag, + TypeList, + StorageList) const { - return this->Superclass::GetBounds( + return this->Superclass::GetRange( DeviceAdapterTag(), TypeList(), StorageList()); } + template + VTKM_CONT_EXPORT + vtkm::Bounds GetBounds(DeviceAdapterTag) const + { + VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag); + + return this->GetBounds(DeviceAdapterTag(), + VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(), + VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); + } + + template + VTKM_CONT_EXPORT + vtkm::Bounds GetBounds(DeviceAdapterTag, TypeList) const + { + VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag); + VTKM_IS_LIST_TAG(TypeList); + + return this->GetBounds(DeviceAdapterTag(), + TypeList(), + VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG()); + } + + template + VTKM_CONT_EXPORT + vtkm::Bounds GetBounds(DeviceAdapterTag, TypeList, StorageList) const + { + VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag); + VTKM_IS_LIST_TAG(TypeList); + VTKM_IS_LIST_TAG(StorageList); + + vtkm::cont::ArrayHandle ranges = + this->GetRange(DeviceAdapterTag(), TypeList(), StorageList()); + + VTKM_ASSERT(ranges.GetNumberOfValues() == 3); + + vtkm::cont::ArrayHandle::PortalConstControl rangePortal = + ranges.GetPortalConstControl(); + + return vtkm::Bounds(rangePortal.Get(0), + rangePortal.Get(1), + rangePortal.Get(2)); + } VTKM_CONT_EXPORT diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index a3b251217..ef083153d 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -20,8 +20,9 @@ #ifndef vtk_m_cont_Field_h #define vtk_m_cont_Field_h -#include #include +#include +#include #include #include @@ -37,13 +38,13 @@ namespace cont { namespace internal { -struct BoundsMin +struct RangeMin { template T operator()(const T& a, const T& b)const { return vtkm::Min(a,b); } }; -struct BoundsMax +struct RangeMax { template T operator()(const T& a, const T& b)const { return vtkm::Max(a,b); } @@ -51,10 +52,10 @@ struct BoundsMax template -class ComputeBounds +class ComputeRange { public: - ComputeBounds(ArrayHandle& bounds) : Bounds(&bounds) {} + ComputeRange(ArrayHandle& range) : Range(&range) {} template void operator()(const ArrayHandleType &input) const @@ -70,16 +71,15 @@ public: ValueType initialMin = input.GetPortalConstControl().Get(0); ValueType initialMax = initialMin; - ValueType minResult = Algorithm::Reduce(input, initialMin, BoundsMin()); - ValueType maxResult = Algorithm::Reduce(input, initialMax, BoundsMax()); + ValueType minResult = Algorithm::Reduce(input, initialMin, RangeMin()); + ValueType maxResult = Algorithm::Reduce(input, initialMax, RangeMax()); - this->Bounds->Allocate(NumberOfComponents * 2); + this->Range->Allocate(NumberOfComponents); for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) { - this->Bounds->GetPortalControl().Set(i * 2, - static_cast(VecType::GetComponent(minResult, i) ) ); - this->Bounds->GetPortalControl().Set(i * 2 + 1, - static_cast(VecType::GetComponent(maxResult, i) ) ); + this->Range->GetPortalControl().Set( + i, vtkm::Range(VecType::GetComponent(minResult, i), + VecType::GetComponent(maxResult, i))); } } @@ -99,19 +99,16 @@ public: vtkm::Vec maximum = portal.Get(portal.GetNumberOfValues()-1); - this->Bounds->Allocate(6); - vtkm::cont::ArrayHandle::PortalControl outPortal = - this->Bounds->GetPortalControl(); - outPortal.Set(0, minimum[0]); - outPortal.Set(1, maximum[0]); - outPortal.Set(2, minimum[1]); - outPortal.Set(3, maximum[1]); - outPortal.Set(4, minimum[2]); - outPortal.Set(5, maximum[2]); + this->Range->Allocate(3); + vtkm::cont::ArrayHandle::PortalControl outPortal = + this->Range->GetPortalControl(); + outPortal.Set(0, vtkm::Range(minimum[0], maximum[0])); + outPortal.Set(1, vtkm::Range(minimum[1], maximum[1])); + outPortal.Set(2, vtkm::Range(minimum[2], maximum[2])); } private: - vtkm::cont::ArrayHandle *Bounds; + vtkm::cont::ArrayHandle *Range; }; } // namespace internal @@ -143,7 +140,7 @@ public: AssocCellSetName(), AssocLogicalDim(-1), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_WHOLE_MESH || @@ -160,7 +157,7 @@ public: AssocCellSetName(), AssocLogicalDim(-1), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT((this->Association == ASSOC_WHOLE_MESH) || @@ -176,7 +173,7 @@ public: Association(association), AssocCellSetName(), AssocLogicalDim(-1), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT((this->Association == ASSOC_WHOLE_MESH) || @@ -194,7 +191,7 @@ public: Association(association), AssocCellSetName(), AssocLogicalDim(-1), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT((this->Association == ASSOC_WHOLE_MESH) || @@ -213,7 +210,7 @@ public: AssocCellSetName(cellSetName), AssocLogicalDim(-1), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_CELL_SET); @@ -230,7 +227,7 @@ public: AssocCellSetName(cellSetName), AssocLogicalDim(-1), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_CELL_SET); @@ -246,7 +243,7 @@ public: Association(association), AssocCellSetName(cellSetName), AssocLogicalDim(-1), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_CELL_SET); @@ -264,7 +261,7 @@ public: Association(association), AssocCellSetName(cellSetName), AssocLogicalDim(-1), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_CELL_SET); @@ -282,7 +279,7 @@ public: AssocCellSetName(), AssocLogicalDim(logicalDim), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_LOGICAL_DIM); @@ -298,7 +295,7 @@ public: Association(association), AssocLogicalDim(logicalDim), Data(data), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_LOGICAL_DIM); @@ -313,7 +310,7 @@ public: : Name(name), Association(association), AssocLogicalDim(logicalDim), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_LOGICAL_DIM); @@ -329,7 +326,7 @@ public: : Name(name), Association(association), AssocLogicalDim(logicalDim), - Bounds(), + Range(), ModifiedFlag(true) { VTKM_ASSERT(this->Association == ASSOC_LOGICAL_DIM); @@ -343,7 +340,7 @@ public: AssocCellSetName(), AssocLogicalDim(), Data(), - Bounds(), + Range(), ModifiedFlag(true) { //Generate an empty field @@ -375,67 +372,73 @@ public: template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag, - TypeList, - StorageList) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag, + TypeList, + StorageList) const { if (this->ModifiedFlag) { - internal::ComputeBounds computeBounds(this->Bounds); - this->Data.ResetTypeAndStorageLists(TypeList(),StorageList()).CastAndCall(computeBounds); + internal::ComputeRange computeRange(this->Range); + this->Data.ResetTypeAndStorageLists(TypeList(),StorageList()).CastAndCall(computeRange); this->ModifiedFlag = false; } - return this->Bounds; + return this->Range; } template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, - DeviceAdapterTag, - TypeList, - StorageList) const + void GetRange(vtkm::Range *range, + DeviceAdapterTag, + TypeList, + StorageList) const { - this->GetBounds(DeviceAdapterTag(), TypeList(), StorageList()); + this->GetRange(DeviceAdapterTag(), TypeList(), StorageList()); - vtkm::Id length = this->Bounds.GetNumberOfValues(); + vtkm::Id length = this->Range.GetNumberOfValues(); for (vtkm::Id i = 0; i < length; ++i) { - bounds[i] = this->Bounds.GetPortalConstControl().Get(i); + range[i] = this->Range.GetPortalConstControl().Get(i); } } template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag, - TypeList) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag, + TypeList) const { - return this->GetBounds(DeviceAdapterTag(), TypeList(), - VTKM_DEFAULT_STORAGE_LIST_TAG()); + return this->GetRange(DeviceAdapterTag(), + TypeList(), + VTKM_DEFAULT_STORAGE_LIST_TAG()); } template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList) const + void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList) const { - this->GetBounds(bounds, DeviceAdapterTag(), TypeList(), - VTKM_DEFAULT_STORAGE_LIST_TAG()); + this->GetRange(range, + DeviceAdapterTag(), + TypeList(), + VTKM_DEFAULT_STORAGE_LIST_TAG()); } template VTKM_CONT_EXPORT - const vtkm::cont::ArrayHandle& GetBounds(DeviceAdapterTag) const + const vtkm::cont::ArrayHandle& GetRange(DeviceAdapterTag) const { - return this->GetBounds(DeviceAdapterTag(), VTKM_DEFAULT_TYPE_LIST_TAG(), - VTKM_DEFAULT_STORAGE_LIST_TAG()); + return this->GetRange(DeviceAdapterTag(), + VTKM_DEFAULT_TYPE_LIST_TAG(), + VTKM_DEFAULT_STORAGE_LIST_TAG()); } template VTKM_CONT_EXPORT - void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag) const + void GetRange(vtkm::Range *range, DeviceAdapterTag) const { - this->GetBounds(bounds, DeviceAdapterTag(), VTKM_DEFAULT_TYPE_LIST_TAG(), - VTKM_DEFAULT_STORAGE_LIST_TAG()); + this->GetRange(range, + DeviceAdapterTag(), + VTKM_DEFAULT_TYPE_LIST_TAG(), + VTKM_DEFAULT_STORAGE_LIST_TAG()); } VTKM_CONT_EXPORT @@ -509,7 +512,7 @@ private: vtkm::IdComponent AssocLogicalDim; ///< only populate if assoc is logical dim vtkm::cont::DynamicArrayHandle Data; - mutable vtkm::cont::ArrayHandle Bounds; + mutable vtkm::cont::ArrayHandle Range; mutable bool ModifiedFlag; }; diff --git a/vtkm/cont/cuda/testing/CMakeLists.txt b/vtkm/cont/cuda/testing/CMakeLists.txt index 34bb56efc..7c06dfe18 100644 --- a/vtkm/cont/cuda/testing/CMakeLists.txt +++ b/vtkm/cont/cuda/testing/CMakeLists.txt @@ -19,7 +19,7 @@ ##============================================================================ set(unit_tests - UnitTestComputeBoundsCuda.cu + UnitTestComputeRangeCuda.cu UnitTestCudaArrayHandle.cu UnitTestCudaArrayHandleFancy.cu UnitTestCudaDataSetExplicit.cu diff --git a/vtkm/cont/cuda/testing/UnitTestComputeBoundsCuda.cu b/vtkm/cont/cuda/testing/UnitTestComputeRangeCuda.cu similarity index 88% rename from vtkm/cont/cuda/testing/UnitTestComputeBoundsCuda.cu rename to vtkm/cont/cuda/testing/UnitTestComputeRangeCuda.cu index 187aa9f8c..519dd8a6a 100644 --- a/vtkm/cont/cuda/testing/UnitTestComputeBoundsCuda.cu +++ b/vtkm/cont/cuda/testing/UnitTestComputeRangeCuda.cu @@ -22,11 +22,11 @@ #include #include -#include +#include -int UnitTestComputeBoundsCuda(int, char *[]) +int UnitTestComputeRangeCuda(int, char *[]) { - int result = vtkm::cont::testing::TestingComputeBounds + int result = vtkm::cont::testing::TestingComputeRange ::Run(); return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result); } diff --git a/vtkm/cont/tbb/testing/CMakeLists.txt b/vtkm/cont/tbb/testing/CMakeLists.txt index 57123e5da..492babb71 100644 --- a/vtkm/cont/tbb/testing/CMakeLists.txt +++ b/vtkm/cont/tbb/testing/CMakeLists.txt @@ -19,7 +19,7 @@ ##============================================================================ set(unit_tests - UnitTestComputeBoundsTBB.cxx + UnitTestComputeRangeTBB.cxx UnitTestDataSetExplicitTBB.cxx UnitTestDataSetSingleTypeTBB.cxx UnitTestDeviceAdapterTBB.cxx diff --git a/vtkm/cont/tbb/testing/UnitTestComputeBoundsTBB.cxx b/vtkm/cont/tbb/testing/UnitTestComputeRangeTBB.cxx similarity index 87% rename from vtkm/cont/tbb/testing/UnitTestComputeBoundsTBB.cxx rename to vtkm/cont/tbb/testing/UnitTestComputeRangeTBB.cxx index 44b10ea5b..ef2c90b04 100644 --- a/vtkm/cont/tbb/testing/UnitTestComputeBoundsTBB.cxx +++ b/vtkm/cont/tbb/testing/UnitTestComputeRangeTBB.cxx @@ -20,10 +20,10 @@ #include -#include +#include -int UnitTestComputeBoundsTBB(int, char *[]) +int UnitTestComputeRangeTBB(int, char *[]) { - return vtkm::cont::testing::TestingComputeBounds + return vtkm::cont::testing::TestingComputeRange ::Run(); } diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index 93a26d207..ac6e267d2 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -23,7 +23,7 @@ set(headers MakeTestDataSet.h Testing.h TestingArrayHandles.h - TestingComputeBounds.h + TestingComputeRange.h TestingDeviceAdapter.h TestingDataSetExplicit.h TestingDataSetSingleType.h @@ -45,7 +45,7 @@ set(unit_tests UnitTestArrayHandleUniformPointCoordinates.cxx UnitTestArrayPortalToIterators.cxx UnitTestContTesting.cxx - UnitTestComputeBoundsSerial.cxx + UnitTestComputeRangeSerial.cxx UnitTestDataSetBuilderExplicit.cxx UnitTestDataSetBuilderRectilinear.cxx UnitTestDataSetBuilderUniform.cxx diff --git a/vtkm/cont/testing/TestingComputeBounds.h b/vtkm/cont/testing/TestingComputeRange.h similarity index 60% rename from vtkm/cont/testing/TestingComputeBounds.h rename to vtkm/cont/testing/TestingComputeRange.h index eeecc6ff7..e5c51a1c2 100644 --- a/vtkm/cont/testing/TestingComputeBounds.h +++ b/vtkm/cont/testing/TestingComputeRange.h @@ -17,8 +17,8 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -#ifndef vtk_m_cont_testing_TestingComputeBounds_h -#define vtk_m_cont_testing_TestingComputeBounds_h +#ifndef vtk_m_cont_testing_TestingComputeRange_h +#define vtk_m_cont_testing_TestingComputeRange_h #include #include @@ -45,7 +45,7 @@ struct CustomTypeList : vtkm::ListTagBase, {}; template -class TestingComputeBounds +class TestingComputeRange { private: template @@ -57,19 +57,13 @@ private: vtkm::cont::Field field("TestField", vtkm::cont::Field::ASSOC_POINTS, data, nvals); - vtkm::Float64 result[2]; - field.GetBounds(result, DeviceAdapterTag()); + vtkm::Range result; + field.GetRange(&result, DeviceAdapterTag()); - if (result[0] == -5.0 && result[1] == 5.0) - { - std::cout << "Success" << std::endl; - } - else - { - std::cout << "Expected: -5.0, 5.0; Got: " << result[0] << ", " << result[1] - << std::endl; - VTKM_TEST_FAIL("Failed"); - } + std::cout << result << std::endl; + VTKM_TEST_ASSERT( + (test_equal(result.Min, -5.0) && test_equal(result.Max, 5.0)), + "Unexpected scalar field range."); } template @@ -89,38 +83,17 @@ private: vtkm::cont::Field field("TestField", vtkm::cont::Field::ASSOC_POINTS, fieldData, nvals); - vtkm::Float64 result[NumberOfComponents * 2]; - field.GetBounds(result, DeviceAdapterTag(), CustomTypeList(), - VTKM_DEFAULT_STORAGE_LIST_TAG()); + vtkm::Range result[NumberOfComponents]; + field.GetRange(result, + DeviceAdapterTag(), + CustomTypeList(), + VTKM_DEFAULT_STORAGE_LIST_TAG()); - bool success = true; for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) { - if (result[i * 2] != -5.0 || result[i * 2 + 1] != 5.0) - { - success = false; - break; - } - } - - if (success) - { - std::cout << "Success" << std::endl; - } - else - { - std::cout << "Expected: -5.0s and 5.0s; Got: "; - for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) - { - std::cout << result[i * 2] << ","; - } - std::cout << " and "; - for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) - { - std::cout << result[i * 2 + 1] << ","; - } - std::cout << std::endl; - VTKM_TEST_FAIL("Failed"); + VTKM_TEST_ASSERT( + (test_equal(result[i].Min, -5.0) && test_equal(result[i].Max, 5.0)), + "Unexpected vector field range."); } } @@ -132,15 +105,14 @@ private: vtkm::Vec(0.0f,-5.0f,4.0f), vtkm::Vec(1.0f,0.5f,2.0f)); - vtkm::Float64 result[6]; - field.GetBounds(result, DeviceAdapterTag()); + vtkm::Bounds result = field.GetBounds(DeviceAdapterTag()); - VTKM_TEST_ASSERT(test_equal(result[0], 0.0), "Min x wrong."); - VTKM_TEST_ASSERT(test_equal(result[1], 9.0), "Max x wrong."); - VTKM_TEST_ASSERT(test_equal(result[2], -5.0), "Min y wrong."); - VTKM_TEST_ASSERT(test_equal(result[3], 4.5), "Max y wrong."); - VTKM_TEST_ASSERT(test_equal(result[4], 4.0), "Min z wrong."); - VTKM_TEST_ASSERT(test_equal(result[5], 12.0), "Max z wrong."); + VTKM_TEST_ASSERT(test_equal(result.X.Min, 0.0), "Min x wrong."); + VTKM_TEST_ASSERT(test_equal(result.X.Max, 9.0), "Max x wrong."); + VTKM_TEST_ASSERT(test_equal(result.Y.Min, -5.0), "Min y wrong."); + VTKM_TEST_ASSERT(test_equal(result.Y.Max, 4.5), "Max y wrong."); + VTKM_TEST_ASSERT(test_equal(result.Z.Min, 4.0), "Min z wrong."); + VTKM_TEST_ASSERT(test_equal(result.Z.Max, 12.0), "Max z wrong."); } struct TestAll @@ -148,34 +120,34 @@ private: VTKM_CONT_EXPORT void operator()() const { std::cout << "Testing (Int32, 1)..." << std::endl; - TestingComputeBounds::TestScalarField(); + TestingComputeRange::TestScalarField(); std::cout << "Testing (Int64, 1)..." << std::endl; - TestingComputeBounds::TestScalarField(); + TestingComputeRange::TestScalarField(); std::cout << "Testing (Float32, 1)..." << std::endl; - TestingComputeBounds::TestScalarField(); + TestingComputeRange::TestScalarField(); std::cout << "Testing (Float64, 1)..." << std::endl; - TestingComputeBounds::TestScalarField(); + TestingComputeRange::TestScalarField(); std::cout << "Testing (Int32, 3)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Int64, 3)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Float32, 3)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Float64, 3)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Int32, 9)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Int64, 9)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Float32, 9)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing (Float64, 9)..." << std::endl; - TestingComputeBounds::TestVecField(); + TestingComputeRange::TestVecField(); std::cout << "Testing UniformPointCoords..." << std::endl; - TestingComputeBounds::TestUniformCoordinateField(); + TestingComputeRange::TestUniformCoordinateField(); } }; @@ -190,4 +162,4 @@ public: } } // namespace vtkm::cont::testing -#endif //vtk_m_cont_testing_TestingComputeBounds_h +#endif //vtk_m_cont_testing_TestingComputeRange_h diff --git a/vtkm/cont/testing/UnitTestComputeBoundsSerial.cxx b/vtkm/cont/testing/UnitTestComputeRangeSerial.cxx similarity index 86% rename from vtkm/cont/testing/UnitTestComputeBoundsSerial.cxx rename to vtkm/cont/testing/UnitTestComputeRangeSerial.cxx index d4eb8e973..f756ff067 100644 --- a/vtkm/cont/testing/UnitTestComputeBoundsSerial.cxx +++ b/vtkm/cont/testing/UnitTestComputeRangeSerial.cxx @@ -20,10 +20,10 @@ #include -#include +#include -int UnitTestComputeBoundsSerial(int, char *[]) +int UnitTestComputeRangeSerial(int, char *[]) { - return vtkm::cont::testing::TestingComputeBounds + return vtkm::cont::testing::TestingComputeRange ::Run(); } diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx index 3b17ad835..203cce3b7 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx @@ -33,27 +33,22 @@ typedef vtkm::cont::DeviceAdapterAlgorithm DFA; typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter; template -void ComputeBounds(std::size_t numPoints, const T *coords, - vtkm::Float64 *bounds) +vtkm::Bounds ComputeBounds(std::size_t numPoints, const T *coords) { - bounds[0] = bounds[1] = coords[0*3 +0]; - bounds[2] = bounds[3] = coords[0*3 +1]; - bounds[4] = bounds[5] = coords[0*3 +2]; + vtkm::Bounds bounds; - for (std::size_t i = 0; i < numPoints; i++) - { - bounds[0] = std::min(bounds[0], static_cast(coords[i*3+0])); - bounds[1] = std::max(bounds[1], static_cast(coords[i*3+0])); - bounds[2] = std::min(bounds[2], static_cast(coords[i*3+1])); - bounds[3] = std::max(bounds[3], static_cast(coords[i*3+1])); - bounds[4] = std::min(bounds[4], static_cast(coords[i*3+2])); - bounds[5] = std::max(bounds[5], static_cast(coords[i*3+2])); - } + for (std::size_t i = 0; i < numPoints; i++) + { + bounds.Include(vtkm::Vec(coords[i*3+0],coords[i*3+1],coords[i*3+2])); + } + + return bounds; } void ValidateDataSet(const vtkm::cont::DataSet &ds, - vtkm::Id numPoints, vtkm::Id numCells, - vtkm::Float64 *bounds) + vtkm::Id numPoints, + vtkm::Id numCells, + const vtkm::Bounds &bounds) { //Verify basics.. VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1, @@ -66,23 +61,21 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds, "Wrong number of coordinates."); VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == numCells, "Wrong number of cells."); - + //Make sure bounds are correct. - vtkm::Float64 res[6]; - ds.GetCoordinateSystem().GetBounds(res, DeviceAdapter()); - VTKM_TEST_ASSERT(test_equal(bounds[0], res[0]) && test_equal(bounds[1], res[1]) && - test_equal(bounds[2], res[2]) && test_equal(bounds[3], res[3]) && - test_equal(bounds[4], res[4]) && test_equal(bounds[5], res[5]), + vtkm::Bounds computedBounds = + ds.GetCoordinateSystem().GetBounds(DeviceAdapter()); + VTKM_TEST_ASSERT(test_equal(bounds, computedBounds), "Bounds of coordinates do not match"); } - + template std::vector createVec(std::size_t n, const T *data) { std::vector vec(n); for (std::size_t i = 0; i < n; i++) - vec[i] = data[i]; + vec[i] = data[i]; return vec; } @@ -98,88 +91,88 @@ createAH(std::size_t n, const T *data) template vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords, - std::size_t numPoints, const T *coords, - std::size_t numCells, std::size_t numConn, - const vtkm::Id *conn, - const vtkm::IdComponent *indices, - const vtkm::UInt8 *shape) + std::size_t numPoints, const T *coords, + std::size_t numCells, std::size_t numConn, + const vtkm::Id *conn, + const vtkm::IdComponent *indices, + const vtkm::UInt8 *shape) { vtkm::cont::DataSetBuilderExplicit dsb; if (useSeparatedCoords) { - std::vector xvals(numPoints), yvals(numPoints), zvals(numPoints); - for (std::size_t i = 0; i < numPoints; i++) - { - xvals[i] = coords[i*3 + 0]; - yvals[i] = coords[i*3 + 1]; - zvals[i] = coords[i*3 + 2]; - } - vtkm::cont::ArrayHandle X,Y,Z; - DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), X); - DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Y); - DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Z); - return dsb.Create(X,Y,Z, - createAH(numCells, shape), - createAH(numCells, indices), - createAH(numConn, conn)); + std::vector xvals(numPoints), yvals(numPoints), zvals(numPoints); + for (std::size_t i = 0; i < numPoints; i++) + { + xvals[i] = coords[i*3 + 0]; + yvals[i] = coords[i*3 + 1]; + zvals[i] = coords[i*3 + 2]; + } + vtkm::cont::ArrayHandle X,Y,Z; + DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), X); + DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Y); + DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Z); + return dsb.Create(X,Y,Z, + createAH(numCells, shape), + createAH(numCells, indices), + createAH(numConn, conn)); } else { - std::vector > tmp(numPoints); - for (std::size_t i = 0; i < numPoints; i++) - { - tmp[i][0] = coords[i*3 + 0]; - tmp[i][1] = coords[i*3 + 1]; - tmp[i][2] = coords[i*3 + 2]; - } + std::vector > tmp(numPoints); + for (std::size_t i = 0; i < numPoints; i++) + { + tmp[i][0] = coords[i*3 + 0]; + tmp[i][1] = coords[i*3 + 1]; + tmp[i][2] = coords[i*3 + 2]; + } - vtkm::cont::ArrayHandle > pts; - DFA::Copy(vtkm::cont::make_ArrayHandle(tmp), pts); - return dsb.Create(pts, - createAH(numCells, shape), - createAH(numCells, indices), - createAH(numConn, conn)); + vtkm::cont::ArrayHandle > pts; + DFA::Copy(vtkm::cont::make_ArrayHandle(tmp), pts); + return dsb.Create(pts, + createAH(numCells, shape), + createAH(numCells, indices), + createAH(numConn, conn)); } } template vtkm::cont::DataSet CreateDataSetVec(bool useSeparatedCoords, - std::size_t numPoints, const T *coords, - std::size_t numCells, std::size_t numConn, - const vtkm::Id *conn, - const vtkm::IdComponent *indices, - const vtkm::UInt8 *shape) + std::size_t numPoints, const T *coords, + std::size_t numCells, std::size_t numConn, + const vtkm::Id *conn, + const vtkm::IdComponent *indices, + const vtkm::UInt8 *shape) { vtkm::cont::DataSetBuilderExplicit dsb; if (useSeparatedCoords) { - std::vector X(numPoints), Y(numPoints), Z(numPoints); - for (std::size_t i = 0; i < numPoints; i++) - { - X[i] = coords[i*3 + 0]; - Y[i] = coords[i*3 + 1]; - Z[i] = coords[i*3 + 2]; - } - return dsb.Create(X,Y,Z, - createVec(numCells, shape), - createVec(numCells, indices), - createVec(numConn, conn)); + std::vector X(numPoints), Y(numPoints), Z(numPoints); + for (std::size_t i = 0; i < numPoints; i++) + { + X[i] = coords[i*3 + 0]; + Y[i] = coords[i*3 + 1]; + Z[i] = coords[i*3 + 2]; + } + return dsb.Create(X,Y,Z, + createVec(numCells, shape), + createVec(numCells, indices), + createVec(numConn, conn)); } else { - std::vector > pts(numPoints); - for (std::size_t i = 0; i < numPoints; i++) + std::vector > pts(numPoints); + for (std::size_t i = 0; i < numPoints; i++) { - pts[i][0] = coords[i*3 + 0]; - pts[i][1] = coords[i*3 + 1]; - pts[i][2] = coords[i*3 + 2]; - } - return dsb.Create(pts, - createVec(numCells, shape), - createVec(numCells, indices), - createVec(numConn, conn)); + pts[i][0] = coords[i*3 + 0]; + pts[i][1] = coords[i*3 + 1]; + pts[i][2] = coords[i*3 + 2]; + } + return dsb.Create(pts, + createVec(numCells, shape), + createVec(numCells, indices), + createVec(numConn, conn)); } } @@ -203,31 +196,31 @@ TestDataSetBuilderExplicit() { vtkm::cont::DataSetBuilderExplicit dsb; vtkm::cont::DataSet ds; - vtkm::Float64 bounds[6]; + vtkm::Bounds bounds; //Iterate over organization of coordinates. for (int i = 0; i < 2; i++) { - //Test ExplicitData0 - ComputeBounds(TEST_BOUNDS(0), bounds); - ds = CreateDataSetArr(i==0,TEST_DATA(0)); - ValidateDataSet(ds, TEST_NUMS(0), bounds); - ds = CreateDataSetVec(i==0, TEST_DATA(0)); - ValidateDataSet(ds, TEST_NUMS(0), bounds); + //Test ExplicitData0 + bounds = ComputeBounds(TEST_BOUNDS(0)); + ds = CreateDataSetArr(i==0,TEST_DATA(0)); + ValidateDataSet(ds, TEST_NUMS(0), bounds); + ds = CreateDataSetVec(i==0, TEST_DATA(0)); + ValidateDataSet(ds, TEST_NUMS(0), bounds); - //Test ExplicitData1 - ComputeBounds(TEST_BOUNDS(1), bounds); - ds = CreateDataSetArr(i==0,TEST_DATA(1)); - ValidateDataSet(ds, TEST_NUMS(1), bounds); - ds = CreateDataSetVec(i==0, TEST_DATA(1)); - ValidateDataSet(ds, TEST_NUMS(1), bounds); + //Test ExplicitData1 + bounds = ComputeBounds(TEST_BOUNDS(1)); + ds = CreateDataSetArr(i==0,TEST_DATA(1)); + ValidateDataSet(ds, TEST_NUMS(1), bounds); + ds = CreateDataSetVec(i==0, TEST_DATA(1)); + ValidateDataSet(ds, TEST_NUMS(1), bounds); - //Test ExplicitData2 - ComputeBounds(TEST_BOUNDS(2), bounds); - ds = CreateDataSetArr(i==0,TEST_DATA(2)); - ValidateDataSet(ds, TEST_NUMS(2), bounds); - ds = CreateDataSetVec(i==0, TEST_DATA(2)); - ValidateDataSet(ds, TEST_NUMS(2), bounds); + //Test ExplicitData2 + bounds = ComputeBounds(TEST_BOUNDS(2)); + ds = CreateDataSetArr(i==0,TEST_DATA(2)); + ValidateDataSet(ds, TEST_NUMS(2), bounds); + ds = CreateDataSetVec(i==0, TEST_DATA(2)); + ValidateDataSet(ds, TEST_NUMS(2), bounds); } } diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx index 4229bc767..056d21be3 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx @@ -47,7 +47,7 @@ typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter; void ValidateDataSet(const vtkm::cont::DataSet &ds, int dim, vtkm::Id numPoints, vtkm::Id numCells, - vtkm::Float64 *bounds) + const vtkm::Bounds &bounds) { //Verify basics.. VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1, @@ -62,11 +62,8 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds, "Wrong number of cells."); //Make sure the bounds are correct. - vtkm::Float64 res[6]; - ds.GetCoordinateSystem().GetBounds(res, DeviceAdapter()); - VTKM_TEST_ASSERT(test_equal(bounds[0], res[0]) && test_equal(bounds[1], res[1]) && - test_equal(bounds[2], res[2]) && test_equal(bounds[3], res[3]) && - test_equal(bounds[4], res[4]) && test_equal(bounds[5], res[5]), + vtkm::Bounds res = ds.GetCoordinateSystem().GetBounds(DeviceAdapter()); + VTKM_TEST_ASSERT(test_equal(bounds, res), "Bounds of coordinates do not match"); if (dim == 2) { @@ -150,11 +147,9 @@ RectilinearTests() std::cout << "2D cases" << std::endl; vtkm::Id numPoints = dimensions[0]*dimensions[1]; vtkm::Id numCells = (dimensions[0]-1)*(dimensions[1]-1); - vtkm::Float64 bounds[6] = { - xCoordinates.front(), xCoordinates.back(), - yCoordinates.front(), yCoordinates.back(), - 0.0, 0.0 - }; + vtkm::Bounds bounds(xCoordinates.front(), xCoordinates.back(), + yCoordinates.front(), yCoordinates.back(), + 0.0, 0.0); std::cout << " Create with std::vector" << std::endl; dataSet = dataSetBuilder.Create(xCoordinates, yCoordinates); @@ -175,8 +170,7 @@ RectilinearTests() std::cout << "3D cases" << std::endl; numPoints *= dimensions[2]; numCells *= dimensions[2]-1; - bounds[4] = zCoordinates.front(); - bounds[5] = zCoordinates.back(); + bounds.Z = vtkm::Range(zCoordinates.front(), zCoordinates.back()); std::cout << " Create with std::vector" << std::endl; dataSet = dataSetBuilder.Create(xCoordinates, yCoordinates, zCoordinates); diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx index 6e8fba61f..2a1158494 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx @@ -47,7 +47,7 @@ typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter; void ValidateDataSet(const vtkm::cont::DataSet &ds, int dim, vtkm::Id numPoints, vtkm::Id numCells, - vtkm::Float64 *bounds) + vtkm::Bounds bounds) { //Verify basics.. VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1, @@ -63,11 +63,8 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds, //Make sure bounds are correct. - vtkm::Float64 res[6]; - ds.GetCoordinateSystem().GetBounds(res, DeviceAdapter()); - VTKM_TEST_ASSERT(test_equal(bounds[0], res[0]) && test_equal(bounds[1], res[1]) && - test_equal(bounds[2], res[2]) && test_equal(bounds[3], res[3]) && - test_equal(bounds[4], res[4]) && test_equal(bounds[5], res[5]), + vtkm::Bounds res = ds.GetCoordinateSystem().GetBounds(DeviceAdapter()); + VTKM_TEST_ASSERT(test_equal(bounds, res), "Bounds of coordinates do not match"); if (dim == 2) @@ -87,12 +84,10 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds, } template -void FillMethod(vtkm::IdComponent method, - vtkm::Id dimensionSize, - T &origin, - T &spacing, - vtkm::Float64 &boundsMin, - vtkm::Float64 &boundsMax) +vtkm::Range FillMethod(vtkm::IdComponent method, + vtkm::Id dimensionSize, + T &origin, + T &spacing) { switch (method) { @@ -122,8 +117,7 @@ void FillMethod(vtkm::IdComponent method, break; } - boundsMin = static_cast(origin); - boundsMax = static_cast(origin + static_cast(dimensionSize-1)*spacing); + return vtkm::Range(origin, origin + static_cast(dimensionSize-1)*spacing); } template @@ -161,25 +155,19 @@ UniformTests() vtkm::Vec origin; vtkm::Vec spacing; - vtkm::Float64 bounds[6]; - FillMethod(fillMethodX, - dimensions[0], - origin[0], - spacing[0], - bounds[0], - bounds[1]); - FillMethod(fillMethodY, - dimensions[1], - origin[1], - spacing[1], - bounds[2], - bounds[3]); - FillMethod(fillMethodZ, - dimensions[2], - origin[2], - spacing[2], - bounds[4], - bounds[5]); + vtkm::Bounds bounds; + bounds.X = FillMethod(fillMethodX, + dimensions[0], + origin[0], + spacing[0]); + bounds.Y = FillMethod(fillMethodY, + dimensions[1], + origin[1], + spacing[1]); + bounds.Z = FillMethod(fillMethodZ, + dimensions[2], + origin[2], + spacing[2]); std::cout << "3D case" << std::endl; vtkm::Id numPoints = dimensions[0]*dimensions[1]*dimensions[2]; @@ -190,7 +178,7 @@ UniformTests() std::cout << "2D case" << std::endl; numPoints = dimensions[0]*dimensions[1]; numCells = (dimensions[0]-1)*(dimensions[1]-1); - bounds[4] = bounds[5] = 0.0; + bounds.Z = vtkm::Range(0, 0); dataSet = dataSetBuilder.Create(vtkm::Id2(dimensions[0], dimensions[1]), vtkm::Vec(origin[0], origin[1]), vtkm::Vec(spacing[0], spacing[1])); diff --git a/vtkm/filter/VertexClustering.hxx b/vtkm/filter/VertexClustering.hxx index e8339a282..4751be138 100644 --- a/vtkm/filter/VertexClustering.hxx +++ b/vtkm/filter/VertexClustering.hxx @@ -25,14 +25,13 @@ namespace { template - void compute_bounds(const vtkm::cont::CoordinateSystem& coords, - vtkm::Float64 *bounds, - const vtkm::filter::PolicyBase&, - const DeviceAdapter& tag) + vtkm::Bounds compute_bounds(const vtkm::cont::CoordinateSystem& coords, + const vtkm::filter::PolicyBase&, + const DeviceAdapter& tag) { typedef typename DerivedPolicy::CoordinateTypeList TypeList; typedef typename DerivedPolicy::CoordinateStorageList StorageList; - coords.GetBounds(bounds, tag, TypeList(), StorageList()); + return coords.GetBounds(tag, TypeList(), StorageList()); } } @@ -57,8 +56,8 @@ vtkm::filter::ResultDataSet VertexClustering::DoExecute(const vtkm::cont::DataSe vtkm::worklet::VertexClustering clustering; //need to compute bounds first - vtkm::Float64 bounds[6]; - compute_bounds(input.GetCoordinateSystem(), bounds, policy, tag); + vtkm::Bounds bounds = + compute_bounds(input.GetCoordinateSystem(), policy, tag); vtkm::cont::DataSet outDataSet = clustering.Run(vtkm::filter::ApplyPolicyUnstructured(input.GetCellSet(), policy), vtkm::filter::ApplyPolicy(input.GetCoordinateSystem(), policy), diff --git a/vtkm/testing/Testing.h b/vtkm/testing/Testing.h index 415aa6071..8b78081af 100644 --- a/vtkm/testing/Testing.h +++ b/vtkm/testing/Testing.h @@ -20,9 +20,11 @@ #ifndef vtk_m_testing_Testing_h #define vtk_m_testing_Testing_h +#include #include #include #include +#include #include #include #include @@ -398,6 +400,29 @@ bool test_equal(const vtkm::Pair &pair1, } +/// Special implementation of test_equal for Ranges. +/// +VTKM_EXEC_CONT_EXPORT +bool test_equal(const vtkm::Range &range1, + const vtkm::Range &range2, + vtkm::Float64 tolerance = 0.0001) +{ + return (test_equal(range1.Min, range2.Min, tolerance) && + test_equal(range1.Max, range2.Max, tolerance)); +} + +/// Special implementation of test_equal for Bounds. +/// +VTKM_EXEC_CONT_EXPORT +bool test_equal(const vtkm::Bounds &bounds1, + const vtkm::Bounds &bounds2, + vtkm::Float64 tolerance = 0.0001) +{ + return (test_equal(bounds1.X, bounds2.X, tolerance) && + test_equal(bounds1.Y, bounds2.Y, tolerance) && + test_equal(bounds1.Z, bounds2.Z, tolerance)); +} + template VTKM_EXEC_CONT_EXPORT T TestValue(vtkm::Id index, T, vtkm::TypeTraitsIntegerTag) diff --git a/vtkm/testing/UnitTestBounds.cxx b/vtkm/testing/UnitTestBounds.cxx index 3be574ef5..2f6ce8b83 100644 --- a/vtkm/testing/UnitTestBounds.cxx +++ b/vtkm/testing/UnitTestBounds.cxx @@ -35,6 +35,7 @@ void TestBounds() std::cout << "Single value bounds." << std::endl; vtkm::Bounds singleValueBounds(1.0, 1.0, 2.0, 2.0, 3.0, 3.0); VTKM_TEST_ASSERT(singleValueBounds.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(singleValueBounds.Center(), Vec3(1,2,3)), "Bad center"); VTKM_TEST_ASSERT(singleValueBounds.Contains(Vec3(1,2,3)), "Contains fail"); VTKM_TEST_ASSERT(!singleValueBounds.Contains(Vec3(0,0,0)), "Contains fail"); VTKM_TEST_ASSERT(!singleValueBounds.Contains(Vec3(2,2,2)), "contains fail"); @@ -42,6 +43,7 @@ void TestBounds() vtkm::Bounds unionBounds = emptyBounds + singleValueBounds; VTKM_TEST_ASSERT(unionBounds.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionBounds.Center(), Vec3(1,2,3)), "Bad center"); VTKM_TEST_ASSERT(unionBounds.Contains(Vec3(1,2,3)), "Contains fail"); VTKM_TEST_ASSERT(!unionBounds.Contains(Vec3(0,0,0)), "Contains fail"); VTKM_TEST_ASSERT(!unionBounds.Contains(Vec3(2,2,2)), "contains fail"); @@ -51,6 +53,7 @@ void TestBounds() std::cout << "Low bounds." << std::endl; vtkm::Bounds lowBounds(Vec3(-10,-5,-1), Vec3(-5, -2, 0)); VTKM_TEST_ASSERT(lowBounds.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(lowBounds.Center(), Vec3(-7.5,-3.5,-0.5)), "Bad center"); VTKM_TEST_ASSERT(!lowBounds.Contains(Vec3(-20)), "Contains fail"); VTKM_TEST_ASSERT(!lowBounds.Contains(Vec3(-2)), "Contains fail"); VTKM_TEST_ASSERT(lowBounds.Contains(Vec3(-7,-2,-0.5)), "Contains fail"); diff --git a/vtkm/testing/UnitTestRange.cxx b/vtkm/testing/UnitTestRange.cxx index e3154edf0..c86a53181 100644 --- a/vtkm/testing/UnitTestRange.cxx +++ b/vtkm/testing/UnitTestRange.cxx @@ -29,25 +29,32 @@ void TestRange() std::cout << "Empty range." << std::endl; vtkm::Range emptyRange; VTKM_TEST_ASSERT(!emptyRange.IsNonEmpty(), "Non empty range not empty."); + VTKM_TEST_ASSERT(test_equal(emptyRange.Length(), 0.0), "Bad length."); std::cout << "Single value range." << std::endl; vtkm::Range singleValueRange(5.0, 5.0); VTKM_TEST_ASSERT(singleValueRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(singleValueRange.Length(), 0.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(singleValueRange.Center(), 5), "Bad center."); VTKM_TEST_ASSERT(singleValueRange.Contains(5.0), "Does not contain value"); VTKM_TEST_ASSERT(!singleValueRange.Contains(0.0), "Contains outside"); VTKM_TEST_ASSERT(!singleValueRange.Contains(10), "Contains outside"); vtkm::Range unionRange = emptyRange + singleValueRange; VTKM_TEST_ASSERT(unionRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionRange.Length(), 0.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(unionRange.Center(), 5), "Bad center."); VTKM_TEST_ASSERT(unionRange.Contains(5.0), "Does not contain value"); VTKM_TEST_ASSERT(!unionRange.Contains(0.0), "Contains outside"); VTKM_TEST_ASSERT(!unionRange.Contains(10), "Contains outside"); VTKM_TEST_ASSERT(singleValueRange == unionRange, "Union not equal"); - VTKM_TEST_ASSERT(!(singleValueRange == unionRange), "Union not equal"); + VTKM_TEST_ASSERT(!(singleValueRange != unionRange), "Union not equal"); std::cout << "Low range." << std::endl; vtkm::Range lowRange(-10.0, -5.0); VTKM_TEST_ASSERT(lowRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(lowRange.Length(), 5.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(lowRange.Center(), -7.5), "Bad center."); VTKM_TEST_ASSERT(!lowRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(lowRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(!lowRange.Contains(0), "Contains fail"); @@ -55,6 +62,8 @@ void TestRange() unionRange = singleValueRange + lowRange; VTKM_TEST_ASSERT(unionRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionRange.Length(), 15.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(unionRange.Center(), -2.5), "Bad center."); VTKM_TEST_ASSERT(!unionRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(unionRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(unionRange.Contains(0), "Contains fail"); @@ -63,6 +72,8 @@ void TestRange() std::cout << "High range." << std::endl; vtkm::Range highRange(15.0, 20.0); VTKM_TEST_ASSERT(highRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(highRange.Length(), 5.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(highRange.Center(), 17.5), "Bad center."); VTKM_TEST_ASSERT(!highRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(!highRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(!highRange.Contains(0), "Contains fail"); @@ -72,6 +83,8 @@ void TestRange() unionRange = highRange.Union(singleValueRange); VTKM_TEST_ASSERT(unionRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionRange.Length(), 15.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(unionRange.Center(), 12.5), "Bad center."); VTKM_TEST_ASSERT(!unionRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(!unionRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(!unionRange.Contains(0), "Contains fail"); @@ -81,6 +94,8 @@ void TestRange() unionRange.Include(-1); VTKM_TEST_ASSERT(unionRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionRange.Length(), 21.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(unionRange.Center(), 9.5), "Bad center."); VTKM_TEST_ASSERT(!unionRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(!unionRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(unionRange.Contains(0), "Contains fail"); @@ -90,6 +105,8 @@ void TestRange() unionRange.Include(lowRange); VTKM_TEST_ASSERT(unionRange.IsNonEmpty(), "Empty?"); + VTKM_TEST_ASSERT(test_equal(unionRange.Length(), 30.0), "Bad length."); + VTKM_TEST_ASSERT(test_equal(unionRange.Center(), 5), "Bad center."); VTKM_TEST_ASSERT(!unionRange.Contains(-20), "Contains fail"); VTKM_TEST_ASSERT(unionRange.Contains(-7), "Contains fail"); VTKM_TEST_ASSERT(unionRange.Contains(0), "Contains fail"); diff --git a/vtkm/worklet/VertexClustering.h b/vtkm/worklet/VertexClustering.h index a3bfd34b5..541036eb1 100644 --- a/vtkm/worklet/VertexClustering.h +++ b/vtkm/worklet/VertexClustering.h @@ -316,7 +316,7 @@ public: typename DeviceAdapter> vtkm::cont::DataSet Run(const DynamicCellSetType &cellSet, const DynamicCoordinateHandleType &coordinates, - vtkm::Float64 *bounds, + const vtkm::Bounds &bounds, const vtkm::Id3& nDivisions, DeviceAdapter) { @@ -325,24 +325,24 @@ public: /// determine grid resolution for clustering GridInfo gridInfo; { - vtkm::Float64 res[3]; - for (vtkm::IdComponent i=0; i<3; i++) - { - res[i] = (bounds[i*2+1]-bounds[i*2])/static_cast(nDivisions[i]); - } + vtkm::Vec res( + bounds.X.Length()/static_cast(nDivisions[0]), + bounds.Y.Length()/static_cast(nDivisions[1]), + bounds.Z.Length()/static_cast(nDivisions[2])); gridInfo.grid_width = vtkm::Max(res[0], vtkm::Max(res[1], res[2])); vtkm::Float64 inv_grid_width = gridInfo.inv_grid_width = vtkm::Float64(1) / gridInfo.grid_width; //printf("Bounds: %lf, %lf, %lf, %lf, %lf, %lf\n", bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); - gridInfo.dim[0] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[1]-bounds[0])*inv_grid_width), nDivisions[0]); - gridInfo.dim[1] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[3]-bounds[2])*inv_grid_width), nDivisions[1]); - gridInfo.dim[2] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[5]-bounds[4])*inv_grid_width), nDivisions[2]); + gridInfo.dim[0] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds.X.Length())*inv_grid_width), nDivisions[0]); + gridInfo.dim[1] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds.Y.Length())*inv_grid_width), nDivisions[1]); + gridInfo.dim[2] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds.Z.Length())*inv_grid_width), nDivisions[2]); // center the mesh in the grids - gridInfo.origin[0] = (bounds[1]+bounds[0])*0.5 - gridInfo.grid_width*static_cast(gridInfo.dim[0])*.5; - gridInfo.origin[1] = (bounds[3]+bounds[2])*0.5 - gridInfo.grid_width*static_cast(gridInfo.dim[1])*.5; - gridInfo.origin[2] = (bounds[5]+bounds[4])*0.5 - gridInfo.grid_width*static_cast(gridInfo.dim[2])*.5; + vtkm::Vec center = bounds.Center(); + gridInfo.origin[0] = center[0] - gridInfo.grid_width*static_cast(gridInfo.dim[0])*.5; + gridInfo.origin[1] = center[1] - gridInfo.grid_width*static_cast(gridInfo.dim[1])*.5; + gridInfo.origin[2] = center[2] - gridInfo.grid_width*static_cast(gridInfo.dim[2])*.5; } //construct the scheduler that will execute all the worklets diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx index 8ce989f04..1456d90d6 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx @@ -194,10 +194,8 @@ void TestExplicitGrid2D() std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl; std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl; - vtkm::cont::ArrayHandle bounds = coordinates.GetBounds(DeviceAdapter()); - std::cout << "Bounds (" - << bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") (" - << bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ")" << std::endl; + vtkm::Bounds bounds = coordinates.GetBounds(DeviceAdapter()); + std::cout << "Bounds " << bounds << std::endl; VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), 14), "Wrong result for Triangulate filter"); } @@ -234,11 +232,8 @@ void TestExplicitGrid3D() std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl; std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl; - vtkm::cont::ArrayHandle bounds = coordinates.GetBounds(DeviceAdapter()); - std::cout << "Bounds (" - << bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") (" - << bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ") (" - << bounds.GetPortalControl().Get(4) << "," << bounds.GetPortalControl().Get(5) << ")" << std::endl; + vtkm::Bounds bounds = coordinates.GetBounds(DeviceAdapter()); + std::cout << "Bounds " << bounds << std::endl; VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), 11), "Wrong result for Tetrahedralize filter"); } diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx index b618a305e..b6f1f64e5 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx @@ -121,11 +121,8 @@ void TestUniformGrid2D() std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl; std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl; - vtkm::cont::ArrayHandle bounds = coordinates.GetBounds(DeviceAdapter()); - std::cout << "Bounds (" - << bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") (" - << bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ") (" - << bounds.GetPortalControl().Get(4) << "," << bounds.GetPortalControl().Get(5) << ")" << std::endl; + vtkm::Bounds bounds = coordinates.GetBounds(DeviceAdapter()); + std::cout << "Bounds " << bounds << std::endl; // Two triangles are created for every quad cell VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), numberOfCells * 2), @@ -172,11 +169,8 @@ void TestUniformGrid3D() std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl; std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl; - vtkm::cont::ArrayHandle bounds = coordinates.GetBounds(DeviceAdapter()); - std::cout << "Bounds (" - << bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") (" - << bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ") (" - << bounds.GetPortalControl().Get(4) << "," << bounds.GetPortalControl().Get(5) << ")" << std::endl; + vtkm::Bounds bounds = coordinates.GetBounds(DeviceAdapter()); + std::cout << "Bounds " << bounds << std::endl; // Five tets are created for every hex cell VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), numberOfCells * 5), diff --git a/vtkm/worklet/testing/UnitTestVertexClustering.cxx b/vtkm/worklet/testing/UnitTestVertexClustering.cxx index 4503ebc4b..9b5c477d4 100644 --- a/vtkm/worklet/testing/UnitTestVertexClustering.cxx +++ b/vtkm/worklet/testing/UnitTestVertexClustering.cxx @@ -36,8 +36,8 @@ void TestVertexClustering() vtkm::cont::DataSet dataSet = maker.Make3DExplicitDataSetCowNose(); //compute the bounds before calling the algorithm - vtkm::Float64 bounds[6]; - dataSet.GetCoordinateSystem().GetBounds(bounds, VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); + vtkm::Bounds bounds = + dataSet.GetCoordinateSystem().GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); // run vtkm::worklet::VertexClustering clustering;