Define LastCell type in cell locator structure

Rather than try to collect all `LastCell` types inside of a single
header and make an uber type, have each cell locator define its own cell
locator type and use that.
This commit is contained in:
Kenneth Moreland 2022-08-05 12:43:50 -06:00
parent 2271d0ef45
commit 5d78780f6e
14 changed files with 65 additions and 94 deletions

@ -35,7 +35,6 @@ set(headers
ImplicitFunction.h
List.h
ListTag.h # Deprecated, replaced by List.h
LocatorGoulash.h
LowerBound.h
Math.h
Matrix.h

@ -1,47 +0,0 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_LocatorGoulash_h
#define vtk_m_LocatorGoulash_h
#include <vtkm/exec/internal/Variant.h>
namespace vtkm
{
//Last cell object for each locator.
struct LastCellUniformGrid
{
};
struct LastCellRectilinearGrid
{
};
struct LastCellTwoLevel
{
vtkm::Id CellId = -1;
vtkm::Id LeafIdx = -1;
};
struct LastCellBoundingHierarchy
{
vtkm::Id CellId = -1;
vtkm::Id NodeIdx = -1;
};
using LastCellType = vtkm::exec::internal::Variant<LastCellUniformGrid,
LastCellRectilinearGrid,
LastCellTwoLevel,
LastCellBoundingHierarchy>;
} //namespace vtkm
#endif // vtk_m_LocatorGoulash_h

@ -39,6 +39,7 @@ public:
vtkm::ListTransform<SupportedCellSets, vtkm::exec::CellLocatorBoundingIntervalHierarchy>;
using ExecObjType = vtkm::ListApply<CellLocatorExecList, vtkm::exec::CellLocatorMultiplexer>;
using LastCell = typename ExecObjType::LastCell;
VTKM_CONT
CellLocatorBoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4,

@ -54,6 +54,7 @@ public:
vtkm::cont::internal::ExecutionObjectType<vtkm::cont::CellLocatorTwoLevel>>;
using ExecObjType = vtkm::ListApply<ExecLocatorList, vtkm::exec::CellLocatorMultiplexer>;
using LastCell = typename ExecObjType::LastCell;
VTKM_CONT ExecObjType PrepareForExecution(vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const;

@ -36,6 +36,8 @@ public:
~CellLocatorRectilinearGrid() = default;
using LastCell = vtkm::exec::CellLocatorRectilinearGrid::LastCell;
VTKM_CONT vtkm::exec::CellLocatorRectilinearGrid PrepareForExecution(
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const;

@ -58,6 +58,7 @@ public:
vtkm::ListTransform<CellExecObjectList, vtkm::exec::CellLocatorTwoLevel>;
using ExecObjType = vtkm::ListApply<CellLocatorExecList, vtkm::exec::CellLocatorMultiplexer>;
using LastCell = typename ExecObjType::LastCell;
CellLocatorTwoLevel()
: DensityL1(32.0f)

@ -25,6 +25,8 @@ class VTKM_CONT_EXPORT CellLocatorUniformGrid
using Superclass = vtkm::cont::internal::CellLocatorBase<CellLocatorUniformGrid>;
public:
using LastCell = vtkm::exec::CellLocatorUniformGrid::LastCell;
VTKM_CONT vtkm::exec::CellLocatorUniformGrid PrepareForExecution(
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const;

@ -187,7 +187,7 @@ public:
const LocatorType& locator,
vtkm::Id& cellId,
vtkm::Vec3f& pcoords,
vtkm::LastCellType& lastCell) const
typename LocatorType::LastCell& lastCell) const
{
vtkm::ErrorCode status = locator.FindCell(point, cellId, pcoords, lastCell);
if (status != vtkm::ErrorCode::Success)
@ -225,7 +225,7 @@ void TestWithDataSet(vtkm::cont::CellLocatorGeneral& locator, const vtkm::cont::
//Test the last cell option.
//Call the locator to fill in the lastCell array.
std::vector<vtkm::LastCellType> lastCell(64);
std::vector<vtkm::cont::CellLocatorGeneral::LastCell> lastCell(64);
auto lastCellArray = vtkm::cont::make_ArrayHandle(lastCell, vtkm::CopyFlag::Off);
invoker(FindCellWorkletWithLastCell{}, points, locator, cellIds, pcoords, lastCellArray);

@ -8,7 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/LocatorGoulash.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/CellLocatorTwoLevel.h>
#include <vtkm/cont/DataSetBuilderUniform.h>
@ -197,7 +196,7 @@ public:
const LocatorType& locator,
vtkm::Id& cellId,
vtkm::Vec3f& pcoords,
vtkm::LastCellType& lastCell) const
typename LocatorType::LastCell& lastCell) const
{
vtkm::ErrorCode status = locator.FindCell(point, cellId, pcoords, lastCell);
if (status != vtkm::ErrorCode::Success)
@ -244,7 +243,7 @@ void TestCellLocator(const vtkm::Vec<vtkm::Id, DIMENSIONS>& dim, vtkm::Id number
//Test the last cell option.
//Call the locator to fill in the lastCell array.
std::vector<vtkm::LastCellType> lastCell(numberOfPoints);
std::vector<vtkm::cont::CellLocatorTwoLevel::LastCell> lastCell(numberOfPoints);
auto lastCellArray = vtkm::cont::make_ArrayHandle(lastCell, vtkm::CopyFlag::Off);
invoker(FindCellWorkletWithLastCell{}, points, locator, cellIds, pcoords, lastCellArray);

@ -10,7 +10,6 @@
#ifndef vtk_m_exec_CellLocatorBoundingIntervalHierarchy_h
#define vtk_m_exec_CellLocatorBoundingIntervalHierarchy_h
#include <vtkm/LocatorGoulash.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/VecFromPortalPermute.h>
#include <vtkm/cont/ArrayHandle.h>
@ -84,12 +83,18 @@ public:
{
}
struct LastCell
{
vtkm::Id CellId = -1;
vtkm::Id NodeIdx = -1;
};
VTKM_EXEC
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric) const
{
vtkm::LastCellBoundingHierarchy lastCell;
LastCell lastCell;
return this->FindCellImpl(point, cellId, parametric, lastCell);
}
@ -97,28 +102,24 @@ public:
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
vtkm::LastCellType& lastCell) const
LastCell& lastCell) const
{
if (lastCell.GetIndex() != lastCell.GetIndexOf<vtkm::LastCellBoundingHierarchy>())
lastCell = vtkm::LastCellBoundingHierarchy();
auto& lastCellBH = lastCell.Get<vtkm::LastCellBoundingHierarchy>();
cellId = -1;
//Check the last cell.
if (lastCellBH.CellId != -1)
if (lastCell.CellId != -1)
{
if (this->PointInCell(point, lastCellBH.CellId, parametric) == vtkm::ErrorCode::Success)
if (this->PointInCell(point, lastCell.CellId, parametric) == vtkm::ErrorCode::Success)
{
cellId = lastCellBH.CellId;
cellId = lastCell.CellId;
return vtkm::ErrorCode::Success;
}
}
//Check the last leaf node.
if (lastCellBH.NodeIdx != -1)
if (lastCell.NodeIdx != -1)
{
const auto& node = this->Nodes.Get(lastCellBH.NodeIdx);
const auto& node = this->Nodes.Get(lastCell.NodeIdx);
VTKM_ASSERT(node.ChildIndex < 0); //should be a leaf node.
if (node.ChildIndex < 0)
@ -126,21 +127,21 @@ public:
VTKM_RETURN_ON_ERROR(this->FindInLeaf(point, parametric, node, cellId));
if (cellId != -1)
{
lastCellBH.CellId = cellId;
lastCell.CellId = cellId;
return vtkm::ErrorCode::Success;
}
}
}
//No fastpath. Do a full search.
return this->FindCellImpl(point, cellId, parametric, lastCellBH);
return this->FindCellImpl(point, cellId, parametric, lastCell);
}
VTKM_EXEC
vtkm::ErrorCode FindCellImpl(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
vtkm::LastCellBoundingHierarchy& lastCell) const
LastCell& lastCell) const
{
cellId = -1;
vtkm::Id nodeIndex = 0;
@ -196,7 +197,7 @@ private:
vtkm::Id& cellId,
vtkm::Id nodeIndex,
vtkm::Vec3f& parametric,
vtkm::LastCellBoundingHierarchy& lastCell) const
LastCell& lastCell) const
{
VTKM_ASSERT(state == FindCellState::EnterNode);

@ -11,7 +11,6 @@
#define vtk_m_exec_CellLocatorMultiplexer_h
#include <vtkm/ErrorCode.h>
#include <vtkm/LocatorGoulash.h>
#include <vtkm/TypeList.h>
#include <vtkm/exec/internal/Variant.h>
@ -35,14 +34,19 @@ struct FindCellFunctor
return locator.FindCell(point, cellId, parametric);
}
template <typename Locator>
template <typename Locator, typename LastCell>
VTKM_EXEC vtkm::ErrorCode operator()(Locator&& locator,
const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
LastCellType& lastCell) const
LastCell& lastCell) const
{
return locator.FindCell(point, cellId, parametric, lastCell);
using ConcreteLastCell = typename std::decay_t<Locator>::LastCell;
if (!lastCell.template IsType<ConcreteLastCell>())
{
lastCell = ConcreteLastCell{};
}
return locator.FindCell(point, cellId, parametric, lastCell.template Get<ConcreteLastCell>());
}
};
@ -56,6 +60,8 @@ class VTKM_ALWAYS_EXPORT CellLocatorMultiplexer
public:
CellLocatorMultiplexer() = default;
using LastCell = vtkm::exec::internal::Variant<typename LocatorTypes::LastCell...>;
template <typename Locator>
VTKM_CONT CellLocatorMultiplexer(const Locator& locator)
: Locators(locator)
@ -72,7 +78,7 @@ public:
VTKM_EXEC vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
LastCellType& lastCell) const
LastCell& lastCell) const
{
return this->Locators.CastAndCall(
detail::FindCellFunctor{}, point, cellId, parametric, lastCell);

@ -11,7 +11,6 @@
#define vtkm_exec_celllocatorrectilineargrid_h
#include <vtkm/Bounds.h>
#include <vtkm/LocatorGoulash.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h>
#include <vtkm/VecFromPortalPermute.h>
@ -43,6 +42,10 @@ private:
VTKM_CONT static vtkm::Id3 ToId3(vtkm::Id&& src) { return vtkm::Id3(src, 1, 1); }
public:
struct LastCell
{
};
template <vtkm::IdComponent dimensions>
VTKM_CONT CellLocatorRectilinearGrid(const vtkm::Id planeSize,
const vtkm::Id rowSize,
@ -92,7 +95,7 @@ public:
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
vtkm::LastCellType& vtkmNotUsed(lastCell)) const
LastCell& vtkmNotUsed(lastCell)) const
{
return this->FindCell(point, cellId, parametric);
}

