Berkeley SfM
covariance_3d.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
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  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 #include <iostream>
39 
40 #include "covariance_3d.h"
41 
42 namespace bsfm {
43 
44 // Default constructor.
45 Covariance3D::Covariance3D() : data_(Matrix3d::Identity()) {}
46 
47 // Element-wise constructor.
48 Covariance3D::Covariance3D(double x11, double x12, double x13,
49  double x21, double x22, double x23,
50  double x31, double x32, double x33) {
51  data_(0, 0) = x11;
52  data_(0, 1) = x12;
53  data_(0, 2) = x13;
54  data_(1, 0) = x21;
55  data_(1, 1) = x22;
56  data_(1, 2) = x23;
57  data_(2, 0) = x31;
58  data_(2, 1) = x32;
59  data_(2, 1) = x33;
60 }
61 
62 // Copy constructor.
63 Covariance3D::Covariance3D(const Covariance3D& in) : data_(in.Get()) {}
64 
65 // Eigen constructor.
66 Covariance3D::Covariance3D(const Matrix3d& in) : data_(in) {}
67 
68 // Static zero.
70  return Covariance3D(Matrix3d::Zero());
71 }
72 
73 // Static identity.
75  return Covariance3D(Matrix3d::Identity());
76 }
77 
78 // Default destructor.
80 
81 // Setters.
83  data_ = in.Get();
84 }
85 
86 void Covariance3D::Set(const Matrix3d& in) {
87  data_ = in;
88 }
89 
90 // Getters.
91 double& Covariance3D::operator()(int row, int col) {
92  // No bound-checking. Be careful!
93  return data_(row, col);
94 }
95 
96 const double& Covariance3D::operator()(int row, int col) const {
97  // No bound-checking. Be careful!
98  return data_(row, col);
99 }
100 
101 const Matrix3d& Covariance3D::Get() const {
102  return data_;
103 }
104 
105 // Utility.
106 void Covariance3D::Print(const std::string& prefix) const {
107  if (!prefix.empty()) {
108  std::cout << prefix << std::endl;
109  }
110 
111  std::cout << data_ << std::endl;
112 }
113 
114 } //\namespace bsfm
static Covariance3D Zero()
const Matrix3d & Get() const
void Set(const Covariance3D &in)
double & operator()(int row, int col)
Definition: camera.cpp:50
static Covariance3D Identity()
void Print(const std::string &prefix=std::string()) const