Hi There!
First of all, thank you for this fantastic plugin. Currently I try to calculate the points that collided with my collider sphere. Therefore I have some questions, that maybe someone more experienced could help me with.
I think my main problem is to get the individual points that belong to an octree node. I first assumed that the numbers in the IBCache Array in “PointCloudOctree” where the index of the Point in the Array that stores all the Points. But the numbers in the IBCache Elements are way higher than my actual number of points, what leads to an “out of bounds” error.
So where and how can I acces only the points that belong to an certain Node?
Of course there could be many more problems with my code, I just started out learning C++…At least It compiles
Here is my code that I added to the OctreeCpp:
//START MYCODE
TArray<FPointCloudPoint> TmpTouchedPoints;
TArray<uint32> TmpTouchedPointsIndex;
TArray<FPointCloudPoint> FPointCloudOctree::GetTouchedPoints(FVector ColliderLocation, int32 Radius, TArray<FPointCloudPoint> &PointCloudPoints, FPointCloudOctree::Node ParamRoot) const
{
GetPointsInNode(TmpTouchedPointsIndex , ColliderLocation, Radius, PointCloudPoints, ParamRoot);
for (auto const &pointIndex : TmpTouchedPointsIndex)
{
TmpTouchedPoints.Add(PointCloudPoints[pointIndex]);
}
return TmpTouchedPoints;
}
void FPointCloudOctree::GetPointsInNode(TArray<uint32> &TouchedPointsIndex, FVector CLocation, int32 Radius, TArray<FPointCloudPoint> &pPointCloudPoints, FPointCloudOctree::Node &pNodeToGetPoints) const
{
FBox nodeBox = pNodeToGetPoints.LocalBounds.GetBox();
// Is the Collider Sphere inside the node or the distance to it smaller than the sphere radius and does the node have 0 children?
if (nodeBox.IsInsideOrOn(CLocation) && ComputeSquaredDistanceFromBoxToPoint(nodeBox.Min, nodeBox., CLocation) < (Radius*Radius) && pNodeToGetPoints.NumChildren == 0)
{
//For every PointIndex in IBCache
for (auto const &pointIndex : pNodeToGetPoints.IBCache)
{
//Is Point inside collider sphere?
if ((pPointCloudPoints[pointIndex].Location - CLocation).SizeSquared() < (Radius * Radius))
{
// Add the Index of the Point to the collection
TouchedPointsIndex.Add(pointIndex);
}
}
}
// Is the Collider Sphere inside the node or the distance to it smaller than the sphere radius
else if (nodeBox.IsInsideOrOn(CLocation) && ComputeSquaredDistanceFromBoxToPoint(nodeBox.Min, nodeBox., CLocation) < (Radius*Radius))
{
//For every PointIndex in IBCache
for (auto const &pointIndex : pNodeToGetPoints.IBCache)
{
// Is Point inside collider Sphere
if ((pPointCloudPoints[pointIndex].Location - CLocation).SizeSquared() < (Radius * Radius))
{
// Add the Index of the Point to the collection
TouchedPointsIndex.Add(pointIndex);
}
}
//For every child of the node call this function and collect points
for (int i = 0; i < pNodeToGetPoints.NumChildren; i++) //alternative: (auto const &ChildNode : pNodeToGetPoints.Children)
{
GetPointsInNode(TouchedPointsIndex, CLocation, Radius, pPointCloudPoints, *pNodeToGetPoints.Children*);
}
}
}
//END MYCODE
Another Thing is, when I take the parts out, that make the “out of bounds” error happen, everything runs cool, but somehow the rendering of some points gets affected. See Pictures:
Thank you all for any help and suggestions!!!