Skip to content

Commit c3218a2

Browse files
committed
Add camera optical_frame_id element
1 parent b59f6e1 commit c3218a2

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

include/sdf/Camera.hh

+14
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,20 @@ namespace sdf
348348
/// \param[in] _frame The name of the pose relative-to frame.
349349
public: void SetPoseRelativeTo(const std::string &_frame);
350350

351+
/// \brief Get the name of the coordinate frame relative to which this
352+
/// object's camera_info message header is expressed.
353+
/// Note: while Gazebo interprets the camera frame to be looking towards +X,
354+
/// other tools, such as ROS interprets this frame as looking towards +Z.
355+
/// The Camera sensor assumes that the color and depth images are captured at
356+
/// the same frame_id.
357+
/// \return The name of the frame this camera uses in its camera_info topic.
358+
public: const std::string OpticalFrameId() const;
359+
360+
/// \brief Set the name of the coordinate frame relative to which this
361+
/// object's camera_info is expressed.
362+
/// \param[in] _frame The frame this camera uses in its camera_info topic.
363+
public: void SetOpticalFrameId(const std::string &_frame);
364+
351365
/// \brief Get the lens type. This is the type of the lens mapping.
352366
/// Supported values are gnomonical, stereographic, equidistant,
353367
/// equisolid_angle, orthographic, custom. For gnomonical (perspective)

sdf/1.7/camera.sdf

+4
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,9 @@
161161
<description><![CDATA[Visibility mask of a camera. When (camera's visibility_mask & visual's visibility_flags) evaluates to non-zero, the visual will be visible to the camera.]]></description>
162162
</element>
163163

164+
<element name="optical_frame_id" type="string" default="" required="0">
165+
<description>An optional frame id name to be used in the camera_info message header.</description>
166+
</element>
167+
164168
<include filename="pose.sdf" required="0"/>
165169
</element> <!-- End Camera -->

sdf/1.8/camera.sdf

+4
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,9 @@
161161
<description><![CDATA[Visibility mask of a camera. When (camera's visibility_mask & visual's visibility_flags) evaluates to non-zero, the visual will be visible to the camera.]]></description>
162162
</element>
163163

164+
<element name="optical_frame_id" type="string" default="" required="0">
165+
<description>An optional frame id name to be used in the camera_info message header.</description>
166+
</element>
167+
164168
<include filename="pose.sdf" required="0"/>
165169
</element> <!-- End Camera -->

sdf/1.9/camera.sdf

+4
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,9 @@
196196
<description><![CDATA[Visibility mask of a camera. When (camera's visibility_mask & visual's visibility_flags) evaluates to non-zero, the visual will be visible to the camera.]]></description>
197197
</element>
198198

199+
<element name="optical_frame_id" type="string" default="" required="0">
200+
<description>An optional frame id name to be used in the camera_info message header.</description>
201+
</element>
202+
199203
<include filename="pose.sdf" required="0"/>
200204
</element> <!-- End Camera -->

src/Camera.cc

+26-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class sdf::Camera::Implementation
142142
/// \brief Frame of the pose.
143143
public: std::string poseRelativeTo = "";
144144

145+
/// \brief Frame ID the camera_info message header is expressed.
146+
public: std::string opticalFrameId{""};
147+
145148
/// \brief Lens type.
146149
public: std::string lensType{"stereographic"};
147150

@@ -348,6 +351,13 @@ Errors Camera::Load(ElementPtr _sdf)
348351
// Load the pose. Ignore the return value since the pose is optional.
349352
loadPose(_sdf, this->dataPtr->pose, this->dataPtr->poseRelativeTo);
350353

354+
// Load the optional optical_frame_id value.
355+
if (_sdf->HasElement("optical_frame_id"))
356+
{
357+
this->dataPtr->opticalFrameId = _sdf->Get<std::string>("optical_frame_id",
358+
this->dataPtr->opticalFrameId).first;
359+
}
360+
351361
// Load the lens values.
352362
if (_sdf->HasElement("lens"))
353363
{
@@ -692,7 +702,8 @@ bool Camera::operator==(const Camera &_cam) const
692702
this->SaveFrames() == _cam.SaveFrames() &&
693703
this->SaveFramesPath() == _cam.SaveFramesPath() &&
694704
this->ImageNoise() == _cam.ImageNoise() &&
695-
this->VisibilityMask() == _cam.VisibilityMask();
705+
this->VisibilityMask() == _cam.VisibilityMask() &&
706+
this->OpticalFrameId() == _cam.OpticalFrameId();
696707
}
697708

698709
//////////////////////////////////////////////////
@@ -809,6 +820,18 @@ void Camera::SetPoseRelativeTo(const std::string &_frame)
809820
this->dataPtr->poseRelativeTo = _frame;
810821
}
811822

823+
/////////////////////////////////////////////////
824+
const std::string Camera::OpticalFrameId() const
825+
{
826+
return this->dataPtr->opticalFrameId;
827+
}
828+
829+
/////////////////////////////////////////////////
830+
void Camera::SetOpticalFrameId(const std::string &_frame)
831+
{
832+
this->dataPtr->opticalFrameId = _frame;
833+
}
834+
812835
/////////////////////////////////////////////////
813836
std::string Camera::LensType() const
814837
{
@@ -1149,5 +1172,7 @@ sdf::ElementPtr Camera::ToElement() const
11491172
this->SegmentationType());
11501173
}
11511174

1175+
elem->GetElement("optical_frame_id")->Set<std::string>(this->OpticalFrameId());
1176+
11521177
return elem;
11531178
}

src/Camera_TEST.cc

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ TEST(DOMCamera, Construction)
130130
cam.SetPoseRelativeTo("/frame");
131131
EXPECT_EQ("/frame", cam.PoseRelativeTo());
132132

133+
EXPECT_TRUE(cam.OpticalFrameId().empty());
134+
cam.SetOpticalFrameId("/optical_frame");
135+
EXPECT_EQ("/optical_frame", cam.OpticalFrameId());
136+
133137
EXPECT_EQ("stereographic", cam.LensType());
134138
cam.SetLensType("custom");
135139
EXPECT_EQ("custom", cam.LensType());
@@ -240,6 +244,7 @@ TEST(DOMCamera, ToElement)
240244
cam.SetPoseRelativeTo("/frame");
241245
cam.SetSaveFrames(true);
242246
cam.SetSaveFramesPath("/tmp");
247+
cam.SetOpticalFrameId("/optical_frame");
243248

244249
sdf::ElementPtr camElem = cam.ToElement();
245250
EXPECT_NE(nullptr, camElem);
@@ -259,6 +264,7 @@ TEST(DOMCamera, ToElement)
259264
EXPECT_EQ("/frame", cam2.PoseRelativeTo());
260265
EXPECT_TRUE(cam2.SaveFrames());
261266
EXPECT_EQ("/tmp", cam2.SaveFramesPath());
267+
EXPECT_EQ("/optical_frame", cam2.OpticalFrameId());
262268

263269
// make changes to DOM and verify ToElement produces updated values
264270
cam2.SetNearClip(0.33);

0 commit comments

Comments
 (0)