Skip to content

Commit

Permalink
Remove inheritance from visual model; Remove the use of visitor for V…
Browse files Browse the repository at this point in the history
…isualStyle and instead call the fwdDraw directly in the two visualVisitor
  • Loading branch information
bakpaul committed Dec 11, 2024
1 parent 8f1aa1f commit dfaee87
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace sofa::component::visual
class SOFA_COMPONENT_VISUAL_API VisualStyle : public sofa::core::visual::BaseVisualStyle
{
public:
SOFA_CLASS(VisualStyle,sofa::core::visual::VisualModel);
SOFA_CLASS(VisualStyle,sofa::core::visual::BaseVisualStyle);

typedef sofa::core::visual::VisualParams VisualParams;
typedef sofa::core::visual::DisplayFlags DisplayFlags;
Expand Down
5 changes: 3 additions & 2 deletions Sofa/framework/Core/src/sofa/core/visual/BaseVisualStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ namespace sofa::core::visual
* Write the graph, starting from a root Node, into a std::ostream.
* The format is the DOT language from Graphviz (https://graphviz.org/)
*/
class SOFA_CORE_API BaseVisualStyle : public sofa::core::visual::VisualModel
class SOFA_CORE_API BaseVisualStyle : public sofa::core::objectmodel::BaseObject
{
public:
SOFA_CLASS(BaseVisualStyle,sofa::core::visual::VisualModel);
SOFA_CLASS(BaseVisualStyle,sofa::core::objectmodel::BaseObject);

typedef sofa::core::visual::VisualParams VisualParams;
typedef sofa::core::visual::DisplayFlags DisplayFlags;
Expand All @@ -47,6 +47,7 @@ class SOFA_CORE_API BaseVisualStyle : public sofa::core::visual::VisualModel

public:
virtual void fwdDraw(VisualParams* ) { };
virtual void bwdDraw(VisualParams* ) { };

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ void updateVisual(Node* root)

sofa::core::visual::VisualParams* vparams = sofa::core::visual::visualparams::defaultInstance();

VisualStyleVisitor act(vparams);
root->execute(act);

if (sofa::core::visual::VisualLoop* vloop = root->getVisualLoop())
{
vloop->updateStep(vparams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ Visitor::Result VisualVisitor::processNodeTopDown(simulation::Node* node)
}



Visitor::Result VisualStyleVisitor::processNodeTopDown(simulation::Node* node)
void VisualVisitor::fwdProcessVisualStyle(simulation::Node* node, core::visual::BaseVisualStyle* vm)
{
for_each(this, node, node->visualStyle, &VisualStyleVisitor::processVisualStyle);
return RESULT_CONTINUE;
vm-> fwdDraw(vparams);
}


void VisualStyleVisitor::processVisualStyle(simulation::Node* /*node*/, sofa::core::visual::BaseVisualStyle* o)
void VisualVisitor::bwdProcessVisualStyle(simulation::Node* node, core::visual::BaseVisualStyle* vm)
{
o-> fwdDraw(vparams);
vm-> bwdDraw(vparams);
}


Expand All @@ -66,6 +64,12 @@ Visitor::Result VisualDrawVisitor::processNodeTopDown(simulation::Node* node)
// which will most probably be the case when there are no visual models, so we skip the search unless we have visual models.
hasShader = !node->visualModel.empty() && (node->getShader()!=nullptr);

if(node->visualStyle.get())
{
fwdProcessVisualStyle(node,node->visualStyle.get());
}


for_each(this, node, node->visualModel, &VisualDrawVisitor::fwdVisualModel);

this->VisualVisitor::processNodeTopDown(node);
Expand All @@ -79,6 +83,12 @@ void VisualDrawVisitor::processNodeBottomUp(simulation::Node* node)
if (!vparams->displayFlags().getShowVisualModels())
return;

if(node->visualStyle.get())
{
bwdProcessVisualStyle(node,node->visualStyle.get());
}


for_each(this, node, node->visualModel, &VisualDrawVisitor::bwdVisualModel);
}

Expand Down Expand Up @@ -163,22 +173,27 @@ void VisualDrawVisitor::processVisualModel(simulation::Node* node, core::visual:

Visitor::Result VisualUpdateVisitor::processNodeTopDown(simulation::Node* node)
{
// for_each(this, node, node->visualModel, &VisualUpdateVisitor::fwdVisualModel);
//Necessary check for first draw
if(node->visualStyle.get())
{
fwdProcessVisualStyle(node,node->visualStyle.get());
}

for_each(this, node, node->visualModel, &VisualUpdateVisitor::processVisualModel);

return RESULT_CONTINUE;
}


void VisualUpdateVisitor::fwdVisualModel(simulation::Node* /*node*/, core::visual::VisualModel* vm)
void VisualUpdateVisitor::processNodeBottomUp(simulation::Node* node)
{
msg_info_when(DO_DEBUG_DRAW, vm) << " entering VisualVisitor::fwdVisualModel()" ;

vm->fwdDraw(vparams);

msg_info_when(DO_DEBUG_DRAW, vm) << " leaving VisualVisitor::fwdVisualModel()" ;
//Necessary check for first draw
if(node->visualStyle.get())
{
bwdProcessVisualStyle(node,node->visualStyle.get());
}
}


void VisualUpdateVisitor::processVisualModel(simulation::Node*, core::visual::VisualModel* vm)
{
helper::ScopedAdvancedTimer timer("VisualUpdateVisitor process: " + vm->getName());
Expand Down
26 changes: 3 additions & 23 deletions Sofa/framework/Simulation/Core/src/sofa/simulation/VisualVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SOFA_SIMULATION_CORE_API VisualVisitor : public Visitor
{}

virtual void processVisualModel(simulation::Node* node, core::visual::VisualModel* vm) = 0;
virtual void fwdProcessVisualStyle(simulation::Node* node, core::visual::BaseVisualStyle* vm);
virtual void bwdProcessVisualStyle(simulation::Node* node, core::visual::BaseVisualStyle* vm);
virtual void processObject(simulation::Node* /*node*/, core::objectmodel::BaseObject* /*o*/) {}

Result processNodeTopDown(simulation::Node* node) override;
Expand All @@ -55,28 +57,6 @@ class SOFA_SIMULATION_CORE_API VisualVisitor : public Visitor
core::visual::VisualParams* vparams;
};

class SOFA_SIMULATION_CORE_API VisualStyleVisitor : public Visitor
{
public:
VisualStyleVisitor(core::visual::VisualParams* params)
: Visitor(sofa::core::visual::visualparams::castToExecParams(params))
,vparams(params)
{}

Result processNodeTopDown(simulation::Node* node) override;
void processVisualStyle(simulation::Node* /*node*/, sofa::core::visual::BaseVisualStyle* o);

/// Return a category name for this action.
/// Only used for debugging / profiling purposes
const char* getCategoryName() const override { return "visual"; }
const char* getClassName() const override { return "VisualStyleVisitor"; }

/// visual visitor must be executed as a tree, such as forward and backward orders are coherent
bool treeTraversal(TreeTraversalRepetition& repeat) override { repeat=NO_REPETITION; return true; }

protected:
core::visual::VisualParams* vparams;
};

class SOFA_SIMULATION_CORE_API VisualDrawVisitor : public VisualVisitor
{
Expand All @@ -103,10 +83,10 @@ class SOFA_SIMULATION_CORE_API VisualUpdateVisitor : public VisualVisitor
VisualUpdateVisitor(core::visual::VisualParams* params)
: VisualVisitor(params)
{}
virtual void fwdVisualModel(simulation::Node* node, core::visual::VisualModel* vm);

virtual void processVisualModel(simulation::Node*, core::visual::VisualModel* vm) override;
Result processNodeTopDown(simulation::Node* node) override;
void processNodeBottomUp(simulation::Node* node) override;

const char* getClassName() const override { return "VisualUpdateVisitor"; }

Expand Down

0 comments on commit dfaee87

Please sign in to comment.