@@ -80,16 +80,13 @@ 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{" " };
84
-
85
- // / \brief LaserScan message from sensor
86
- public: msgs::LogicalCameraSensor msg;
83
+ public: std::string frustumString;
87
84
88
85
// / \brief Pose of the frustum visual
89
86
public: math::Pose3d frustumPose{math::Pose3d::Zero};
90
87
91
88
// / \brief Topic name to subscribe
92
- public: std::string topicName{ " " } ;
89
+ public: std::string topicName;
93
90
94
91
// / \brief List of topics publishing LogicalCameraSensor messages.
95
92
public: QStringList topicList;
@@ -99,7 +96,6 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
99
96
100
97
// / \brief Mutex for variable mutated by the checkbox
101
98
// / callbacks.
102
- // / The variables are: msg
103
99
public: std::mutex serviceMutex;
104
100
105
101
// / \brief Initialization flag
@@ -125,7 +121,6 @@ using namespace sim;
125
121
VisualizeFrustum::VisualizeFrustum ()
126
122
: GuiSystem(), dataPtr(new VisualizeFrustumPrivate)
127
123
{
128
- // no ops
129
124
}
130
125
131
126
// ///////////////////////////////////////////////
@@ -138,43 +133,13 @@ VisualizeFrustum::~VisualizeFrustum()
138
133
// ///////////////////////////////////////////////
139
134
void VisualizeFrustum::LoadFrustum ()
140
135
{
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 ();
167
137
if (!scene)
168
138
{
169
139
gzerr << " Internal error: scene is null." << std::endl;
170
140
return ;
171
141
}
172
142
173
- if (!scene->IsInitialized () || scene->VisualCount () == 0 )
174
- {
175
- return ;
176
- }
177
-
178
143
// Create frustum visual
179
144
gzdbg << " Creating frustum visual" << std::endl;
180
145
auto root = scene->RootVisual ();
@@ -254,17 +219,17 @@ bool VisualizeFrustum::eventFilter(QObject *_obj, QEvent *_event)
254
219
void VisualizeFrustum::Update (const UpdateInfo &,
255
220
EntityComponentManager &_ecm)
256
221
{
257
- GZ_PROFILE (" VisualizeFrusum ::Update" );
222
+ GZ_PROFILE (" VisualizeFrustum ::Update" );
258
223
259
224
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
260
225
261
226
if (this ->dataPtr ->frustumEntityDirty )
262
227
{
263
- auto frustumURIVec = common::split (common::trimmed (
228
+ const auto frustumURIVec = common::split (common::trimmed (
264
229
this ->dataPtr ->frustumString ), " ::" );
265
- if (frustumURIVec.size () > 0 )
230
+ if (! frustumURIVec.empty () )
266
231
{
267
- auto baseEntity = _ecm.EntityByComponents (
232
+ const auto baseEntity = _ecm.EntityByComponents (
268
233
components::Name (frustumURIVec[0 ]));
269
234
if (!baseEntity)
270
235
{
@@ -277,22 +242,21 @@ void VisualizeFrustum::Update(const UpdateInfo &,
277
242
{
278
243
auto parent = baseEntity;
279
244
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 )
281
246
{
282
- auto children = _ecm.EntitiesByComponents (
247
+ const auto children = _ecm.EntitiesByComponents (
283
248
components::ParentEntity (parent));
284
249
bool foundChild = false ;
285
- for (auto child : children)
250
+ for (const auto child : children)
286
251
{
287
- std::string nextstring = frustumURIVec[i+1 ];
252
+ const auto & nextstring = frustumURIVec[i+1 ];
288
253
auto comp = _ecm.Component <components::Name>(child);
289
254
if (!comp)
290
255
{
291
256
continue ;
292
257
}
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)
296
260
{
297
261
parent = child;
298
262
foundChild = true ;
@@ -322,7 +286,7 @@ void VisualizeFrustum::Update(const UpdateInfo &,
322
286
// Only update frustumPose if the frustumEntity exists and the frustum is
323
287
// initialized and the sensor message is yet to arrive.
324
288
//
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
326
290
// data arrives, the visual is offset from the obstacle if the sensor is
327
291
// moving fast.
328
292
if (!this ->dataPtr ->frustumEntityDirty && this ->dataPtr ->initialized &&
@@ -364,7 +328,7 @@ void VisualizeFrustum::DisplayVisual(bool _value)
364
328
{
365
329
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
366
330
this ->dataPtr ->frustum ->SetVisible (_value);
367
- gzerr << " Frustum Visual Display " << (( _value) ? " ON." : " OFF." )
331
+ gzdbg << " Frustum Visual Display " << (_value ? " ON." : " OFF." )
368
332
<< std::endl;
369
333
}
370
334
@@ -377,12 +341,12 @@ void VisualizeFrustum::OnRefresh()
377
341
// Get updated list
378
342
std::vector<std::string> allTopics;
379
343
this ->dataPtr ->node .TopicList (allTopics);
380
- for (auto topic : allTopics)
344
+ for (const auto & topic : allTopics)
381
345
{
382
346
std::vector<transport::MessagePublisher> publishers;
383
347
std::vector<transport::MessagePublisher> subscribers;
384
348
this ->dataPtr ->node .TopicInfo (topic, publishers, subscribers);
385
- for (auto pub : publishers)
349
+ for (const auto & pub : publishers)
386
350
{
387
351
if (pub.MsgTypeName () == " gz.msgs.LogicalCameraSensor" )
388
352
{
@@ -391,7 +355,7 @@ void VisualizeFrustum::OnRefresh()
391
355
}
392
356
}
393
357
}
394
- if (this ->dataPtr ->topicList .size () > 0 )
358
+ if (! this ->dataPtr ->topicList .empty () )
395
359
{
396
360
this ->OnTopic (this ->dataPtr ->topicList .at (0 ));
397
361
}
@@ -418,21 +382,19 @@ void VisualizeFrustum::OnScan(const msgs::LogicalCameraSensor &_msg)
418
382
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
419
383
if (this ->dataPtr ->initialized )
420
384
{
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 ());
427
389
428
390
this ->dataPtr ->visualDirty = true ;
429
391
430
- for (auto data_values : this -> dataPtr -> msg .header ().data ())
392
+ for (const auto & data_values : _msg .header ().data ())
431
393
{
432
394
if (data_values.key () == " frame_id" )
433
395
{
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 )))
436
398
{
437
399
this ->dataPtr ->frustumString = common::trimmed (data_values.value (0 ));
438
400
this ->dataPtr ->frustumEntityDirty = true ;
0 commit comments