Gazebo Sensors

API Reference

8.3.0
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 <gz/msgs/boolean.pb.h>
25 #include <gz/msgs/image.pb.h>
26 
27 #include <sdf/sdf.hh>
28 
29 #include <gz/utils/SuppressWarning.hh>
30 
31 // TODO(louise) Remove these pragmas once gz-rendering is disabling the
32 // warnings
33 #ifdef _WIN32
34 #pragma warning(push)
35 #pragma warning(disable: 4251)
36 #endif
37 #include <gz/rendering/Camera.hh>
38 #ifdef _WIN32
39 #pragma warning(pop)
40 #endif
41 
42 #include "gz/sensors/camera/Export.hh"
43 #include "gz/sensors/config.hh"
44 #include "gz/sensors/Export.hh"
46 
47 namespace gz
48 {
49  namespace sensors
50  {
51  // Inline bracket to help doxygen filtering.
52  inline namespace GZ_SENSORS_VERSION_NAMESPACE {
53  //
55  class CameraSensorPrivate;
56 
64  class GZ_SENSORS_CAMERA_VISIBLE CameraSensor : public RenderingSensor
65  {
67  public: CameraSensor();
68 
70  public: virtual ~CameraSensor();
71 
75  public: virtual bool Load(const sdf::Sensor &_sdf) override;
76 
80  public: virtual bool Load(sdf::ElementPtr _sdf) override;
81 
84  public: virtual bool Init() override;
85 
86  using Sensor::Update;
87 
91  public: virtual bool Update(
92  const std::chrono::steady_clock::duration &_now) override;
93 
102  public: gz::common::ConnectionPtr ConnectImageCallback(
104  void(const gz::msgs::Image &)> _callback);
105 
108  public: virtual void SetScene(
109  gz::rendering::ScenePtr _scene) override;
110 
113  public: virtual unsigned int ImageWidth() const;
114 
117  public: virtual unsigned int ImageHeight() const;
118 
121  public: virtual rendering::CameraPtr RenderingCamera() const;
122 
126  public: bool SetInfoTopic(const std::string &_topic);
127 
130  public: std::string InfoTopic() const;
131 
135  public: void SetBaseline(double _baseline);
136 
139  public: double Baseline() const;
140 
141  // Documentation inherited.
142  public: virtual bool HasConnections() const override;
143 
146  public: virtual bool HasImageConnections() const;
147 
150  public: virtual bool HasInfoConnections() const;
151 
154  public: const std::string& OpticalFrameId() const;
155 
165  rendering::CameraPtr _camera, sdf::Camera &_cameraSdf);
166 
169  protected: bool AdvertiseInfo();
170 
176  protected: bool AdvertiseInfo(const std::string &_topic);
177 
181  protected: void PopulateInfo(const sdf::Camera *_cameraSdf);
182 
185  protected: void PublishInfo(
186  const std::chrono::steady_clock::duration &_now);
187 
190  private: bool CreateCamera();
191 
195  private: void OnSceneChange(gz::rendering::ScenePtr /*_scene*/);
196 
197  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
200  private: std::unique_ptr<CameraSensorPrivate> dataPtr;
201  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
202  };
203  }
204  }
205 }
206 
207 #endif