ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
model_viewer_widget.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 #include <QOpenGLFunctions_3_2_Core>
11 #include <QtCore>
12 #include <QtGlobal>
13 #include <QtOpenGL>
14 // QOpenGLWidget: In Qt5 it's in QtOpenGL module, in Qt6 it's in QtOpenGLWidgets
15 // module Use direct include which works for both when the appropriate module is
16 // linked
17 #include <QOpenGLWidget>
18 
19 #include "base/database.h"
20 #include "base/reconstruction.h"
21 #include "ui/colormaps.h"
22 #include "ui/image_viewer_widget.h"
23 #include "ui/line_painter.h"
25 #include "ui/point_painter.h"
26 #include "ui/point_viewer_widget.h"
27 #include "ui/render_options.h"
28 #include "ui/triangle_painter.h"
29 #include "util/option_manager.h"
30 
31 namespace colmap {
32 
33 class ModelViewerWidget : public QOpenGLWidget,
34  protected QOpenGLFunctions_3_2_Core {
35 public:
36  const float kInitNearPlane = 1.0f;
37  const float kMinNearPlane = 1e-3f;
38  const float kMaxNearPlane = 1e5f;
39  const float kNearPlaneScaleSpeed = 0.02f;
40  const float kFarPlane = 1e5f;
41  const float kInitFocusDistance = 100.0f;
42  const float kMinFocusDistance = 1e-5f;
43  const float kMaxFocusDistance = 1e8f;
44  const float kFieldOfView = 25.0f;
45  const float kFocusSpeed = 2.0f;
46  const float kInitPointSize = 1.0f;
47  const float kMinPointSize = 0.5f;
48  const float kMaxPointSize = 100.0f;
49  const float kPointScaleSpeed = 0.1f;
50  const float kInitImageSize = 0.2f;
51  const float kMinImageSize = 1e-6f;
52  const float kMaxImageSize = 1e3f;
53  const float kImageScaleSpeed = 0.1f;
54  const int kDoubleClickInterval = 250;
55 
56  ModelViewerWidget(QWidget* parent, OptionManager* options);
57 
58  void ReloadReconstruction();
59  void ClearReconstruction();
60 
61  int GetProjectionType() const;
62 
63  // Takes ownwership of the colormap objects.
64  void SetPointColormap(PointColormapBase* colormap);
65  void SetImageColormap(ImageColormapBase* colormap);
66 
67  void UpdateMovieGrabber();
68 
69  void EnableCoordinateGrid();
70  void DisableCoordinateGrid();
71 
72  void ChangeFocusDistance(const float delta);
73  void ChangeNearPlane(const float delta);
74  void ChangePointSize(const float delta);
75  void ChangeCameraSize(const float delta);
76 
77  void RotateView(const float x,
78  const float y,
79  const float prev_x,
80  const float prev_y);
81  void TranslateView(const float x,
82  const float y,
83  const float prev_x,
84  const float prev_y);
85 
86  void ResetView();
87 
88  QMatrix4x4 ModelViewMatrix() const;
89  void SetModelViewMatrix(const QMatrix4x4& matrix);
90 
91  void SelectObject(const int x, const int y);
92  void SelectMoviewGrabberView(const size_t view_idx);
93 
94  QImage GrabImage();
95  void GrabMovie();
96 
97  void ShowPointInfo(const point3D_t point3D_id);
98  void ShowImageInfo(const image_t image_id);
99 
100  float PointSize() const;
101  float ImageSize() const;
102  void SetPointSize(const float point_size);
103  void SetImageSize(const float image_size);
104 
105  void SetBackgroundColor(const float r, const float g, const float b);
106 
107  // Copy of current scene data that is displayed
109  std::unordered_map<camera_t, Camera> cameras;
110  std::unordered_map<image_t, Image> images;
111  std::unordered_map<point3D_t, Point3D> points3D;
112  std::vector<image_t> reg_image_ids;
113 
115 
116 protected:
117  void initializeGL() override;
118  void resizeGL(int width, int height) override;
119  void paintGL() override;
120 
121 private:
122  void mousePressEvent(QMouseEvent* event) override;
123  void mouseReleaseEvent(QMouseEvent* event) override;
124  void mouseMoveEvent(QMouseEvent* event) override;
125  void wheelEvent(QWheelEvent* event) override;
126 
127  void SetupPainters();
128  void SetupView();
129 
130  void Upload();
131  void UploadCoordinateGridData();
132  void UploadPointData(const bool selection_mode = false);
133  void UploadPointConnectionData();
134  void UploadImageData(const bool selection_mode = false);
135  void UploadImageConnectionData();
136  void UploadMovieGrabberData();
137 
138  void ComposeProjectionMatrix();
139 
140  float ZoomScale() const;
141  float AspectRatio() const;
142  float OrthographicWindowExtent() const;
143 
144  Eigen::Vector3f PositionToArcballVector(const float x, const float y) const;
145 
146  OptionManager* options_;
147 
148  QMatrix4x4 model_view_matrix_;
149  QMatrix4x4 projection_matrix_;
150 
151  LinePainter coordinate_axes_painter_;
152  LinePainter coordinate_grid_painter_;
153 
154  PointPainter point_painter_;
155  LinePainter point_connection_painter_;
156 
157  LinePainter image_line_painter_;
158  TrianglePainter image_triangle_painter_;
159  LinePainter image_connection_painter_;
160 
161  LinePainter movie_grabber_path_painter_;
162  LinePainter movie_grabber_line_painter_;
163  TrianglePainter movie_grabber_triangle_painter_;
164 
165  PointViewerWidget* point_viewer_widget_;
166  DatabaseImageViewerWidget* image_viewer_widget_;
167  MovieGrabberWidget* movie_grabber_widget_;
168 
169  std::unique_ptr<PointColormapBase> point_colormap_;
170  std::unique_ptr<ImageColormapBase> image_colormap_;
171 
172  bool mouse_is_pressed_;
173  QTimer mouse_press_timer_;
174  QPoint prev_mouse_pos_;
175 
176  float focus_distance_;
177 
178  std::vector<std::pair<size_t, char>> selection_buffer_;
179  image_t selected_image_id_;
180  point3D_t selected_point3D_id_;
181  size_t selected_movie_grabber_view_;
182 
183  bool coordinate_grid_enabled_;
184 
185  // Size of points (dynamic): does not require re-uploading of points.
186  float point_size_;
187  // Size of image models (not dynamic): requires re-uploading of image
188  // models.
189  float image_size_;
190  // Near clipping plane.
191  float near_plane_;
192 
193  float background_color_[3];
194 };
195 
196 } // namespace colmap
MouseEvent event
int width
int height
void ChangeFocusDistance(const float delta)
void ShowPointInfo(const point3D_t point3D_id)
void SetBackgroundColor(const float r, const float g, const float b)
std::unordered_map< point3D_t, Point3D > points3D
std::unordered_map< camera_t, Camera > cameras
ModelViewerWidget(QWidget *parent, OptionManager *options)
void SetPointColormap(PointColormapBase *colormap)
void TranslateView(const float x, const float y, const float prev_x, const float prev_y)
QMatrix4x4 ModelViewMatrix() const
void SetImageColormap(ImageColormapBase *colormap)
void SetImageSize(const float image_size)
void SetPointSize(const float point_size)
void ShowImageInfo(const image_t image_id)
void ChangeNearPlane(const float delta)
void SelectMoviewGrabberView(const size_t view_idx)
std::vector< image_t > reg_image_ids
void SelectObject(const int x, const int y)
void resizeGL(int width, int height) override
void RotateView(const float x, const float y, const float prev_x, const float prev_y)
void ChangePointSize(const float delta)
void SetModelViewMatrix(const QMatrix4x4 &matrix)
std::unordered_map< image_t, Image > images
void ChangeCameraSize(const float delta)
normal_z y
normal_z x
uint64_t point3D_t
Definition: types.h:72
uint32_t image_t
Definition: types.h:61