From 4e7b59c65e46ab7cc032dcf71f3d9d9754f5bcad Mon Sep 17 00:00:00 2001 From: Abhishek Yenpure Date: Tue, 6 Aug 2019 10:52:10 -0600 Subject: [PATCH] Adding changes for 2D uniform cell locator --- vtkm/cont/CellLocatorUniformGrid.cxx | 81 ++++++++++++++++++-------- vtkm/cont/CellLocatorUniformGrid.h | 1 + vtkm/exec/CellLocatorRectilinearGrid.h | 2 +- vtkm/exec/CellLocatorUniformGrid.h | 18 +++--- 4 files changed, 69 insertions(+), 33 deletions(-) diff --git a/vtkm/cont/CellLocatorUniformGrid.cxx b/vtkm/cont/CellLocatorUniformGrid.cxx index eebaea902..180f2c741 100644 --- a/vtkm/cont/CellLocatorUniformGrid.cxx +++ b/vtkm/cont/CellLocatorUniformGrid.cxx @@ -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()) - 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().GetSchedulingRange(vtkm::TopologyElementTagCell()); - - this->RangeTransform[0] = static_cast(this->CellDims[0]) / - static_cast(this->Bounds.X.Length()); - this->RangeTransform[1] = static_cast(this->CellDims[1]) / - static_cast(this->Bounds.Y.Length()); - this->RangeTransform[2] = static_cast(this->CellDims[2]) / - static_cast(this->Bounds.Z.Length()); + if (cellSet.IsSameType(Structured2DType())) + { + this->Is3D = false; + this->Bounds = coords.GetBounds(); + vtkm::Id2 cellDims = + cellSet.Cast().GetSchedulingRange(vtkm::TopologyElementTagCell()); + this->CellDims = vtkm::Id3(cellDims[0], cellDims[1], 0); + this->RangeTransform[0] = static_cast(this->CellDims[0]) / + static_cast(this->Bounds.X.Length()); + this->RangeTransform[1] = static_cast(this->CellDims[1]) / + static_cast(this->Bounds.Y.Length()); + } + else if (cellSet.IsSameType(Structured2DType())) + { + this->Is3D = true; + this->Bounds = coords.GetBounds(); + this->CellDims = + cellSet.Cast().GetSchedulingRange(vtkm::TopologyElementTagCell()); + this->RangeTransform[0] = static_cast(this->CellDims[0]) / + static_cast(this->Bounds.X.Length()); + this->RangeTransform[1] = static_cast(this->CellDims[1]) / + static_cast(this->Bounds.Y.Length()); + this->RangeTransform[2] = static_cast(this->CellDims[2]) / + static_cast(this->Bounds.Z.Length()); + } + else + { + throw vtkm::cont::ErrorInternal("Cells are not structured."); + } } namespace { +template struct CellLocatorUniformGridPrepareForExecutionFunctor { template @@ -57,7 +76,7 @@ struct CellLocatorUniformGridPrepareForExecutionFunctor vtkm::cont::VirtualObjectHandle& execLocator, Args&&... args) const { - using ExecutionType = vtkm::exec::CellLocatorUniformGrid; + using ExecutionType = vtkm::exec::CellLocatorUniformGrid; ExecutionType* execObject = new ExecutionType(std::forward(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(), - 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(), + this->GetCoordinates().GetData()); + } + else + { + success = vtkm::cont::TryExecuteOnDevice(device, + CellLocatorUniformGridPrepareForExecutionFunctor<2>(), + this->ExecutionObjectHandle, + this->Bounds, + this->RangeTransform, + this->CellDims, + this->GetCellSet().template Cast(), + this->GetCoordinates().GetData()); + } if (!success) { throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", device); diff --git a/vtkm/cont/CellLocatorUniformGrid.h b/vtkm/cont/CellLocatorUniformGrid.h index 698f61f57..f24a3360b 100644 --- a/vtkm/cont/CellLocatorUniformGrid.h +++ b/vtkm/cont/CellLocatorUniformGrid.h @@ -35,6 +35,7 @@ private: vtkm::Bounds Bounds; vtkm::Vec3f RangeTransform; vtkm::Id3 CellDims; + bool Is3D = true; mutable vtkm::cont::VirtualObjectHandle ExecutionObjectHandle; }; diff --git a/vtkm/exec/CellLocatorRectilinearGrid.h b/vtkm/exec/CellLocatorRectilinearGrid.h index ccbeba8e6..3e5036122 100644 --- a/vtkm/exec/CellLocatorRectilinearGrid.h +++ b/vtkm/exec/CellLocatorRectilinearGrid.h @@ -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 diff --git a/vtkm/exec/CellLocatorUniformGrid.h b/vtkm/exec/CellLocatorUniformGrid.h index 5fda04d39..6a2e95a83 100644 --- a/vtkm/exec/CellLocatorUniformGrid.h +++ b/vtkm/exec/CellLocatorUniformGrid.h @@ -27,7 +27,7 @@ namespace vtkm namespace exec { -template +template 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; + 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& 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::Floor((point[0] - Bounds.X.Min) * RangeTransform[0])); logicalCell[1] = (point[1] == Bounds.Y.Max) ? CellDims[1] - 1 : static_cast(vtkm::Floor((point[1] - Bounds.Y.Min) * RangeTransform[1])); - logicalCell[2] = (point[2] == Bounds.Z.Max) - ? CellDims[2] - 1 - : static_cast(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::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];