##

MapShape.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PHYSISCS_MAPSHAPE_HH_
#define GAZEBO_PHYSISCS_MAPSHAPE_HH_
#include <deque>
#include <string>
#include "gazebo/physics/Collision.hh"
#include "gazebo/physics/Shape.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
class Image;
}
namespace physics
{
class SpaceTree;
class QuadNode;
class GZ_PHYSICS_VISIBLE MapShape : public Shape
{
public: explicit MapShape(CollisionPtr _parent);
public: virtual ~MapShape();
public: void Update();
public: virtual void Load(sdf::ElementPtr _sdf);
public: virtual void Init();
public: void FillMsg(msgs::Geometry &_msg);
public: virtual void ProcessMsg(const msgs::Geometry &_msg);
public: std::string GetURI() const;
public: void SetScale(const ignition::math::Vector3d &_scale);
public: virtual ignition::math::Vector3d Scale() const;
public: int GetThreshold() const;
public: double GetHeight() const;
public: int GetGranularity() const;
private: void BuildTree(QuadNode *_node);
private: void GetPixelCount(unsigned int _xStart, unsigned int _yStart,
unsigned int _width, unsigned int _height,
unsigned int &_freePixels,
unsigned int &_occPixels);
private: void ReduceTree(QuadNode *_node);
private: void Merge(QuadNode *_nodeA, QuadNode *_nodeB);
private: void CreateBox();
private: void CreateBoxes(QuadNode *_node);
private: common::Image *mapImage;
private: QuadNode *root;
private: bool merged;
private: static unsigned int collisionCounter;
};
class GZ_PHYSICS_VISIBLE QuadNode
{
public: explicit QuadNode(QuadNode *_parent)
: x(0), y(0), width(0), height(0)
{
parent = _parent;
occupied = false;
leaf = true;
valid = true;
}
public: ~QuadNode()
{
std::deque<QuadNode*>::iterator iter;
for (iter = children.begin(); iter != children.end(); ++iter)
delete (*iter);
}
public: void Print(std::string _space)
{
std::deque<QuadNode*>::iterator iter;
printf("%sXY[%d %d] WH[%d %d] O[%d] L[%d] V[%d]\n",
_space.c_str(), x, y, width, height, occupied, leaf, valid);
_space += " ";
for (iter = children.begin(); iter != children.end(); ++iter)
if ((*iter)->occupied)
(*iter)->Print(_space);
}
public: uint32_t x, y;
public: uint32_t width, height;
public: QuadNode *parent;
public: std::deque<QuadNode*> children;
public: bool occupied;
public: bool leaf;
public: bool valid;
};
}
}
#endif
gazebo::physics::MapShape::MapShape
MapShape(CollisionPtr _parent)
Constructor.
gazebo::physics::MapShape::GetThreshold
int GetThreshold() const
Returns image threshold for this geometry.
QuadNode
gazebo::physics::MapShape::SetScale
void SetScale(const ignition::math::Vector3d &_scale)
Set the scale of the map shape.
gazebo::physics::MapShape::Update
void Update()
Update function.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
Collision.hh
gazebo::physics::MapShape::Scale
virtual ignition::math::Vector3d Scale() const
Returns scaling factor for this geometry.
common
common
Definition: FuelModelDatabase.hh:37
system.hh
gazebo::common::Image
Encapsulates an image.
Definition: Image.hh:66
gazebo::physics::MapShape::~MapShape
virtual ~MapShape()
Destructor.
gazebo::physics::MapShape::GetHeight
double GetHeight() const
Returns height of this geometry.
Shape.hh
gazebo::physics::MapShape
Creates box extrusions based on an image. This function is not yet complete, to be implemented.
Definition: MapShape.hh:45
gazebo::physics::MapShape::GetGranularity
int GetGranularity() const
Returns granularity of this geometry.
gazebo::physics::MapShape::FillMsg
void FillMsg(msgs::Geometry &_msg)
Fills out a msgs::Geometry message containing information about this map geometry object.
gazebo::physics::MapShape::Load
virtual void Load(sdf::ElementPtr _sdf)
Load the map.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::CollisionPtr
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
gazebo::physics::MapShape::Init
virtual void Init()
Init the map.
gazebo::physics::MapShape::ProcessMsg
virtual void ProcessMsg(const msgs::Geometry &_msg)
\TODO: Implement this function.
gazebo::physics::MapShape::GetURI
std::string GetURI() const
Returns the image URI for this geometry.
gazebo::physics::Shape
Base class for all shapes.
Definition: Shape.hh:39