@@ -80,7 +80,7 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
80
80
public: rendering::FrustumVisualPtr frustum;
81
81
82
82
// / \brief URI sequence to the frustum link
83
- public: std::string frustumString{ " " } ;
83
+ public: std::string frustumString;
84
84
85
85
// / \brief LaserScan message from sensor
86
86
public: msgs::LogicalCameraSensor msg;
@@ -89,7 +89,7 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
89
89
public: math::Pose3d frustumPose{math::Pose3d::Zero};
90
90
91
91
// / \brief Topic name to subscribe
92
- public: std::string topicName{ " " } ;
92
+ public: std::string topicName;
93
93
94
94
// / \brief List of topics publishing LogicalCameraSensor messages.
95
95
public: QStringList topicList;
@@ -125,7 +125,6 @@ using namespace sim;
125
125
VisualizeFrustum::VisualizeFrustum ()
126
126
: GuiSystem(), dataPtr(new VisualizeFrustumPrivate)
127
127
{
128
- // no ops
129
128
}
130
129
131
130
// ///////////////////////////////////////////////
@@ -138,43 +137,13 @@ VisualizeFrustum::~VisualizeFrustum()
138
137
// ///////////////////////////////////////////////
139
138
void VisualizeFrustum::LoadFrustum ()
140
139
{
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 );
140
+ auto scene = rendering::sceneFromFirstRenderEngine ();
167
141
if (!scene)
168
142
{
169
143
gzerr << " Internal error: scene is null." << std::endl;
170
144
return ;
171
145
}
172
146
173
- if (!scene->IsInitialized () || scene->VisualCount () == 0 )
174
- {
175
- return ;
176
- }
177
-
178
147
// Create frustum visual
179
148
gzdbg << " Creating frustum visual" << std::endl;
180
149
auto root = scene->RootVisual ();
@@ -254,17 +223,17 @@ bool VisualizeFrustum::eventFilter(QObject *_obj, QEvent *_event)
254
223
void VisualizeFrustum::Update (const UpdateInfo &,
255
224
EntityComponentManager &_ecm)
256
225
{
257
- GZ_PROFILE (" VisualizeFrusum ::Update" );
226
+ GZ_PROFILE (" VisualizeFrustum ::Update" );
258
227
259
228
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
260
229
261
230
if (this ->dataPtr ->frustumEntityDirty )
262
231
{
263
- auto frustumURIVec = common::split (common::trimmed (
232
+ const auto frustumURIVec = common::split (common::trimmed (
264
233
this ->dataPtr ->frustumString ), " ::" );
265
- if (frustumURIVec.size () > 0 )
234
+ if (! frustumURIVec.empty () )
266
235
{
267
- auto baseEntity = _ecm.EntityByComponents (
236
+ const auto baseEntity = _ecm.EntityByComponents (
268
237
components::Name (frustumURIVec[0 ]));
269
238
if (!baseEntity)
270
239
{
@@ -277,22 +246,21 @@ void VisualizeFrustum::Update(const UpdateInfo &,
277
246
{
278
247
auto parent = baseEntity;
279
248
bool success = false ;
280
- for (size_t i = 0u ; i < frustumURIVec.size ()-1 ; i++ )
249
+ for (size_t i = 0u ; i < frustumURIVec.size ()-1 ; ++i )
281
250
{
282
- auto children = _ecm.EntitiesByComponents (
251
+ const auto children = _ecm.EntitiesByComponents (
283
252
components::ParentEntity (parent));
284
253
bool foundChild = false ;
285
- for (auto child : children)
254
+ for (const auto child : children)
286
255
{
287
- std::string nextstring = frustumURIVec[i+1 ];
256
+ const auto & nextstring = frustumURIVec[i+1 ];
288
257
auto comp = _ecm.Component <components::Name>(child);
289
258
if (!comp)
290
259
{
291
260
continue ;
292
261
}
293
- std::string childname = std::string (
294
- comp->Data ());
295
- if (nextstring.compare (childname) == 0 )
262
+ const auto &childname = comp->Data ();
263
+ if (nextstring == childname)
296
264
{
297
265
parent = child;
298
266
foundChild = true ;
@@ -322,7 +290,7 @@ void VisualizeFrustum::Update(const UpdateInfo &,
322
290
// Only update frustumPose if the frustumEntity exists and the frustum is
323
291
// initialized and the sensor message is yet to arrive.
324
292
//
325
- // If we update the worldpose on the physics thread **after** the sensor
293
+ // If we update the worldPose on the physics thread **after** the sensor
326
294
// data arrives, the visual is offset from the obstacle if the sensor is
327
295
// moving fast.
328
296
if (!this ->dataPtr ->frustumEntityDirty && this ->dataPtr ->initialized &&
@@ -364,7 +332,7 @@ void VisualizeFrustum::DisplayVisual(bool _value)
364
332
{
365
333
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
366
334
this ->dataPtr ->frustum ->SetVisible (_value);
367
- gzerr << " Frustum Visual Display " << (( _value) ? " ON." : " OFF." )
335
+ gzdbg << " Frustum Visual Display " << (_value ? " ON." : " OFF." )
368
336
<< std::endl;
369
337
}
370
338
@@ -377,12 +345,12 @@ void VisualizeFrustum::OnRefresh()
377
345
// Get updated list
378
346
std::vector<std::string> allTopics;
379
347
this ->dataPtr ->node .TopicList (allTopics);
380
- for (auto topic : allTopics)
348
+ for (const auto & topic : allTopics)
381
349
{
382
350
std::vector<transport::MessagePublisher> publishers;
383
351
std::vector<transport::MessagePublisher> subscribers;
384
352
this ->dataPtr ->node .TopicInfo (topic, publishers, subscribers);
385
- for (auto pub : publishers)
353
+ for (const auto & pub : publishers)
386
354
{
387
355
if (pub.MsgTypeName () == " gz.msgs.LogicalCameraSensor" )
388
356
{
@@ -391,7 +359,7 @@ void VisualizeFrustum::OnRefresh()
391
359
}
392
360
}
393
361
}
394
- if (this ->dataPtr ->topicList .size () > 0 )
362
+ if (! this ->dataPtr ->topicList .empty () )
395
363
{
396
364
this ->OnTopic (this ->dataPtr ->topicList .at (0 ));
397
365
}
@@ -418,21 +386,19 @@ void VisualizeFrustum::OnScan(const msgs::LogicalCameraSensor &_msg)
418
386
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
419
387
if (this ->dataPtr ->initialized )
420
388
{
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 ());
389
+ this ->dataPtr ->frustum ->SetNearClipPlane (_msg.near_clip ());
390
+ this ->dataPtr ->frustum ->SetFarClipPlane (_msg.far_clip ());
391
+ this ->dataPtr ->frustum ->SetHFOV (_msg.horizontal_fov ());
392
+ this ->dataPtr ->frustum ->SetAspectRatio (_msg.aspect_ratio ());
427
393
428
394
this ->dataPtr ->visualDirty = true ;
429
395
430
- for (auto data_values : this -> dataPtr -> msg .header ().data ())
396
+ for (const auto & data_values : _msg .header ().data ())
431
397
{
432
398
if (data_values.key () == " frame_id" )
433
399
{
434
- if (this ->dataPtr ->frustumString . compare (
435
- common::trimmed (data_values.value (0 ))) != 0 )
400
+ if (this ->dataPtr ->frustumString !=
401
+ common::trimmed (data_values.value (0 )))
436
402
{
437
403
this ->dataPtr ->frustumString = common::trimmed (data_values.value (0 ));
438
404
this ->dataPtr ->frustumEntityDirty = true ;
0 commit comments