Developer documentation
Version 3.0.3-105-gd3941f44
window.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gui_mrview_window_h__
18#define __gui_mrview_window_h__
19
20#include "image.h"
21#include "memory.h"
22#include "gui/cursor.h"
23#include "gui/gui.h"
25#include "gui/opengl/font.h"
28
29
30namespace MR
31{
32 namespace GUI
33 {
34 namespace GL {
35 class Lighting;
36 }
37
38 namespace MRView
39 {
40
41 namespace Mode
42 {
43 class Base;
44 class __Entry__;
45 }
46 namespace Tool
47 {
48 class Base;
49 class ODF;
50 class CameraInteractor;
51 }
52
53
54 class Window : public QMainWindow, ColourMapButtonObserver
56 Q_OBJECT
57
58 private:
59 Cursor cursors_do_not_use;
60
61 class GLArea : public GL::Area { MEMALIGN(GLArea)
62 public:
63 GLArea (Window& parent);
64 QSize sizeHint () const override;
65
66 protected:
67 void dragEnterEvent (QDragEnterEvent* event) override;
68 void dragMoveEvent (QDragMoveEvent* event) override;
69 void dragLeaveEvent (QDragLeaveEvent* event) override;
70 void dropEvent (QDropEvent* event) override;
71 bool event (QEvent* event) override;
72 private:
73 void initializeGL () override;
74 void paintGL () override;
75 void mousePressEvent (QMouseEvent* event) override;
76 void mouseMoveEvent (QMouseEvent* event) override;
77 void mouseReleaseEvent (QMouseEvent* event) override;
78 void wheelEvent (QWheelEvent* event) override;
79 };
80 GLArea* glarea;
81
82 public:
85
87 void add_images (vector<std::unique_ptr<MR::Header>>& list);
88
89 const QPoint& mouse_position () const { return mouse_position_; }
90 const QPoint& mouse_displacement () const { return mouse_displacement_; }
91 Qt::MouseButtons mouse_buttons () const { return buttons_; }
92 Qt::KeyboardModifiers modifiers () const { return modifiers_; }
93
94 void selected_colourmap(size_t colourmap, const ColourMapButton&) override;
95 void selected_custom_colour(const QColor&colour, const ColourMapButton&) override;
96
97 const Image* image () const {
98 return static_cast<const Image*> (image_group->checkedAction());
99 }
100 QActionGroup* tools () const {
101 return tool_group;
102 }
103
104 int slice () const {
105 if (!image())
106 return -1;
107 else
108 return std::round ((image()->image.transform().inverse().cast<float>() * focus()) (anatomical_plane) / image()->image.spacing (anatomical_plane));
109 }
110
111 Mode::Base* get_current_mode () const { return mode.get(); }
112 const Eigen::Vector3f& focus () const { return focal_point; }
113 const Eigen::Vector3f& target () const { return camera_target; }
114 float FOV () const { return field_of_view; }
115 int plane () const { return anatomical_plane; }
116 const Eigen::Quaternionf& orientation () const { return orient; }
117 bool snap_to_image () const { return snap_to_image_axes_and_voxel; }
118 Image* image () { return static_cast<Image*> (image_group->checkedAction()); }
119
120 void set_focus (const Eigen::Vector3f& p) { focal_point = p; emit focusChanged(); }
121 void set_target (const Eigen::Vector3f& p) { camera_target = p; emit targetChanged(); }
122 void set_FOV (float value) { field_of_view = value; emit fieldOfViewChanged(); }
123 void set_plane (int p) { anatomical_plane = p; emit planeChanged(); }
124 void set_orientation (const Eigen::Quaternionf& V) { orient = V; orient.normalize(); emit orientationChanged(); }
125 void set_scaling (float min, float max) { if (!image()) return; image()->set_windowing (min, max); }
126 void set_snap_to_image (bool onoff) { snap_to_image_axes_and_voxel = onoff; snap_to_image_action->setChecked(onoff); emit focusChanged(); }
127
128 void set_scaling_all (float min, float max) {
129 QList<QAction*> list = image_group->actions();
130 for (int n = 0; n < list.size(); ++n)
131 static_cast<Image*> (list[n])->set_windowing (min, max);
132 }
133
134 void set_image_volume (size_t axis, ssize_t index);
135
136 bool get_image_visibility () const { return ! image_hide_action->isChecked(); }
137 void set_image_visibility (bool flag);
138
139 bool show_crosshairs () const { return show_crosshairs_action->isChecked(); }
140 bool show_comments () const { return show_comments_action->isChecked(); }
141 bool show_voxel_info () const { return show_voxel_info_action->isChecked(); }
142 bool show_orientation_labels () const { return show_orientation_labels_action->isChecked(); }
143 bool show_colourbar () const { return show_colourbar_action->isChecked(); }
144
145 bool sync_focus_on () const { return sync_focus_action->isChecked(); }
146
147 void captureGL (std::string filename) {
148 QImage image (glarea->grabFramebuffer());
149 image.save (qstr (filename));
150 }
151
152 GL::Area* glwidget () const { return glarea; }
153 GL::Lighting& lighting () { return *lighting_; }
155
157 Tool::CameraInteractor* active_camera_interactor () { return camera_interactor; }
158
160 static Window* main;
161 static bool tools_floating;
162
163 signals:
170 void modeChanged ();
176
177 public slots:
179 void updateGL ();
180 void drawGL ();
181
182 private slots:
183 void image_open_slot ();
184 void image_import_DICOM_slot ();
185 void image_save_slot ();
186 void image_close_slot ();
187 void image_properties_slot ();
188
189 void select_mode_slot (QAction* action);
190 void select_mouse_mode_slot (QAction* action);
191 void select_tool_slot (QAction* action);
192 void select_plane_slot (QAction* action);
193 void zoom_in_slot ();
194 void zoom_out_slot ();
195 void invert_scaling_slot ();
196 void full_screen_slot ();
197 void toggle_annotations_slot ();
198 void snap_to_image_slot ();
199 void wrap_volumes_slot ();
200
201 void sync_slot();
202
203 void hide_image_slot ();
204 void slice_next_slot ();
205 void slice_previous_slot ();
206 void image_next_slot ();
207 void image_previous_slot ();
208 void image_next_volume_slot ();
209 void image_previous_volume_slot ();
210 void image_goto_volume_slot ();
211 void image_next_volume_group_slot ();
212 void image_goto_volume_group_slot ();
213 void image_previous_volume_group_slot ();
214 void image_reset_slot ();
215 void image_interpolate_slot ();
216 void image_select_slot (QAction* action);
217
218 void reset_view_slot ();
219 void background_colour_slot ();
220
221 void OpenGL_slot ();
222 void about_slot ();
223 void aboutQt_slot ();
224
225 void process_commandline_option_slot ();
226
227
228 private:
229 QPoint mouse_position_, mouse_displacement_;
230 Qt::MouseButtons buttons_;
231 Qt::KeyboardModifiers modifiers_;
232
233 enum MouseAction {
234 NoAction,
235 SetFocus,
236 Contrast,
237 Pan,
238 PanThrough,
239 Tilt,
240 Rotate
241 };
242
243 std::unique_ptr<Mode::Base> mode;
244 GL::Lighting* lighting_;
245 GL::Font font;
246
247 const Qt::KeyboardModifiers FocusModifier, MoveModifier, RotateModifier;
248 MouseAction mouse_action;
249
250 Eigen::Vector3f focal_point, camera_target;
251 Eigen::Quaternionf orient;
252 float field_of_view;
253 int anatomical_plane, annotations;
254 ColourBars::Position colourbar_position, tools_colourbar_position;
255 bool snap_to_image_axes_and_voxel;
256 std::string current_folder;
257
258 float background_colour[3];
259
260 Tool::CameraInteractor* camera_interactor;
261
262 QMenu *image_menu;
263
264 ColourMapButton *colourmap_button;
265
266 QActionGroup *mode_group,
267 *tool_group,
268 *image_group,
269 *mode_action_group,
270 *plane_group;
271
272 QAction *save_action,
273 *close_action,
274 *properties_action,
275
276 **tool_actions,
277 *invert_scale_action,
278 *extra_controls_action,
279 *snap_to_image_action,
280 *image_hide_action,
281 *next_image_action,
282 *prev_image_action,
283 *next_image_volume_action,
284 *prev_image_volume_action,
285 *goto_image_volume_action,
286 *next_slice_action,
287 *prev_slice_action,
288 *reset_view_action,
289 *next_image_volume_group_action,
290 *prev_image_volume_group_action,
291 *goto_image_volume_group_action,
292 *wrap_volumes_action,
293 *image_list_area,
294
295 *reset_windowing_action,
296 *axial_action,
297 *sagittal_action,
298 *coronal_action,
299
300 *toggle_annotations_action,
301 *show_comments_action,
302 *show_voxel_info_action,
303 *show_orientation_labels_action,
304 *show_crosshairs_action,
305 *show_colourbar_action,
306 *image_interpolate_action,
307 *full_screen_action,
308
309 *sync_focus_action,
310
311 *OpenGL_action,
312 *about_action,
313 *aboutQt_action;
314
315 static ColourBars::Position parse_colourmap_position_str (const std::string& position_str);
316
317 void paintGL ();
318 void initGL ();
319 void keyPressEvent (QKeyEvent* event) override;
320 void keyReleaseEvent (QKeyEvent* event) override;
321 void mousePressEventGL (QMouseEvent* event);
322 void mouseMoveEventGL (QMouseEvent* event);
323 void mouseReleaseEventGL (QMouseEvent* event);
324 void wheelEventGL (QWheelEvent* event);
325 bool gestureEventGL (QGestureEvent* event);
326
327 int get_mouse_mode ();
328 void set_cursor ();
329 void set_image_menu ();
330 void set_mode_features ();
331 void set_image_navigation_menu ();
332
333 void closeEvent (QCloseEvent* event) override;
334 void create_tool (QAction* action, bool show);
335
336 void process_commandline_option ();
337
338 template <class Event> void grab_mouse_state (Event* event);
339 template <class Event> void update_mouse_state (Event* event);
340
341 Tool::Base* tool_has_focus;
342
343 vector<double> render_times;
344 double best_FPS, best_FPS_time;
345 bool show_FPS;
346 size_t current_option;
347
348 friend class ImageBase;
349 friend class Mode::Base;
350 friend class Tool::Base;
351 friend class Tool::ODF;
352 friend class Window::GLArea;
353 friend class GrabContext;
354 };
355
356
357 }
358 }
359}
360
361#endif
a class to hold the list of option groups
Definition: app.h:139
void set_scaling_all(float min, float max)
Definition: window.h:128
void set_plane(int p)
Definition: window.h:123
void imageVisibilityChanged(bool)
static Window * main
Definition: window.h:160
friend class GrabContext
Definition: window.h:353
static void add_commandline_options(MR::App::OptionList &options)
void set_snap_to_image(bool onoff)
Definition: window.h:126
const Eigen::Vector3f & focus() const
Definition: window.h:112
void selected_colourmap(size_t colourmap, const ColourMapButton &) override
const Image * image() const
Definition: window.h:97
void set_image_visibility(bool flag)
bool sync_focus_on() const
Definition: window.h:145
bool snap_to_image() const
Definition: window.h:117
bool show_crosshairs() const
Definition: window.h:139
Tool::CameraInteractor * active_camera_interactor()
Definition: window.h:157
void set_target(const Eigen::Vector3f &p)
Definition: window.h:121
bool get_image_visibility() const
Definition: window.h:136
void selected_custom_colour(const QColor &colour, const ColourMapButton &) override
void add_images(vector< std::unique_ptr< MR::Header > > &list)
Qt::MouseButtons mouse_buttons() const
Definition: window.h:91
QActionGroup * tools() const
Definition: window.h:100
bool show_colourbar() const
Definition: window.h:143
ColourBars colourbar_renderer
Definition: window.h:154
GL::Area * glwidget() const
Definition: window.h:152
const Eigen::Quaternionf & orientation() const
Definition: window.h:116
int plane() const
Definition: window.h:115
const QPoint & mouse_displacement() const
Definition: window.h:90
bool show_voxel_info() const
Definition: window.h:141
void set_scaling(float min, float max)
Definition: window.h:125
bool show_orientation_labels() const
Definition: window.h:142
friend class Window::GLArea
Definition: window.h:352
float FOV() const
Definition: window.h:114
const Eigen::Vector3f & target() const
Definition: window.h:113
bool show_comments() const
Definition: window.h:140
void register_camera_interactor(Tool::CameraInteractor *agent=nullptr)
void set_FOV(float value)
Definition: window.h:122
Mode::Base * get_current_mode() const
Definition: window.h:111
void captureGL(std::string filename)
Definition: window.h:147
GL::Lighting & lighting()
Definition: window.h:153
void set_orientation(const Eigen::Quaternionf &V)
Definition: window.h:124
const QPoint & mouse_position() const
Definition: window.h:89
void set_focus(const Eigen::Vector3f &p)
Definition: window.h:120
void set_image_volume(size_t axis, ssize_t index)
Qt::KeyboardModifiers modifiers() const
Definition: window.h:92
static bool tools_floating
Definition: window.h:161
int slice() const
Definition: window.h:104
constexpr I round(const T x)
Definition: math.h:64
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
Definition: SH.h:233
const uint32_t Lighting
Definition: displayable.h:44
QString qstr(const std::string &s)
Definition: gui.h:31
Definition: base.h:24
int axis
size_t index
#define MEMALIGN(...)
Definition: types.h:185