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  {
49  public: explicit HeightmapShape(CollisionPtr _parent);
50 
52  public: virtual ~HeightmapShape();
53 
56  public: virtual void Load(sdf::ElementPtr _sdf);
57 
59  public: virtual void Init();
60 
63  public: virtual void SetScale(const ignition::math::Vector3d &_scale);
64 
67  public: std::string GetURI() const;
68 
71  public: ignition::math::Vector3d Size() const;
72 
75  public: ignition::math::Vector3d Pos() const;
76 
81  public: ignition::math::Vector2i VertexCount() const;
82 
87  public: float GetHeight(int _x, int _y) const;
88 
93  public: void FillMsg(msgs::Geometry &_msg);
94 
97  public: void FillHeights(msgs::Geometry &_msg) const;
98 
101  public: virtual void ProcessMsg(const msgs::Geometry &_msg);
102 
104  public: virtual double ComputeVolume() const;
105 
108  public: float GetMaxHeight() const;
109 
112  public: float GetMinHeight() const;
113 
116  public: int GetSubSampling() const;
117 
121  public: common::Image GetImage() const;
122 
129  private: int LoadTerrainFile(const std::string &_filename);
130 
133  private: void OnRequest(ConstRequestPtr &_msg);
134 
136  protected: std::vector<float> heights;
137 
140 
143 
145  protected: unsigned int vertSize;
146 
148  protected: bool flipY;
149 
151  protected: int subSampling;
152 
154  private: transport::NodePtr node;
155 
157  private: transport::SubscriberPtr requestSub;
158 
160  private: transport::PublisherPtr responsePub;
161 
163  private: std::string fileFormat;
164 
166  private: ignition::math::Vector3d heightmapSize;
167 
168  #ifdef HAVE_GDAL
169  private: common::Dem dem;
171  #endif
172 
173  // Place ignition::transport objects at the end of this file to
174  // guarantee they are destructed first.
175 
177  private: ignition::transport::Node nodeIgn;
178 
180  private: ignition::transport::Node::Publisher responsePubIgn;
181  };
183  }
184 }
185 #endif
Definition: Dem.hh:44
HeightmapShape collision shape builds a heightmap from an image.
Definition: HeightmapShape.hh:45
std::vector< float > heights
Lookup table of heights.
Definition: HeightmapShape.hh:136
Encapsulates a generic heightmap data file.
Definition: HeightmapData.hh:39
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Base class for all shapes.
Definition: Shape.hh:45
Encapsulates an image that will be interpreted as a heightmap.
Definition: ImageHeightmap.hh:38
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
default namespace for gazebo
unsigned int vertSize
Size of the height lookup table.
Definition: HeightmapShape.hh:145
int subSampling
The amount of subsampling. Default is 2.
Definition: HeightmapShape.hh:151
bool flipY
True to flip the heights along the y direction.
Definition: HeightmapShape.hh:148
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
common::ImageHeightmap img
Image used to generate the heights.
Definition: HeightmapShape.hh:139
Encapsulates an image.
Definition: Image.hh:75
common::HeightmapData * heightmapData
HeightmapData used to generate the heights.
Definition: HeightmapShape.hh:142
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113