Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ Visitor::Result InitVisitor::processNodeTopDown(simulation::Node* node)
node->initialize();

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

for(unsigned int i=0; i<node->object.size(); ++i)
{
node->object[i]->init();
node->object[i]->computeBBox(params, true);
nodeBBox->include(node->object[i]->f_bbox.getValue());
if(!node->bboxIsFixed())
nodeBBox->include(node->object[i]->f_bbox.getValue());
}
node->f_bbox.endEdit();
return RESULT_CONTINUE;
Expand All @@ -60,7 +61,8 @@ void InitVisitor::processNodeBottomUp(simulation::Node* node)
for(std::size_t i=node->object.size(); i>0; --i)
{
node->object[i-1]->bwdInit();
nodeBBox->include(node->object[i-1]->f_bbox.getValue());
if(!node->bboxIsFixed())
nodeBBox->include(node->object[i-1]->f_bbox.getValue());
}

node->f_bbox.endEdit();
Expand Down
7 changes: 7 additions & 0 deletions Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ void Node::parse( sofa::core::objectmodel::BaseObjectDescription* arg )
objDesc.setAttribute("displayFlags", oldFlags);
sofa::core::objectmodel::BaseComponent::SPtr obj = sofa::core::ObjectFactory::CreateObject(this, &objDesc);
}

// BoundingBox state management
const char* bboxAttrStr = arg->getAttribute("bbox", nullptr);
if(bboxAttrStr != nullptr)
{
this->m_bboxIsFixed = true;
}
}

/// Initialize the components of this node and all the nodes which depend on it.
Expand Down
4 changes: 3 additions & 1 deletion Sofa/framework/Simulation/Core/src/sofa/simulation/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,12 @@ class SOFA_SIMULATION_CORE_API Node : public sofa::core::objectmodel::BaseNode,

/// return the smallest common parent between this and node2 (returns nullptr if separated sub-graphes)
Node* findCommonParent( simulation::Node* node2 );


bool bboxIsFixed() const { return m_bboxIsFixed; }
protected:
bool debug_;
bool initialized;
bool m_bboxIsFixed{false};

virtual bool doAddObject(sofa::core::objectmodel::BaseComponent::SPtr obj, sofa::core::objectmodel::TypeOfInsertion insertionLocation= sofa::core::objectmodel::TypeOfInsertion::AtEnd);
virtual bool doRemoveObject(sofa::core::objectmodel::BaseComponent::SPtr obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Visitor::Result UpdateBoundingBoxVisitor::processNodeTopDown(Node* node)
type::vector<BaseObject*>::iterator object;
node->get<BaseObject>(&objectList,BaseContext::Local);
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
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..
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..
nodeBBox->invalidate();
for ( object = objectList.begin(); object != objectList.end(); ++object)
{
Expand All @@ -53,22 +53,31 @@ Visitor::Result UpdateBoundingBoxVisitor::processNodeTopDown(Node* node)
// if some objects does not participate to the bounding box where they should,
// you should overload their computeBBox function to correct that
(*object)->computeBBox(params, true);

nodeBBox->include((*object)->f_bbox.getValue());

if(!node->bboxIsFixed())
nodeBBox->include((*object)->f_bbox.getValue());
}
node->f_bbox.endEdit();
return RESULT_CONTINUE;
}

void UpdateBoundingBoxVisitor::processNodeBottomUp(simulation::Node* node)
{
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
Node::ChildIterator childNode;
for( childNode = node->child.begin(); childNode!=node->child.end(); ++childNode)
if(!node->bboxIsFixed())
{
nodeBBox->include((*childNode)->f_bbox.getValue());
sofa::type::BoundingBox* nodeBBox = node->f_bbox.beginEdit();
Node::ChildIterator childNode;
for( childNode = node->child.begin(); childNode!=node->child.end(); ++childNode)
{
nodeBBox->include((*childNode)->f_bbox.getValue());
}
node->f_bbox.endEdit();
}
node->f_bbox.endEdit();
else
{
// the node bounding box is supposed to be fixed
}

}

}
Loading