Skip to content

Commit

Permalink
Fixed lifetime markers
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Jul 7, 2021
1 parent 0ed2d8e commit 48108e2
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/plugins/marker_manager/MarkerManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class ignition::gui::plugins::MarkerManagerPrivate
/// \brief Sim time according to world stats message
public: std::chrono::steady_clock::duration simTime;

/// \brief Previous sim time received
public: std::chrono::steady_clock::duration lastSimTime;

/// \brief The last marker message received
public: ignition::msgs::Marker msg;
};
Expand Down Expand Up @@ -177,7 +180,7 @@ void MarkerManagerPrivate::Initialize()
igndbg << "Advertise " << this->topicName << "_array.\n";

// World name from window, to construct default topics and services
std::string worldName;
std::string worldName = "example";
auto worldNames = gui::worldNames();
if (!worldNames.empty())
worldName = worldNames[0].toStdString();
Expand Down Expand Up @@ -221,6 +224,40 @@ void MarkerManagerPrivate::OnRender()
this->ProcessMarkerMsg(*markerIter);
this->markerMsgs.erase(markerIter++);
}

// Erase any markers that have a lifetime.
for (auto mit = this->visuals.begin();
mit != this->visuals.end();)
{
for (auto it = mit->second.cbegin();
it != mit->second.cend(); ++it)
{
if (it->second->GeometryCount() == 0u)
continue;

ignition::rendering::MarkerPtr markerPtr =
std::dynamic_pointer_cast<ignition::rendering::Marker>
(it->second->GeometryByIndex(0u));
if (markerPtr != nullptr)
{
if (markerPtr->Lifetime().count() != 0 &&
(markerPtr->Lifetime() <= this->simTime ||
this->simTime < this->lastSimTime))
{
this->scene->DestroyVisual(it->second);
it = mit->second.erase(it);
break;
}
}
}

// Erase a namespace if it's empty
if (mit->second.empty())
mit = this->visuals.erase(mit);
else
++mit;
}
this->lastSimTime = this->simTime;
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 48108e2

Please sign in to comment.