HeightmapShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 /* Desc: Heightmap shape
18  * Author: Nate Koenig, Andrew Howard
19  * Date: 8 May 2003
20  */
21 
22 #ifndef _HEIGHTMAPSHAPE_HH_
23 #define _HEIGHTMAPSHAPE_HH_
24 
25 #include <string>
26 #include <vector>
27 
30 #include "gazebo/common/Dem.hh"
31 #include "gazebo/math/Vector3.hh"
34 #include "gazebo/physics/Shape.hh"
35 #include "gazebo/util/system.hh"
36 
37 namespace gazebo
38 {
39  namespace physics
40  {
43 
48  class GZ_PHYSICS_VISIBLE HeightmapShape : public Shape
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 math::Vector3 &_scale);
67 
70  public: std::string GetURI() const;
71 
74  public: math::Vector3 GetSize() const;
75 
78  public: math::Vector3 GetPos() const;
79 
84  public: math::Vector2i GetVertexCount() const;
85 
90  public: float GetHeight(int _x, int _y) const;
91 
94  public: void FillMsg(msgs::Geometry &_msg);
95 
98  public: virtual void ProcessMsg(const msgs::Geometry &_msg);
99 
101  public: virtual double ComputeVolume() const;
102 
105  public: float GetMaxHeight() const;
106 
109  public: float GetMinHeight() const;
110 
113  public: int GetSubSampling() const;
114 
118  public: common::Image GetImage() const;
119 
126  private: int LoadTerrainFile(const std::string &_filename);
127 
128  #ifdef HAVE_GDAL
129  private: int LoadDEMAsTerrain(const std::string &_filename);
133  #endif
134 
138  private: int LoadImageAsTerrain(const std::string &_filename);
139 
142  private: void OnRequest(ConstRequestPtr &_msg);
143 
145  protected: std::vector<float> heights;
146 
149 
152 
154  protected: unsigned int vertSize;
155 
157  protected: bool flipY;
158 
160  protected: int subSampling;
161 
163  private: transport::NodePtr node;
164 
166  private: transport::SubscriberPtr requestSub;
167 
169  private: transport::PublisherPtr responsePub;
170 
172  private: std::string fileFormat;
173 
175  private: math::Vector3 heightmapSize;
176 
177  #ifdef HAVE_GDAL
178  private: common::Dem dem;
180  #endif
181  };
183  }
184 }
185 #endif
Definition: Dem.hh:45
Forward declarations for the common classes.
Definition: Animation.hh:33
HeightmapShape collision shape builds a heightmap from an image.
Definition: HeightmapShape.hh:48
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
std::vector< float > heights
Lookup table of heights.
Definition: HeightmapShape.hh:145
Encapsulates a generic heightmap data file.
Definition: HeightmapData.hh:37
Generic integer x, y vector.
Definition: Vector2i.hh:36
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:46
Encapsulates an image that will be interpreted as a heightmap.
Definition: ImageHeightmap.hh:39
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:154
int subSampling
The amount of subsampling. Default is 2.
Definition: HeightmapShape.hh:160
bool flipY
True to flip the heights along the y direction.
Definition: HeightmapShape.hh:157
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:148
Encapsulates an image.
Definition: Image.hh:74
common::HeightmapData * heightmapData
HeightmapData used to generate the heights.
Definition: HeightmapShape.hh:151
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:104