GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/rbprm-rom-validation.cc Lines: 35 39 89.7 %
Date: 2024-02-02 12:21:48 Branches: 29 46 63.0 %

Line Branch Exec Source
1
// Copyright (c) 2014, LAAS-CNRS
2
// Authors: Steve Tonneau (steve.tonneau@laas.fr)
3
//
4
// This file is part of hpp-rbprm.
5
// hpp-rbprm is free software: you can redistribute it
6
// and/or modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation, either version
8
// 3 of the License, or (at your option) any later version.
9
//
10
// hpp-rbprm is distributed in the hope that it will be
11
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
// General Lesser Public License for more details.  You should have
14
// received a copy of the GNU Lesser General Public License along with
15
// hpp-rbprm. If not, see <http://www.gnu.org/licenses/>.
16
17
#include "hpp/rbprm/rbprm-rom-validation.hh"
18
19
#include <hpp/fcl/BVH/BVH_model.h>
20
#include <hpp/fcl/collision.h>
21
22
#include <hpp/rbprm/rbprm-validation-report.hh>
23
24
#include "hpp/rbprm/utils/algorithms.h"
25
26
namespace hpp {
27
using namespace core;
28
namespace rbprm {
29
30
112
RbPrmRomValidationPtr_t RbPrmRomValidation::create(
31
    const pinocchio::DevicePtr_t& robot,
32
    const std::vector<std::string>& affFilters) {
33
112
  RbPrmRomValidation* ptr = new RbPrmRomValidation(robot, affFilters);
34
112
  return RbPrmRomValidationPtr_t(ptr);
35
}
36
37
112
RbPrmRomValidation::RbPrmRomValidation(
38
    const pinocchio::DevicePtr_t& robot,
39
112
    const std::vector<std::string>& affFilters)
40
    : hpp::core::CollisionValidation(robot),
41
      filter_(affFilters),
42
112
      unusedReport_(new CollisionValidationReport),
43

224
      optional_(false) {}
44
45
bool RbPrmRomValidation::validate(const Configuration_t& config) {
46
  return validate(config, unusedReport_);
47
}
48
49
1251144
bool RbPrmRomValidation::validate(const Configuration_t& config,
50
                                  ValidationReportPtr_t& validationReport) {
51
1251144
  ValidationReportPtr_t romReport;
52
53
1251144
  bool collision = !hpp::core::CollisionValidation::validate(config, romReport);
54
  // CollisionValidationReportPtr_t reportCast =
55
  // dynamic_pointer_cast<CollisionValidationReport>(romReport);
56
  // hppDout(notice,"number of contacts  : "<<reportCast->result.numContacts());
57
  // hppDout(notice,"contact 1 "<<reportCast->result.getContact(0).pos);
58
  RbprmValidationReportPtr_t rbprmReport =
59
2502288
      dynamic_pointer_cast<RbprmValidationReport>(validationReport);
60
1251144
  if (rbprmReport) {
61
    // hppDout(notice,"rbprm-validation-report correctly cast");
62

1251144
    rbprmReport->ROMFilters.insert(std::make_pair(robot_->name(), collision));
63
  } else {
64
    hppDout(
65
        notice,
66
        "Validation report is not a valid rbprm-validation-report instance");
67
  }
68
1251144
  if (collision) {
69
1250710
    if (rbprmReport) {  // if the report is a correct rbprm report, we add the
70
                        // rom information
71
      core::CollisionValidationReportPtr_t romCollisionReport =
72
2501420
          HPP_DYNAMIC_PTR_CAST(CollisionValidationReport, romReport);
73
1250710
      rbprmReport->ROMReports.insert(
74

1250710
          std::make_pair(robot_->name(), romCollisionReport));
75
76
      // re arrange the collision pair such that the first one is the pair in
77
      // collision (allow us to maintain the contact with the same obstacle as
78
      // long as possible)
79
2501420
      CollisionObjectConstPtr_t obj2 = romCollisionReport->object2;
80
1250710
      bool first(true);
81
1250710
      std::size_t i = 0;
82
1255876
      for (; i < pairs().size(); ++i)
83
1255876
        if (pairs()[i].second == obj2) break;
84
85

1250710
      if (i != 0 && !pairs().empty()) {
86
1726
        std::swap(pairs()[0], pairs()[i]);
87
1726
        std::swap(requests()[0], requests()[i]);
88
      }
89
    } else {
90
      validationReport = romReport;
91
    }
92
  }
93
94
1251144
  if (optional_)
95
    return true;
96
  else
97
1251144
    return collision;
98
}
99
100
2104
void RbPrmRomValidation::randomnizeCollisionPairs() {
101
14348
  for (std::size_t i = 0; i < pairs().size(); ++i) {
102
    // XXX rand() % N is not uniformly distributed
103
12244
    std::size_t j = std::rand() % (i + 1);
104
12244
    if (i != j) {
105
7194
      std::swap(pairs()[i], pairs()[j]);
106
7194
      std::swap(requests()[i], requests()[j]);
107
    }
108
  }
109
2104
}
110
111
}  // namespace rbprm
112
}  // namespace hpp