implement PointLocator without virtual methods

This commit is contained in:
nadavi 2020-11-11 22:02:10 +00:00
parent 3aa2c7521a
commit f70ecd4354
11 changed files with 257 additions and 59 deletions

@ -121,9 +121,11 @@ function(do_verify root_dir prefix)
cont/ArrayHandleVirtual.hxx
cont/ArrayHandleVirtualCoordinates.h
cont/CellLocator.h
cont/PointLocator.h
cont/StorageVirtual.h
cont/StorageVirtual.hxx
exec/CellLocator.h
exec/PointLocator.h
)
#by default every header in a testing directory doesn't need to be installed

@ -104,7 +104,6 @@ set(headers
Logging.h
ParticleArrayCopy.h
PartitionedDataSet.h
PointLocator.h
PointLocatorUniformGrid.h
PointLocatorSparseGrid.h
RuntimeDeviceInformation.h
@ -183,7 +182,6 @@ set(device_sources
FieldRangeCompute.cxx
FieldRangeGlobalCompute.cxx
PartitionedDataSet.cxx
PointLocator.cxx
PointLocatorSparseGrid.cxx
RuntimeDeviceInformation.cxx
Timer.cxx
@ -195,6 +193,7 @@ if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
ArrayHandleVirtual.h
ArrayHandleVirtualCoordinates.h
CellLocator.h
PointLocator.h
StorageVirtual.h
)
@ -206,6 +205,7 @@ if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
set(device_sources ${device_sources}
ArrayHandleVirtual.cxx
CellLocator.cxx
PointLocator.cxx
StorageVirtual.cxx
)
endif()

@ -24,6 +24,8 @@ namespace vtkm
{
namespace cont
{
VTKM_DEPRECATED_SUPPRESS_BEGIN
PointLocator::~PointLocator() = default;
VTKM_DEPRECATED_SUPPRESS_BEGIN
}
}

@ -10,18 +10,28 @@
#ifndef vtk_m_cont_PointLocator_h
#define vtk_m_cont_PointLocator_h
#include <vtkm/Deprecated.h>
#include <vtkm/cont/vtkm_cont_export.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/exec/PointLocator.h>
#ifdef VTKM_NO_DEPRECATED_VIRTUAL
#error "PointLocator with virtual methods is removed. Do not include PointLocator.h"
#endif
namespace vtkm
{
namespace cont
{
class VTKM_CONT_EXPORT PointLocator : public vtkm::cont::ExecutionObjectBase
class VTKM_CONT_EXPORT VTKM_DEPRECATED(1.6, "PointLocator with virtual methods no longer supported")
PointLocator : public vtkm::cont::ExecutionObjectBase
{
VTKM_DEPRECATED_SUPPRESS_BEGIN
public:
virtual ~PointLocator();
@ -47,12 +57,9 @@ public:
}
}
VTKM_CONT const vtkm::exec::PointLocator* PrepareForExecution(vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const
{
this->PrepareExecutionObject(this->ExecutionObjectHandle, device, token);
return this->ExecutionObjectHandle.PrepareForExecution(device, token);
}
VTKM_CONT virtual const vtkm::exec::PointLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const = 0;
VTKM_CONT
VTKM_DEPRECATED(1.6, "PrepareForExecution now requires a vtkm::cont::Token object")
@ -69,18 +76,13 @@ protected:
virtual void Build() = 0;
using ExecutionObjectHandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator>;
VTKM_CONT virtual void PrepareExecutionObject(ExecutionObjectHandleType& execObjHandle,
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const = 0;
private:
vtkm::cont::CoordinateSystem Coords;
bool Modified;
mutable ExecutionObjectHandleType ExecutionObjectHandle;
};
}
}
VTKM_DEPRECATED_SUPPRESS_END
} // namespace vtkm::cont
} // namespace vtkm
#endif // vtk_m_cont_PointLocator_h

