Skip to content
Snippets Groups Projects
Commit 23af3dd8 authored by Fabian Paus's avatar Fabian Paus
Browse files

ArViz Performance: Do not create new nodes on every update call

parent 1a903e48
No related merge requests found
......@@ -4,8 +4,9 @@
#include <RobotAPI/interface/ArViz/Elements.h>
#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
#include <Inventor/nodes/SoComplexity.h>
#include <Inventor/nodes/SoScale.h>
#include <Inventor/nodes/SoSphere.h>
namespace armarx::viz::coin
{
......@@ -13,43 +14,33 @@ namespace armarx::viz::coin
{
using ElementType = data::ElementEllipsoid;
VisualizationEllipsoid()
{
complexity = new SoComplexity();
complexity->type.setValue(SoComplexity::OBJECT_SPACE);
complexity->value.setValue(1.0f);
scale = new SoScale;
sphere = new SoSphere();
// We create a unit sphere and create an ellipsoid through scaling
sphere->radius.setValue(1.0f);
node->addChild(complexity);
node->addChild(scale);
node->addChild(sphere);
}
bool update(ElementType const& element)
{
auto color = element.color;
constexpr float conv = 1.0f / 255.0f;
const float r = color.r * conv;
const float g = color.g * conv;
const float b = color.b * conv;
const float a = color.a * conv;
VirtualRobot::VisualizationNodePtr ellipsoid_node;
{
// Params.
SoMaterial* mat = new SoMaterial;
mat->diffuseColor.setValue(r, g, b);
mat->ambientColor.setValue(r, g, b);
mat->transparency.setValue(1. - a);
const bool show_axes = false; // Do not show axes. If needed, draw a Pose instead.
SoSeparator* res = new SoSeparator();
res->ref();
SoUnits* u = new SoUnits();
u->units = SoUnits::MILLIMETERS;
res->addChild(u);
res->addChild(VirtualRobot::CoinVisualizationFactory::CreateEllipse(
element.axisLengths.e0, element.axisLengths.e1,
element.axisLengths.e2, mat, show_axes));
ellipsoid_node.reset(new VirtualRobot::CoinVisualizationNode(res));
res->unref();
}
SoNode* ellipsoid = dynamic_cast<VirtualRobot::CoinVisualizationNode&>(
*ellipsoid_node).getCoinVisualization();
node->removeAllChildren();
node->addChild(ellipsoid);
scale->scaleFactor.setValue(element.axisLengths.e0, element.axisLengths.e1, element.axisLengths.e2);
return true;
}
SoMaterial* material = nullptr;
SoComplexity* complexity = nullptr;
SoScale* scale = nullptr;
SoSphere* sphere = nullptr;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment