test_fcl_auto_diff.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * Copyright (c) 2016, Toyota Research Institute
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Open Source Robotics Foundation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
39 #include <gtest/gtest.h>
40 #include <Eigen/Core>
41 #include <unsupported/Eigen/AutoDiff>
43 
44 using namespace fcl;
45 
46 //==============================================================================
47 template <typename S>
49 {
51 
52  S dist;
53 
54  Sphere<S> s1(20);
55  Sphere<S> s2(10);
56 
59 
60  tf2.translation() = p;
61 
62  solver.shapeDistance(s1, tf1, s2, tf2, &dist);
63 
64  return dist;
65 }
66 
67 //==============================================================================
68 template <typename S>
69 void test_basic()
70 {
71  using derivative_t = Eigen::Matrix<S, 3, 1>;
72  using scalar_t = Eigen::AutoDiffScalar<derivative_t>;
73  using input_t = Eigen::Matrix<scalar_t, 3, 1>;
74 
75  input_t pos(40, 0, 0);
76  pos(0).derivatives() = derivative_t::Unit(3, 0);
77  pos(1).derivatives() = derivative_t::Unit(3, 1);
78  pos(2).derivatives() = derivative_t::Unit(3, 2);
79 
80  auto dist = getDistance(pos);
81  EXPECT_EQ(dist, (S)10);
82  EXPECT_EQ(dist.value(), (S)10);
83  EXPECT_EQ(dist.derivatives(), Vector3<S>(1, 0, 0));
84 
85  pos << 0, 40, 0;
86  pos(0).derivatives() = derivative_t::Unit(3, 0);
87  pos(1).derivatives() = derivative_t::Unit(3, 1);
88  pos(2).derivatives() = derivative_t::Unit(3, 2);
89  dist = getDistance(pos);
90  EXPECT_EQ(dist, (S)10);
91  EXPECT_EQ(dist.value(), (S)10);
92  EXPECT_EQ(dist.derivatives(), Vector3<S>(0, 1, 0));
93 
94  pos << 0, 0, 40;
95  pos(0).derivatives() = derivative_t::Unit(3, 0);
96  pos(1).derivatives() = derivative_t::Unit(3, 1);
97  pos(2).derivatives() = derivative_t::Unit(3, 2);
98  dist = getDistance(pos);
99  EXPECT_EQ(dist, (S)10);
100  EXPECT_EQ(dist.value(), (S)10);
101  EXPECT_EQ(dist.derivatives(), Vector3<S>(0, 0, 1));
102 }
103 
104 //==============================================================================
105 GTEST_TEST(FCL_AUTO_DIFF, basic)
106 {
107 // test_basic<float>();
108  test_basic<double>();
109 }
110 
111 //==============================================================================
112 int main(int argc, char* argv[])
113 {
114  ::testing::InitGoogleTest(&argc, argv);
115  return RUN_ALL_TESTS();
116 }
fcl::Transform3
Eigen::Transform< S, 3, Eigen::Isometry > Transform3
Definition: types.h:91
fcl::detail::GJKSolver_libccd
collision and distance solver based on libccd library.
Definition: gjk_solver_libccd.h:54
test_basic
void test_basic()
Definition: test_fcl_auto_diff.cpp:69
GTEST_TEST
GTEST_TEST(FCL_AUTO_DIFF, basic)
Definition: test_fcl_auto_diff.cpp:105
getDistance
S getDistance(const Vector3< S > &p)
Definition: test_fcl_auto_diff.cpp:48
fcl::Vector3
Eigen::Matrix< S, 3, 1 > Vector3
Definition: types.h:70
distance.h
main
int main(int argc, char *argv[])
Definition: test_fcl_auto_diff.cpp:112
fcl::Sphere
Center at zero point sphere.
Definition: sphere.h:51
fcl::detail::GJKSolver_libccd::shapeDistance
bool shapeDistance(const Shape1 &s1, const Transform3< S > &tf1, const Shape2 &s2, const Transform3< S > &tf2, S *dist=nullptr, Vector3< S > *p1=nullptr, Vector3< S > *p2=nullptr) const
distance computation between two shapes
Definition: gjk_solver_libccd-inl.h:640
fcl
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
EXPECT_EQ
#define EXPECT_EQ(a, b)


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:49