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"
29 #include "gazebo/math/Vector3.hh"
32 #include "gazebo/physics/Shape.hh"
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace physics
38  {
41 
46  class GZ_PHYSICS_VISIBLE HeightmapShape : public Shape
47  {
50  public: explicit HeightmapShape(CollisionPtr _parent);
51 
53  public: virtual ~HeightmapShape();
54 
57  public: virtual void Load(sdf::ElementPtr _sdf);
58 
60  public: virtual void Init();
61 
64  public: virtual void SetScale(const ignition::math::Vector3d &_scale);
65 
68  public: std::string GetURI() const;
69 
73  public: math::Vector3 GetSize() const GAZEBO_DEPRECATED(8.0);
74 
77  public: ignition::math::Vector3d Size() const;
78 
82  public: math::Vector3 GetPos() const GAZEBO_DEPRECATED(8.0);
83 
86  public: ignition::math::Vector3d Pos() const;
87 
93  public: math::Vector2i GetVertexCount() const GAZEBO_DEPRECATED(8.0);
94 
99  public: ignition::math::Vector2i VertexCount() const;
100 
105  public: float GetHeight(int _x, int _y) const;
106 
111  public: void FillMsg(msgs::Geometry &_msg);
112 
115  public: void FillHeights(msgs::Geometry &_msg) const;
116 
119  public: virtual void ProcessMsg(const msgs::Geometry &_msg);
120 
122  public: virtual double ComputeVolume() const;
123 
126  public: float GetMaxHeight() const;
127 
130  public: float GetMinHeight() const;
131 
134  public: int GetSubSampling() const;
135 
139  public: common::Image GetImage() const;
140 
147  private: int LoadTerrainFile(const std::string &_filename);
148 
151  private: void OnRequest(ConstRequestPtr &_msg);
152 
154  protected: std::vector<float> heights;
155 
158 
161 
163  protected: unsigned int vertSize;
164 
166  protected: bool flipY;
167 
169  protected: int subSampling;
170 
172  private: transport::NodePtr node;
173 
175  private: transport::SubscriberPtr requestSub;
176 
178  private: transport::PublisherPtr responsePub;
179 
181  private: std::string fileFormat;
182 
184  private: ignition::math::Vector3d heightmapSize;
185 
186  #ifdef HAVE_GDAL
187  private: common::Dem dem;
189  #endif
190 
191  // Place ignition::transport objects at the end of this file to
192  // guarantee they are destructed first.
193 
195  private: ignition::transport::Node nodeIgn;
196 
198  private: ignition::transport::Node::Publisher responsePubIgn;
199  };
201  }
202 }
203 #endif
Definition: Dem.hh:44
HeightmapShape collision shape builds a heightmap from an image.
Definition: HeightmapShape.hh:46
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
std::vector< float > heights
Lookup table of heights.
Definition: HeightmapShape.hh:154
Encapsulates a generic heightmap data file.
Definition: HeightmapData.hh:39
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:45
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:163
int subSampling
The amount of subsampling. Default is 2.
Definition: HeightmapShape.hh:169
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
bool flipY
True to flip the heights along the y direction.
Definition: HeightmapShape.hh:166
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:157
Encapsulates an image.
Definition: Image.hh:74
common::HeightmapData * heightmapData
HeightmapData used to generate the heights.
Definition: HeightmapShape.hh:160
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113