2018-06-05 03:04:38 +00:00
|
|
|
//============================================================================
|
2018-06-24 01:33:50 +00:00
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-06-24 01:33:50 +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-07-12 21:34:29 +00:00
|
|
|
#ifndef vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h
|
|
|
|
#define vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h
|
2018-06-05 03:04:38 +00:00
|
|
|
|
2018-06-25 00:16:46 +00:00
|
|
|
#include <vtkm/TopologyElementTag.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/VecFromPortalPermute.h>
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2018-06-25 00:16:46 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/exec/CellInside.h>
|
2018-06-25 00:16:46 +00:00
|
|
|
#include <vtkm/exec/CellLocator.h>
|
2018-06-05 03:04:38 +00:00
|
|
|
#include <vtkm/exec/ParametricCoordinates.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2018-07-12 21:34:29 +00:00
|
|
|
|
|
|
|
struct CellLocatorBoundingIntervalHierarchyNode
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2018-07-12 21:34:29 +00:00
|
|
|
vtkm::IdComponent Dimension;
|
|
|
|
vtkm::Id ParentIndex;
|
|
|
|
vtkm::Id ChildIndex;
|
|
|
|
union {
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
vtkm::FloatDefault LMax;
|
|
|
|
vtkm::FloatDefault RMin;
|
|
|
|
} Node;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
vtkm::Id Start;
|
|
|
|
vtkm::Id Size;
|
|
|
|
} Leaf;
|
|
|
|
};
|
2018-06-05 03:04:38 +00:00
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
VTKM_EXEC_CONT
|
|
|
|
CellLocatorBoundingIntervalHierarchyNode()
|
|
|
|
: Dimension()
|
|
|
|
, ParentIndex()
|
|
|
|
, ChildIndex()
|
|
|
|
, Node{ 0, 0 }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}; // struct CellLocatorBoundingIntervalHierarchyNode
|
2018-06-05 03:04:38 +00:00
|
|
|
|
2018-06-13 22:08:15 +00:00
|
|
|
template <typename DeviceAdapter, typename CellSetType>
|
2019-06-17 12:44:33 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT CellLocatorBoundingIntervalHierarchyExec final
|
|
|
|
: public vtkm::exec::CellLocator
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2018-07-12 21:34:29 +00:00
|
|
|
using NodeArrayHandle =
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>;
|
|
|
|
using CellIdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
|
|
|
|
|
2018-06-05 03:04:38 +00:00
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2018-07-12 21:34:29 +00:00
|
|
|
CellLocatorBoundingIntervalHierarchyExec() {}
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
VTKM_CONT
|
2018-07-12 21:34:29 +00:00
|
|
|
CellLocatorBoundingIntervalHierarchyExec(const NodeArrayHandle& nodes,
|
|
|
|
const CellIdArrayHandle& cellIds,
|
|
|
|
const CellSetType& cellSet,
|
|
|
|
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
|
|
|
|
DeviceAdapter)
|
2018-06-05 03:04:38 +00:00
|
|
|
: Nodes(nodes.PrepareForInput(DeviceAdapter()))
|
|
|
|
, CellIds(cellIds.PrepareForInput(DeviceAdapter()))
|
2019-07-30 16:53:51 +00:00
|
|
|
, CellSet(cellSet.PrepareForInput(DeviceAdapter(), VisitType(), IncidentType()))
|
2018-07-12 21:34:29 +00:00
|
|
|
, Coords(coords.PrepareForInput(DeviceAdapter()))
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:10:21 +00:00
|
|
|
|
|
|
|
VTKM_EXEC_CONT virtual ~CellLocatorBoundingIntervalHierarchyExec() noexcept
|
|
|
|
{
|
|
|
|
// This must not be defaulted, since defaulted virtual destructors are
|
|
|
|
// troublesome with CUDA __host__ __device__ markup.
|
|
|
|
}
|
|
|
|
|
2018-06-13 22:08:15 +00:00
|
|
|
VTKM_EXEC
|
2019-07-31 16:20:38 +00:00
|
|
|
void FindCell(const vtkm::Vec3f& point,
|
2018-06-13 22:08:15 +00:00
|
|
|
vtkm::Id& cellId,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f& parametric,
|
2018-06-13 22:08:15 +00:00
|
|
|
const vtkm::exec::FunctorBase& worklet) const override
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2018-07-12 21:04:50 +00:00
|
|
|
cellId = -1;
|
|
|
|
vtkm::Id nodeIndex = 0;
|
|
|
|
FindCellState state = FindCellState::EnterNode;
|
|
|
|
|
|
|
|
while ((cellId < 0) && !((nodeIndex == 0) && (state == FindCellState::AscendFromNode)))
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case FindCellState::EnterNode:
|
|
|
|
this->EnterNode(state, point, cellId, nodeIndex, parametric, worklet);
|
|
|
|
break;
|
|
|
|
case FindCellState::AscendFromNode:
|
|
|
|
this->AscendFromNode(state, nodeIndex);
|
|
|
|
break;
|
|
|
|
case FindCellState::DescendLeftChild:
|
|
|
|
this->DescendLeftChild(state, point, nodeIndex);
|
|
|
|
break;
|
|
|
|
case FindCellState::DescendRightChild:
|
|
|
|
this->DescendRightChild(state, point, nodeIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-07-12 21:04:50 +00:00
|
|
|
enum struct FindCellState
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2018-07-12 21:04:50 +00:00
|
|
|
EnterNode,
|
|
|
|
AscendFromNode,
|
|
|
|
DescendLeftChild,
|
|
|
|
DescendRightChild
|
|
|
|
};
|
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
void EnterNode(FindCellState& state,
|
2019-07-31 16:20:38 +00:00
|
|
|
const vtkm::Vec3f& point,
|
2018-07-12 21:04:50 +00:00
|
|
|
vtkm::Id& cellId,
|
|
|
|
vtkm::Id nodeIndex,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f& parametric,
|
2018-07-12 21:04:50 +00:00
|
|
|
const vtkm::exec::FunctorBase& worklet) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(state == FindCellState::EnterNode);
|
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
|
2018-07-12 21:04:50 +00:00
|
|
|
|
2018-06-05 03:04:38 +00:00
|
|
|
if (node.ChildIndex < 0)
|
|
|
|
{
|
2018-07-12 21:04:50 +00:00
|
|
|
// In a leaf node. Look for a containing cell.
|
|
|
|
cellId = this->FindInLeaf(point, parametric, node, worklet);
|
|
|
|
state = FindCellState::AscendFromNode;
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-12 21:04:50 +00:00
|
|
|
state = FindCellState::DescendLeftChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
void AscendFromNode(FindCellState& state, vtkm::Id& nodeIndex) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(state == FindCellState::AscendFromNode);
|
|
|
|
|
|
|
|
vtkm::Id childNodeIndex = nodeIndex;
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& childNode =
|
|
|
|
this->Nodes.Get(childNodeIndex);
|
2018-07-12 21:04:50 +00:00
|
|
|
nodeIndex = childNode.ParentIndex;
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& parentNode =
|
|
|
|
this->Nodes.Get(nodeIndex);
|
2018-07-12 21:04:50 +00:00
|
|
|
|
|
|
|
if (parentNode.ChildIndex == childNodeIndex)
|
|
|
|
{
|
|
|
|
// Ascending from left child. Descend into the right child.
|
|
|
|
state = FindCellState::DescendRightChild;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(parentNode.ChildIndex + 1 == childNodeIndex);
|
|
|
|
// Ascending from right child. Ascend again. (Don't need to change state.)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2019-07-31 16:20:38 +00:00
|
|
|
void DescendLeftChild(FindCellState& state, const vtkm::Vec3f& point, vtkm::Id& nodeIndex) const
|
2018-07-12 21:04:50 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT(state == FindCellState::DescendLeftChild);
|
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
|
2018-07-12 21:04:50 +00:00
|
|
|
const vtkm::FloatDefault& coordinate = point[node.Dimension];
|
|
|
|
if (coordinate <= node.Node.LMax)
|
|
|
|
{
|
|
|
|
// Left child does contain the point. Do the actual descent.
|
|
|
|
nodeIndex = node.ChildIndex;
|
|
|
|
state = FindCellState::EnterNode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Left child does not contain the point. Skip to the right child.
|
|
|
|
state = FindCellState::DescendRightChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2019-07-31 16:20:38 +00:00
|
|
|
void DescendRightChild(FindCellState& state, const vtkm::Vec3f& point, vtkm::Id& nodeIndex) const
|
2018-07-12 21:04:50 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT(state == FindCellState::DescendRightChild);
|
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex);
|
2018-07-12 21:04:50 +00:00
|
|
|
const vtkm::FloatDefault& coordinate = point[node.Dimension];
|
|
|
|
if (coordinate >= node.Node.RMin)
|
|
|
|
{
|
|
|
|
// Right child does contain the point. Do the actual descent.
|
|
|
|
nodeIndex = node.ChildIndex + 1;
|
|
|
|
state = FindCellState::EnterNode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Right child does not contain the point. Skip to ascent
|
|
|
|
state = FindCellState::AscendFromNode;
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
VTKM_EXEC vtkm::Id FindInLeaf(const vtkm::Vec3f& point,
|
|
|
|
vtkm::Vec3f& parametric,
|
2018-07-12 21:34:29 +00:00
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node,
|
2018-06-05 03:04:38 +00:00
|
|
|
const vtkm::exec::FunctorBase& worklet) const
|
|
|
|
{
|
2018-06-13 22:08:15 +00:00
|
|
|
using IndicesType = typename CellSetPortal::IndicesType;
|
2018-06-05 03:04:38 +00:00
|
|
|
for (vtkm::Id i = node.Leaf.Start; i < node.Leaf.Start + node.Leaf.Size; ++i)
|
|
|
|
{
|
2018-07-12 21:34:29 +00:00
|
|
|
vtkm::Id cellId = this->CellIds.Get(i);
|
|
|
|
IndicesType cellPointIndices = this->CellSet.GetIndices(cellId);
|
|
|
|
vtkm::VecFromPortalPermute<IndicesType, CoordsPortal> cellPoints(&cellPointIndices,
|
|
|
|
this->Coords);
|
|
|
|
if (IsPointInCell(point, parametric, this->CellSet.GetCellShape(cellId), cellPoints, worklet))
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
|
|
|
return cellId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CoordsType, typename CellShapeTag>
|
2019-07-31 16:20:38 +00:00
|
|
|
VTKM_EXEC static bool IsPointInCell(const vtkm::Vec3f& point,
|
|
|
|
vtkm::Vec3f& parametric,
|
2018-06-05 03:04:38 +00:00
|
|
|
CellShapeTag cellShape,
|
|
|
|
const CoordsType& cellPoints,
|
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
|
|
|
{
|
|
|
|
bool success = false;
|
2018-06-13 22:08:15 +00:00
|
|
|
parametric = vtkm::exec::WorldCoordinatesToParametricCoordinates(
|
|
|
|
cellPoints, point, cellShape, success, worklet);
|
|
|
|
return success && vtkm::exec::CellInside(parametric, cellShape);
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
using VisitType = vtkm::TopologyElementTagCell;
|
|
|
|
using IncidentType = vtkm::TopologyElementTagPoint;
|
2018-06-05 03:04:38 +00:00
|
|
|
using NodePortal = typename NodeArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
|
|
|
using CellIdPortal =
|
|
|
|
typename CellIdArrayHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
2019-07-30 16:53:51 +00:00
|
|
|
using CellSetPortal = typename CellSetType::template ExecutionTypes<DeviceAdapter,
|
|
|
|
VisitType,
|
|
|
|
IncidentType>::ExecObjectType;
|
2018-06-13 22:08:15 +00:00
|
|
|
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
|
|
|
|
DeviceAdapter>::PortalConst;
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
NodePortal Nodes;
|
|
|
|
CellIdPortal CellIds;
|
2018-06-13 22:08:15 +00:00
|
|
|
CellSetPortal CellSet;
|
|
|
|
CoordsPortal Coords;
|
2018-07-12 21:34:29 +00:00
|
|
|
}; // class CellLocatorBoundingIntervalHierarchyExec
|
2018-06-05 03:04:38 +00:00
|
|
|
|
|
|
|
} // namespace exec
|
|
|
|
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
#endif //vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h
|