ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
point2d.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 "util/types.h"
15 
16 namespace colmap {
17 
18 // 2D point class corresponds to a feature in an image. It may or may not have a
19 // corresponding 3D point if it is part of a triangulated track.
20 class Point2D {
21 public:
22  Point2D();
23 
24  // The coordinate in image space in pixels.
25  inline const Eigen::Vector2d& XY() const;
26  inline Eigen::Vector2d& XY();
27  inline double X() const;
28  inline double Y() const;
29  inline void SetXY(const Eigen::Vector2d& xy);
30 
31  // The identifier of the observed 3D point. If the image point does not
32  // observe a 3D point, the identifier is `kInvalidPoint3Did`.
33  inline point3D_t Point3DId() const;
34  inline bool HasPoint3D() const;
35  inline void SetPoint3DId(const point3D_t point3D_id);
36 
37  inline bool operator==(const Point2D& other) const;
38  inline bool operator!=(const Point2D& other) const;
39 
40 private:
41  // The image coordinates in pixels, starting at upper left corner with 0.
42  Eigen::Vector2d xy_;
43 
44  // The identifier of the 3D point. If the 2D point is not part of a 3D point
45  // track the identifier is `kInvalidPoint3DId` and `HasPoint3D() = false`.
46  point3D_t point3D_id_;
47 };
48 
50 // Implementation
52 
53 const Eigen::Vector2d& Point2D::XY() const { return xy_; }
54 
55 Eigen::Vector2d& Point2D::XY() { return xy_; }
56 
57 double Point2D::X() const { return xy_.x(); }
58 
59 double Point2D::Y() const { return xy_.y(); }
60 
61 void Point2D::SetXY(const Eigen::Vector2d& xy) { xy_ = xy; }
62 
63 point3D_t Point2D::Point3DId() const { return point3D_id_; }
64 
65 bool Point2D::HasPoint3D() const { return point3D_id_ != kInvalidPoint3DId; }
66 
67 void Point2D::SetPoint3DId(const point3D_t point3D_id) {
68  point3D_id_ = point3D_id;
69 }
70 
71 bool Point2D::operator==(const Point2D& other) const {
72  return XY() == other.XY() && Point3DId() == other.Point3DId();
73 }
74 
75 bool Point2D::operator!=(const Point2D& other) const {
76  return !(*this == other);
77 }
78 
79 } // namespace colmap
void SetXY(const Eigen::Vector2d &xy)
Definition: point2d.h:61
point3D_t Point3DId() const
Definition: point2d.h:63
double X() const
Definition: point2d.h:57
bool operator==(const Point2D &other) const
Definition: point2d.h:71
double Y() const
Definition: point2d.h:59
bool HasPoint3D() const
Definition: point2d.h:65
void SetPoint3DId(const point3D_t point3D_id)
Definition: point2d.h:67
bool operator!=(const Point2D &other) const
Definition: point2d.h:75
const Eigen::Vector2d & XY() const
Definition: point2d.h:53
uint64_t point3D_t
Definition: types.h:72
const point3D_t kInvalidPoint3DId
Definition: types.h:80