math.cc 5.71 KB
Newer Older
Joseph Mirabel's avatar
Joseph Mirabel committed
1
2
3
//
// Software License Agreement (BSD License)
//
4
//  Copyright (c) 2019 CNRS-LAAS INRIA
Joseph Mirabel's avatar
Joseph Mirabel committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//  Author: Joseph Mirabel
//  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions
//  are met:
//
//   * Redistributions of source code must retain the above copyright
//     notice, this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above
//     copyright notice, this list of conditions and the following
//     disclaimer in the documentation and/or other materials provided
//     with the distribution.
//   * Neither the name of CNRS-LAAS. nor the names of its
//     contributors may be used to endorse or promote products derived
//     from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
//  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//  POSSIBILITY OF SUCH DAMAGE.

#include <boost/python.hpp>
36
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
Joseph Mirabel's avatar
Joseph Mirabel committed
37
38
39
40
41
42
43
44

#include <eigenpy/eigenpy.hpp>
#include <eigenpy/geometry.hpp>

#include <hpp/fcl/fwd.hh>
#include <hpp/fcl/math/transform.h>

#include "fcl.hh"
45

46
#ifdef HPP_FCL_HAS_DOXYGEN_AUTODOC
Joseph Mirabel's avatar
Joseph Mirabel committed
47
#include "doxygen_autodoc/hpp/fcl/math/transform.h"
48
#endif
Joseph Mirabel's avatar
Joseph Mirabel committed
49

50
#include "../doc/python/doxygen.hh"
51
#include "../doc/python/doxygen-boost.hh"
Joseph Mirabel's avatar
Joseph Mirabel committed
52

Joseph Mirabel's avatar
Joseph Mirabel committed
53
54
55
using namespace boost::python;
using namespace hpp::fcl;

56
57
namespace dv = doxygen::visitor;

Joseph Mirabel's avatar
Joseph Mirabel committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
struct TriangleWrapper
{
  static Triangle::index_type getitem (const Triangle& t, int i)
  {
    if (i >= 3) throw std::out_of_range("index is out of range");
    return t[i];
  }
  static void setitem (Triangle& t, int i, Triangle::index_type v)
  {
    if (i >= 3) throw std::out_of_range("index is out of range");
    t[i] = v;
  }
};

void exposeMaths ()
{
  eigenpy::enableEigenPy();

  if(!eigenpy::register_symbolic_link_to_registered_type<Eigen::Quaterniond>())
    eigenpy::exposeQuaternion();
  if(!eigenpy::register_symbolic_link_to_registered_type<Eigen::AngleAxisd>())
    eigenpy::exposeAngleAxis();

Joseph Mirabel's avatar
Joseph Mirabel committed
81
82
83
  eigenpy::enableEigenPySpecific<Matrix3f>();
  eigenpy::enableEigenPySpecific<Vec3f   >();

84
  class_ <Transform3f> ("Transform3f", doxygen::class_doc<Transform3f>(), init<>(arg("self"),doxygen::constructor_doc<Transform3f>()))
Joseph Mirabel's avatar
Joseph Mirabel committed
85
86
87
88
89
    .def (init<Matrix3f, Vec3f>    (doxygen::constructor_doc<Transform3f, const Matrix3f::MatrixBase&, const Vec3f::MatrixBase&>()))
    .def (init<Quaternion3f, Vec3f>(doxygen::constructor_doc<Transform3f, const Quaternion3f&        , const Vec3f::MatrixBase&>()))
    .def (init<Matrix3f>           (doxygen::constructor_doc<Transform3f, const Matrix3f&                                      >()))
    .def (init<Quaternion3f>       (doxygen::constructor_doc<Transform3f, const Quaternion3f&                                  >()))
    .def (init<Vec3f>              (doxygen::constructor_doc<Transform3f, const Vec3f&                                         >()))
90
    .def (init<Transform3f>        (doxygen::constructor_doc<Transform3f, const Transform3f&                                   >()))
Joseph Mirabel's avatar
Joseph Mirabel committed
91

92
    .def (dv::member_func("getQuatRotation", &Transform3f::getQuatRotation))
93
    .def ("getTranslation", &Transform3f::getTranslation, doxygen::member_func_doc(&Transform3f::getTranslation), return_value_policy<copy_const_reference>())
Joseph Mirabel's avatar
Joseph Mirabel committed
94
    .def ("getRotation", &Transform3f::getRotation, return_value_policy<copy_const_reference>())
95
    .def (dv::member_func("isIdentity", &Transform3f::isIdentity))
Joseph Mirabel's avatar
Joseph Mirabel committed
96

97
    .def (dv::member_func("setQuatRotation", &Transform3f::setQuatRotation))
Joseph Mirabel's avatar
Joseph Mirabel committed
98
99
    .def ("setTranslation", &Transform3f::setTranslation<Vec3f>)
    .def ("setRotation", &Transform3f::setRotation<Matrix3f>)
100
101
102
    .def (dv::member_func("setTransform", &Transform3f::setTransform<Matrix3f,Vec3f>))
    .def (dv::member_func("setTransform", static_cast<void (Transform3f::*)(const Quaternion3f&, const Vec3f&)>(&Transform3f::setTransform)))
    .def (dv::member_func("setIdentity", &Transform3f::setIdentity))
Joseph Mirabel's avatar
Joseph Mirabel committed
103

104
    .def (dv::member_func("transform", &Transform3f::transform<Vec3f>))
Joseph Mirabel's avatar
Joseph Mirabel committed
105
    .def ("inverseInPlace", &Transform3f::inverseInPlace, return_internal_reference<>(), doxygen::member_func_doc(&Transform3f::inverseInPlace))
106
107
    .def (dv::member_func("inverse", &Transform3f::inverse))
    .def (dv::member_func("inverseTimes", &Transform3f::inverseTimes))
Joseph Mirabel's avatar
Joseph Mirabel committed
108
109
110
111
112
113
114
115
116
117
118
119

    .def (self * self)
    .def (self *= self)
    .def (self == self)
    .def (self != self)
    ;

  class_ <Triangle> ("Triangle", init<>())
    .def (init <Triangle::index_type, Triangle::index_type, Triangle::index_type>())
    .def ("__getitem__", &TriangleWrapper::getitem)
    .def ("__setitem__", &TriangleWrapper::setitem)
    ;
120
121
122
123
124
125
126
127
128
129
130
131
132

  if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<Vec3f> >())
  {
    class_< std::vector<Vec3f> >("StdVec_Vec3f")
      .def(vector_indexing_suite< std::vector<Vec3f> >())
      ;
  }
  if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<Triangle> >())
  {
    class_< std::vector<Triangle> >("StdVec_Triangle")
      .def(vector_indexing_suite< std::vector<Triangle> >())
      ;
  }
Joseph Mirabel's avatar
Joseph Mirabel committed
133
}