ome-qtwidgets 5.2.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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
54 namespace ome
55 {
57 namespace qtwidgets
58 {
59
63 class GLView2D : public GLWindow
64 {
65 Q_OBJECT
66
67 public:
69 enum MouseMode
70 {
71 MODE_ZOOM,
72 MODE_PAN,
73 MODE_ROTATE
74 };
75
85 GLView2D(ome::compat::shared_ptr<ome::files::FormatReader> reader,
86 ome::files::dimension_size_type series,
87 QWidget *parent = 0);
88
90 ~GLView2D();
91
97 QSize minimumSizeHint() const;
98
104 QSize sizeHint() const;
105
106 public slots:
112 void
113 setZoom(int zoom);
114
120 void
121 setXTranslation(int xtran);
122
128 void
129 setYTranslation(int ytran);
130
136 void
137 setZRotation(int angle);
138
144 void
145 setChannelMin(int min);
146
152 void
153 setChannelMax(int max);
154
160 void
161 setPlane(ome::files::dimension_size_type plane);
162
168 void
169 setMouseMode(MouseMode mode);
170
171 public:
177 ome::compat::shared_ptr<ome::files::FormatReader>
178 getReader();
179
185 ome::files::dimension_size_type
186 getSeries();
187
193 int
194 getZoom() const;
195
201 int
202 getXTranslation() const;
203
209 int
210 getYTranslation() const;
211
217 int
218 getZRotation() const;
219
225 int
226 getChannelMin() const;
227
233 int
234 getChannelMax() const;
235
241 ome::files::dimension_size_type
242 getPlane() const;
243
249 MouseMode
250 getMouseMode() const;
251
252 signals:
258 void
259 zoomChanged(int zoom);
260
266 void
267 xTranslationChanged(int xtran);
268
274 void
275 yTranslationChanged(int ytran);
276
282 void
283 zRotationChanged(int angle);
284
290 void
291 channelMinChanged(int min);
292
298 void
299 channelMaxChanged(int max);
300
306 void
307 planeChanged(ome::files::dimension_size_type plane);
308
309 protected:
311 void
312 initialize();
313
314 using GLWindow::render;
315
317 void
318 render();
319
321 void
322 resize();
323
331 void
332 mousePressEvent(QMouseEvent *event);
333
341 void
342 mouseMoveEvent(QMouseEvent *event);
343
351 void
352 timerEvent (QTimerEvent *event);
353
354 private:
358 struct Camera
359 {
361 enum ProjectionType
362 {
363 ORTHOGRAPHIC,
364 PERSPECTIVE
365 };
366
367 Camera():
368 projectionType(ORTHOGRAPHIC),
369 zoom(0),
370 xTran(0),
371 yTran(0),
372 zRot(0),
373 model(1.0f),
374 view(1.0f),
375 projection(1.0f)
376 {}
377
379 ProjectionType projectionType;
381 int zoom;
383 int xTran;
385 int yTran;
387 int zRot;
389 glm::mat4 model;
391 glm::mat4 view;
393 glm::mat4 projection;
394
403 float
404 zoomfactor() const
405 {
406 return std::pow(10.0f, static_cast<float>(zoom)/1024.0f);
407 }
408
414 float
415 rotation() const
416 {
417 return glm::radians(-static_cast<float>(zRot)/16.0f);
418 }
419
428 glm::mat4
429 mvp() const
430 {
431 return projection * view * model;
432 }
433 };
434
436 Camera camera;
438 MouseMode mouseMode;
440 QElapsedTimer etimer;
442 glm::vec3 cmin;
444 glm::vec3 cmax;
446 ome::files::dimension_size_type plane;
448 ome::files::dimension_size_type oldplane;
450 QPoint lastPos;
452 gl::Image2D *image;
454 gl::Axis2D *axes;
456 gl::Grid2D *grid;
458 ome::compat::shared_ptr<ome::files::FormatReader> reader;
460 ome::files::dimension_size_type series;
461 };
462
463 }
464 }
465
466 #endif // OME_QTWIDGETS_GLVIEW2D_H
467
468 /*
469 * Local Variables:
470 * mode:C++
471 * End:
472 */
ome::qtwidgets::GLView2D::Camera::view
glm::mat4 view
Current view.
Definition: GLView2D.h:391
ome::qtwidgets::GLView2D::Camera::yTran
int yTran
y translation.
Definition: GLView2D.h:385
ome::qtwidgets::GLView2D::Camera::PERSPECTIVE
Perspective projection.
Definition: GLView2D.h:364
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:389
ome::qtwidgets::GLView2D::channelMaxChanged
void channelMaxChanged(int max)
Signal maximum value for linear contrast changed.
ome::qtwidgets::GLView2D::Camera::zoomfactor
float zoomfactor() const
Get zoom factor.
Definition: GLView2D.h:404
memory.h
ome::qtwidgets::GLView2D::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Handle mouse button movement events.
Definition: GLView2D.cpp:338
ome::qtwidgets::GLView2D::getChannelMax
int getChannelMax() const
Get maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:155
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:361
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:444
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:379
ome::qtwidgets::GLView2D::getXTranslation
int getXTranslation() const
Get x translation factor.
Definition: GLView2D.cpp:131
ome::qtwidgets::gl::Grid2D
2D (xy) grid renderer.
Definition: Grid2D.h:66
ome::qtwidgets::GLView2D::MODE_PAN
Pan in x and y.
Definition: GLView2D.h:72
ome::qtwidgets::GLView2D::plane
ome::files::dimension_size_type plane
Current plane.
Definition: GLView2D.h:446
ome::qtwidgets::GLView2D::getMouseMode
MouseMode getMouseMode() const
Get mouse behaviour mode.
Definition: GLView2D.cpp:214
ome::qtwidgets::GLView2D::sizeHint
QSize sizeHint() const
Get window size hint.
Definition: GLView2D.cpp:107
ome::qtwidgets::GLView2D::minimumSizeHint
QSize minimumSizeHint() const
Get window minimum size hint.
Definition: GLView2D.cpp:102
ome::qtwidgets::GLView2D::Camera::zRot
int zRot
Rotation factor.
Definition: GLView2D.h:387
ome::qtwidgets::GLView2D::lastPos
QPoint lastPos
Last mouse position.
Definition: GLView2D.h:450
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:442
ome::qtwidgets::GLView2D
2D GL view of an image with axes and gridlines.
Definition: GLView2D.h:63
ome::qtwidgets::GLView2D::oldplane
ome::files::dimension_size_type oldplane
Previous plane.
Definition: GLView2D.h:448
ome::qtwidgets::GLView2D::MODE_ZOOM
Zoom in and out.
Definition: GLView2D.h:71
ome::qtwidgets::GLView2D::setZRotation
void setZRotation(int angle)
Set z rotation factor.
Definition: GLView2D.cpp:197
ome::qtwidgets::GLView2D::Camera::projection
glm::mat4 projection
Current projection.
Definition: GLView2D.h:393
ome::qtwidgets::GLView2D::series
ome::files::dimension_size_type series
The image series.
Definition: GLView2D.h:460
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:383
ome::qtwidgets::GLView2D::getChannelMin
int getChannelMin() const
Get minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:149
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
ome::qtwidgets::GLWindow::event
bool event(QEvent *event)
Handle events.
Definition: GLWindow.cpp:113
ome::qtwidgets::GLView2D::getZRotation
int getZRotation() const
Get z rotation factor.
Definition: GLView2D.cpp:143
ome::qtwidgets::GLView2D::zoomChanged
void zoomChanged(int zoom)
Signal zoom level changed.
ome::qtwidgets::GLView2D::etimer
QElapsedTimer etimer
Rendering timer.
Definition: GLView2D.h:440
ome::qtwidgets::GLView2D::Camera::mvp
glm::mat4 mvp() const
Get modelview projection matrix.
Definition: GLView2D.h:429
ome::qtwidgets::GLView2D::getYTranslation
int getYTranslation() const
Get y translation factor.
Definition: GLView2D.cpp:137
ome::qtwidgets::GLWindow
Top level GL window.
Definition: GLWindow.h:65
ome::qtwidgets::GLWindow::render
virtual void render()
Render using OpenGL.
Definition: GLWindow.cpp:90
ome::qtwidgets::GLView2D::Camera::zoom
int zoom
Zoom factor.
Definition: GLView2D.h:381
ome::qtwidgets::GLView2D::Camera::rotation
float rotation() const
Get rotation factor.
Definition: GLView2D.h:415
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::getZoom
int getZoom() const
Get zoom factor.
Definition: GLView2D.cpp:125
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:358
ome::qtwidgets::GLView2D::axes
gl::Axis2D * axes
Axes to render.
Definition: GLView2D.h:454
ome::qtwidgets::GLView2D::image
gl::Image2D * image
Image to render.
Definition: GLView2D.h:452
ome::qtwidgets::GLView2D::camera
Camera camera
Current projection.
Definition: GLView2D.h:436
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:456
ome::qtwidgets::GLView2D::MODE_ROTATE
Rotate around point in z.
Definition: GLView2D.h:73
ome::qtwidgets::GLView2D::channelMinChanged
void channelMinChanged(int min)
Signal minimum value for linear contrast changed.
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::MouseMode
MouseMode
Mouse behaviour.
Definition: GLView2D.h:69
ome::qtwidgets::GLView2D::reader
ome::compat::shared_ptr< ome::files::FormatReader > reader
The image reader.
Definition: GLView2D.h:458
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:69
ome::qtwidgets::GLView2D::Camera::ORTHOGRAPHIC
Orthographic projection.
Definition: GLView2D.h:363
ome::qtwidgets::GLView2D::~GLView2D
~GLView2D()
Destructor.
Definition: GLView2D.cpp:97
ome::qtwidgets::GLView2D::mouseMode
MouseMode mouseMode
Current mouse behaviour.
Definition: GLView2D.h:438
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::render
void render()
Render the scene with the current view settings.
Definition: GLView2D.cpp:297