MapShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 GAZEBO_PHYSISCS_MAPSHAPE_HH_
18 #define GAZEBO_PHYSISCS_MAPSHAPE_HH_
19 
20 #include <deque>
21 #include <string>
22 
24 #include "gazebo/physics/Shape.hh"
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace common
30  {
31  class Image;
32  }
33 
34  namespace physics
35  {
36  class SpaceTree;
37  class QuadNode;
38 
41 
45  class GZ_PHYSICS_VISIBLE MapShape : public Shape
46  {
49  public: explicit MapShape(CollisionPtr _parent);
50 
52  public: virtual ~MapShape();
53 
55  public: void Update();
56 
59  public: virtual void Load(sdf::ElementPtr _sdf);
60 
62  public: virtual void Init();
63 
67  public: void FillMsg(msgs::Geometry &_msg);
68 
71  public: virtual void ProcessMsg(const msgs::Geometry &_msg);
72 
75  public: std::string GetURI() const;
76 
79  public: void SetScale(const ignition::math::Vector3d &_scale);
80 
84  public: virtual math::Vector3 GetScale() const GAZEBO_DEPRECATED(8.0);
85 
88  public: virtual ignition::math::Vector3d Scale() const;
89 
94  public: int GetThreshold() const;
95 
100  public: double GetHeight() const;
101 
105  public: int GetGranularity() const;
106 
109  private: void BuildTree(QuadNode *_node);
110 
118  private: void GetPixelCount(unsigned int _xStart, unsigned int _yStart,
119  unsigned int _width, unsigned int _height,
120  unsigned int &_freePixels,
121  unsigned int &_occPixels);
122 
125  private: void ReduceTree(QuadNode *_node);
126 
130  private: void Merge(QuadNode *_nodeA, QuadNode *_nodeB);
131 
133  private: void CreateBox();
134 
137  private: void CreateBoxes(QuadNode *_node);
138 
140  private: common::Image *mapImage;
141 
143  private: QuadNode *root;
144 
146  private: bool merged;
147 
150  private: static unsigned int collisionCounter;
151  };
152 
153 
156  class GZ_PHYSICS_VISIBLE QuadNode
157  {
160  public: QuadNode(QuadNode *_parent)
161  : x(0), y(0), width(0), height(0)
162  {
163  parent = _parent;
164  occupied = false;
165  leaf = true;
166  valid = true;
167  }
168 
170  public: ~QuadNode()
171  {
172  std::deque<QuadNode*>::iterator iter;
173  for (iter = children.begin(); iter != children.end(); ++iter)
174  delete (*iter);
175  }
176 
179  public: void Print(std::string _space)
180  {
181  std::deque<QuadNode*>::iterator iter;
182 
183  printf("%sXY[%d %d] WH[%d %d] O[%d] L[%d] V[%d]\n",
184  _space.c_str(), x, y, width, height, occupied, leaf, valid);
185  _space += " ";
186  for (iter = children.begin(); iter != children.end(); ++iter)
187  if ((*iter)->occupied)
188  (*iter)->Print(_space);
189  }
190 
192  public: uint32_t x, y;
193 
195  public: uint32_t width, height;
196 
198  public: QuadNode *parent;
199 
201  public: std::deque<QuadNode*> children;
202 
204  public: bool occupied;
205 
207  public: bool leaf;
208 
210  public: bool valid;
211  };
213 
215  }
216 }
217 #endif
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
Base class for all shapes.
Definition: Shape.hh:45
Creates box extrusions based on an image.
Definition: MapShape.hh:45
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Encapsulates an image.
Definition: Image.hh:74
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113