Skip to content

Commit f34d9b5

Browse files
fredroyepernod
andauthored
[Simulation.Core] Fix BoundingBox initialization and updates (#6146)
* add a boolean to track bounding box value, and use this state at init to compute bbox (or not) * make it protected --------- Co-authored-by: erik pernod <erik.pernod@gmail.com>
1 parent e3e24dc commit f34d9b5

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

Sofa/framework/Simulation/Core/src/sofa/simulation/InitVisitor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ Visitor::Result InitVisitor::processNodeTopDown(simulation::Node* node)
3737
node->initialize();
3838

3939
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
40-
if(!node->f_bbox.isSet())
40+
if(!node->bboxIsFixed())
4141
nodeBBox->invalidate();
4242

4343
for(unsigned int i=0; i<node->object.size(); ++i)
4444
{
4545
node->object[i]->init();
4646
node->object[i]->computeBBox(params, true);
47-
nodeBBox->include(node->object[i]->f_bbox.getValue());
47+
if(!node->bboxIsFixed())
48+
nodeBBox->include(node->object[i]->f_bbox.getValue());
4849
}
4950
node->f_bbox.endEdit();
5051
return RESULT_CONTINUE;
@@ -60,7 +61,8 @@ void InitVisitor::processNodeBottomUp(simulation::Node* node)
6061
for(std::size_t i=node->object.size(); i>0; --i)
6162
{
6263
node->object[i-1]->bwdInit();
63-
nodeBBox->include(node->object[i-1]->f_bbox.getValue());
64+
if(!node->bboxIsFixed())
65+
nodeBBox->include(node->object[i-1]->f_bbox.getValue());
6466
}
6567

6668
node->f_bbox.endEdit();

Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ void Node::parse( sofa::core::objectmodel::BaseObjectDescription* arg )
191191
objDesc.setAttribute("displayFlags", oldFlags);
192192
sofa::core::objectmodel::BaseComponent::SPtr obj = sofa::core::ObjectFactory::CreateObject(this, &objDesc);
193193
}
194+
195+
// BoundingBox state management
196+
const char* bboxAttrStr = arg->getAttribute("bbox", nullptr);
197+
if(bboxAttrStr != nullptr)
198+
{
199+
this->m_bboxIsFixed = true;
200+
}
194201
}
195202

196203
/// Initialize the components of this node and all the nodes which depend on it.

Sofa/framework/Simulation/Core/src/sofa/simulation/Node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,12 @@ class SOFA_SIMULATION_CORE_API Node : public sofa::core::objectmodel::BaseNode,
555555

556556
/// return the smallest common parent between this and node2 (returns nullptr if separated sub-graphes)
557557
Node* findCommonParent( simulation::Node* node2 );
558-
558+
559+
bool bboxIsFixed() const { return m_bboxIsFixed; }
559560
protected:
560561
bool debug_;
561562
bool initialized;
563+
bool m_bboxIsFixed{false};
562564

563565
virtual bool doAddObject(sofa::core::objectmodel::BaseComponent::SPtr obj, sofa::core::objectmodel::TypeOfInsertion insertionLocation= sofa::core::objectmodel::TypeOfInsertion::AtEnd);
564566
virtual bool doRemoveObject(sofa::core::objectmodel::BaseComponent::SPtr obj);

Sofa/framework/Simulation/Core/src/sofa/simulation/UpdateBoundingBoxVisitor.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Visitor::Result UpdateBoundingBoxVisitor::processNodeTopDown(Node* node)
4141
type::vector<BaseObject*>::iterator object;
4242
node->get<BaseObject>(&objectList,BaseContext::Local);
4343
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
44-
if(!node->f_bbox.isSet()) // bmarques: Without invalidating the bbox, the node's bbox will only be sized up, and never down with this visitor, to my understanding..
44+
if(!node->bboxIsFixed()) // bmarques: Without invalidating the bbox, the node's bbox will only be sized up, and never down with this visitor, to my understanding..
4545
nodeBBox->invalidate();
4646
for ( object = objectList.begin(); object != objectList.end(); ++object)
4747
{
@@ -53,22 +53,31 @@ Visitor::Result UpdateBoundingBoxVisitor::processNodeTopDown(Node* node)
5353
// if some objects does not participate to the bounding box where they should,
5454
// you should overload their computeBBox function to correct that
5555
(*object)->computeBBox(params, true);
56-
57-
nodeBBox->include((*object)->f_bbox.getValue());
56+
57+
if(!node->bboxIsFixed())
58+
nodeBBox->include((*object)->f_bbox.getValue());
5859
}
5960
node->f_bbox.endEdit();
6061
return RESULT_CONTINUE;
6162
}
6263

6364
void UpdateBoundingBoxVisitor::processNodeBottomUp(simulation::Node* node)
6465
{
65-
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
66-
Node::ChildIterator childNode;
67-
for( childNode = node->child.begin(); childNode!=node->child.end(); ++childNode)
66+
if(!node->bboxIsFixed())
6867
{
69-
nodeBBox->include((*childNode)->f_bbox.getValue());
68+
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
69+
Node::ChildIterator childNode;
70+
for( childNode = node->child.begin(); childNode!=node->child.end(); ++childNode)
71+
{
72+
nodeBBox->include((*childNode)->f_bbox.getValue());
73+
}
74+
node->f_bbox.endEdit();
7075
}
71-
node->f_bbox.endEdit();
76+
else
77+
{
78+
// the node bounding box is supposed to be fixed
79+
}
80+
7281
}
7382

7483
}

0 commit comments

Comments
 (0)