Commit b5415169 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Change Field and related methods to use Range and Bounds

First, be more explicit when we mean a range of values in a field or a
spacial bounds. Use the Range and Bounds structs in Field and
CoordinateSystem to make all of this more clear (and reduce a bit of
code as well).
parent d75857d0
......@@ -50,11 +50,16 @@ struct Bounds
const vtkm::Range &zRange)
: X(xRange), Y(yRange), Z(zRange) { }
template<typename T>
template<typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
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<vtkm::Float64,3> Center() const
{
return vtkm::Vec<vtkm::Float64,3>(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
......@@ -87,6 +87,42 @@ struct Range
(this->Max >= static_cast<vtkm::Float64>(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
......@@ -20,6 +20,8 @@
#ifndef vtk_m_cont_CoordinateSystem_h
#define vtk_m_cont_CoordinateSystem_h
#include <vtkm/Bounds.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/ArrayHandleCompositeVector.h>
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
......@@ -136,10 +138,10 @@ public:
template<typename DeviceAdapterTag>
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<typename DeviceAdapterTag, typename TypeList>
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<typename DeviceAdapterTag, typename TypeList, typename StorageList>
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<typename DeviceAdapterTag>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag) const
const vtkm::cont::ArrayHandle<vtkm::Range>& 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<typename DeviceAdapterTag, typename TypeList>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
const vtkm::cont::ArrayHandle<vtkm::Range>& 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<typename DeviceAdapterTag, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag,
TypeList,
StorageList) const
{
return this->Superclass::GetBounds(
return this->Superclass::GetRange(
DeviceAdapterTag(),
TypeList(),
StorageList());
}
template<typename DeviceAdapterTag>
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<typename DeviceAdapterTag, typename TypeList>
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<typename DeviceAdapterTag, typename TypeList, typename StorageList>
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<vtkm::Range> ranges =
this->GetRange(DeviceAdapterTag(), TypeList(), StorageList());
VTKM_ASSERT(ranges.GetNumberOfValues() == 3);
vtkm::cont::ArrayHandle<vtkm::Range>::PortalConstControl rangePortal =
ranges.GetPortalConstControl();
return vtkm::Bounds(rangePortal.Get(0),
rangePortal.Get(1),
rangePortal.Get(2));
}
VTKM_CONT_EXPORT
......
......@@ -20,8 +20,9 @@
#ifndef vtk_m_cont_Field_h
#define vtk_m_cont_Field_h
#include <vtkm/Types.h>
#include <vtkm/Math.h>
#include <vtkm/Range.h>
#include <vtkm/Types.h>
#include <vtkm/VecTraits.h>
#include <vtkm/cont/ArrayHandle.h>
......@@ -37,13 +38,13 @@ namespace cont {
namespace internal {
struct BoundsMin
struct RangeMin
{
template<typename T>
T operator()(const T& a, const T& b)const { return vtkm::Min(a,b); }
};
struct BoundsMax
struct RangeMax
{
template<typename T>
T operator()(const T& a, const T& b)const { return vtkm::Max(a,b); }
......@@ -51,10 +52,10 @@ struct BoundsMax
template<typename DeviceAdapterTag>
class ComputeBounds
class ComputeRange
{
public:
ComputeBounds(ArrayHandle<vtkm::Float64>& bounds) : Bounds(&bounds) {}
ComputeRange(ArrayHandle<vtkm::Range>& range) : Range(&range) {}
template<typename ArrayHandleType>
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<vtkm::Float64>(VecType::GetComponent(minResult, i) ) );
this->Bounds->GetPortalControl().Set(i * 2 + 1,
static_cast<vtkm::Float64>(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<vtkm::FloatDefault,3> maximum =
portal.Get(portal.GetNumberOfValues()-1);
this->Bounds->Allocate(6);
vtkm::cont::ArrayHandle<vtkm::Float64>::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<vtkm::Range>::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<vtkm::Float64> *Bounds;
vtkm::cont::ArrayHandle<vtkm::Range> *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,66 +372,72 @@ public:
template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag,
TypeList,
StorageList) const
{
if (this->ModifiedFlag)
{
internal::ComputeBounds<DeviceAdapterTag> computeBounds(this->Bounds);
this->Data.ResetTypeAndStorageLists(TypeList(),StorageList()).CastAndCall(computeBounds);
internal::ComputeRange<DeviceAdapterTag> computeRange(this->Range);
this->Data.ResetTypeAndStorageLists(TypeList(),StorageList()).CastAndCall(computeRange);
this->ModifiedFlag = false;
}
return this->Bounds;
return this->Range;
}
template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
void GetBounds(vtkm::Float64 *bounds,
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<typename DeviceAdapterTag, typename TypeList>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag,
TypeList) const
{
return this->GetBounds(DeviceAdapterTag(), TypeList(),
return this->GetRange(DeviceAdapterTag(),
TypeList(),
VTKM_DEFAULT_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag, typename TypeList>
VTKM_CONT_EXPORT
void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList) const
void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList) const
{
this->GetBounds(bounds, DeviceAdapterTag(), TypeList(),
this->GetRange(range,
DeviceAdapterTag(),
TypeList(),
VTKM_DEFAULT_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag) const
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag) const
{
return this->GetBounds(DeviceAdapterTag(), VTKM_DEFAULT_TYPE_LIST_TAG(),
return this->GetRange(DeviceAdapterTag(),
VTKM_DEFAULT_TYPE_LIST_TAG(),
VTKM_DEFAULT_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag>
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(),
this->GetRange(range,
DeviceAdapterTag(),
VTKM_DEFAULT_TYPE_LIST_TAG(),
VTKM_DEFAULT_STORAGE_LIST_TAG());
}
......@@ -509,7 +512,7 @@ private:
vtkm::IdComponent AssocLogicalDim; ///< only populate if assoc is logical dim
vtkm::cont::DynamicArrayHandle Data;
mutable vtkm::cont::ArrayHandle<vtkm::Float64> Bounds;
mutable vtkm::cont::ArrayHandle<vtkm::Range> Range;
mutable bool ModifiedFlag;
};
......
......@@ -19,7 +19,7 @@
##============================================================================
set(unit_tests
UnitTestComputeBoundsCuda.cu
UnitTestComputeRangeCuda.cu
UnitTestCudaArrayHandle.cu
UnitTestCudaArrayHandleFancy.cu
UnitTestCudaDataSetExplicit.cu
......
......@@ -22,11 +22,11 @@
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/cuda/internal/testing/Testing.h>
#include <vtkm/cont/testing/TestingComputeBounds.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestComputeBoundsCuda(int, char *[])
int UnitTestComputeRangeCuda(int, char *[])
{
int result = vtkm::cont::testing::TestingComputeBounds
int result = vtkm::cont::testing::TestingComputeRange
<vtkm::cont::DeviceAdapterTagCuda>::Run();
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
}
......@@ -19,7 +19,7 @@
##============================================================================
set(unit_tests
UnitTestComputeBoundsTBB.cxx
UnitTestComputeRangeTBB.cxx
UnitTestDataSetExplicitTBB.cxx
UnitTestDataSetSingleTypeTBB.cxx
UnitTestDeviceAdapterTBB.cxx
......
......@@ -20,10 +20,10 @@
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/cont/testing/TestingComputeBounds.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestComputeBoundsTBB(int, char *[])
int UnitTestComputeRangeTBB(int, char *[])
{
return vtkm::cont::testing::TestingComputeBounds
return vtkm::cont::testing::TestingComputeRange
<vtkm::cont::DeviceAdapterTagTBB>::Run();
}
......@@ -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
......
......@@ -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