Skip to content

Commit 56a3bc1

Browse files
committed
Cleanup for Visualize Frustum
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
1 parent 4df5170 commit 56a3bc1

File tree

5 files changed

+26
-67
lines changed

5 files changed

+26
-67
lines changed

src/gui/plugins/global_illumination_civct/GlobalIlluminationCiVct.cc

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ GlobalIlluminationCiVct::GlobalIlluminationCiVct() :
161161
GuiSystem(),
162162
dataPtr(new GlobalIlluminationCiVctPrivate)
163163
{
164-
// no ops
165164
}
166165

167166
/////////////////////////////////////////////////

src/gui/plugins/global_illumination_vct/GlobalIlluminationVct.cc

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ GlobalIlluminationVct::GlobalIlluminationVct() :
155155
GuiSystem(),
156156
dataPtr(new GlobalIlluminationVctPrivate)
157157
{
158-
// no ops
159158
}
160159

161160
/////////////////////////////////////////////////

src/gui/plugins/visualize_frustum/VisualizeFrustum.cc

+25-63
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
8080
public: rendering::FrustumVisualPtr frustum;
8181

8282
/// \brief URI sequence to the frustum link
83-
public: std::string frustumString{""};
84-
85-
/// \brief LaserScan message from sensor
86-
public: msgs::LogicalCameraSensor msg;
83+
public: std::string frustumString;
8784

8885
/// \brief Pose of the frustum visual
8986
public: math::Pose3d frustumPose{math::Pose3d::Zero};
9087

9188
/// \brief Topic name to subscribe
92-
public: std::string topicName{""};
89+
public: std::string topicName;
9390

9491
/// \brief List of topics publishing LogicalCameraSensor messages.
9592
public: QStringList topicList;
@@ -99,7 +96,6 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
9996

10097
/// \brief Mutex for variable mutated by the checkbox
10198
/// callbacks.
102-
/// The variables are: msg
10399
public: std::mutex serviceMutex;
104100

105101
/// \brief Initialization flag
@@ -125,7 +121,6 @@ using namespace sim;
125121
VisualizeFrustum::VisualizeFrustum()
126122
: GuiSystem(), dataPtr(new VisualizeFrustumPrivate)
127123
{
128-
// no ops
129124
}
130125

