momentumopt
TerrainDescription.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <array>
12 #include <vector>
13 #include <memory>
14 #include <iostream>
15 #include <Eigen/Eigen>
16 
18 
19 namespace momentumopt {
20 
25  {
26  public:
27  TerrainRegion() : terrain_id_(-1) {}
28  ~TerrainRegion(){}
29 
31  int& terrainId() { return terrain_id_; }
32  Eigen::Vector3d& pointOnTerrain() { return point_; }
33  Eigen::Vector3d& normalToTerrain() { return normal_; }
34  Eigen::Matrix3d& terrainRotation() { return rotation_; }
35  Eigen::VectorXd& terrainDescriptionVector() { return b_; }
36  Eigen::Matrix<double,Eigen::Dynamic,3>& terrainDescriptionMatrix() { return A_; }
37 
38  const int& terrainId() const { return terrain_id_; }
39  const Eigen::Vector3d& pointOnTerrain() const { return point_; }
40  const Eigen::Vector3d& normalToTerrain() const { return normal_; }
41  const Eigen::Matrix3d& terrainRotation() const { return rotation_; }
42  const Eigen::VectorXd& terrainDescriptionVector() const { return b_; }
43  const Eigen::Matrix<double,Eigen::Dynamic,3>& terrainDescriptionMatrix() const { return A_; }
44  const Eigen::Quaternion<double> terrainOrientation() const { return Eigen::Quaternion<double>(rotation_); }
45 
46  std::string toString() const;
47  friend std::ostream& operator<<(std::ostream &os, const TerrainRegion& obj) { return os << obj.toString(); }
48 
49  private:
50  friend class TerrainDescription;
51 
52  /* initialization function only available to terrain description */
53  void initialize(const Eigen::Matrix<double,Eigen::Dynamic,3>& ccwvertices, int terrain_id);
54 
55  private:
56  int terrain_id_;
57  Eigen::VectorXd b_;
58  Eigen::Matrix3d rotation_;
59  Eigen::Vector3d point_, normal_;
60  Eigen::Matrix<double,Eigen::Dynamic,3> A_;
61  };
62 
67  {
68  public:
69  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
70 
71  public:
72  TerrainDescription() : num_terrain_regions_(-1) {}
74 
75  void addTerrainRegion(const Eigen::Matrix<double,Eigen::Dynamic,3>& ccwvertices);
76  void loadFromFile(const std::string cfg_file, const std::string terrain_description_name = "terrain_description");
77 
79  const int numRegions() const { return terrain_regions_.size(); }
80  TerrainRegion& terrainRegion(int terrain_id) { return terrain_regions_[terrain_id]; }
81  const TerrainRegion& terrainRegion(int terrain_id) const { return terrain_regions_[terrain_id]; }
82 
83  std::string toString() const;
84  friend std::ostream& operator<<(std::ostream &os, const TerrainDescription& obj) { return os << obj.toString(); }
85 
86  private:
87  int num_terrain_regions_;
88  std::vector<TerrainRegion> terrain_regions_;
89  };
90 
91 }
This class is a container for all variables required to define a terrain region.
Definition: TerrainDescription.hpp:24
This class is a container for a terrain description in terms of terrain surfaces. ...
Definition: TerrainDescription.hpp:66
const int numRegions() const
Definition: TerrainDescription.hpp:79
int & terrainId()
Definition: TerrainDescription.hpp:31