height_map.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 
7 * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9 
10 * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 * Neither the name of the copyright holder nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
30 #ifndef TOWR_HEIGHT_MAP_H_
31 #define TOWR_HEIGHT_MAP_H_
32 
33 #include <memory>
34 #include <vector>
35 #include <map>
36 #include <string>
37 
38 #include <Eigen/Dense>
39 
41 
42 namespace towr {
43 
71 class HeightMap {
72 public:
73  using Ptr = std::shared_ptr<HeightMap>;
74  using Vector3d = Eigen::Vector3d;
75 
79  enum TerrainID { FlatID,
87 
89 
91 
92  HeightMap() = default;
93  virtual ~HeightMap () = default;
94 
100  virtual double GetHeight(double x, double y) const = 0;
101 
109  double GetDerivativeOfHeightWrt(Dim2D dim, double x, double y) const;
110 
118  Vector3d GetNormalizedBasis(Direction direction, double x, double y) const;
119 
129  double x, double y) const;
133  double GetFrictionCoeff() const { return friction_coeff_; };
134 
135 protected:
136  double friction_coeff_ = 0.5;
137 
138 private:
139  using DimDerivs = std::vector<Dim2D>;
140 
149  Vector3d GetBasis(Direction direction, double x, double y,
150  const DimDerivs& dim_deriv= {}) const;
151 
152  Vector3d GetNormal(double x, double y, const DimDerivs& = {}) const;
153  Vector3d GetTangent1(double x, double y, const DimDerivs& = {}) const;
154  Vector3d GetTangent2(double x, double y, const DimDerivs& = {}) const;
155 
156  double GetSecondDerivativeOfHeightWrt(Dim2D dim1, Dim2D dim2,
157  double x, double y) const;
158 
160  const Vector3d& non_normalized, int index) const;
161 
162  // first derivatives that must be implemented by the user
163  virtual double GetHeightDerivWrtX(double x, double y) const { return 0.0; };
164  virtual double GetHeightDerivWrtY(double x, double y) const { return 0.0; };
165 
166  // second derivatives with respect to first letter, then second
167  virtual double GetHeightDerivWrtXX(double x, double y) const { return 0.0; };
168  virtual double GetHeightDerivWrtXY(double x, double y) const { return 0.0; };
169  virtual double GetHeightDerivWrtYX(double x, double y) const { return 0.0; };
170  virtual double GetHeightDerivWrtYY(double x, double y) const { return 0.0; };
171 };
172 
173 
174 const static std::map<HeightMap::TerrainID, std::string> terrain_names =
175 {
176  {HeightMap::FlatID, "Flat" },
177  {HeightMap::BlockID, "Block" },
178  {HeightMap::StairsID, "Stairs" },
179  {HeightMap::GapID, "Gap" },
180  {HeightMap::SlopeID, "Slope" },
181  {HeightMap::ChimneyID, "Chimney" },
182  {HeightMap::ChimneyLRID, "ChimenyLR" }
183 };
184 
185 } /* namespace towr */
186 
187 #endif /* TOWR_HEIGHT_MAP_H_ */
Vector3d GetBasis(Direction direction, double x, double y, const DimDerivs &dim_deriv={}) const
returns either the terrain normal/tangent or its derivative.
Definition: height_map.cc:69
virtual double GetHeightDerivWrtY(double x, double y) const
Definition: height_map.h:164
virtual double GetHeightDerivWrtYY(double x, double y) const
Definition: height_map.h:170
TerrainID
Terrains IDs corresponding for factory method.
Definition: height_map.h:79
Holds the height and slope information of the terrain.
Definition: height_map.h:71
Vector3d GetDerivativeOfNormalizedVectorWrtNonNormalizedIndex(const Vector3d &non_normalized, int index) const
Definition: height_map.cc:142
Vector3d GetTangent1(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:113
static const std::map< HeightMap::TerrainID, std::string > terrain_names
Definition: height_map.h:174
virtual double GetHeightDerivWrtYX(double x, double y) const
Definition: height_map.h:169
Vector3d GetNormalizedBasis(Direction direction, double x, double y) const
Returns either the vector normal or tangent to the terrain patch.
Definition: height_map.cc:63
double GetFrictionCoeff() const
Definition: height_map.h:133
double friction_coeff_
Definition: height_map.h:136
static HeightMap::Ptr MakeTerrain(TerrainID type)
Definition: height_map.cc:38
double GetSecondDerivativeOfHeightWrt(Dim2D dim1, Dim2D dim2, double x, double y) const
Definition: height_map.cc:151
virtual ~HeightMap()=default
Eigen::Vector3d Vector3d
Definition: height_map.h:74
Vector3d GetDerivativeOfNormalizedBasisWrt(Direction direction, Dim2D dim, double x, double y) const
How the terrain normal/tangent vectors change when moving in x or y.
Definition: height_map.cc:81
virtual double GetHeightDerivWrtX(double x, double y) const
Definition: height_map.h:163
virtual double GetHeightDerivWrtXX(double x, double y) const
Definition: height_map.h:167
virtual double GetHeight(double x, double y) const =0
virtual double GetHeightDerivWrtXY(double x, double y) const
Definition: height_map.h:168
std::vector< Dim2D > DimDerivs
dimensional derivatives
Definition: height_map.h:139
double GetDerivativeOfHeightWrt(Dim2D dim, double x, double y) const
How the height value changes at a 2D position in direction dim.
Definition: height_map.cc:53
Vector3d GetTangent2(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:128
HeightMap()=default
std::shared_ptr< HeightMap > Ptr
Definition: height_map.h:73
Vector3d GetNormal(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:94


towr
Author(s): Alexander W. Winkler
autogenerated on Sat Apr 13 2019 02:28:00