131126
/////////////////////////////////////////////////
@@ -138,43 +133,13 @@ VisualizeFrustum::~VisualizeFrustum()
138133
/////////////////////////////////////////////////
139134
void VisualizeFrustum::LoadFrustum()
140135
{
141-
auto loadedEngNames = rendering::loadedEngines();
142-
if (loadedEngNames.empty())
143-
return;
144-
145-
// assume there is only one engine loaded
146-
auto engineName = loadedEngNames[0];
147-
if (loadedEngNames.size() > 1)
148-
{
149-
gzdbg << "More than one engine is available. "
150-
<< "VisualizeFrustum plugin will use engine ["
151-
<< engineName << "]" << std::endl;
152-
}
153-
auto engine = rendering::engine(engineName);
154-
if (!engine)
155-
{
156-
gzerr << "Internal error: failed to load engine [" << engineName
157-
<< "]. VisualizeFrustum plugin won't work." << std::endl;
158-
return;
159-
}
160-
161-
if (engine->SceneCount() == 0)
162-
return;
163-
164-
// assume there is only one scene
165-
// load scene
166-
auto scene = engine->SceneByIndex(0);
136+
auto scene = rendering::sceneFromFirstRenderEngine();
167137
if (!scene)
168138
{
169139
gzerr << "Internal error: scene is null." << std::endl;
170140
return;
171141
}
172142

173-
if (!scene->IsInitialized() || scene->VisualCount() == 0)
174-
{
175-
return;
176-
}
177-
178143
// Create frustum visual
179144
gzdbg << "Creating frustum visual" << std::endl;
180145
auto root = scene->RootVisual();
@@ -254,17 +219,17 @@ bool VisualizeFrustum::eventFilter(QObject *_obj, QEvent *_event)
254219
void VisualizeFrustum::Update(const UpdateInfo &,
255220
EntityComponentManager &_ecm)
256221
{
257-
GZ_PROFILE("VisualizeFrusum::Update");
222+
GZ_PROFILE("VisualizeFrustum::Update");
258223

259224
std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
260225

261226
if (this->dataPtr->frustumEntityDirty)
262227
{
263-
auto frustumURIVec = common::split(common::trimmed(
228+
const auto frustumURIVec = common::split(common::trimmed(
264229
this->dataPtr->frustumString), "::");
265-
if (frustumURIVec.size() > 0)
230+
if (!frustumURIVec.empty())
266231
{
267-
auto baseEntity = _ecm.EntityByComponents(
232+
const auto baseEntity = _ecm.EntityByComponents(
268233
components::Name(frustumURIVec[0]));
269234
if (!baseEntity)
270235
{
@@ -277,22 +242,21 @@ void VisualizeFrustum::Update(const UpdateInfo &,
277242
{
278243
auto parent = baseEntity;
279244
bool success = false;
280-
for (size_t i = 0u; i < frustumURIVec.size()-1; i++)
245+
for (size_t i = 0u; i < frustumURIVec.size()-1; ++i)
281246
{
282-
auto children = _ecm.EntitiesByComponents(
247+
const auto children = _ecm.EntitiesByComponents(
283248
components::ParentEntity(parent));
284249
bool foundChild = false;
285-
for (auto child : children)
250+
for (const auto child : children)
286251
{
287-
std::string nextstring = frustumURIVec[i+1];
252+
const auto &nextstring = frustumURIVec[i+1];
288253
auto comp = _ecm.Component<components::Name>(child);
289254
if (!comp)
290255
{
291256
continue;
292257
}
293-
std::string childname = std::string(
294-
comp->Data());
295-
if (nextstring.compare(childname) == 0)
258+
const auto &childname = comp->Data();
259+
if (nextstring == childname)
296260
{
297261
parent = child;
298262
foundChild = true;
@@ -322,7 +286,7 @@ void VisualizeFrustum::Update(const UpdateInfo &,
322286
// Only update frustumPose if the frustumEntity exists and the frustum is
323287
// initialized and the sensor message is yet to arrive.
324288
//
325-
// If we update the worldpose on the physics thread **after** the sensor
289+
// If we update the worldPose on the physics thread **after** the sensor
326290
// data arrives, the visual is offset from the obstacle if the sensor is
327291
// moving fast.
328292
if (!this->dataPtr->frustumEntityDirty && this->dataPtr->initialized &&
@@ -364,7 +328,7 @@ void VisualizeFrustum::DisplayVisual(bool _value)
364328
{
365329
std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
366330
this->dataPtr->frustum->SetVisible(_value);
367-
gzerr << "Frustum Visual Display " << ((_value) ? "ON." : "OFF.")
331+
gzdbg << "Frustum Visual Display " << (_value ? "ON." : "OFF.")
368332
<< std::endl;
369333
}
370334

@@ -377,12 +341,12 @@ void VisualizeFrustum::OnRefresh()
377341
// Get updated list
378342
std::vector<std::string> allTopics;
379343
this->dataPtr->node.TopicList(allTopics);
380-
for (auto topic : allTopics)
344+
for (const auto &topic : allTopics)
381345
{
382346
std::vector<transport::MessagePublisher> publishers;
383347
std::vector<transport::MessagePublisher> subscribers;
384348
this->dataPtr->node.TopicInfo(topic, publishers, subscribers);
385-
for (auto pub : publishers)
349+
for (const auto &pub : publishers)
386350
{
387351
if (pub.MsgTypeName() == "gz.msgs.LogicalCameraSensor")
388352
{
@@ -391,7 +355,7 @@ void VisualizeFrustum::OnRefresh()
391355
}
392356
}
393357
}
394-
if (this->dataPtr->topicList.size() > 0)
358+
if (!this->dataPtr->topicList.empty())
395359
{
396360
this->OnTopic(this->dataPtr->topicList.at(0));
397361
}
@@ -418,21 +382,19 @@ void VisualizeFrustum::OnScan(const msgs::LogicalCameraSensor &_msg)
418382
std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
419383
if (this->dataPtr->initialized)
420384
{
421-
this->dataPtr->msg = std::move(_msg);
422-
423-
this->dataPtr->frustum->SetNearClipPlane(this->dataPtr->msg.near_clip());
424-
this->dataPtr->frustum->SetFarClipPlane(this->dataPtr->msg.far_clip());
425-
this->dataPtr->frustum->SetHFOV(this->dataPtr->msg.horizontal_fov());
426-
this->dataPtr->frustum->SetAspectRatio(this->dataPtr->msg.aspect_ratio());
385+
this->dataPtr->frustum->SetNearClipPlane(_msg.near_clip());
386+
this->dataPtr->frustum->SetFarClipPlane(_msg.far_clip());
387+
this->dataPtr->frustum->SetHFOV(_msg.horizontal_fov());
388+
this->dataPtr->frustum->SetAspectRatio(_msg.aspect_ratio());
427389

428390
this->dataPtr->visualDirty = true;
429391

430-
for (auto data_values : this->dataPtr->msg.header().data())
392+
for (const auto &data_values : _msg.header().data())
431393
{
432394
if (data_values.key() == "frame_id")
433395
{
434-
if (this->dataPtr->frustumString.compare(
435-
common::trimmed(data_values.value(0))) != 0)
396+
if (this->dataPtr->frustumString !=
397+
common::trimmed(data_values.value(0)))
436398
{
437399
this->dataPtr->frustumString = common::trimmed(data_values.value(0));
438400
this->dataPtr->frustumEntityDirty = true;

src/gui/plugins/visualize_lidar/VisualizeLidar.cc

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ using namespace sim;
127127
VisualizeLidar::VisualizeLidar()
128128
: GuiSystem(), dataPtr(new VisualizeLidarPrivate)
129129
{
130-
// no ops
131130
}
132131

133132
/////////////////////////////////////////////////

src/systems/log/LogPlayback.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void LogPlaybackPrivate::ReplaceResourceURIs(EntityComponentManager &_ecm)
308308
// Define equality functions for replacing component uri
309309
auto uriEqual = [&](const std::string &_s1, const std::string &_s2) -> bool
310310
{
311-
return (_s1.compare(_s2) == 0);
311+
return _s1 == _s2;
312312
};
313313

314314
auto geoUriEqual = [&](const sdf::Geometry &_g1,

0 commit comments

Comments
 (0)