@ -16,7 +16,6 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/LocatorGoulash.h>
#include <vtkm/Math.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h>
@ -154,10 +153,16 @@ public:
{
}
struct LastCell
{
vtkm::Id CellId = -1;
vtkm::Id LeafIdx = -1;
};
VTKM_EXEC
vtkm::ErrorCode FindCell(const FloatVec3& point, vtkm::Id& cellId, FloatVec3& parametric) const
{
vtkm::LastCellTwoLevel lastCell;
LastCell lastCell;
return this->FindCellImpl(point, cellId, parametric, lastCell);
}
@ -165,34 +170,29 @@ public:
vtkm::ErrorCode FindCell(const FloatVec3& point,
vtkm::Id& cellId,
FloatVec3& parametric,
vtkm::LastCellType& lastCell) const
LastCell& lastCell) const
{
if (lastCell.GetIndex() != lastCell.GetIndexOf<vtkm::LastCellTwoLevel>())
lastCell = vtkm::LastCellTwoLevel();
auto& lastCell2L = lastCell.Get<vtkm::LastCellTwoLevel>();
vtkm::Vec3f pc;
//See if point is inside the last cell.
if (lastCell2L.CellId != -1 &&
this->PointInCell(point, lastCell2L.CellId, pc) == vtkm::ErrorCode::Success)
if (lastCell.CellId != -1 &&
this->PointInCell(point, lastCell.CellId, pc) == vtkm::ErrorCode::Success)
{
parametric = pc;
cellId = lastCell2L.CellId;
cellId = lastCell.CellId;
return vtkm::ErrorCode::Success;
}
//See if it's in the last leaf.
if (lastCell2L.LeafIdx != -1 &&
this->PointInLeaf(point, lastCell2L.LeafIdx, cellId, pc) == vtkm::ErrorCode::Success)
if (lastCell.LeafIdx != -1 &&
this->PointInLeaf(point, lastCell.LeafIdx, cellId, pc) == vtkm::ErrorCode::Success)
{
parametric = pc;
lastCell2L.CellId = cellId;
lastCell.CellId = cellId;
return vtkm::ErrorCode::Success;
}
//Call the full point search.
return this->FindCellImpl(point, cellId, parametric, lastCell2L);
return this->FindCellImpl(point, cellId, parametric, lastCell);
}
VTKM_DEPRECATED(1.6, "Locators are no longer pointers. Use . operator.")
@ -250,7 +250,7 @@ private:
vtkm::ErrorCode FindCellImpl(const FloatVec3& point,
vtkm::Id& cellId,
FloatVec3& parametric,
vtkm::LastCellTwoLevel& lastCell) const
LastCell& lastCell) const
{
using namespace vtkm::internal::cl_uniform_bins;

@ -11,7 +11,6 @@
#define vtkm_exec_celllocatoruniformgrid_h
#include <vtkm/Bounds.h>
#include <vtkm/LocatorGoulash.h>
#include <vtkm/Math.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h>
@ -56,11 +55,15 @@ public:
return inside;
}
struct LastCell
{
};
VTKM_EXEC
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
vtkm::LastCellType& vtkmNotUsed(lastCell)) const
LastCell& vtkmNotUsed(lastCell)) const
{
return this->FindCell(point, cellId, parametric);
}