g2o
Loading...
Searching...
No Matches
vertex_cam.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 Kurt Konolige
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 "vertex_cam.h"
28
29#include "g2o/stuff/logger.h"
30
31namespace g2o {
32
33// constructor
35
36bool VertexCam::read(std::istream& is) {
37 // first the position and orientation (vector3 and quaternion)
38 Vector3 t;
40 Quaternion r;
41 internal::readVector(is, r.coeffs());
42 r.normalize(); // recover nummeric precision
43
44 // form the camera object
45 SBACam cam(r, t);
46
47 // now fx, fy, cx, cy, baseline
48 double fx;
49
50 // try to read one value
51 is >> fx;
52 if (is.good()) {
53 double fy, cx, cy, tx;
54 is >> fy >> cx >> cy >> tx;
55 cam.setKcam(fx, fy, cx, cy, tx);
56 } else {
57 is.clear();
58 G2O_WARN("cam not defined, using defaults");
59 cam.setKcam(300, 300, 320, 320, cst(0.1));
60 }
61
62 setEstimate(cam);
63 return true;
64}
65
66bool VertexCam::write(std::ostream& os) const {
67 const SBACam& cam = estimate();
68
69 // first the position and orientation (vector3 and quaternion)
71 internal::writeVector(os, cam.rotation().coeffs());
72
73 // now fx, fy, cx, cy, baseline
74 os << cam.Kcam(0, 0) << " ";
75 os << cam.Kcam(1, 1) << " ";
76 os << cam.Kcam(0, 2) << " ";
77 os << cam.Kcam(1, 2) << " ";
78 os << cam.baseline << " ";
79 return os.good();
80}
81
82} // namespace g2o
const EstimateType & estimate() const
return the current estimate of the vertex
Matrix3 Kcam
Definition sbacam.h:51
double baseline
Definition sbacam.h:52
void setKcam(double fx, double fy, double cx, double cy, double tx)
Definition sbacam.cpp:92
const Quaternion & rotation() const
Definition se3quat.h:93
const Vector3 & translation() const
Definition se3quat.h:89
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual void setEstimate(const SBACam &cam)
Definition vertex_cam.h:53
#define G2O_WARN(...)
Definition logger.h:88
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition io_helper.h:36
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition io_helper.h:42
VectorN< 3 > Vector3
Definition eigen_types.h:51
constexpr double cst(long double v)
Definition misc.h:60
Eigen::Quaternion< double > Quaternion
Definition eigen_types.h:81