@ -57,7 +57,7 @@ private:
vtkm::Vec3f Dxdydz;
};
} // internal
} // vtkm::cont::internal
void PointLocatorSparseGrid::Build()
{
@ -98,8 +98,7 @@ void PointLocatorSparseGrid::Build()
vtkm::cont::Algorithm::LowerBounds(cellIds, cell_ids_counting, this->CellLower);
}
VTKM_CONT void PointLocatorSparseGrid::PrepareExecutionObject(
ExecutionObjectHandleType& execObjHandle,
vtkm::exec::PointLocatorSparseGrid PointLocatorSparseGrid::PrepareForExecution(
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const
{
@ -109,7 +108,7 @@ VTKM_CONT void PointLocatorSparseGrid::PrepareExecutionObject(
auto rmax = vtkm::make_Vec(static_cast<vtkm::FloatDefault>(this->Range[0].Max),
static_cast<vtkm::FloatDefault>(this->Range[1].Max),
static_cast<vtkm::FloatDefault>(this->Range[2].Max));
vtkm::exec::PointLocatorSparseGrid* h = new vtkm::exec::PointLocatorSparseGrid(
return vtkm::exec::PointLocatorSparseGrid(
rmin,
rmax,
this->Dims,
@ -117,7 +116,7 @@ VTKM_CONT void PointLocatorSparseGrid::PrepareExecutionObject(
this->PointIds.PrepareForInput(device, token),
this->CellLower.PrepareForInput(device, token),
this->CellUpper.PrepareForInput(device, token));
execObjHandle.Reset(h);
}
}
} // vtkm::cont
} // vtkm

@ -16,7 +16,7 @@
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/PointLocator.h>
#include <vtkm/cont/internal/PointLocatorBase.h>
#include <vtkm/exec/PointLocatorSparseGrid.h>
namespace vtkm
@ -38,8 +38,11 @@ namespace cont
/// Parallel Techniques." In _Eurographics Symposium on Parallel Graphics and Visualization
/// (EGPGV)_, June 2019. DOI 10.2312/pgv.20191112.
///
class VTKM_CONT_EXPORT PointLocatorSparseGrid : public vtkm::cont::PointLocator
class VTKM_CONT_EXPORT PointLocatorSparseGrid
: public vtkm::cont::internal::PointLocatorBase<PointLocatorSparseGrid>
{
using Superclass = vtkm::cont::internal::PointLocatorBase<PointLocatorSparseGrid>;
public:
using RangeType = vtkm::Vec<vtkm::Range, 3>;
@ -74,22 +77,20 @@ public:
const vtkm::Id3& GetNumberOfBins() const { return this->Dims; }
protected:
void Build() override;
struct PrepareExecutionObjectFunctor;
VTKM_CONT void PrepareExecutionObject(ExecutionObjectHandleType& execObjHandle,
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const override;
VTKM_CONT
vtkm::exec::PointLocatorSparseGrid PrepareForExecution(vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const;
private:
bool IsRangeInvalid() const
{
return (this->Range[0].Max < this->Range[0].Min) || (this->Range[1].Max < this->Range[1].Min) ||
(this->Range[2].Max < this->Range[2].Min);
}
private:
friend Superclass;
VTKM_CONT void Build();
RangeType Range = { { 0.0, -1.0 } };
vtkm::Id3 Dims = { 32 };

@ -29,6 +29,7 @@ set(headers
OptionParser.h
ParallelRadixSort.h
ParallelRadixSortInterface.h
PointLocatorBase.h
ReverseConnectivityBuilder.h
StorageDeprecated.h
StorageError.h

@ -0,0 +1,185 @@
//============================================================================
// 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_cont_internal_PointLocatorBase_h
#define vtk_m_cont_internal_PointLocatorBase_h
#include <vtkm/cont/vtkm_cont_export.h>
#include <vtkm/Types.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ExecutionObjectBase.h>
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
#include <vtkm/cont/PointLocator.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/exec/PointLocator.h>
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
namespace vtkm
{
namespace cont
{
namespace internal
{
namespace detail
{
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
VTKM_DEPRECATED_SUPPRESS_BEGIN
// Wrong namespace, but it's only for deprecated code.
template <typename LocatorType>
class VTKM_ALWAYS_EXPORT PointLocatorBaseExecWrapper : public vtkm::exec::PointLocator
{
LocatorType Locator;
public:
VTKM_CONT PointLocatorBaseExecWrapper(const LocatorType& locator)
: Locator(locator)
{
}
VTKM_EXEC_CONT virtual ~PointLocatorBaseExecWrapper() noexcept override
{
// This must not be defaulted, since defaulted virtual destructors are
// troublesome with CUDA __host__ __device__ markup.
}
VTKM_EXEC void FindNearestNeighbor(const vtkm::Vec3f& queryPoint,
vtkm::Id& pointId,
vtkm::FloatDefault& distanceSquared) const override
{
return this->Locator.FindNearestNeighbor(queryPoint, pointId, distanceSquared);
}
};
template <typename LocatorType>
struct PointLocatorBaseWrapperPrepareForExecutionFunctor
{
template <typename Device>
VTKM_CONT bool operator()(Device device,
vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator>& execHandle,
const LocatorType& locator,
vtkm::cont::Token& token)
{
auto execObject = locator.PrepareForExecution(device, token);
using WrapType = PointLocatorBaseExecWrapper<decltype(execObject)>;
execHandle.Reset(new WrapType(execObject));
return true;
}
};
template <typename Derived>
class VTKM_ALWAYS_EXPORT PointLocatorBaseWrapper : public vtkm::cont::PointLocator
{
Derived Locator;
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator> ExecutionObjectHandle;
public:
PointLocatorBaseWrapper() = default;
PointLocatorBaseWrapper(const Derived& locator)
: Locator(locator)
{
this->SetCoordinates(locator.GetCoordinates());
}
VTKM_CONT const vtkm::exec::PointLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token) const override
{
const bool success =
vtkm::cont::TryExecuteOnDevice(device,
PointLocatorBaseWrapperPrepareForExecutionFunctor<Derived>{},
this->ExecutionObjectHandle,
this->Locator,
token);
if (!success)
{
throwFailedRuntimeDeviceTransfer("PointLocatorWrapper", device);
}
return this->ExecutionObjectHandle.PrepareForExecution(device, token);
}
private:
void Build() override
{
this->Locator.SetCoordinates(this->GetCoordinates());
this->Locator.Update();
}
};
VTKM_DEPRECATED_SUPPRESS_END
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
} // namespace detail
/// \brief Base class for all `PointLocator` classes.
///
/// `PointLocatorBase` uses the curiously recurring template pattern (CRTP). Subclasses
/// must provide their own type for the template parameter. Subclasses must implement
/// `Build` and `PrepareForExecution` methods.
///
template <typename Derived>
class VTKM_ALWAYS_EXPORT PointLocatorBase : public vtkm::cont::ExecutionObjectBase
{
public:
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
VTKM_DEPRECATED_SUPPRESS_BEGIN
// Support deprecated classes
operator detail::PointLocatorBaseWrapper<Derived>() const
{
return detail::PointLocatorBaseWrapper<Derived>(reinterpret_cast<const Derived&>(*this));
}
VTKM_DEPRECATED_SUPPRESS_END
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
vtkm::cont::CoordinateSystem GetCoordinates() const { return this->Coords; }
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords)
{
this->Coords = coords;
this->SetModified();
}
void Update()
{
if (this->Modified)
{
static_cast<Derived*>(const_cast<PointLocatorBase*>(this))->Build();
this->Modified = false;
}
}
template <typename Device>
VTKM_CONT VTKM_DEPRECATED(1.6, "PrepareForExecution now requires a vtkm::cont::Token object")
const vtkm::cont::internal::ExecutionObjectType<Derived, Device> PrepareForExecution(
Device device) const
{
vtkm::cont::Token token;
return this->PrepareForExecution(device, token);
}
protected:
void SetModified() { this->Modified = true; }
bool GetModified() const { return this->Modified; }
private:
vtkm::cont::CoordinateSystem Coords;
mutable bool Modified = true;
};
} // vtkm::cont::internal
} // vtkm::cont
} // vtkm
#endif // vtk_m_cont_internal_PointLocatorBase_h

@ -83,7 +83,7 @@ public:
vtkm::Id& nnIdOut,
vtkm::FloatDefault& nnDis) const
{
locator->FindNearestNeighbor(qc, nnIdOut, nnDis);
locator.FindNearestNeighbor(qc, nnIdOut, nnDis);
}
};
@ -121,13 +121,12 @@ public:
vtkm::cont::CoordinateSystem coord("points", coordi_Handle);
vtkm::cont::PointLocatorSparseGrid pointLocatorUG;
pointLocatorUG.SetCoordinates(coord);
pointLocatorUG.SetRange({ { 0.0, 10.0 } });
pointLocatorUG.SetNumberOfBins({ 5, 5, 5 });
vtkm::cont::PointLocatorSparseGrid locator;
locator.SetCoordinates(coord);
locator.SetRange({ { 0.0, 10.0 } });
locator.SetNumberOfBins({ 5, 5, 5 });
vtkm::cont::PointLocator* locator = &pointLocatorUG;
locator->Update();
locator.Update();
///// randomly generate testing points/////
std::vector<vtkm::Vec3f_32> qcVec;

@ -12,13 +12,19 @@
#include <vtkm/VirtualObjectBase.h>
#ifdef VTKM_NO_DEPRECATED_VIRTUAL
#error "PointLocator with virtual methods is removed. Do not include PointLocator.h"
#endif
namespace vtkm
{
namespace exec
{
class VTKM_ALWAYS_EXPORT PointLocator : public vtkm::VirtualObjectBase
class VTKM_DEPRECATED(1.6, "PointLocator with virtual methods no longer supported.")
VTKM_ALWAYS_EXPORT PointLocator : public vtkm::VirtualObjectBase
{
VTKM_DEPRECATED_SUPPRESS_BEGIN
public:
VTKM_EXEC_CONT virtual ~PointLocator() noexcept
{
@ -26,10 +32,14 @@ public:
// troublesome with CUDA __host__ __device__ markup.
}
VTKM_EXEC virtual void FindNearestNeighbor(const vtkm::Vec3f& queryPoint,
vtkm::Id& pointId,
vtkm::FloatDefault& distanceSquared) const = 0;
VTKM_EXEC
virtual void FindNearestNeighbor(const vtkm::Vec3f& queryPoint,
vtkm::Id& pointId,
vtkm::FloatDefault& distanceSquared) const = 0;
VTKM_DEPRECATED_SUPPRESS_END
};
}
}
} // vtkm::exec
} // vtkm
#endif // vtk_m_exec_PointLocator_h

