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

Visual::SetPose performance improvement / minor fixes #3350

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions gazebo/rendering/Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2142,8 +2142,7 @@ void Scene::PreRender()
ignition::math::Pose3d pose = msgs::ConvertIgn(pIter->second);
GZ_ASSERT(iter->second, "Visual pointer is NULL");
iter->second->SetPose(pose);
PoseMsgs_M::iterator prev = pIter++;
this->dataPtr->poseMsgs.erase(prev);
pIter = this->dataPtr->poseMsgs.erase(pIter);
}
else
++pIter;
Expand All @@ -2157,8 +2156,7 @@ void Scene::PreRender()
ignition::math::Pose3d pose = msgs::ConvertIgn(pIter->second);
lIter->second->SetPosition(pose.Pos());
lIter->second->SetRotation(pose.Rot());
auto prev = pIter++;
this->dataPtr->poseMsgs.erase(prev);
pIter = this->dataPtr->poseMsgs.erase(pIter);
}
else
++pIter;
Expand Down
20 changes: 17 additions & 3 deletions gazebo/rendering/Visual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ void Visual::Fini()
}
this->dataPtr->scene.reset();

dataPtr->poseElem.reset();

if (this->dataPtr->sdf)
this->dataPtr->sdf->Reset();
this->dataPtr->sdf.reset();
Expand Down Expand Up @@ -458,6 +460,7 @@ void Visual::Load()
}

// Set the pose of the scene node
this->dataPtr->poseElem.reset();
this->SetPose(pose);
this->dataPtr->initialRelativePose = pose;

Expand Down Expand Up @@ -1984,14 +1987,25 @@ void Visual::SetRotation(const ignition::math::Quaterniond &_rot)
this->dataPtr->sceneNode->setOrientation(
Ogre::Quaternion(_rot.W(), _rot.X(), _rot.Y(), _rot.Z()));

this->dataPtr->sdf->GetElement("pose")->Set(this->Pose());
if(!dataPtr->poseElem)
{
dataPtr->poseElem = this->dataPtr->sdf->GetElement("pose");
}

dataPtr->poseElem->Set(this->Pose());
}

//////////////////////////////////////////////////
void Visual::SetPose(const ignition::math::Pose3d &_pose)
{
this->SetPosition(_pose.Pos());
this->SetRotation(_pose.Rot());
this->dataPtr->sceneNode->setPosition(_pose.Pos().X(), _pose.Pos().Y(), _pose.Pos().Z());
this->dataPtr->sceneNode->setOrientation(
Ogre::Quaternion(_pose.Rot().W(), _pose.Rot().X(), _pose.Rot().Y(), _pose.Rot().Z()));
if(!dataPtr->poseElem)
{
dataPtr->poseElem = this->dataPtr->sdf->GetElement("pose");
}
dataPtr->poseElem->Set(this->Pose());
}

//////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions gazebo/rendering/VisualPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace gazebo

/// \brief The SDF element for the visual.
public: sdf::ElementPtr sdf;
public: sdf::ElementPtr poseElem;

/// \brief The unique name for the visual's material.
public: std::string myMaterialName;
Expand Down