Gazebo Sensors

API Reference

8.2.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 
125  public: std::string InfoTopic() const;
126 
130  public: void SetBaseline(double _baseline);
131 
134  public: double Baseline() const;
135 
136  // Documentation inherited.
137  public: virtual bool HasConnections() const override;
138 
141  public: virtual bool HasImageConnections() const;
142 
145  public: virtual bool HasInfoConnections() const;
146 
149  public: const std::string& OpticalFrameId() const;
150 
160  rendering::CameraPtr _camera, sdf::Camera &_cameraSdf);
161 
164  protected: bool AdvertiseInfo();
165 
171  protected: bool AdvertiseInfo(const std::string &_topic);
172 
176  protected: void PopulateInfo(const sdf::Camera *_cameraSdf);
177 
180  protected: void PublishInfo(
181  const std::chrono::steady_clock::duration &_now);
182 
185  private: bool CreateCamera();
186 
190  private: void OnSceneChange(gz::rendering::ScenePtr /*_scene*/);
191 
192  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
195  private: std::unique_ptr<CameraSensorPrivate> dataPtr;
196  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
197  };
198  }
199  }
200 }
201 
202 #endif