@ -14,8 +14,6 @@
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/exec/PointLocator.h>
#include <vtkm/Deprecated.h>
#include <vtkm/VectorAnalysis.h>
@ -24,7 +22,7 @@ namespace vtkm
namespace exec
{
class VTKM_ALWAYS_EXPORT PointLocatorSparseGrid : public vtkm::exec::PointLocator
class VTKM_ALWAYS_EXPORT PointLocatorSparseGrid
{
public:
using CoordPortalType =
@ -32,8 +30,6 @@ public:
using IdPortalType = typename vtkm::cont::ArrayHandle<vtkm::Id>::ReadPortalType;
PointLocatorSparseGrid() = default;
PointLocatorSparseGrid(const vtkm::Vec3f& min,
const vtkm::Vec3f& max,
const vtkm::Id3& dims,
@ -61,9 +57,9 @@ public:
/// \param nearestNeighborId Neareast neighbor in the training dataset for each points in
/// the test set
/// \param distance2 Squared distance between query points and their nearest neighbors.
VTKM_EXEC virtual void FindNearestNeighbor(const vtkm::Vec3f& queryPoint,
vtkm::Id& nearestNeighborId,
vtkm::FloatDefault& distance2) const override
VTKM_EXEC void FindNearestNeighbor(const vtkm::Vec3f& queryPoint,
vtkm::Id& nearestNeighborId,
vtkm::FloatDefault& distance2) const
{
//std::cout << "FindNeareastNeighbor: " << queryPoint << std::endl;
vtkm::Id3 ijk = (queryPoint - this->Min) / this->Dxdydz;
@ -230,7 +226,8 @@ private:
queryPoint, planeCenter, div, mod, origin, numInPlane, nearestNeighborId, nearestDistance2);
}
};
}
}
} // vtkm::exec
} // vtkm
#endif // vtk_m_exec_PointLocatorSparseGrid_h