Berkeley SfM
point_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 "point_3d.h"
41 
42 namespace bsfm {
43 
44 // Default constructor.
45 Point3D::Point3D() : data_(Vector3d::Zero()) {}
46 
47 // (x, y, z) constructor.
48 Point3D::Point3D(double x, double y, double z)
49  : data_(Vector3d(x, y, z)) {}
50 
51 // Copy constructors.
52 Point3D::Point3D(const Point3D& in) : data_(in.Get()) {}
53 
54 // Eigen constructor.
55 Point3D::Point3D(const Vector3d& in) : data_(in) {}
56 
57 // Basic destructor.
59 
60 // Setters.
61 void Point3D::SetX(double x) { data_(0) = x; }
62 
63 void Point3D::SetY(double y) { data_(1) = y; }
64 
65 void Point3D::SetZ(double z) { data_(2) = z; }
66 
67 void Point3D::Set(double x, double y, double z) {
68  data_(0) = x;
69  data_(1) = y;
70  data_(2) = z;
71 }
72 
73 void Point3D::Set(const Point3D& in) {
74  data_ = in.Get();
75 }
76 
77 void Point3D::Set(const Vector3d& in) {
78  data_ = in;
79 }
80 
81 // Getters.
82 double& Point3D::operator()(int index) {
83  // No bound-checking. Be careful!
84  return data_(index);
85 }
86 
87 const double& Point3D::operator()(int index) const {
88  // No bound-checking. Be careful!
89  return data_(index);
90 }
91 
92 double Point3D::X() const { return data_(0); }
93 
94 double Point3D::Y() const { return data_(1); }
95 
96 double Point3D::Z() const { return data_(2); }
97 
98 Vector3d& Point3D::Get() {
99  return data_;
100 }
101 
102 const Vector3d& Point3D::Get() const {
103  return data_;
104 }
105 
106 // Utility.
107 void Point3D::Print(const std::string& prefix) const {
108  if (!prefix.empty()) {
109  std::cout << prefix << std::endl;
110  }
111 
112  std::cout << data_ << std::endl;
113 }
114 
115 // Math operations.
117  data_.normalize();
118 }
119 
121  Point3D out(data_);
122  out.Normalize();
123  return out;
124 }
125 
126 double Point3D::Dot(const Point3D& other) const {
127  return data_.dot(other.Get());
128 }
129 
130 } //\namespace bsfm
double & operator()(int index)
Definition: point_3d.cpp:82
void Normalize()
Definition: point_3d.cpp:116
Point3D Normalized() const
Definition: point_3d.cpp:120
void SetY(double x)
Definition: point_3d.cpp:63
void SetZ(double x)
Definition: point_3d.cpp:65
double Y() const
Definition: point_3d.cpp:94
double X() const
Definition: point_3d.cpp:92
void Print(const std::string &prefix=std::string()) const
Definition: point_3d.cpp:107
void SetX(double x)
Definition: point_3d.cpp:61
Definition: camera.cpp:50
Vector3d & Get()
Definition: point_3d.cpp:98
double Z() const
Definition: point_3d.cpp:96
Vector3d data_
Definition: point_3d.h:96
void Set(double x, double y, double z)
Definition: point_3d.cpp:67
double Dot(const Point3D &other) const
Definition: point_3d.cpp:126