ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
point3d.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // clang-format off
11 #include "util/alignment.h"
12 // clang-format on
13 
14 #include <vector>
15 
16 #include "base/track.h"
17 #include "util/logging.h"
18 #include "util/types.h"
19 
20 namespace colmap {
21 
22 // 3D point class that holds information about triangulated 2D points.
23 class Point3D {
24 public:
25  Point3D();
26 
27  // The point coordinate in world space.
28  inline const Eigen::Vector3d& XYZ() const;
29  inline Eigen::Vector3d& XYZ();
30  inline double XYZ(const size_t idx) const;
31  inline double& XYZ(const size_t idx);
32  inline double X() const;
33  inline double Y() const;
34  inline double Z() const;
35  inline void SetXYZ(const Eigen::Vector3d& xyz);
36 
37  // The RGB color of the point.
38  inline const Eigen::Vector3ub& Color() const;
39  inline Eigen::Vector3ub& Color();
40  inline uint8_t Color(const size_t idx) const;
41  inline uint8_t& Color(const size_t idx);
42  inline void SetColor(const Eigen::Vector3ub& color);
43 
44  // The mean reprojection error in image space.
45  inline double Error() const;
46  inline bool HasError() const;
47  inline void SetError(const double error);
48 
49  inline const class Track& Track() const;
50  inline class Track& Track();
51  inline void SetTrack(const class Track& track);
52 
53  inline bool operator==(const Point3D& other) const;
54  inline bool operator!=(const Point3D& other) const;
55 
56 private:
57  // The 3D position of the point.
58  Eigen::Vector3d xyz_;
59 
60  // The color of the point in the range [0, 255].
61  Eigen::Vector3ub color_;
62 
63  // The mean reprojection error in pixels.
64  double error_;
65 
66  // The track of the point as a list of image observations.
67  class Track track_;
68 };
69 
71 // Implementation
73 
74 const Eigen::Vector3d& Point3D::XYZ() const { return xyz_; }
75 
76 Eigen::Vector3d& Point3D::XYZ() { return xyz_; }
77 
78 double Point3D::XYZ(const size_t idx) const { return xyz_(idx); }
79 
80 double& Point3D::XYZ(const size_t idx) { return xyz_(idx); }
81 
82 double Point3D::X() const { return xyz_.x(); }
83 
84 double Point3D::Y() const { return xyz_.y(); }
85 
86 double Point3D::Z() const { return xyz_.z(); }
87 
88 void Point3D::SetXYZ(const Eigen::Vector3d& xyz) { xyz_ = xyz; }
89 
90 const Eigen::Vector3ub& Point3D::Color() const { return color_; }
91 
92 Eigen::Vector3ub& Point3D::Color() { return color_; }
93 
94 uint8_t Point3D::Color(const size_t idx) const { return color_(idx); }
95 
96 uint8_t& Point3D::Color(const size_t idx) { return color_(idx); }
97 
98 void Point3D::SetColor(const Eigen::Vector3ub& color) { color_ = color; }
99 
100 double Point3D::Error() const { return error_; }
101 
102 bool Point3D::HasError() const { return error_ != -1.0; }
103 
104 void Point3D::SetError(const double error) { error_ = error; }
105 
106 const class Track& Point3D::Track() const { return track_; }
107 
108 class Track& Point3D::Track() { return track_; }
109 
110 void Point3D::SetTrack(const class Track& track) { track_ = track; }
111 
112 bool Point3D::operator==(const Point3D& other) const {
113  return XYZ() == other.XYZ() && Color() == other.Color() &&
114  Error() == other.Error() && Track() == other.Track();
115 }
116 
117 bool Point3D::operator!=(const Point3D& other) const {
118  return !(*this == other);
119 }
120 
121 } // namespace colmap
122 
123 // EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION_CUSTOM(colmap::Point3D)
math::float4 color
double Y() const
Definition: point3d.h:84
void SetError(const double error)
Definition: point3d.h:104
void SetTrack(const class Track &track)
Definition: point3d.h:110
const Eigen::Vector3d & XYZ() const
Definition: point3d.h:74
const class Track & Track() const
Definition: point3d.h:106
double X() const
Definition: point3d.h:82
bool operator==(const Point3D &other) const
Definition: point3d.h:112
double Z() const
Definition: point3d.h:86
void SetColor(const Eigen::Vector3ub &color)
Definition: point3d.h:98
bool HasError() const
Definition: point3d.h:102
void SetXYZ(const Eigen::Vector3d &xyz)
Definition: point3d.h:88
double Error() const
Definition: point3d.h:100
const Eigen::Vector3ub & Color() const
Definition: point3d.h:90
bool operator!=(const Point3D &other) const
Definition: point3d.h:117
Matrix< uint8_t, 3, 1 > Vector3ub
Definition: types.h:42