| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// Copyright (c) 2019, LAAS-CNRS |
| 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 |
|
|
#ifndef HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH |
| 30 |
|
|
#define HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH |
| 31 |
|
|
|
| 32 |
|
|
#include <hpp/core/validation-report.hh> |
| 33 |
|
|
#include <hpp/manipulation/config.hh> |
| 34 |
|
|
#include <hpp/manipulation/fwd.hh> |
| 35 |
|
|
#include <hpp/manipulation/graph/fwd.hh> |
| 36 |
|
|
#include <hpp/manipulation/graph/graph.hh> |
| 37 |
|
|
#include <string> |
| 38 |
|
|
#include <vector> |
| 39 |
|
|
|
| 40 |
|
|
namespace hpp { |
| 41 |
|
|
namespace manipulation { |
| 42 |
|
|
namespace graph { |
| 43 |
|
|
/// \addtogroup constraint_graph |
| 44 |
|
|
/// \{ |
| 45 |
|
|
|
| 46 |
|
|
/// Check that graph components are valid. |
| 47 |
|
|
/// |
| 48 |
|
|
/// A stringified validation report can be obtained via |
| 49 |
|
|
/// Validation::print or operator<< (std::ostream&, const Validation&). |
| 50 |
|
|
class HPP_MANIPULATION_DLLAPI Validation { |
| 51 |
|
|
public: |
| 52 |
|
|
typedef std::vector<std::string> Collision; |
| 53 |
|
|
typedef std::vector<Collision> CollisionList; |
| 54 |
|
|
typedef std::map<std::string, CollisionList> CollisionMap; |
| 55 |
|
|
Validation(const core::ProblemPtr_t& problem) : problem_(problem) {} |
| 56 |
|
|
|
| 57 |
|
|
void clear() { |
| 58 |
|
|
warnings_.clear(); |
| 59 |
|
|
errors_.clear(); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
bool hasWarnings() const { return !warnings_.empty(); } |
| 63 |
|
|
|
| 64 |
|
|
bool hasErrors() const { return !errors_.empty(); } |
| 65 |
|
|
|
| 66 |
|
|
virtual std::ostream& print(std::ostream& os) const; |
| 67 |
|
|
|
| 68 |
|
|
/// Validate a graph component. |
| 69 |
|
|
/// It dynamically casts in order to call the right function among |
| 70 |
|
|
/// the validation method below. |
| 71 |
|
|
/// |
| 72 |
|
|
/// \return true if the component could not be proven infeasible. |
| 73 |
|
|
/// \note Even if true is returned, the report can contain warnings. |
| 74 |
|
|
bool validate(const GraphComponentPtr_t& comp); |
| 75 |
|
|
|
| 76 |
|
|
/// Validate a state |
| 77 |
|
|
/// \return true if the state could not be proven infeasible. |
| 78 |
|
|
/// \note Even if true is returned, the report can contain warnings. |
| 79 |
|
|
bool validateState(const StatePtr_t& state); |
| 80 |
|
|
|
| 81 |
|
|
/// Validate an edge |
| 82 |
|
|
/// \return true if the edge could not be proven infeasible. |
| 83 |
|
|
/// \note Even if true is returned, the report can contain warnings. |
| 84 |
|
|
bool validateEdge(const EdgePtr_t& edge); |
| 85 |
|
|
|
| 86 |
|
|
/// Validate an graph |
| 87 |
|
|
/// \return true if no component of the graph could not be proven infeasible. |
| 88 |
|
|
/// \note Even if true is returned, the report can contain warnings. |
| 89 |
|
|
bool validateGraph(const GraphPtr_t& graph); |
| 90 |
|
|
|
| 91 |
|
|
CollisionList getCollisionsForNode(const std::string& nodeName) { |
| 92 |
|
|
return collisions_[nodeName]; |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
|
private: |
| 96 |
|
✗ |
void addWarning(const GraphComponentPtr_t& c, const std::string& w) { |
| 97 |
|
✗ |
warnings_.push_back(Message(c, w)); |
| 98 |
|
|
} |
| 99 |
|
|
|
| 100 |
|
✗ |
void addError(const GraphComponentPtr_t& c, const std::string& w) { |
| 101 |
|
✗ |
errors_.push_back(Message(c, w)); |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
✗ |
void addCollision(const GraphComponentPtr_t& c, const std::string& obj1, |
| 105 |
|
|
const std::string& obj2) { |
| 106 |
|
✗ |
Collision coll = Collision{obj1, obj2}; |
| 107 |
|
✗ |
collisions_[c->name()].push_back(coll); |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
typedef std::pair<GraphComponentPtr_t, std::string> Message; |
| 111 |
|
|
std::vector<Message> warnings_, errors_; |
| 112 |
|
|
CollisionMap collisions_; |
| 113 |
|
|
|
| 114 |
|
|
core::ProblemPtr_t problem_; |
| 115 |
|
|
}; |
| 116 |
|
|
|
| 117 |
|
|
inline std::ostream& operator<<(std::ostream& os, const Validation& v) { |
| 118 |
|
|
return v.print(os); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
/// \} |
| 122 |
|
|
} // namespace graph |
| 123 |
|
|
} // namespace manipulation |
| 124 |
|
|
|
| 125 |
|
|
} // namespace hpp |
| 126 |
|
|
|
| 127 |
|
|
#endif // HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH |
| 128 |
|
|
|