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>
|
2020-06-30 21:10:48 +00:00
|
|
|
#include <vtkm/cont/CoordinateSystem.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
|
|
|
|
2020-01-13 21:03:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-12 21:34:29 +00:00
|
|
|
struct CellLocatorBoundingIntervalHierarchyNode
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2020-01-13 21:03:03 +00:00
|
|
|
#if defined(VTKM_CLANG)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wnested-anon-types"
|
|
|
|
#endif // gcc || clang
|
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;
|
|
|
|
};
|
2020-01-13 21:03:03 +00:00
|
|
|
#if defined(VTKM_CLANG)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif // gcc || clang
|
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
|
2020-06-30 21:10:48 +00:00
|
|
|
CellLocatorBoundingIntervalHierarchyExec(
|
|
|
|
const NodeArrayHandle& nodes,
|
|
|
|
const CellIdArrayHandle& cellIds,
|
|
|
|
const CellSetType& cellSet,
|
|
|
|
const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coords,
|
|
|
|
DeviceAdapter,
|
|
|
|
vtkm::cont::Token& token)
|
2020-01-21 20:18:03 +00:00
|
|
|
: Nodes(nodes.PrepareForInput(DeviceAdapter(), token))
|
|
|
|
, CellIds(cellIds.PrepareForInput(DeviceAdapter(), token))
|
|
|
|
, CellSet(cellSet.PrepareForInput(DeviceAdapter(), VisitType(), IncidentType(), token))
|
|
|
|
, Coords(coords.PrepareForInput(DeviceAdapter(), token))
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:10:21 +00:00
|
|
|
|
2020-01-13 15:06:47 +00:00
|
|
|
VTKM_EXEC_CONT virtual ~CellLocatorBoundingIntervalHierarchyExec() noexcept override
|
2019-04-26 14:10:21 +00:00
|
|
|
{
|
|
|
|
// 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
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
|
|
|
|
vtkm::Id& cellId,
|
|
|
|
vtkm::Vec3f& parametric) 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:
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_RETURN_ON_ERROR(this->EnterNode(state, point, cellId, nodeIndex, parametric));
|
2018-07-12 21:04:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 23:38:27 +00:00
|
|
|
|
|
|
|
if (cellId >= 0)
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::Success;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::CellNotFound;
|
|
|
|
}
|
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
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::ErrorCode EnterNode(FindCellState& state,
|
|
|
|
const vtkm::Vec3f& point,
|
|
|
|
vtkm::Id& cellId,
|
|
|
|
vtkm::Id nodeIndex,
|
|
|
|
vtkm::Vec3f& parametric) const
|
2018-07-12 21:04:50 +00:00
|
|
|
{
|
|
|
|
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.
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_RETURN_ON_ERROR(this->FindInLeaf(point, parametric, node, cellId));
|
2018-07-12 21:04:50 +00:00
|
|
|
state = FindCellState::AscendFromNode;
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-12 21:04:50 +00:00
|
|
|
state = FindCellState::DescendLeftChild;
|
|
|
|
}
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::Success;
|
2018-07-12 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode FindInLeaf(
|
|
|
|
const vtkm::Vec3f& point,
|
|
|
|
vtkm::Vec3f& parametric,
|
|
|
|
const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node,
|
|
|
|
vtkm::Id& containingCellId) const
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
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);
|
2020-03-12 23:38:27 +00:00
|
|
|
bool found;
|
|
|
|
VTKM_RETURN_ON_ERROR(this->IsPointInCell(
|
|
|
|
point, parametric, this->CellSet.GetCellShape(cellId), cellPoints, found));
|
|
|
|
if (found)
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
containingCellId = cellId;
|
|
|
|
return vtkm::ErrorCode::Success;
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-12 23:38:27 +00:00
|
|
|
containingCellId = -1;
|
|
|
|
return vtkm::ErrorCode::Success;
|
2018-06-05 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CoordsType, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC static vtkm::ErrorCode IsPointInCell(const vtkm::Vec3f& point,
|
|
|
|
vtkm::Vec3f& parametric,
|
|
|
|
CellShapeTag cellShape,
|
|
|
|
const CoordsType& cellPoints,
|
|
|
|
bool& isInside)
|
2018-06-05 03:04:38 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
isInside = false;
|
|
|
|
VTKM_RETURN_ON_ERROR(vtkm::exec::WorldCoordinatesToParametricCoordinates(
|
|
|
|
cellPoints, point, cellShape, parametric));
|
|
|
|
isInside = vtkm::exec::CellInside(parametric, cellShape);
|
|
|
|
return vtkm::ErrorCode::Success;
|
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;
|
2020-06-30 21:10:48 +00:00
|
|
|
using CoordsPortal =
|
|
|
|
typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::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
|