Skip to content

Commit

Permalink
Adapt to lack of optional fields in proto3 syntax
Browse files Browse the repository at this point in the history
With new version of ignition-msgs, proto3 syntax is used,
which does not support optional fields for primitive
datatypes. Instead of checking `has_*()`, check instead
if the value is 0, false, or empty ''.
  • Loading branch information
scpeters committed Dec 3, 2020
1 parent b855c65 commit c747432
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
3 changes: 1 addition & 2 deletions delphyne-gui/visualizer/playback_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace gui {
namespace {

std::chrono::nanoseconds TimeToChrono(const ignition::msgs::Time& src) {
return (std::chrono::seconds(src.has_sec() ? src.sec() : 0) +
std::chrono::nanoseconds(src.has_nsec() ? src.nsec() : 0));
return (std::chrono::seconds(src.sec()) + std::chrono::nanoseconds(src.nsec()));
}

void ChronoToDuration(const std::chrono::nanoseconds& src, ignition::msgs::Duration* dst) {
Expand Down
54 changes: 15 additions & 39 deletions delphyne-gui/visualizer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,17 @@ bool RenderWidget::CreateVisual(const ignition::msgs::Visual& _vis, ignition::re
const auto& material = _vis.material();
if (material.has_diffuse()) {
const auto& diffuse = material.diffuse();
if (diffuse.has_r() && diffuse.has_g() && diffuse.has_b()) {
_material->SetDiffuse(diffuse.r(), diffuse.g(), diffuse.b());
}
_material->SetDiffuse(diffuse.r(), diffuse.g(), diffuse.b());

const auto& ambient = material.ambient();
if (ambient.has_r() && ambient.has_g() && ambient.has_b()) {
_material->SetAmbient(ambient.r(), ambient.g(), ambient.b());
}
_material->SetAmbient(ambient.r(), ambient.g(), ambient.b());

const auto& specular = material.specular();
if (specular.has_r() && specular.has_g() && specular.has_b()) {
_material->SetSpecular(specular.r(), specular.g(), specular.b());
}
_material->SetSpecular(specular.r(), specular.g(), specular.b());
}
}

if (_vis.has_transparency()) {
_material->SetTransparency(_vis.transparency());
}
_material->SetTransparency(_vis.transparency());

_material->SetShininess(50);
_material->SetReflectivity(0);
Expand Down Expand Up @@ -321,11 +315,9 @@ ignition::rendering::VisualPtr RenderWidget::RenderSphere(const ignition::msgs::
ignition::rendering::MaterialPtr& _material) {
ignition::math::Vector3d scale = ignition::math::Vector3d::One;
auto geomSphere = _vis.geometry().sphere();
if (geomSphere.has_radius()) {
scale.X() *= geomSphere.radius();
scale.Y() *= geomSphere.radius();
scale.Z() *= geomSphere.radius();
}
scale.X() *= geomSphere.radius();
scale.Y() *= geomSphere.radius();
scale.Z() *= geomSphere.radius();

_visual->AddGeometry(this->scene->CreateSphere());
this->Render(_vis, scale, _material, _visual);
Expand All @@ -338,13 +330,9 @@ ignition::rendering::VisualPtr RenderWidget::RenderCylinder(const ignition::msgs
ignition::rendering::MaterialPtr& _material) {
ignition::math::Vector3d scale = ignition::math::Vector3d::One;
auto geomCylinder = _vis.geometry().cylinder();
if (geomCylinder.has_radius()) {
scale.X() *= 2 * geomCylinder.radius();
scale.Y() *= 2 * geomCylinder.radius();
}
if (geomCylinder.has_length()) {
scale.Z() = geomCylinder.length();
}
scale.X() *= 2 * geomCylinder.radius();
scale.Y() *= 2 * geomCylinder.radius();
scale.Z() = geomCylinder.length();

_visual->AddGeometry(this->scene->CreateCylinder());
this->Render(_vis, scale, _material, _visual);
Expand All @@ -362,7 +350,7 @@ ignition::rendering::VisualPtr RenderWidget::RenderMesh(const ignition::msgs::Vi
ignerr << "Unable to find mesh in message" << std::endl;
}

if (!_vis.geometry().mesh().has_filename()) {
if (_vis.geometry().mesh().filename().empty()) {
ignerr << "Unable to find filename in message" << std::endl;
}

Expand Down Expand Up @@ -466,17 +454,11 @@ ignition::rendering::VisualPtr RenderWidget::CreateLinkRootVisual(ignition::msgs

/////////////////////////////////////////////////
void RenderWidget::LoadModel(const ignition::msgs::Model& _msg) {
// Sanity check: It's required to have a model Id.
if (!_msg.has_id()) {
ignerr << "Skipping model without id" << std::endl;
return;
}

for (int i = 0; i < _msg.link_size(); ++i) {
auto link = _msg.link(i);

// Sanity check: Verify that the link contains the required name.
if (!link.has_name()) {
if (link.name().empty()) {
ignerr << "No name on link, skipping" << std::endl;
continue;
}
Expand Down Expand Up @@ -547,17 +529,11 @@ void RenderWidget::UpdateScene(const ignition::msgs::Model_V& _msg) {
for (int j = 0; j < _msg.models_size(); ++j) {
auto model = _msg.models(j);

// Sanity check: It's required to have a model Id.
if (!model.has_id()) {
ignerr << "Skipping model without id" << std::endl;
continue;
}

for (int i = 0; i < model.link_size(); ++i) {
auto link = model.link(i);

// Sanity check: It's required to have a link name.
if (!link.has_name()) {
if (link.name().empty()) {
ignerr << "Skipping link without name" << std::endl;
continue;
}
Expand Down

0 comments on commit c747432

Please sign in to comment.