HeightmapShape.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_PHYSICS_HEIGHTMAPSHAPE_HH_
18 #define GAZEBO_PHYSICS_HEIGHTMAPSHAPE_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <ignition/transport/Node.hh>
23 
24 #include <ignition/math/Vector2.hh>
25 
28 #include "gazebo/common/Dem.hh"
31 #include "gazebo/physics/Shape.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
45  class GZ_PHYSICS_VISIBLE HeightmapShape : public Shape
46  {
48  public: typedef float HeightType;
49 
52  public: explicit HeightmapShape(CollisionPtr _parent);
53 
55  public: virtual ~HeightmapShape();
56 
59  public: virtual void Load(sdf::ElementPtr _sdf);
60 
62  public: virtual void Init();
63 
66  public: virtual void SetScale(const ignition::math::Vector3d &_scale);
67 
70  public: std::string GetURI() const;
71 
74  public: ignition::math::Vector3d Size() const;
75 
78  public: ignition::math::Vector3d Pos() const;
79 
84  public: ignition::math::Vector2i VertexCount() const;
85 
90  public: HeightType GetHeight(int _x, int _y) const;
91 
95  public: void SetHeight(int _x, int _y, float _value);
96 
101  public: void FillMsg(msgs::Geometry &_msg);
102 
105  public: void FillHeights(msgs::Geometry &_msg) const;
106 
109  public: virtual void ProcessMsg(const msgs::Geometry &_msg);
110 
112  public: virtual double ComputeVolume() const;
113 
116  public: HeightType GetMaxHeight() const;
117 
120  public: HeightType GetMinHeight() const;
121 
124  public: int GetSubSampling() const;
125 
129  public: common::Image GetImage() const;
130 
137  private: int LoadTerrainFile(const std::string &_filename);
138 
141  private: void OnRequest(ConstRequestPtr &_msg);
142 
146  public: void FillHeightfield(std::vector<float>& heights);
147 
149  public: void FillHeightfield(std::vector<double>& heights);
150 
152  protected: std::vector<HeightType> heights;
153 
156 
159 
161  protected: unsigned int vertSize;
162 
164  protected: bool flipY;
165 
167  protected: int subSampling;
168 
170  private: transport::NodePtr node;
171 
173  private: transport::SubscriberPtr requestSub;
174 
176  private: transport::PublisherPtr responsePub;
177 
179  private: std::string fileFormat;
180 
182  private: ignition::math::Vector3d heightmapSize;
183 
184  #ifdef HAVE_GDAL
185  private: common::Dem dem;
187  #endif
188 
189  // Place ignition::transport objects at the end of this file to
190  // guarantee they are destructed first.
191 
193  private: ignition::transport::Node nodeIgn;
194 
196  private: ignition::transport::Node::Publisher responsePubIgn;
197  };
199  }
200 }
201 #endif
Encapsulates a generic heightmap data file.
Definition: HeightmapData.hh:40
Forward declarations for the common classes.
Definition: Animation.hh:27
void FillHeightfield(std::vector< float > &heights)
Fills the heightmap data (float) into the vector by calling HeightmapData::FillHeightMap with heights...
float HeightType
height field type, float or double
Definition: HeightmapShape.hh:48
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
HeightmapShape(CollisionPtr _parent)
Constructor.
void FillHeights(msgs::Geometry &_msg) const
Fill a geometry message with this shape's height data.
Forward declarations for transport.
std::string GetURI() const
Get the URI of the heightmap image.
HeightType GetMaxHeight() const
Get the maximum height.
void FillMsg(msgs::Geometry &_msg)
Fill a geometry message with this shape's data.
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
virtual double ComputeVolume() const
Documentation inherited.
default namespace for gazebo
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
Encapsulates an image.
Definition: Image.hh:66
void FillHeightfield(std::vector< double > &heights)
Version of FillHeightfield() for double vectors.
void SetHeight(int _x, int _y, float _value)
Sets a height value at a position.
unsigned int vertSize
Size of the height lookup table.
Definition: HeightmapShape.hh:161
ignition::math::Vector2i VertexCount() const
Return the number of vertices, which equals the size of the image used to load the heightmap.
HeightType GetHeight(int _x, int _y) const
Get a height at a position.
HeightmapShape collision shape builds a heightmap from an image.
Definition: HeightmapShape.hh:46
virtual ~HeightmapShape()
Destructor.
int subSampling
The amount of subsampling. Default is 2.
Definition: HeightmapShape.hh:167
ignition::math::Vector3d Size() const
Get the size in meters.
virtual void SetScale(const ignition::math::Vector3d &_scale)
Set the scale of the heightmap shape.
Definition: Dem.hh:45
bool flipY
True to flip the heights along the y direction.
Definition: HeightmapShape.hh:164
common::Image GetImage() const
Return an image representation of the heightmap.
virtual void ProcessMsg(const msgs::Geometry &_msg)
Update the heightmap from a message.
common::HeightmapData * heightmapData
HeightmapData used to generate the heights.
Definition: HeightmapShape.hh:158
HeightType GetMinHeight() const
Get the minimum height.
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:114
virtual void Init()
Initialize the heightmap.
std::vector< HeightType > heights
Lookup table of heights.
Definition: HeightmapShape.hh:152
common::ImageHeightmap img
Image used to generate the heights.
Definition: HeightmapShape.hh:155
int GetSubSampling() const
Get the amount of subsampling.
ignition::math::Vector3d Pos() const
Get the origin in world coordinate frame.
Encapsulates an image that will be interpreted as a heightmap.
Definition: ImageHeightmap.hh:40
Base class for all shapes.
Definition: Shape.hh:40
virtual void Load(sdf::ElementPtr _sdf)
Load the heightmap.