GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/rbprm/sampling/sample-db.hh Lines: 0 2 0.0 %
Date: 2024-02-02 12:21:48 Branches: 0 0 - %

Line Branch Exec Source
1
//
2
// Copyright (c) 2014 CNRS
3
// Authors: Steve Tonneau (steve.tonneau@laas.fr)
4
//
5
// This file is part of hpp-rbprm.
6
// hpp-rbprm is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation, either version
9
// 3 of the License, or (at your option) any later version.
10
//
11
// hpp-rbprm is distributed in the hope that it will be
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Lesser Public License for more details.  You should have
15
// received a copy of the GNU Lesser General Public License along with
16
// hpp-core  If not, see
17
// <http://www.gnu.org/licenses/>.
18
19
#ifndef HPP_RBPRM_SAMPLEDB_HH
20
#define HPP_RBPRM_SAMPLEDB_HH
21
22
#include <hpp/fcl/octree.h>
23
24
#include <boost/function.hpp>
25
#include <hpp/rbprm/config.hh>
26
#include <hpp/rbprm/sampling/heuristic.hh>
27
#include <hpp/rbprm/sampling/sample.hh>
28
#include <map>
29
#include <vector>
30
31
namespace hpp {
32
33
namespace rbprm {
34
namespace sampling {
35
36
/// Collision report for a Sample for which the octree node is
37
/// colliding with the environment.
38
struct OctreeReport {
39
  OctreeReport(const Sample*, const fcl::Contact, const double,
40
               const fcl::Vec3f& normal, const fcl::Vec3f& v1,
41
               const fcl::Vec3f& v2,
42
               const fcl::Vec3f& v3);  // vertices of triangle collided
43
  /// Sample considered for contact generation
44
  const Sample* sample_;
45
  /// Contact information returned from fcl
46
  fcl::Contact contact_;
47
  /// heuristic evaluation of the sample
48
  double value_;
49
  /// normal vector of the surface in contact
50
  fcl::Vec3f normal_, v1_, v2_, v3_;
51
};
52
53
/// Comparaison operator between Samples
54
/// Used to sort the contact candidates depending
55
/// on their heuristic value
56
struct sample_compare {
57
  bool operator()(const OctreeReport& lhs, const OctreeReport& rhs) const {
58
    return lhs.value_ > rhs.value_;
59
  }
60
};
61
62
typedef std::multiset<OctreeReport, sample_compare> T_OctreeReport;
63
64
HPP_PREDEF_CLASS(SampleDB);
65
66
typedef std::vector<double> T_Double;
67
typedef std::map<std::string, T_Double> T_Values;
68
typedef sampling::SampleVector_t T_Sample;
69
70
/// Defines an evaluation function for a sample.
71
/// \param SampleDB used database with already computed values
72
/// \param sample sample candidate
73
/// \param normal contact surface normal relatively to the candidate
74
// typedef double (*evaluate) (const SampleDB& sampleDB, const sampling::Sample&
75
// sample);
76
typedef boost::function<double(const SampleDB& sampleDB,
77
                               const sampling::Sample& sample)>
78
    evaluate;
79
typedef std::map<std::string, evaluate> T_evaluate;
80
// first sample index, number of samples
81
typedef std::pair<std::size_t, std::size_t> VoxelSampleId;
82
typedef std::map<long int, VoxelSampleId> T_VoxelSampleId;
83
typedef std::pair<double, double> ValueBound;
84
typedef std::map<std::string, ValueBound> T_ValueBound;
85
86
/// Sample configuration for a robot limb, stored
87
/// in an octree and used for proximity requests for contact creation.
88
/// assumes that joints are compact, ie they all are consecutive in
89
/// configuration.
90
class HPP_RBPRM_DLLAPI SampleDB {
91
 public:
92
  SampleDB(std::ifstream& databaseStream, bool loadValues = true);
93
  SampleDB(const pinocchio::JointPtr_t limb, const std::string& effector,
94
           const std::size_t nbSamples,
95
           const fcl::Vec3f& offset = fcl::Vec3f(0, 0, 0),
96
           const fcl::Vec3f& limbOffset = fcl::Vec3f(0, 0, 0),
97
           const double resolution = 0.1, const T_evaluate& data = T_evaluate(),
98
           const std::string& staticValue = "");
99
  ~SampleDB();
100
  /*
101
      private:
102
           SampleDB(const SampleDB&);
103
           const SampleDB& operator=(const SampleDB&);
104
  */
105
 public:
106
  double resolution_;
107
  T_Sample samples_;
108
  hpp::fcl::shared_ptr<const octomap::OcTree> octomapTree_;
109
  fcl::OcTree* octree_;  // deleted with geometry_
110
  hpp::fcl::shared_ptr<fcl::CollisionGeometry> geometry_;
111
  T_Values values_;
112
  T_ValueBound valueBounds_;
113
  T_VoxelSampleId samplesInVoxels_;
114
  /// fcl collision object used for collisions with environment
115
  fcl::CollisionObject treeObject_;
116
  /// Bounding boxes of areas of interest of the octree
117
  std::map<std::size_t, fcl::CollisionObject*> boxes_;
118
119
};  // class SampleDB
120
121
HPP_RBPRM_DLLAPI SampleDB& addValue(SampleDB& database,
122
                                    const std::string& valueName,
123
                                    const evaluate eval,
124
                                    bool isStaticValue = true,
125
                                    bool sortSamples = true);
126
HPP_RBPRM_DLLAPI bool saveLimbDatabase(const SampleDB& database,
127
                                       std::ofstream& dbFile);
128
129
/// Given the current position of a robot, returns a set
130
/// of candidate sample configurations for contact generation.
131
/// The set is strictly ordered using a heuristic to determine
132
/// the most relevant contacts.
133
///
134
/// \param sc the SampleDB containing all the samples for a given limb
135
/// \param treeTrf the current transformation of the root of the robot
136
/// \param direction the current direction of motion, used to evaluate the
137
/// sample heuristically \param evaluate heuristic used to sort candidates
138
/// \return a set of OctreeReport with all the possible candidates for contact
139
HPP_RBPRM_DLLAPI T_OctreeReport GetCandidates(
140
    const SampleDB& sc, const fcl::Transform3f& treeTrf,
141
    const hpp::pinocchio::CollisionObjectPtr_t& o2, const fcl::Vec3f& direction,
142
    const HeuristicParam& params, const heuristic evaluate = 0);
143
144
/// Given the current position of a robot, returns a set
145
/// of candidate sample configurations for contact generation.
146
/// The set is strictly ordered using a heuristic to determine
147
/// the most relevant contacts.
148
///
149
/// \param sc the SampleDB containing all the samples for a given limb
150
/// \param treeTrf the current transformation of the root of the robot
151
/// \param direction the current direction of motion, used to evaluate the
152
/// sample heuristically \param a set of OctreeReport updated as the samples are
153
/// explored \param evaluate heuristic used to sort candidates \return true if
154
/// at least one candidate was found
155
HPP_RBPRM_DLLAPI bool GetCandidates(
156
    const SampleDB& sc, const fcl::Transform3f& treeTrf,
157
    const hpp::pinocchio::CollisionObjectPtr_t& o2, const fcl::Vec3f& direction,
158
    T_OctreeReport& report, const HeuristicParam& params,
159
    const heuristic evaluate = 0);
160
161
}  // namespace sampling
162
}  // namespace rbprm
163
}  // namespace hpp
164
#endif  // HPP_RBPRM_SAMPLEDB_HH