Debian Codegraph @

unit_test/slam3d_addons/io_slam3d_addons.cpp

raw symbols SCIP
1 // g2o - General Graph Optimization
2 // Copyright (C) 2020 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
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 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 #include <sstream>
28
29 #include "g2o/types/slam3d_addons/edge_plane.h"
30 #include "g2o/types/slam3d_addons/edge_se3_calib.h"
31 #include "g2o/types/slam3d_addons/edge_se3_line.h"
32 #include "g2o/types/slam3d_addons/edge_se3_plane_calib.h"
33 #include "g2o/types/slam3d_addons/vertex_line3d.h"
34 #include "g2o/types/slam3d_addons/vertex_plane.h"
35 #include "g2o/types/slam3d_addons/vertex_se3_euler.h"
36 #include "gtest/gtest.h"
37 #include "unit_test/test_helper/io.h"
38 #include "unit_test/test_helper/random_state.h"
39
40 using namespace std;
41 using namespace g2o;
42
43 struct RandomPlane3D {
44 static Plane3D create() { return Plane3D(Vector4::Random()); }
45 static bool isApprox(const Plane3D& a, const Plane3D& b) {
46 return a.coeffs().isApprox(b.coeffs(), 1e-5);
47 }
48 };
49
50 struct RandomLine3D {
51 static Line3D create() { return Line3D(Vector6::Random()); }
52 static bool isApprox(const Line3D& a, const Line3D& b) {
53 return a.isApprox(b, 1e-5);
54 }
55 };
56
57 class IoSlam3dAddonsParam : public ::testing::Test {
58 protected:
59 void SetUp() override {
60 graph.reset(new g2o::OptimizableGraph);
61
62 // setting up parameters for tests
63 paramOffset = new ParameterSE3Offset();
64 paramOffset->setId(63);
65 graph->addParameter(paramOffset);
66
67 // setting up some vertices
68 int numVertices = 0;
69 pose = new VertexSE3;
70 pose->setId(numVertices++);
71 graph->addVertex(pose);
72 line = new VertexLine3D;
73 line->setId(numVertices++);
74 graph->addVertex(line);
75 }
76
77 std::shared_ptr<g2o::OptimizableGraph> graph;
78 ParameterSE3Offset* paramOffset = nullptr;
79 VertexSE3* pose = nullptr;
80 VertexLine3D* line = nullptr;
81 };
82
83 TEST(IoSlam3dAddOns, ReadWriteVertexSE3Euler) {
84 readWriteVectorBasedVertex<VertexSE3Euler, internal::RandomIsometry3>();
85 }
86
87 TEST(IoSlam3dAddOns, ReadWriteVertexPlane) {
88 // setting up the vertex for output
89 VertexPlane* outputVertex = new VertexPlane();
90 outputVertex->color = Vector3::Random();
91 // IO Test
92 readWriteVectorBasedVertex<VertexPlane, RandomPlane3D>(outputVertex);
93 }
94
95 TEST(IoSlam3dAddOns, ReadWriteVertexLine3D) {
96 readWriteVectorBasedVertex<VertexLine3D, RandomLine3D>();
97 }
98
99 TEST(IoSlam3dAddOns, ReadWriteEdgeSE3Calib) {
100 readWriteVectorBasedEdge<EdgeSE3Calib, internal::RandomIsometry3>();
101 }
102
103 TEST_F(IoSlam3dAddonsParam, ReadWriteEdgeSE3Line3D) {
104 // prepare edge
105 EdgeSE3Line3D* outputEdge = new EdgeSE3Line3D();
106 outputEdge->setParameterId(0, paramOffset->id());
107 outputEdge->setVertex(0, pose);
108 outputEdge->setVertex(1, line);
109 ASSERT_TRUE(graph->addEdge(outputEdge));
110 // test IO
111 readWriteVectorBasedEdge<EdgeSE3Line3D, RandomLine3D>(outputEdge);
112 }
113
114 TEST(IoSlam3dAddOns, ReadWriteEdgeSE3PlaneSensorCalib) {
115 readWriteVectorBasedEdge<EdgeSE3PlaneSensorCalib, RandomPlane3D>();
116 }