Gazebo Rendering

API Reference

6.6.4
gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2021 Open Source Robotics Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */
18 
19 #ifndef IGNITION_RENDERING_OGRE2_OGRE2BOUNDINGBOXCAMERA_HH_
20 #define IGNITION_RENDERING_OGRE2_OGRE2BOUNDINGBOXCAMERA_HH_
21 
22 #ifdef _WIN32
23  // Ensure that Winsock2.h is included before Windows.h, which can get
24  // pulled in by anybody (e.g., Boost).
25  #include <Winsock2.h>
26 #endif
27 
28 #include <memory>
29 #include <vector>
30 
34 
35 namespace ignition
36 {
37  namespace rendering
38  {
39  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
40  //
41  // Forward declaration
42  class Ogre2BoundingBoxCameraPrivate;
43 
46  class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2BoundingBoxCamera :
47  public BaseBoundingBoxCamera<Ogre2Sensor>
48  {
50  protected: Ogre2BoundingBoxCamera();
51 
53  public: virtual ~Ogre2BoundingBoxCamera();
54 
56  public: virtual void Init() override;
57 
59  public: virtual void Destroy() override;
60 
61  // Documentation inherited
62  public: virtual void PreRender() override;
63 
64  // Documentation inherited
65  public: virtual void Render() override;
66 
67  // Documentation inherited
68  public: virtual void PostRender() override;
69 
70  // Documentation inherited
71  public: virtual const std::vector<BoundingBox> &BoundingBoxData() const
72  override;
73 
74  // Documentation inherited
75  public: virtual ignition::common::ConnectionPtr
77  std::function<void(const std::vector<BoundingBox> &)>) override;
78 
79  // Documentation inherited
80  public: virtual void SetBoundingBoxType(BoundingBoxType _type) override;
81 
82  // Documentation inherited
83  public: virtual BoundingBoxType Type() const override;
84 
87  public: void CreateBoundingBoxTexture();
88 
91  public: void CreateRenderTexture();
92 
96  public: void FullBoundingBoxes();
97 
100  public: void VisibleBoundingBoxes();
101 
103  public: void BoundingBoxes3D();
104 
115  public: void MeshMinimalBox(
116  const Ogre::MeshPtr _mesh,
117  const Ogre::Matrix4 &_viewMatrix,
118  const Ogre::Matrix4 &_projMatrix,
119  Ogre::Vector3 &_minVertex,
120  Ogre::Vector3 &_maxVertex,
121  const Ogre::Vector3 &_position,
122  const Ogre::Quaternion &_orientation,
123  const Ogre::Vector3 &_scale
124  );
125 
126  // Documentation inherited
127  public: virtual void DrawBoundingBox(unsigned char *_data,
128  const math::Color &_color, const BoundingBox &_box) const override;
129 
136  public: void DrawLine(unsigned char *_data,
137  const math::Vector2i &_point1, const math::Vector2i &_point2,
138  const ignition::math::Color &_color) const;
139 
143  public: void ConvertToScreenCoord(Ogre::Vector3 &_minVertex,
144  Ogre::Vector3 &_maxVertex) const;
145 
148  public: void MarkVisibleBoxes();
149 
152  protected: virtual RenderTargetPtr RenderTarget() const override;
153 
155  private: void CreateCamera();
156 
158  private: void MergeMultiLinksModels2D();
159 
161  private: void MergeMultiLinksModels3D();
162 
166 
167  private: friend class Ogre2Scene;
168  };
169  }
170  }
171 }
172 #endif
Definition: gz/rendering/base/BaseBoundingBoxCamera.hh:39
2D or 3D Bounding box. It stores the position / orientation / size info of the box and its label
Definition: gz/rendering/BoundingBox.hh:42
BoundingBox camera used to detect 2d / 3d bounding boxes of labeled objects in the scene.
Definition: gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh:48
virtual RenderTargetPtr RenderTarget() const override
Get a pointer to the render target.
void BoundingBoxes3D()
Compute the 3D bounding boxes.
void MarkVisibleBoxes()
Mark the visible boxes by checking the ogre ids map and mark the ogre id which appears in the map.
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
void CreateRenderTexture()
Create dummy render texture. Needed to satisfy inheritance and to set image's dims.
virtual void PostRender() override
Preforms any necessary final rendering work. Once rendering is complete the camera will alert any lis...
virtual BoundingBoxType Type() const override
Get the BoundingBox Type (Visible / Full)
virtual void DrawBoundingBox(unsigned char *_data, const math::Color &_color, const BoundingBox &_box) const override
Draw a bounding box on the given image.
virtual const std::vector< BoundingBox > & BoundingBoxData() const override
Get the BoundingBox data.
void ConvertToScreenCoord(Ogre::Vector3 &_minVertex, Ogre::Vector3 &_maxVertex) const
Convert from clip coord (after projection) to screen coord.
virtual void Destroy() override
Destroy the camera.
virtual ignition::common::ConnectionPtr ConnectNewBoundingBoxes(std::function< void(const std::vector< BoundingBox > &)>) override
Connect to the new BoundingBox info.
void DrawLine(unsigned char *_data, const math::Vector2i &_point1, const math::Vector2i &_point2, const ignition::math::Color &_color) const
Draw line between any 2 points in the image data buffer Algorithm: https://en.wikipedia....
void FullBoundingBoxes()
Compute the full bounding boxes by projecting all mesh vertices of each object, then get the min & ma...
virtual void SetBoundingBoxType(BoundingBoxType _type) override
Set BoundingBox Type (Visible / Full)
void CreateBoundingBoxTexture()
Create texture to hold ogre Ids to calculate the boundaries of each ogre id mask.
virtual void Init() override
Initialize the camera.
virtual void Render() override
Renders the current scene using this camera. This function assumes PreRender() has already been calle...
void MeshMinimalBox(const Ogre::MeshPtr _mesh, const Ogre::Matrix4 &_viewMatrix, const Ogre::Matrix4 &_projMatrix, Ogre::Vector3 &_minVertex, Ogre::Vector3 &_maxVertex, const Ogre::Vector3 &_position, const Ogre::Quaternion &_orientation, const Ogre::Vector3 &_scale)
Get minimal bounding box of the mesh by projecting the 3d vertices of the vertex buffer to 2d,...
void VisibleBoundingBoxes()
Compute the visible bounding boxes by looping over pixels of the ogre Ids map, to get the boundaries ...
Ogre2.x implementation of the scene class.
Definition: gz/rendering/ogre2/Ogre2Scene.hh:59
BoundingBoxType
BoundingBox types for Visible / Full 2D Boxes / 3D Boxes.
Definition: gz/rendering/BoundingBoxCamera.hh:38