Skip to content

Commit ecb2681

Browse files
authored
Publish logical camera frustum info for frustum visualization
--------- Signed-off-by: Utkarsh <[email protected]>
1 parent cd283ae commit ecb2681

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

include/gz/sensors/LogicalCameraSensor.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ namespace gz
104104
/// \return True if there are subscribers, false otherwise
105105
public: virtual bool HasConnections() const override;
106106

107+
/// \brief Check if there are any image subscribers
108+
/// \return True if there are image subscribers, false otherwise
109+
public: virtual bool HasImageConnections() const;
110+
111+
/// \brief Check if there are any frustum subscribers
112+
/// \return True if there are info subscribers, false otherwise
113+
public: virtual bool HasFrustumConnections() const;
114+
107115
/// \brief Get the latest image. An image is an instance of
108116
/// msgs::LogicalCameraImage, which contains a list of detected models.
109117
/// \return List of detected models.

src/LogicalCameraSensor.cc

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ class gz::sensors::LogicalCameraSensorPrivate
3636
/// \brief node to create publisher
3737
public: transport::Node node;
3838

39+
/// \brief node to create publisher for frustum
40+
public: transport::Node nodeLogic;
41+
3942
/// \brief publisher to publish logical camera messages.
4043
public: transport::Node::Publisher pub;
4144

45+
/// \brief Publisher to publish logical camera frustum information
46+
public: transport::Node::Publisher pubLogic;
47+
4248
/// \brief true if Load() has been called and was successful
4349
public: bool initialized = false;
4450

@@ -55,7 +61,10 @@ class gz::sensors::LogicalCameraSensorPrivate
5561
public: std::map<std::string, math::Pose3d> models;
5662

5763
/// \brief Msg containg info on models detected by logical camera
58-
msgs::LogicalCameraImage msg;
64+
public: msgs::LogicalCameraImage msg;
65+
66+
/// \brief Msg containing logical camera frustum info
67+
public: msgs::LogicalCameraSensor msgLogic;
5968
};
6069

6170
//////////////////////////////////////////////////
@@ -110,12 +119,23 @@ bool LogicalCameraSensor::Load(sdf::ElementPtr _sdf)
110119
this->dataPtr->node.Advertise<msgs::LogicalCameraImage>(
111120
this->Topic());
112121

122+
this->dataPtr->pubLogic =
123+
this->dataPtr->nodeLogic.Advertise<msgs::LogicalCameraSensor>(
124+
this->Topic() + "/frustum");
125+
113126
if (!this->dataPtr->pub)
114127
{
115128
gzerr << "Unable to create publisher on topic[" << this->Topic() << "].\n";
116129
return false;
117130
}
118131

132+
if (!this->dataPtr->pubLogic)
133+
{
134+
gzerr << "Unable to create publisher on topic[" << this->Topic()
135+
<< "/frustum].\n";
136+
return false;
137+
}
138+
119139
gzdbg << "Logical images for [" << this->Name() << "] advertised on ["
120140
<< this->Topic() << "]" << std::endl;
121141

@@ -166,9 +186,25 @@ bool LogicalCameraSensor::Update(
166186
frame->set_key("frame_id");
167187
frame->add_value(this->FrameId());
168188

189+
*this->dataPtr->msgLogic.mutable_header()->mutable_stamp() =
190+
msgs::Convert(_now);
191+
this->dataPtr->msgLogic.mutable_header()->clear_data();
192+
auto frame_log = this->dataPtr->msgLogic.mutable_header()->add_data();
193+
194+
frame_log->set_key("frame_id");
195+
frame_log->add_value(this->FrameId());
196+
169197
// publish
198+
this->dataPtr->msgLogic.set_near_clip(this->dataPtr->frustum.Near());
199+
this->dataPtr->msgLogic.set_far_clip(this->dataPtr->frustum.Far());
200+
this->dataPtr->msgLogic.set_horizontal_fov(
201+
this->dataPtr->frustum.FOV().Radian());
202+
this->dataPtr->msgLogic.set_aspect_ratio(
203+
this->dataPtr->frustum.AspectRatio());
170204
this->AddSequence(this->dataPtr->msg.mutable_header());
205+
171206
this->dataPtr->pub.Publish(this->dataPtr->msg);
207+
this->dataPtr->pubLogic.Publish(this->dataPtr->msgLogic);
172208

173209
return true;
174210
}
@@ -206,7 +242,18 @@ msgs::LogicalCameraImage LogicalCameraSensor::Image() const
206242

207243
//////////////////////////////////////////////////
208244
bool LogicalCameraSensor::HasConnections() const
245+
{
246+
return this->HasImageConnections() || this->HasFrustumConnections();
247+
}
248+
249+
//////////////////////////////////////////////////
250+
bool LogicalCameraSensor::HasImageConnections() const
209251
{
210252
return this->dataPtr->pub && this->dataPtr->pub.HasConnections();
211253
}
212254

255+
//////////////////////////////////////////////////
256+
bool LogicalCameraSensor::HasFrustumConnections() const
257+
{
258+
return this->dataPtr->pubLogic && this->dataPtr->pubLogic.HasConnections();
259+
}

0 commit comments

Comments
 (0)