ome-qtwidgets 5.3.2

GLView2D.h
1 /*
2 * #%L
3 * OME-QTWIDGETS C++ library for display of OME-Files pixel data and metadata.
4 * %%
5 * Copyright © 2014 - 2015 Open Microscopy Environment:
6 * - Massachusetts Institute of Technology
7 * - National Institutes of Health
8 * - University of Dundee
9 * - Board of Regents of the University of Wisconsin-Madison
10 * - Glencoe Software, Inc.
11 * %%
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
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 HOLDERS 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 * The views and conclusions contained in the software and documentation are
34 * those of the authors and should not be interpreted as representing official
35 * policies, either expressed or implied, of any organization.
36 * #L%
37 */
38
39 #ifndef OME_QTWIDGETS_GLVIEW2D_H
40 #define OME_QTWIDGETS_GLVIEW2D_H
41
42 #include <ome/files/FormatReader.h>
43
44 #include <ome/compat/memory.h>
45
46 #include <ome/qtwidgets/glm.h>
47 #include <ome/qtwidgets/GLWindow.h>
48 #include <ome/qtwidgets/gl/Image2D.h>
49 #include <ome/qtwidgets/gl/Grid2D.h>
50 #include <ome/qtwidgets/gl/Axis2D.h>
51
52 #include <QElapsedTimer>
53
57 namespace ome
58 {
60 namespace qtwidgets
61 {
62
66 class GLView2D : public GLWindow
67 {
68 Q_OBJECT
69
70 public:
72 enum MouseMode
73 {
74 MODE_ZOOM,
75 MODE_PAN,
76 MODE_ROTATE
77 };
78
88 GLView2D(ome::compat::shared_ptr<ome::files::FormatReader> reader,
89 ome::files::dimension_size_type series,
90 QWidget *parent = 0);
91
93 ~GLView2D();
94
100 QSize minimumSizeHint() const;
101
107 QSize sizeHint() const;
108
109 public slots:
115 void
116 setZoom(int zoom);
117
123 void
124 setXTranslation(int xtran);
125
131 void
132 setYTranslation(int ytran);
133
139 void
140 setZRotation(int angle);
141
147 void
148 setChannelMin(int min);
149
155 void
156 setChannelMax(int max);
157
163 void
164 setPlane(ome::files::dimension_size_type plane);
165
171 void
172 setMouseMode(MouseMode mode);
173
174 public:
180 ome::compat::shared_ptr<ome::files::FormatReader>
181 getReader();
182
188 ome::files::dimension_size_type
189 getSeries();
190
196 int
197 getZoom() const;
198
204 int
205 getXTranslation() const;
206
212 int
213 getYTranslation() const;
214
220 int
221 getZRotation() const;
222
228 int
229 getChannelMin() const;
230
236 int
237 getChannelMax() const;
238
244 ome::files::dimension_size_type
245 getPlane() const;
246
252 MouseMode
253 getMouseMode() const;
254
255 signals:
261 void
262 zoomChanged(int zoom);
263
269 void
270 xTranslationChanged(int xtran);
271
277 void
278 yTranslationChanged(int ytran);
279
285 void
286 zRotationChanged(int angle);
287
293 void
294 channelMinChanged(int min);
295
301 void
302 channelMaxChanged(int max);
303
309 void
310 planeChanged(ome::files::dimension_size_type plane);
311
312 protected:
314 void
315 initialize();
316
317 using GLWindow::render;
318
320 void
321 render();
322
324 void
325 resize();
326
334 void
335 mousePressEvent(QMouseEvent *event);
336
344 void
345 mouseMoveEvent(QMouseEvent *event);
346
354 void
355 timerEvent (QTimerEvent *event);
356
357 private:
361 struct Camera
362 {
364 enum ProjectionType
365 {
366 ORTHOGRAPHIC,
367 PERSPECTIVE
368 };
369
370 Camera():
371 projectionType(ORTHOGRAPHIC),
372 zoom(0),
373 xTran(0),
374 yTran(0),
375 zRot(0),
376 model(1.0f),
377 view(1.0f),
378 projection(1.0f)
379 {}
380
382 ProjectionType projectionType;
384 int zoom;
386 int xTran;
388 int yTran;
390 int zRot;
392 glm::mat4 model;
394 glm::mat4 view;
396 glm::mat4 projection;
397
406 float
407 zoomfactor() const
408 {
409 return std::pow(10.0f, static_cast<float>(zoom)/1024.0f);
410 }
411
417 float
418 rotation() const
419 {
420 return glm::radians(-static_cast<float>(zRot)/16.0f);
421 }
422
431 glm::mat4
432 mvp() const
433 {
434 return projection * view * model;
435 }
436 };
437
439 Camera camera;
441 MouseMode mouseMode;
443 QElapsedTimer etimer;
445 glm::vec3 cmin;
447 glm::vec3 cmax;
449 ome::files::dimension_size_type plane;
451 ome::files::dimension_size_type oldplane;
453 QPoint lastPos;
455 gl::Image2D *image;
457 gl::Axis2D *axes;
459 gl::Grid2D *grid;
461 ome::compat::shared_ptr<ome::files::FormatReader> reader;
463 ome::files::dimension_size_type series;
464 };
465
466 }
467 }
468
469 #endif // OME_QTWIDGETS_GLVIEW2D_H
470
471 /*
472 * Local Variables:
473 * mode:C++
474 * End:
475 */
ome::qtwidgets::GLView2D::Camera::view
glm::mat4 view
Current view.
Definition: GLView2D.h:394
ome::qtwidgets::GLView2D::Camera::yTran
int yTran
y translation.
Definition: GLView2D.h:388
ome::qtwidgets::GLView2D::Camera::PERSPECTIVE
Perspective projection.
Definition: GLView2D.h:367
ome::qtwidgets::GLView2D::timerEvent
void timerEvent(QTimerEvent *event)
Handle timer events.
Definition: GLView2D.cpp:366
ome::qtwidgets::GLView2D::Camera::model
glm::mat4 model
Current model.
Definition: GLView2D.h:392
ome::qtwidgets::GLView2D::Camera::zoomfactor
float zoomfactor() const
Get zoom factor.
Definition: GLView2D.h:407
ome::qtwidgets::GLView2D::channelMaxChanged
void channelMaxChanged(int max)
Signal maximum value for linear contrast changed.
ome::qtwidgets::GLView2D::sizeHint
QSize sizeHint() const
Get window size hint.
Definition: GLView2D.cpp:107
ome::qtwidgets::GLView2D::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Handle mouse button movement events.
Definition: GLView2D.cpp:338
ome::qtwidgets::GLView2D::planeChanged
void planeChanged(ome::files::dimension_size_type plane)
Signal current plane changed.
ome::qtwidgets::gl::Axis2D
2D (xy) axis renderer.
Definition: Axis2D.h:67
ome::qtwidgets::GLView2D::Camera::ProjectionType
ProjectionType
Projection type.
Definition: GLView2D.h:364
ome::qtwidgets::GLView2D::getZRotation
int getZRotation() const
Get z rotation factor.
Definition: GLView2D.cpp:143
ome::files::dimension_size_type
std::size_t dimension_size_type
ome::qtwidgets::GLView2D::cmax
glm::vec3 cmax
Maximum level for linear contrast.
Definition: GLView2D.h:447
ome::qtwidgets::GLView2D::resize
void resize()
Resize the view.
Definition: GLView2D.cpp:314
ome::qtwidgets::GLView2D::Camera::projectionType
ProjectionType projectionType
Projection type.
Definition: GLView2D.h:382
ome::qtwidgets::gl::Grid2D
2D (xy) grid renderer.
Definition: Grid2D.h:67
ome::qtwidgets::GLView2D::MODE_PAN
Pan in x and y.
Definition: GLView2D.h:75
ome::qtwidgets::GLView2D::plane
ome::files::dimension_size_type plane
Current plane.
Definition: GLView2D.h:449
ome::qtwidgets::GLView2D::getYTranslation
int getYTranslation() const
Get y translation factor.
Definition: GLView2D.cpp:137
ome::qtwidgets::GLView2D::Camera::zRot
int zRot
Rotation factor.
Definition: GLView2D.h:390
ome::qtwidgets::GLView2D::getChannelMin
int getChannelMin() const
Get minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:149
ome::qtwidgets::GLView2D::lastPos
QPoint lastPos
Last mouse position.
Definition: GLView2D.h:453
ome::qtwidgets::GLView2D::setPlane
void setPlane(ome::files::dimension_size_type plane)
Set plane to render.
Definition: GLView2D.cpp:250
ome::qtwidgets::GLView2D::cmin
glm::vec3 cmin
Minimum level for linear contrast.
Definition: GLView2D.h:445
ome::qtwidgets::GLView2D
2D GL view of an image with axes and gridlines.
Definition: GLView2D.h:66
ome::qtwidgets::GLView2D::getZoom
int getZoom() const
Get zoom factor.
Definition: GLView2D.cpp:125
ome::qtwidgets::GLView2D::oldplane
ome::files::dimension_size_type oldplane
Previous plane.
Definition: GLView2D.h:451
ome::qtwidgets::GLView2D::MODE_ZOOM
Zoom in and out.
Definition: GLView2D.h:74
ome::qtwidgets::GLView2D::setZRotation
void setZRotation(int angle)
Set z rotation factor.
Definition: GLView2D.cpp:197
ome::qtwidgets::GLView2D::Camera::mvp
glm::mat4 mvp() const
Get modelview projection matrix.
Definition: GLView2D.h:432
ome::qtwidgets::GLView2D::Camera::projection
glm::mat4 projection
Current projection.
Definition: GLView2D.h:396
ome::qtwidgets::GLView2D::series
ome::files::dimension_size_type series
The image series.
Definition: GLView2D.h:463
ome::qtwidgets::GLView2D::getReader
ome::compat::shared_ptr< ome::files::FormatReader > getReader()
Get reader.
Definition: GLView2D.cpp:113
ome::qtwidgets::GLView2D::Camera::xTran
int xTran
x translation
Definition: GLView2D.h:386
ome::qtwidgets::GLView2D::setChannelMax
void setChannelMax(int max)
Set maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:236
ome::qtwidgets::GLView2D::zRotationChanged
void zRotationChanged(int angle)
Signal z rotation changed.
ome
Open Microscopy Environment C++.
ome::qtwidgets::GLWindow::event
bool event(QEvent *event)
Handle events.
Definition: GLWindow.cpp:114
ome::qtwidgets::GLView2D::zoomChanged
void zoomChanged(int zoom)
Signal zoom level changed.
ome::qtwidgets::GLView2D::etimer
QElapsedTimer etimer
Rendering timer.
Definition: GLView2D.h:443
ome::qtwidgets::GLView2D::getChannelMax
int getChannelMax() const
Get maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:155
ome::qtwidgets::GLWindow
Top level GL window.
Definition: GLWindow.h:65
ome::qtwidgets::GLView2D::minimumSizeHint
QSize minimumSizeHint() const
Get window minimum size hint.
Definition: GLView2D.cpp:102
ome::qtwidgets::GLWindow::render
virtual void render()
Render using OpenGL.
Definition: GLWindow.cpp:91
ome::qtwidgets::GLView2D::Camera::zoom
int zoom
Zoom factor.
Definition: GLView2D.h:384
memory.h
ome::qtwidgets::GLView2D::yTranslationChanged
void yTranslationChanged(int ytran)
Signal y translation changed.
ome::qtwidgets::GLView2D::GLView2D
GLView2D(ome::compat::shared_ptr< ome::files::FormatReader > reader, ome::files::dimension_size_type series, QWidget *parent=0)
Create a 2D image view.
Definition: GLView2D.cpp:77
ome::qtwidgets::GLView2D::setMouseMode
void setMouseMode(MouseMode mode)
Set mouse behaviour mode.
Definition: GLView2D.cpp:208
ome::qtwidgets::GLView2D::Camera
Camera (modelview projection matrix manipulation)
Definition: GLView2D.h:361
ome::qtwidgets::GLView2D::axes
gl::Axis2D * axes
Axes to render.
Definition: GLView2D.h:457
ome::qtwidgets::GLView2D::image
gl::Image2D * image
Image to render.
Definition: GLView2D.h:455
ome::qtwidgets::GLView2D::camera
Camera camera
Current projection.
Definition: GLView2D.h:439
ome::qtwidgets::GLView2D::setYTranslation
void setYTranslation(int ytran)
Set y translation factor.
Definition: GLView2D.cpp:187
ome::qtwidgets::GLView2D::setZoom
void setZoom(int zoom)
Set zoom factor.
Definition: GLView2D.cpp:167
ome::qtwidgets::GLView2D::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Handle mouse button press events.
Definition: GLView2D.cpp:324
ome::qtwidgets::GLView2D::grid
gl::Grid2D * grid
Grid to render.
Definition: GLView2D.h:459
ome::qtwidgets::GLView2D::MODE_ROTATE
Rotate around point in z.
Definition: GLView2D.h:76
ome::qtwidgets::GLView2D::channelMinChanged
void channelMinChanged(int min)
Signal minimum value for linear contrast changed.
ome::qtwidgets::GLView2D::getMouseMode
MouseMode getMouseMode() const
Get mouse behaviour mode.
Definition: GLView2D.cpp:214
ome::qtwidgets::GLView2D::getPlane
ome::files::dimension_size_type getPlane() const
Get plane to render.
Definition: GLView2D.cpp:161
ome::qtwidgets::GLView2D::initialize
void initialize()
Set up GL context and subsidiary objects.
Definition: GLView2D.cpp:261
ome::qtwidgets::GLView2D::Camera::rotation
float rotation() const
Get rotation factor.
Definition: GLView2D.h:418
ome::qtwidgets::GLView2D::MouseMode
MouseMode
Mouse behaviour.
Definition: GLView2D.h:72
ome::qtwidgets::GLView2D::reader
ome::compat::shared_ptr< ome::files::FormatReader > reader
The image reader.
Definition: GLView2D.h:461
ome::qtwidgets::GLView2D::xTranslationChanged
void xTranslationChanged(int xtran)
Signal x translation changed.
ome::qtwidgets::GLView2D::setChannelMin
void setChannelMin(int min)
Set minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:222
ome::qtwidgets::gl::Image2D
2D (xy) image renderer.
Definition: Image2D.h:70
ome::qtwidgets::GLView2D::Camera::ORTHOGRAPHIC
Orthographic projection.
Definition: GLView2D.h:366
ome::qtwidgets::GLView2D::~GLView2D
~GLView2D()
Destructor.
Definition: GLView2D.cpp:97
ome::qtwidgets::GLView2D::mouseMode
MouseMode mouseMode
Current mouse behaviour.
Definition: GLView2D.h:441
ome::qtwidgets::GLView2D::getSeries
ome::files::dimension_size_type getSeries()
Get series.
Definition: GLView2D.cpp:119
ome::qtwidgets::GLView2D::setXTranslation
void setXTranslation(int xtran)
Set x translation factor.
Definition: GLView2D.cpp:177
ome::qtwidgets::GLView2D::getXTranslation
int getXTranslation() const
Get x translation factor.
Definition: GLView2D.cpp:131
ome::qtwidgets::GLView2D::render
void render()
Render the scene with the current view settings.
Definition: GLView2D.cpp:297