| 1 | // g2o - General Graph Optimization |
| 2 | // Copyright (C) 2014 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/sba/types_six_dof_expmap.h" |
| 30 | #include "gtest/gtest.h" |
| 31 | #include "unit_test/test_helper/io.h" |
| 32 | #include "unit_test/test_helper/random_state.h" |
| 33 | |
| 34 | using namespace std; |
| 35 | using namespace g2o; |
| 36 | |
| 37 | /* |
| 38 | * VERTEX Tests |
| 39 | */ |
| 40 | TEST(IoSixDofExpmap, ReadWriteVertexSE3Expmap) { |
| 41 | readWriteVectorBasedVertex<VertexSE3Expmap, internal::RandomSE3Quat>(); |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * EDGE Tests |
| 46 | */ |
| 47 | TEST(IoSixDofExpmap, ReadWriteEdgeSE3Expmap) { |
| 48 | readWriteVectorBasedEdge<EdgeSE3Expmap, internal::RandomSE3Quat>(); |
| 49 | } |
| 50 | |
| 51 | TEST(IoSixDofExpmap, ReadWriteEdgeSE3ProjectXYZ) { |
| 52 | readWriteVectorBasedEdge<EdgeSE3ProjectXYZ>(); |
| 53 | } |
| 54 | |
| 55 | TEST(IoSixDofExpmap, ReadWriteEdgeStereoSE3ProjectXYZ) { |
| 56 | readWriteVectorBasedEdge<EdgeStereoSE3ProjectXYZ>(); |
| 57 | } |
| 58 | |
| 59 | TEST(IoSixDofExpmap, ReadWriteEdgeSE3ProjectXYZOnlyPose) { |
| 60 | readWriteVectorBasedEdge<EdgeSE3ProjectXYZOnlyPose>(); |
| 61 | } |
| 62 | |
| 63 | TEST(IoSixDofExpmap, ReadWriteEdgeStereoSE3ProjectXYZOnlyPose) { |
| 64 | readWriteVectorBasedEdge<EdgeStereoSE3ProjectXYZOnlyPose>(); |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * EDGE Tests including a Camera Parameter |
| 69 | */ |
| 70 | class IoSixDofExpmapParam : public ::testing::Test { |
| 71 | protected: |
| 72 | void SetUp() override { |
| 73 | graph.reset(new g2o::OptimizableGraph); |
| 74 | |
| 75 | CameraParameters* paramCam = new CameraParameters(); |
| 76 | paramCam->setId(42); |
| 77 | graph->addParameter(paramCam); |
| 78 | |
| 79 | // setting up some vertices |
| 80 | point = new VertexPointXYZ; |
| 81 | point->setId(0); |
| 82 | graph->addVertex(point); |
| 83 | pose = new VertexSE3Expmap; |
| 84 | pose->setId(1); |
| 85 | graph->addVertex(pose); |
| 86 | } |
| 87 | |
| 88 | void prepareEdge(OptimizableGraph::Edge* e) { |
| 89 | e->setParameterId(0, 42); |
| 90 | e->setVertex(0, point); |
| 91 | e->setVertex(1, pose); |
| 92 | graph->addEdge(e); |
| 93 | } |
| 94 | |
| 95 | std::shared_ptr<g2o::OptimizableGraph> graph; |
| 96 | VertexPointXYZ* point = nullptr; |
| 97 | VertexSE3Expmap* pose = nullptr; |
| 98 | }; |
| 99 | |
| 100 | TEST_F(IoSixDofExpmapParam, ReadWriteEdgeProjectXYZ2UV) { |
| 101 | EdgeProjectXYZ2UV* outputEdge = new EdgeProjectXYZ2UV; |
| 102 | prepareEdge(outputEdge); |
| 103 | readWriteVectorBasedEdge<EdgeProjectXYZ2UV>(outputEdge); |
| 104 | } |
| 105 | |
| 106 | TEST_F(IoSixDofExpmapParam, ReadWriteEdgeProjectPSI2UV) { |
| 107 | VertexSE3Expmap* p2 = new VertexSE3Expmap; |
| 108 | p2->setId(2); |
| 109 | graph->addVertex(p2); |
| 110 | EdgeProjectPSI2UV* outputEdge = new EdgeProjectPSI2UV; |
| 111 | outputEdge->setVertex(2, p2); |
| 112 | prepareEdge(outputEdge); |
| 113 | readWriteVectorBasedEdge<EdgeProjectPSI2UV>(outputEdge); |
| 114 | } |
| 115 | |
| 116 | TEST_F(IoSixDofExpmapParam, ReadWriteEdgeProjectXYZ2UVU) { |
| 117 | EdgeProjectXYZ2UVU* outputEdge = new EdgeProjectXYZ2UVU; |
| 118 | prepareEdge(outputEdge); |
| 119 | readWriteVectorBasedEdge<EdgeProjectXYZ2UVU>(outputEdge); |
| 120 | } |