GCC Code Coverage Report


Directory: ./
File: src/problem.cc
Date: 2025-03-07 11:10:46
Exec Total Coverage
Lines: 32 49 65.3%
Branches: 15 48 31.2%

Line Branch Exec Source
1 // Copyright (c) 2015, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #include <hpp/core/path-validation/discretized-collision-checking.hh>
30 #include <hpp/manipulation/graph-path-validation.hh>
31 #include <hpp/manipulation/graph/graph.hh>
32 #include <hpp/manipulation/problem.hh>
33 #include <hpp/manipulation/steering-method/graph.hh>
34 #include <hpp/manipulation/weighed-distance.hh>
35
36 namespace hpp {
37 namespace manipulation {
38 2 ProblemPtr_t Problem::create(DevicePtr_t robot) {
39
3/6
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
2 ProblemPtr_t p(new Problem(robot));
40
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 p->init(p);
41 2 return p;
42 }
43
44
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 Problem::Problem(DevicePtr_t robot) : Parent(robot), graph_() {}
45
46 2 void Problem::init(ProblemWkPtr_t wkPtr) {
47
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 Parent::init(wkPtr);
48 2 wkPtr_ = wkPtr;
49
50
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 Parent::steeringMethod(steeringMethod::Graph::create(wkPtr_.lock()));
51 2 distance(
52
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 WeighedDistance::create(HPP_DYNAMIC_PTR_CAST(Device, robot()), graph_));
53
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 setPathValidationFactory(
54 2 core::pathValidation::createDiscretizedCollisionChecking, 0.05);
55 2 }
56
57 void Problem::constraintGraph(const graph::GraphPtr_t& graph) {
58 graph_ = graph;
59 graph_->problem(wkPtr_.lock());
60
61 GraphPathValidationPtr_t pv =
62 HPP_DYNAMIC_PTR_CAST(GraphPathValidation, pathValidation());
63 if (pv) pv->constraintGraph(graph_);
64 WeighedDistancePtr_t d = HPP_DYNAMIC_PTR_CAST(WeighedDistance, distance());
65 if (d) d->constraintGraph(graph);
66 }
67
68 PathValidationPtr_t Problem::pathValidation() const {
69 return Parent::pathValidation();
70 }
71
72 void Problem::pathValidation(const PathValidationPtr_t& pathValidation) {
73 GraphPathValidationPtr_t pv =
74 HPP_DYNAMIC_PTR_CAST(GraphPathValidation, pathValidation);
75 if (pv) pv->constraintGraph(graph_);
76 Parent::pathValidation(pathValidation);
77 }
78
79 8 PathValidationPtr_t Problem::pathValidationFactory() const {
80
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 PathValidationPtr_t pv(pvFactory_(robot(), pvTol_));
81
82 shared_ptr<core::ObstacleUserInterface> oui =
83 8 HPP_DYNAMIC_PTR_CAST(core::ObstacleUserInterface, pv);
84
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 if (oui) {
85
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 const core::ObjectStdVector_t& obstacles(collisionObstacles());
86 // Insert obstacles in path validation object
87 8 for (core::ObjectStdVector_t::const_iterator _obs = obstacles.begin();
88
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 _obs != obstacles.end(); ++_obs)
89 oui->addObstacle(*_obs);
90 }
91 8 GraphPathValidationPtr_t gpv = HPP_DYNAMIC_PTR_CAST(GraphPathValidation, pv);
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (gpv) return gpv->innerValidation();
93 8 return pv;
94 8 }
95
96 8 SteeringMethodPtr_t Problem::manipulationSteeringMethod() const {
97 8 return HPP_DYNAMIC_PTR_CAST(SteeringMethod, Parent::steeringMethod());
98 }
99
100 2 void Problem::setPathValidationFactory(
101 const core::PathValidationBuilder_t& factory, const value_type& tol) {
102 2 pvFactory_ = factory;
103 2 pvTol_ = tol;
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (graph_) graph_->invalidate();
105 2 }
106
107 void Problem::checkProblem() const {
108 core::Problem::checkProblem();
109 if (!graph_) throw std::runtime_error("No graph in the problem.");
110 }
111 } // namespace manipulation
112 } // namespace hpp
113