Gazebo Sensors

API Reference

6.9.0
gz/sensors/CameraSensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_SENSORS_CAMERASENSOR_HH_
18 #define GZ_SENSORS_CAMERASENSOR_HH_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 
24 #include <sdf/sdf.hh>
25 
26 #include <gz/common/SuppressWarning.hh>
27 
28 #ifdef _WIN32
29 #pragma warning(push)
30 #pragma warning(disable: 4005)
31 #pragma warning(disable: 4251)
32 #endif
33 #include <ignition/msgs.hh>
34 #ifdef _WIN32
35 #pragma warning(pop)
36 #endif
37 
38 // TODO(louise) Remove these pragmas once ign-rendering is disabling the
39 // warnings
40 #ifdef _WIN32
41 #pragma warning(push)
42 #pragma warning(disable: 4251)
43 #endif
44 #include <gz/rendering/Camera.hh>
45 #ifdef _WIN32
46 #pragma warning(pop)
47 #endif
48 
49 #include "gz/sensors/camera/Export.hh"
50 #include "gz/sensors/config.hh"
51 #include "gz/sensors/Export.hh"
53 
54 namespace ignition
55 {
56  namespace sensors
57  {
58  // Inline bracket to help doxygen filtering.
59  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
60  //
62  class CameraSensorPrivate;
63 
71  class IGNITION_SENSORS_CAMERA_VISIBLE CameraSensor : public RenderingSensor
72  {
74  public: CameraSensor();
75 
77  public: virtual ~CameraSensor();
78 
82  public: virtual bool Load(const sdf::Sensor &_sdf) override;
83 
87  public: virtual bool Load(sdf::ElementPtr _sdf) override;
88 
91  public: virtual bool Init() override;
92 
96  public: virtual bool Update(
97  const std::chrono::steady_clock::duration &_now) override;
98 
107  public: gz::common::ConnectionPtr ConnectImageCallback(
109  void(const gz::msgs::Image &)> _callback);
110 
113  public: virtual void SetScene(
114  gz::rendering::ScenePtr _scene) override;
115 
118  public: virtual unsigned int ImageWidth() const;
119 
122  public: virtual unsigned int ImageHeight() const;
123 
126  public: rendering::CameraPtr RenderingCamera() const;
127 
130  public: std::string InfoTopic() const;
131 
135  public: void SetBaseline(double _baseline);
136 
139  public: double Baseline() const;
140 
144  public: bool HasConnections() const;
145 
149  public: bool HasImageConnections() const;
150 
154  public: bool HasInfoConnections() const;
155 
158  public: const std::string &OpticalFrameId() const;
159 
162  protected: bool AdvertiseInfo();
163 
169  protected: bool AdvertiseInfo(const std::string &_topic);
170 
174  protected: void PopulateInfo(const sdf::Camera *_cameraSdf);
175 
178  protected: void PublishInfo(
179  const std::chrono::steady_clock::duration &_now);
180 
183  private: bool CreateCamera();
184 
188  private: void OnSceneChange(gz::rendering::ScenePtr /*_scene*/);
189 
190  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
193  private: std::unique_ptr<CameraSensorPrivate> dataPtr;
194  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
195  };
196  }
197  }
198 }
199 
200 #endif
Camera Sensor Class.
Definition: gz/sensors/CameraSensor.hh:72
virtual void SetScene(gz::rendering::ScenePtr _scene) override
Set the rendering scene.
bool HasInfoConnections() const
Check if there are any info subscribers.
void PublishInfo(const std::chrono::steady_clock::duration &_now)
Publish camera info message.
const std::string & OpticalFrameId() const
Get the camera optical frame.
virtual unsigned int ImageHeight() const
Get image height.
std::string InfoTopic() const
Topic where camera info is published.
virtual unsigned int ImageWidth() const
Get image width.
double Baseline() const
Get baseline for stereo cameras.
void PopulateInfo(const sdf::Camera *_cameraSdf)
Populate camera info message.
virtual ~CameraSensor()
destructor
virtual bool Load(sdf::ElementPtr _sdf) override
Load the sensor with SDF parameters.
bool AdvertiseInfo(const std::string &_topic)
Advertise camera info topic. This version takes a string that allows one to override the camera_info ...
virtual bool Load(const sdf::Sensor &_sdf) override
Load the sensor based on data from an sdf::Sensor object.
rendering::CameraPtr RenderingCamera() const
Get pointer to rendering camera object.
bool HasImageConnections() const
Check if there are any image subscribers.
gz::common::ConnectionPtr ConnectImageCallback(std::function< void(const gz::msgs::Image &)> _callback)
Set a callback to be called when image frame data is generated.
virtual bool Update(const std::chrono::steady_clock::duration &_now) override
Force the sensor to generate data.
bool AdvertiseInfo()
Advertise camera info topic.
virtual bool Init() override
Initialize values in the sensor.
bool HasConnections() const
Check if there are any subscribers.
void SetBaseline(double _baseline)
Set baseline for stereo cameras. This is used to populate the projection matrix in the camera info me...
a rendering sensor class
Definition: gz/sensors/RenderingSensor.hh:54
Definition: gz/sensors/AirPressureSensor.hh:32