Skip to content

Commit

Permalink
Place object in child node after splitting an octree node
Browse files Browse the repository at this point in the history
The octree split is invoked after it is determined that an object should be
placed in a child node, so we shouldn't add it to the current node.
  • Loading branch information
ajtribick committed May 9, 2024
1 parent 35cbb52 commit de99a2b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/celengine/octree.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,33 @@ template <class OBJ, class PREC>
inline void DynamicOctree<OBJ, PREC>::insertObject(const OBJ& obj, const PREC scale)
{
// If the object can't be placed into this node's children, then put it here:
if (limitingFactorPredicate(obj, exclusionFactor) || straddlingPredicate(cellCenterPos, obj, exclusionFactor) )
if (limitingFactorPredicate(obj, exclusionFactor) || straddlingPredicate(cellCenterPos, obj, exclusionFactor))
{
add(obj);
else
return;
}

// If we haven't allocated child nodes yet, try to fit
// the object in this node, even though it could be put
// in a child. Only if there are more than SPLIT_THRESHOLD
// objects in the node will we attempt to place the
// object into a child node. This is done in order
// to avoid having the octree degenerate into one object
// per node.
if (_children == nullptr)
{
// If we haven't allocated child nodes yet, try to fit
// the object in this node, even though it could be put
// in a child. Only if there are more than SPLIT_THRESHOLD
// objects in the node will we attempt to place the
// object into a child node. This is done in order
// to avoid having the octree degenerate into one object
// per node.
if (_children == nullptr)
if (_objects == nullptr || _objects->size() < DynamicOctree<OBJ, PREC>::SPLIT_THRESHOLD)
{
// Make sure that there's enough room left in this node
if (_objects != nullptr && _objects->size() >= DynamicOctree<OBJ, PREC>::SPLIT_THRESHOLD)
split(scale * 0.5f);
add(obj);
return;
}
else
// We've already allocated child nodes; place the object
// into the appropriate one.
this->getChild(obj, cellCenterPos)->insertObject(obj, scale * (PREC) 0.5);

split(scale * 0.5f);
}

// We've already allocated child nodes; place the object
// into the appropriate one.
this->getChild(obj, cellCenterPos)->insertObject(obj, scale * (PREC) 0.5);
}


Expand Down

0 comments on commit de99a2b

Please sign in to comment.