mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
fixed all most of compiler error, able to print something from point locator on execution side
This commit is contained in:
parent
b4f7e9467d
commit
c4921c0e7a
@ -55,16 +55,18 @@ public:
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT const vtkm::exec::PointLocator* PrepareForExecution(DeviceAdapter device)
|
||||
VTKM_CONT const vtkm::exec::PointLocator* PrepareForExecution(DeviceAdapter device) const
|
||||
{
|
||||
return PrepareForExecution(GetDeviceId(device));
|
||||
vtkm::cont::DeviceAdapterId deviceId = vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetId();
|
||||
return PrepareForExecutionImp(deviceId);
|
||||
}
|
||||
|
||||
VTKM_CONT virtual const vtkm::exec::PointLocator* PrepareForExecution(
|
||||
vtkm::cont::DeviceAdapterId deviceId) = 0;
|
||||
VTKM_CONT virtual const vtkm::exec::PointLocator* PrepareForExecutionImp(
|
||||
vtkm::cont::DeviceAdapterId deviceId) const = 0;
|
||||
|
||||
private:
|
||||
vtkm::cont::CoordinateSystem coordinates;
|
||||
|
||||
bool dirty;
|
||||
};
|
||||
}
|
||||
|
@ -82,8 +82,6 @@ public:
|
||||
/// \param coords An ArrayHandle of x, y, z coordinates of input points.
|
||||
/// \param device Tag for selecting device adapter
|
||||
|
||||
//template <typename DeviceAdapter>
|
||||
//void Build(const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>& coords, DeviceAdapter)
|
||||
struct BuildFunctor
|
||||
{
|
||||
BuildFunctor(vtkm::cont::PointLocatorUniformGrid _self)
|
||||
@ -106,17 +104,17 @@ public:
|
||||
|
||||
// bin points into cells and give each of them the cell id.
|
||||
BinPointsWorklet cellIdWorklet(self.Min, self.Max, self.Dims);
|
||||
vtkm::worklet::DispatcherMapField<BinPointsWorklet> dispatchCellId(cellIdWorklet);
|
||||
dispatchCellId.Invoke(self.coords, self._CellIds);
|
||||
vtkm::worklet::DispatcherMapField<BinPointsWorklet, Device> dispatchCellId(cellIdWorklet);
|
||||
dispatchCellId.Invoke(self.coords, self.cellIds);
|
||||
|
||||
// Group points of the same cell together by sorting them according to the cell ids
|
||||
Algorithm::SortByKey(self._CellIds, self.pointIds);
|
||||
Algorithm::SortByKey(self.cellIds, self.pointIds);
|
||||
|
||||
// for each cell, find the lower and upper bound of indices to the sorted point ids.
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> cell_ids_counting(
|
||||
0, 1, self.Dims[0] * self.Dims[1] * self.Dims[2]);
|
||||
Algorithm::UpperBounds(self._CellIds, cell_ids_counting, self._CellUpper);
|
||||
Algorithm::LowerBounds(self._CellIds, cell_ids_counting, self._CellLower);
|
||||
Algorithm::UpperBounds(self.cellIds, cell_ids_counting, self.cellUpper);
|
||||
Algorithm::LowerBounds(self.cellIds, cell_ids_counting, self.cellLower);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -139,22 +137,41 @@ public:
|
||||
|
||||
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator>;
|
||||
|
||||
struct PrepareForExecutionFunctor
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT void operator()(DeviceAdapter,
|
||||
const vtkm::cont::PointLocatorUniformGrid& self,
|
||||
HandleType handle) const
|
||||
{
|
||||
vtkm::exec::PointLocatorUniformGrid* locator =
|
||||
new vtkm::exec::PointLocatorUniformGrid(self.Min,
|
||||
self.Max,
|
||||
self.Dims,
|
||||
self.coords.PrepareForInput(DeviceAdapter()),
|
||||
self.pointIds.PrepareForInput(DeviceAdapter()),
|
||||
self.cellLower.PrepareForInput(DeviceAdapter()),
|
||||
self.cellUpper.PrepareForInput(DeviceAdapter()));
|
||||
handle.Reset(locator);
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const vtkm::exec::PointLocator* PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId) override
|
||||
const vtkm::exec::PointLocator* PrepareForExecutionImp(
|
||||
vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
// TODO: call VirtualObjectHandle::PrepareForExecution() and return vtkm::exec::PointLocator
|
||||
// TODO: how to convert deviceId back to DeviceAdapter tag?
|
||||
using DeviceAdapter = vtkm::cont::DeviceAdapterTagSerial;
|
||||
vtkm::exec::PointLocatorUniformGrid* locator =
|
||||
new vtkm::exec::PointLocatorUniformGrid(Min,
|
||||
Max,
|
||||
Dims,
|
||||
coords.PrepareForInput(DeviceAdapter()),
|
||||
pointIds.PrepareForInput(DeviceAdapter()),
|
||||
_CellLower.PrepareForInput(DeviceAdapter()),
|
||||
_CellUpper.PrepareForInput(DeviceAdapter()));
|
||||
ExecHandle = new HandleType(locator, false);
|
||||
return ExecHandle->PrepareForExecution(DeviceAdapter());
|
||||
using DeviceList = vtkm::ListTagBase<vtkm::cont::DeviceAdapterTagCuda,
|
||||
vtkm::cont::DeviceAdapterTagTBB,
|
||||
vtkm::cont::DeviceAdapterTagSerial>;
|
||||
|
||||
//HandleType ExecHandle; // = new HandleType(locator, false);
|
||||
vtkm::cont::internal::FindDeviceAdapterTagAndCall(
|
||||
deviceId, DeviceList(), PrepareForExecutionFunctor(), *this, ExecHandle);
|
||||
|
||||
return ExecHandle.PrepareForExecution(DeviceAdapter());
|
||||
}
|
||||
|
||||
private:
|
||||
@ -165,12 +182,12 @@ private:
|
||||
// TODO: how to convert CoordinateSystem to ArrayHandle<Vec<Float, 3>>?
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> coords;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> pointIds;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> _CellIds;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> _CellLower;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> _CellUpper;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellLower;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellUpper;
|
||||
|
||||
// TODO: std::unique_ptr/std::shared_ptr?
|
||||
HandleType* ExecHandle;
|
||||
HandleType ExecHandle;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,14 @@
|
||||
#ifndef vtk_m_cont_testing_TestingPointLocatorUniformGrid_h
|
||||
#define vtk_m_cont_testing_TestingPointLocatorUniformGrid_h
|
||||
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
||||
//#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
||||
|
||||
#include <random>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/cont/PointLocatorUniformGrid.h>
|
||||
#include <vtkm/exec/PointLocatorUniformGrid.h>
|
||||
|
||||
////brute force method /////
|
||||
template <typename CoordiVecT, typename CoordiPortalT, typename CoordiT>
|
||||
@ -77,7 +78,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
class PointLocatorUniformGridWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
@ -98,7 +99,7 @@ public:
|
||||
IdType& nnIdOut,
|
||||
CoordiType& nnDis) const
|
||||
{
|
||||
locator.FindNearestPoint(qc, nnIdOut, nnDis);
|
||||
locator->FindNearestNeighbor(qc, nnIdOut, nnDis);
|
||||
};
|
||||
};
|
||||
#endif
|
||||
@ -110,7 +111,15 @@ public:
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
void TestTest() const
|
||||
{
|
||||
#if 0
|
||||
|
||||
// TODO: locator needs to be a point to have runtime polymorphism.
|
||||
//vtkm::cont::PointLocator * locator = new vtkm::cont::PointLocatorUniformGrid(
|
||||
// { 0.0f, 0.0f, 0.0f }, { 10.0f, 10.0f, 10.0f }, { 5, 5, 5 });
|
||||
vtkm::cont::PointLocatorUniformGrid locator(
|
||||
{ 0.0f, 0.0f, 0.0f }, { 10.0f, 10.0f, 10.0f }, { 5, 5, 5 });
|
||||
// TODO: generate training points
|
||||
locator.Build();
|
||||
|
||||
vtkm::Int32 nTrainingPoints = 1000;
|
||||
vtkm::Int32 nTestingPoint = 1000;
|
||||
|
||||
@ -126,10 +135,12 @@ public:
|
||||
}
|
||||
auto coordi_Handle = vtkm::cont::make_ArrayHandle(coordi);
|
||||
|
||||
#if 0
|
||||
vtkm::cont::PointLocatorUniformGrid<vtkm::Float32> uniformGrid(
|
||||
{ 0.0f, 0.0f, 0.0f }, { 10.0f, 10.0f, 10.0f }, { 5, 5, 5 });
|
||||
uniformGrid.Build(coordi_Handle, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
auto locator = uniformGrid.PrepareForExecution(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
#endif
|
||||
|
||||
///// randomly generate training points/////
|
||||
std::vector<vtkm::Vec<vtkm::Float32, 3>> qcVec;
|
||||
@ -141,12 +152,14 @@ public:
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> nnId_Handle;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> nnDis_Handle;
|
||||
|
||||
#if 1
|
||||
PointLocatorUniformGridWorklet pointLocatorUniformGridWorklet;
|
||||
vtkm::worklet::DispatcherMapField<PointLocatorUniformGridWorklet> locatorDispatcher(
|
||||
pointLocatorUniformGridWorklet);
|
||||
vtkm::worklet::DispatcherMapField<PointLocatorUniformGridWorklet, DeviceAdapter>
|
||||
locatorDispatcher(pointLocatorUniformGridWorklet);
|
||||
locatorDispatcher.Invoke(qc_Handle, locator, nnId_Handle, nnDis_Handle);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// brute force
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> bfnnId_Handle;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> bfnnDis_Handle;
|
||||
|
@ -30,9 +30,9 @@ namespace exec
|
||||
class PointLocator : public vtkm::VirtualObjectBase
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC virtual void FindNeareastNeighbor(vtkm::Vec<vtkm::FloatDefault, 3> queryPoint,
|
||||
vtkm::Id& pointId,
|
||||
FloatDefault& distanceSquared) = 0;
|
||||
VTKM_EXEC virtual void FindNearestNeighbor(vtkm::Vec<vtkm::FloatDefault, 3> queryPoint,
|
||||
vtkm::Id& pointId,
|
||||
FloatDefault& distanceSquared) const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -77,10 +77,12 @@ public:
|
||||
/// \param nearestNeighborId Neareast neighbor in the training dataset for each points in
|
||||
/// the test set
|
||||
/// \param distance Distance between query points and their nearest neighbors.
|
||||
VTKM_EXEC virtual void FindNeareastNeighbor(vtkm::Vec<vtkm::FloatDefault, 3> queryPoint,
|
||||
vtkm::Id& nearestNeighborId,
|
||||
FloatDefault& distance) override
|
||||
VTKM_EXEC virtual void FindNearestNeighbor(vtkm::Vec<vtkm::FloatDefault, 3> queryPoint,
|
||||
vtkm::Id& nearestNeighborId,
|
||||
FloatDefault& distance) const override
|
||||
{
|
||||
std::cout << "FindNeareastNeighbor: " << queryPoint << std::endl;
|
||||
#if 0
|
||||
auto nlayers = vtkm::Max(vtkm::Max(Dims[0], Dims[1]), Dims[2]);
|
||||
|
||||
vtkm::Vec<vtkm::Id, 3> xyz = (queryPoint - Min) / Dxdydz;
|
||||
@ -104,7 +106,7 @@ public:
|
||||
for (auto k = minz; k <= maxz; k++)
|
||||
{
|
||||
if (i == (xyz[0] + layer) || i == (xyz[0] - layer) || j == (xyz[1] + layer) ||
|
||||
j == (xyz[1] - layer) || k == (xyz[2] + layer) || k == (xyz[2] - layer))
|
||||
j == (xyz[1] - layer) || k == (xyz[2] + layer) || k == (xyz[2] - layer))
|
||||
{
|
||||
auto cellid = i + j * Dims[0] + k * Dims[0] * Dims[1];
|
||||
auto lower = cellLower.Get(cellid);
|
||||
@ -133,6 +135,7 @@ public:
|
||||
|
||||
nearestNeighborId = neareast;
|
||||
distance = vtkm::Sqrt(min_distance);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user