Adding changes for 2D uniform cell locator

This commit is contained in:
Abhishek Yenpure 2019-08-06 10:52:10 -06:00
parent f30a7ac94c
commit 4e7b59c65e
4 changed files with 69 additions and 33 deletions

@ -24,7 +24,8 @@ CellLocatorUniformGrid::CellLocatorUniformGrid() = default;
CellLocatorUniformGrid::~CellLocatorUniformGrid() = default;
using UniformType = vtkm::cont::ArrayHandleUniformPointCoordinates;
using StructuredType = vtkm::cont::CellSetStructured<3>;
using Structured2DType = vtkm::cont::CellSetStructured<2>;
using Structured3DType = vtkm::cont::CellSetStructured<3>;
void CellLocatorUniformGrid::Build()
{
@ -32,24 +33,42 @@ void CellLocatorUniformGrid::Build()
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
if (!coords.GetData().IsType<UniformType>())
throw vtkm::cont::ErrorBadType("Coordinate system is not uniform type");
if (!cellSet.IsSameType(StructuredType()))
throw vtkm::cont::ErrorBadType("Cell set is not 3D structured type");
throw vtkm::cont::ErrorInternal("Coordinates are not uniform.");
this->Bounds = coords.GetBounds();
this->CellDims =
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
this->RangeTransform[0] = static_cast<vtkm::FloatDefault>(this->CellDims[0]) /
static_cast<vtkm::FloatDefault>(this->Bounds.X.Length());
this->RangeTransform[1] = static_cast<vtkm::FloatDefault>(this->CellDims[1]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Y.Length());
this->RangeTransform[2] = static_cast<vtkm::FloatDefault>(this->CellDims[2]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Z.Length());
if (cellSet.IsSameType(Structured2DType()))
{
this->Is3D = false;
this->Bounds = coords.GetBounds();
vtkm::Id2 cellDims =
cellSet.Cast<Structured2DType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
this->CellDims = vtkm::Id3(cellDims[0], cellDims[1], 0);
this->RangeTransform[0] = static_cast<vtkm::FloatDefault>(this->CellDims[0]) /
static_cast<vtkm::FloatDefault>(this->Bounds.X.Length());
this->RangeTransform[1] = static_cast<vtkm::FloatDefault>(this->CellDims[1]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Y.Length());
}
else if (cellSet.IsSameType(Structured2DType()))
{
this->Is3D = true;
this->Bounds = coords.GetBounds();
this->CellDims =
cellSet.Cast<Structured3DType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
this->RangeTransform[0] = static_cast<vtkm::FloatDefault>(this->CellDims[0]) /
static_cast<vtkm::FloatDefault>(this->Bounds.X.Length());
this->RangeTransform[1] = static_cast<vtkm::FloatDefault>(this->CellDims[1]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Y.Length());
this->RangeTransform[2] = static_cast<vtkm::FloatDefault>(this->CellDims[2]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Z.Length());
}
else
{
throw vtkm::cont::ErrorInternal("Cells are not structured.");
}
}
namespace
{
template <vtkm::IdComponent dimensions>
struct CellLocatorUniformGridPrepareForExecutionFunctor
{
template <typename DeviceAdapter, typename... Args>
@ -57,7 +76,7 @@ struct CellLocatorUniformGridPrepareForExecutionFunctor
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& execLocator,
Args&&... args) const
{
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>;
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter, dimensions>;
ExecutionType* execObject = new ExecutionType(std::forward<Args>(args)..., DeviceAdapter());
execLocator.Reset(execObject);
return true;
@ -68,15 +87,29 @@ struct CellLocatorUniformGridPrepareForExecutionFunctor
const vtkm::exec::CellLocator* CellLocatorUniformGrid::PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const
{
const bool success =
vtkm::cont::TryExecuteOnDevice(device,
CellLocatorUniformGridPrepareForExecutionFunctor(),
this->ExecutionObjectHandle,
this->Bounds,
this->RangeTransform,
this->CellDims,
this->GetCellSet().template Cast<StructuredType>(),
this->GetCoordinates().GetData());
bool success = true;
if (this->Is3D)
{
success = vtkm::cont::TryExecuteOnDevice(device,
CellLocatorUniformGridPrepareForExecutionFunctor<3>(),
this->ExecutionObjectHandle,
this->Bounds,
this->RangeTransform,
this->CellDims,
this->GetCellSet().template Cast<Structured3DType>(),
this->GetCoordinates().GetData());
}
else
{
success = vtkm::cont::TryExecuteOnDevice(device,
CellLocatorUniformGridPrepareForExecutionFunctor<2>(),
this->ExecutionObjectHandle,
this->Bounds,
this->RangeTransform,
this->CellDims,
this->GetCellSet().template Cast<Structured2DType>(),
this->GetCoordinates().GetData());
}
if (!success)
{
throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", device);

@ -35,6 +35,7 @@ private:
vtkm::Bounds Bounds;
vtkm::Vec3f RangeTransform;
vtkm::Id3 CellDims;
bool Is3D = true;
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
};

@ -111,7 +111,7 @@ public:
// Get the Cell Id from the point.
vtkm::Id3 logicalCell(0, 0, 0);
for (vtkm::Int32 dim = 0; dim < 3; ++dim)
for (vtkm::Int32 dim = 0; dim < dimensions; ++dim)
{
//
// When searching for points, we consider the max value of the cell

@ -27,7 +27,7 @@ namespace vtkm
namespace exec
{
template <typename DeviceAdapter>
template <typename DeviceAdapter, vtkm::IdComponent dimensions>
class VTKM_ALWAYS_EXPORT CellLocatorUniformGrid final : public vtkm::exec::CellLocator
{
private:
@ -35,7 +35,7 @@ private:
using ToType = vtkm::TopologyElementTagCell;
using CellSetPortal = vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
3>;
dimensions>;
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
DeviceAdapter>::PortalConst;
@ -44,7 +44,7 @@ public:
CellLocatorUniformGrid(const vtkm::Bounds& bounds,
const vtkm::Vec3f rangeTransform,
const vtkm::Id3 cellDims,
const vtkm::cont::CellSetStructured<3>& cellSet,
const vtkm::cont::CellSetStructured<dimensions>& cellSet,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
DeviceAdapter)
: Bounds(bounds)
@ -75,17 +75,19 @@ public:
return;
}
// Get the Cell Id from the point.
vtkm::Id3 logicalCell;
vtkm::Id3 logicalCell(0, 0, 0);
logicalCell[0] = (point[0] == Bounds.X.Max)
? CellDims[0] - 1
: static_cast<vtkm::Id>(vtkm::Floor((point[0] - Bounds.X.Min) * RangeTransform[0]));
logicalCell[1] = (point[1] == Bounds.Y.Max)
? CellDims[1] - 1
: static_cast<vtkm::Id>(vtkm::Floor((point[1] - Bounds.Y.Min) * RangeTransform[1]));
logicalCell[2] = (point[2] == Bounds.Z.Max)
? CellDims[2] - 1
: static_cast<vtkm::Id>(vtkm::Floor((point[2] - Bounds.Z.Min) * RangeTransform[2]));
if (dimensions == 3)
{
logicalCell[2] = (point[2] == Bounds.Z.Max)
? CellDims[2] - 1
: static_cast<vtkm::Id>(vtkm::Floor((point[2] - Bounds.Z.Min) * RangeTransform[2]));
}
// Get the actual cellId, from the logical cell index of the cell
cellId = logicalCell[2] * PlaneSize + logicalCell[1] * RowSize + logicalCell[0];