Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Fix display of Visual's scaleV #430

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

arntanguy
Copy link
Collaborator

This PR modifies mc_rtc::gui::Visual to publish the scaleV property (scale along x,y,z axes) instead of the scale property (global scale for all axes). This allows the display interface to properly display scaled meshes. For example:

  gui()->addElement({"Scale"},
        mc_rtc::gui::NumberSlider("x", [this]() { return scale.x(); }, [this](double x) { scale.x() = x; }, 0., 10.),
        mc_rtc::gui::NumberSlider("y", [this]() { return scale.y(); }, [this](double y) { scale.y() = y; }, 0, 10),
        mc_rtc::gui::NumberSlider("z", [this]() { return scale.z(); }, [this](double z) { scale.z() = z; }, 0, 10)
      );
  auto & robot = this->robot();
  for (auto & visual : const_cast<mc_rbdyn::RobotModule &>(robot.module())._visual)
  {
    for (size_t i = 0; i < visual.second.size(); i++)
    {
      auto & v = visual.second[i];
      gui()->addElement({"Human", "Visuals"},
          mc_rtc::gui::Visual(fmt::format("{}_{}", visual.first, i), [&v]() { return v;},
          [this, &robot, &v, &visual]() {
            if (v.geometry.type == rbd::parsers::Geometry::MESH)
            {
              auto & mesh = boost::get<rbd::parsers::Geometry::Mesh>(v.geometry.data);
              mesh.scaleV = scale;
            }
            return v.origin * robot.frame(visual.first).position();
          }));
    }
  }

This publishes all of the robot visuals and allows to rescale individiual axes of its meshes online. Note that this is displayed correctly in rviz, but currently not in magnum (as the scale is taken into account only at mesh creation).

In addition, I do not see the point of keeping both scale and scaleV properties. They are somewhat contradictory, and scaleV contains all of the necessary information. Thus I suggest the corresponding PR in RBDyn to remove scale.

Copy link
Member

@gergondet gergondet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arntanguy

No problem with this PR except for the small backward compatibility issue

In addition, I do not see the point of keeping both scale and scaleV properties. They are somewhat contradictory, and scaleV contains all of the necessary information. Thus I suggest the corresponding PR in RBDyn to remove scale

This was done to introduce the vector form of scale without breaking existing code but it should be fine to retire scale (as suggested in the RBDyn PR)

@@ -685,15 +685,15 @@ rbd::parsers::Geometry::Mesh ConfigurationLoader<rbd::parsers::Geometry::Mesh>::
{
rbd::parsers::Geometry::Mesh m;
m.filename = static_cast<std::string>(config("filename"));
m.scale = config("scale");
m.scaleV = config("scaleV");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it compatible if people update mc_rtc without updating the GUI implementations

Suggested change
m.scaleV = config("scaleV");
if(auto scale = config.find("scale"))
{
m.scale = scale->operator<double>();
m.scaleV.setConstant(m.scale);
}
else
{
m.scaleV = config("scaleV");
m.scale = m.scaleV(0);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m.scale won't exist after the RBDyn PR, so I'm not sure what you are suggesting here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes. I guess we can skip this then release a new version of mc_rtc that does not require scale and then release a version of RBDyn without scale?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as is it works without updating RBDyn, it's just less confusing not to have both properties in the future ;)

@gergondet
Copy link
Member

Thanks @arntanguy

If everything builds feel free to (in that order):

I'll release new versions of RBDyn/mc_rtc/mc_rtc_ros on Monday

@arntanguy arntanguy merged commit 15f2b8f into jrl-umi3218:master Feb 2, 2024
20 checks passed
gergondet added a commit that referenced this pull request Feb 5, 2024
Added
--

- [mc_rbdyn/GUI] Add helpers to visualize surfaces and convexes (#431)
- [mc_rtc/GUI] Added RobotMsg: a complete view of the robot state (#425)
- [mc_rtc] Add path helpers (#431)
- [utils/RobotVisualizer] Add a new tool to visualize a robot built on mc_rtc GUI (#431)

Changes
--

- [mc_rtc/GUI] Send scale vector for visual mesh instead of scalar (#430)

Fixes
--

- [mc_rbdyn] Always use default_attitude to initialize the attitude (#424)
- [mc_tasks] Clarify usage of targetSurface/targetFrame in ImpedanceTask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants