24
24
#include < utility>
25
25
#include < vector>
26
26
27
- #include < sdf/Link.hh>
28
- #include < sdf/Model.hh>
29
-
30
27
#include < gz/common/Console.hh>
31
28
#include < gz/common/Profiler.hh>
32
29
33
30
#include < gz/plugin/Register.hh>
34
31
35
- #include < gz/math/Vector3.hh>
36
32
#include < gz/math/Pose3.hh>
37
33
38
34
#include < gz/transport/Node.hh>
43
39
#include < gz/gui/MainWindow.hh>
44
40
45
41
#include " gz/sim/components/Name.hh"
46
- #include " gz/sim/components/World .hh"
42
+ #include " gz/sim/components/ParentEntity .hh"
47
43
#include " gz/sim/EntityComponentManager.hh"
48
44
#include " gz/sim/Entity.hh"
49
45
#include " gz/sim/rendering/RenderUtil.hh"
54
50
#include " gz/rendering/Scene.hh"
55
51
#include " gz/rendering/FrustumVisual.hh"
56
52
57
- #include " gz/sim/components/Link.hh"
58
- #include " gz/sim/components/Sensor.hh"
59
- #include " gz/sim/components/Model.hh"
60
- #include " gz/sim/components/ParentEntity.hh"
61
- #include " gz/sim/components/Pose.hh"
62
53
#include " gz/sim/Util.hh"
63
54
64
55
namespace gz
@@ -80,16 +71,13 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
80
71
public: rendering::FrustumVisualPtr frustum;
81
72
82
73
// / \brief URI sequence to the frustum link
83
- public: std::string frustumString{" " };
84
-
85
- // / \brief LaserScan message from sensor
86
- public: msgs::LogicalCameraSensor msg;
74
+ public: std::string frustumString;
87
75
88
76
// / \brief Pose of the frustum visual
89
77
public: math::Pose3d frustumPose{math::Pose3d::Zero};
90
78
91
79
// / \brief Topic name to subscribe
92
- public: std::string topicName{ " " } ;
80
+ public: std::string topicName;
93
81
94
82
// / \brief List of topics publishing LogicalCameraSensor messages.
95
83
public: QStringList topicList;
@@ -99,7 +87,6 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
99
87
100
88
// / \brief Mutex for variable mutated by the checkbox
101
89
// / callbacks.
102
- // / The variables are: msg
103
90
public: std::mutex serviceMutex;
104
91
105
92
// / \brief Initialization flag
@@ -125,7 +112,6 @@ using namespace sim;
125
112
VisualizeFrustum::VisualizeFrustum ()
126
113
: GuiSystem(), dataPtr(new VisualizeFrustumPrivate)
127
114
{
128
- // no ops
129
115
}
130
116
131
117
// ///////////////////////////////////////////////
@@ -138,43 +124,13 @@ VisualizeFrustum::~VisualizeFrustum()
138
124
// ///////////////////////////////////////////////
139
125
void VisualizeFrustum::LoadFrustum ()
140
126
{
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 );
127
+ auto scene = rendering::sceneFromFirstRenderEngine ();
167
128
if (!scene)
168
129
{
169
130
gzerr << " Internal error: scene is null." << std::endl;
170
131
return ;
171
132
}
172
133
173
- if (!scene->IsInitialized () || scene->VisualCount () == 0 )
174
- {
175
- return ;
176
- }
177
-
178
134
// Create frustum visual
179
135
gzdbg << " Creating frustum visual" << std::endl;
180
136
auto root = scene->RootVisual ();
@@ -254,17 +210,17 @@ bool VisualizeFrustum::eventFilter(QObject *_obj, QEvent *_event)
254
210
void VisualizeFrustum::Update (const UpdateInfo &,
255
211
EntityComponentManager &_ecm)
256
212
{
257
- GZ_PROFILE (" VisualizeFrusum ::Update" );
213
+ GZ_PROFILE (" VisualizeFrustum ::Update" );
258
214
259
215
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
260
216
261
217
if (this ->dataPtr ->frustumEntityDirty )
262
218
{
263
- auto frustumURIVec = common::split (common::trimmed (
219
+ const auto frustumURIVec = common::split (common::trimmed (
264
220
this ->dataPtr ->frustumString ), " ::" );
265
- if (frustumURIVec.size () > 0 )
221
+ if (! frustumURIVec.empty () )
266
222
{
267
- auto baseEntity = _ecm.EntityByComponents (
223
+ const auto baseEntity = _ecm.EntityByComponents (
268
224
components::Name (frustumURIVec[0 ]));
269
225
if (!baseEntity)
270
226
{
@@ -277,22 +233,21 @@ void VisualizeFrustum::Update(const UpdateInfo &,
277
233
{
278
234
auto parent = baseEntity;
279
235
bool success = false ;
280
- for (size_t i = 0u ; i < frustumURIVec.size ()-1 ; i++ )
236
+ for (size_t i = 0u ; i < frustumURIVec.size ()-1 ; ++i )
281
237
{
282
- auto children = _ecm.EntitiesByComponents (
238
+ const auto children = _ecm.EntitiesByComponents (
283
239
components::ParentEntity (parent));
284
240
bool foundChild = false ;
285
- for (auto child : children)
241
+ for (const auto child : children)
286
242
{
287
- std::string nextstring = frustumURIVec[i+1 ];
243
+ const auto & nextstring = frustumURIVec[i+1 ];
288
244
auto comp = _ecm.Component <components::Name>(child);
289
245
if (!comp)
290
246
{
291
247
continue ;
292
248
}
293
- std::string childname = std::string (
294
- comp->Data ());
295
- if (nextstring.compare (childname) == 0 )
249
+ const auto &childname = comp->Data ();
250
+ if (nextstring == childname)
296
251
{
297
252
parent = child;
298
253
foundChild = true ;
@@ -322,7 +277,7 @@ void VisualizeFrustum::Update(const UpdateInfo &,
322
277
// Only update frustumPose if the frustumEntity exists and the frustum is
323
278
// initialized and the sensor message is yet to arrive.
324
279
//
325
- // If we update the worldpose on the physics thread **after** the sensor
280
+ // If we update the worldPose on the physics thread **after** the sensor
326
281
// data arrives, the visual is offset from the obstacle if the sensor is
327
282
// moving fast.
328
283
if (!this ->dataPtr ->frustumEntityDirty && this ->dataPtr ->initialized &&
@@ -364,7 +319,7 @@ void VisualizeFrustum::DisplayVisual(bool _value)
364
319
{
365
320
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
366
321
this ->dataPtr ->frustum ->SetVisible (_value);
367
- gzerr << " Frustum Visual Display " << (( _value) ? " ON." : " OFF." )
322
+ gzdbg << " Frustum Visual Display " << (_value ? " ON." : " OFF." )
368
323
<< std::endl;
369
324
}
370
325
@@ -377,12 +332,12 @@ void VisualizeFrustum::OnRefresh()
377
332
// Get updated list
378
333
std::vector<std::string> allTopics;
379
334
this ->dataPtr ->node .TopicList (allTopics);
380
- for (auto topic : allTopics)
335
+ for (const auto & topic : allTopics)
381
336
{
382
337
std::vector<transport::MessagePublisher> publishers;
383
338
std::vector<transport::MessagePublisher> subscribers;
384
339
this ->dataPtr ->node .TopicInfo (topic, publishers, subscribers);
385
- for (auto pub : publishers)
340
+ for (const auto & pub : publishers)
386
341
{
387
342
if (pub.MsgTypeName () == " gz.msgs.LogicalCameraSensor" )
388
343
{
@@ -391,7 +346,7 @@ void VisualizeFrustum::OnRefresh()
391
346
}
392
347
}
393
348
}
394
- if (this ->dataPtr ->topicList .size () > 0 )
349
+ if (! this ->dataPtr ->topicList .empty () )
395
350
{
396
351
this ->OnTopic (this ->dataPtr ->topicList .at (0 ));
397
352
}
@@ -418,21 +373,19 @@ void VisualizeFrustum::OnScan(const msgs::LogicalCameraSensor &_msg)
418
373
std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
419
374
if (this ->dataPtr ->initialized )
420
375
{
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 ());
376
+ this ->dataPtr ->frustum ->SetNearClipPlane (_msg.near_clip ());
377
+ this ->dataPtr ->frustum ->SetFarClipPlane (_msg.far_clip ());
378
+ this ->dataPtr ->frustum ->SetHFOV (_msg.horizontal_fov ());
379
+ this ->dataPtr ->frustum ->SetAspectRatio (_msg.aspect_ratio ());
427
380
428
381
this ->dataPtr ->visualDirty = true ;
429
382
430
- for (auto data_values : this -> dataPtr -> msg .header ().data ())
383
+ for (const auto & data_values : _msg .header ().data ())
431
384
{
432
385
if (data_values.key () == " frame_id" )
433
386
{
434
- if (this ->dataPtr ->frustumString . compare (
435
- common::trimmed (data_values.value (0 ))) != 0 )
387
+ if (this ->dataPtr ->frustumString !=
388
+ common::trimmed (data_values.value (0 )))
436
389
{
437
390
this ->dataPtr ->frustumString = common::trimmed (data_values.value (0 ));
438
391
this ->dataPtr ->frustumEntityDirty = true ;
0 commit comments