GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: python/distance.cc Lines: 36 40 90.0 %
Date: 2024-02-09 12:57:42 Branches: 29 58 50.0 %

Line Branch Exec Source
1
//
2
// Software License Agreement (BSD License)
3
//
4
//  Copyright (c) 2019 CNRS-LAAS INRIA
5
//  Author: Joseph Mirabel
6
//  All rights reserved.
7
//
8
//  Redistribution and use in source and binary forms, with or without
9
//  modification, are permitted provided that the following conditions
10
//  are met:
11
//
12
//   * Redistributions of source code must retain the above copyright
13
//     notice, this list of conditions and the following disclaimer.
14
//   * Redistributions in binary form must reproduce the above
15
//     copyright notice, this list of conditions and the following
16
//     disclaimer in the documentation and/or other materials provided
17
//     with the distribution.
18
//   * Neither the name of CNRS-LAAS. nor the names of its
19
//     contributors may be used to endorse or promote products derived
20
//     from this software without specific prior written permission.
21
//
22
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
//  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
//  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
//  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
//  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
//  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
//  POSSIBILITY OF SUCH DAMAGE.
34
35
#include <eigenpy/eigenpy.hpp>
36
37
#include "fcl.hh"
38
39
#include <hpp/fcl/fwd.hh>
40
#include <hpp/fcl/distance.h>
41
42
#ifdef HPP_FCL_HAS_DOXYGEN_AUTODOC
43
#include "doxygen_autodoc/functions.h"
44
#include "doxygen_autodoc/hpp/fcl/collision_data.h"
45
#endif
46
47
using namespace boost::python;
48
using namespace hpp::fcl;
49
50
namespace dv = doxygen::visitor;
51
52
struct DistanceRequestWrapper {
53
  static Vec3f getNearestPoint1(const DistanceResult& res) {
54
    return res.nearest_points[0];
55
  }
56
  static Vec3f getNearestPoint2(const DistanceResult& res) {
57
    return res.nearest_points[1];
58
  }
59
};
60
61
5
void exposeDistanceAPI() {
62
5
  if (!eigenpy::register_symbolic_link_to_registered_type<DistanceRequest>()) {
63
5
    class_<DistanceRequest, bases<QueryRequest> >(
64
        "DistanceRequest", doxygen::class_doc<DistanceRequest>(),
65
5
        init<optional<bool, FCL_REAL, FCL_REAL> >(
66


20
            (arg("self"), arg("enable_nearest_points"), arg("rel_err"),
67
10
             arg("abs_err")),
68
            "Constructor"))
69
5
        .DEF_RW_CLASS_ATTRIB(DistanceRequest, enable_nearest_points)
70
5
        .DEF_RW_CLASS_ATTRIB(DistanceRequest, rel_err)
71
5
        .DEF_RW_CLASS_ATTRIB(DistanceRequest, abs_err);
72
  }
73
74
5
  if (!eigenpy::register_symbolic_link_to_registered_type<
75
5
          std::vector<DistanceRequest> >()) {
76
10
    class_<std::vector<DistanceRequest> >("StdVec_DistanceRequest")
77
5
        .def(vector_indexing_suite<std::vector<DistanceRequest> >());
78
  }
79
80
5
  if (!eigenpy::register_symbolic_link_to_registered_type<DistanceResult>()) {
81
10
    class_<DistanceResult, bases<QueryResult> >(
82
        "DistanceResult", doxygen::class_doc<DistanceResult>(), no_init)
83
5
        .def(dv::init<DistanceResult>())
84
5
        .DEF_RW_CLASS_ATTRIB(DistanceResult, min_distance)
85
5
        .DEF_RW_CLASS_ATTRIB(DistanceResult, normal)
86
        //.def_readwrite ("nearest_points", &DistanceResult::nearest_points)
87
        .def("getNearestPoint1", &DistanceRequestWrapper::getNearestPoint1,
88
5
             doxygen::class_attrib_doc<DistanceResult>("nearest_points"))
89
        .def("getNearestPoint2", &DistanceRequestWrapper::getNearestPoint2,
90
5
             doxygen::class_attrib_doc<DistanceResult>("nearest_points"))
91
5
        .DEF_RO_CLASS_ATTRIB(DistanceResult, o1)
92
5
        .DEF_RO_CLASS_ATTRIB(DistanceResult, o2)
93
5
        .DEF_RW_CLASS_ATTRIB(DistanceResult, b1)
94
5
        .DEF_RW_CLASS_ATTRIB(DistanceResult, b2)
95
96
        .def("clear", &DistanceResult::clear,
97
5
             doxygen::member_func_doc(&DistanceResult::clear));
98
  }
99
100
5
  if (!eigenpy::register_symbolic_link_to_registered_type<
101
5
          std::vector<DistanceResult> >()) {
102
10
    class_<std::vector<DistanceResult> >("StdVec_DistanceResult")
103
5
        .def(vector_indexing_suite<std::vector<DistanceResult> >());
104
  }
105
106
5
  doxygen::def(
107
      "distance",
108
      static_cast<FCL_REAL (*)(const CollisionObject*, const CollisionObject*,
109
                               const DistanceRequest&, DistanceResult&)>(
110
          &distance));
111
5
  doxygen::def(
112
      "distance",
113
      static_cast<FCL_REAL (*)(const CollisionGeometry*, const Transform3f&,
114
                               const CollisionGeometry*, const Transform3f&,
115
                               DistanceRequest&, DistanceResult&)>(&distance));
116
117
5
  class_<ComputeDistance>("ComputeDistance",
118
                          doxygen::class_doc<ComputeDistance>(), no_init)
119
      .def(dv::init<ComputeDistance, const CollisionGeometry*,
120
10
                    const CollisionGeometry*>())
121
5
      .def("__call__",
122
           static_cast<FCL_REAL (ComputeDistance::*)(
123
               const Transform3f&, const Transform3f&, DistanceRequest&,
124
5
               DistanceResult&) const>(&ComputeDistance::operator()));
125
5
}