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