bioformats  5.1.4
GLView2D.h
1 /*
2  * #%L
3  * OME-QTWIDGETS C++ library for display of Bio-Formats 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/bioformats/FormatReader.h>
43 
44 #include <ome/compat/memory.h>
45 
46 #include <ome/qtwidgets/GLWindow.h>
47 #include <ome/qtwidgets/gl/Image2D.h>
48 #include <ome/qtwidgets/gl/Grid2D.h>
49 #include <ome/qtwidgets/gl/Axis2D.h>
50 
51 #include <QElapsedTimer>
52 
53 #include <glm/glm.hpp>
54 
55 namespace ome
56 {
58  namespace qtwidgets
59  {
60 
64  class GLView2D : public GLWindow
65  {
66  Q_OBJECT
67 
68  public:
70  enum MouseMode
71  {
75  };
76 
86  GLView2D(ome::compat::shared_ptr<ome::bioformats::FormatReader> reader,
88  QWidget *parent = 0);
89 
91  ~GLView2D();
92 
98  QSize minimumSizeHint() const;
99 
105  QSize sizeHint() const;
106 
107  public slots:
113  void
114  setZoom(int zoom);
115 
121  void
122  setXTranslation(int xtran);
123 
129  void
130  setYTranslation(int ytran);
131 
137  void
138  setZRotation(int angle);
139 
145  void
146  setChannelMin(int min);
147 
153  void
154  setChannelMax(int max);
155 
161  void
163 
169  void
170  setMouseMode(MouseMode mode);
171 
172  public:
178  ome::compat::shared_ptr<ome::bioformats::FormatReader>
179  getReader();
180 
187  getSeries();
188 
194  int
195  getZoom() const;
196 
202  int
203  getXTranslation() const;
204 
210  int
211  getYTranslation() const;
212 
218  int
219  getZRotation() const;
220 
226  int
227  getChannelMin() const;
228 
234  int
235  getChannelMax() const;
236 
243  getPlane() const;
244 
250  MouseMode
251  getMouseMode() const;
252 
253  signals:
259  void
260  zoomChanged(int zoom);
261 
267  void
268  xTranslationChanged(int xtran);
269 
275  void
276  yTranslationChanged(int ytran);
277 
283  void
284  zRotationChanged(int angle);
285 
291  void
292  channelMinChanged(int min);
293 
299  void
300  channelMaxChanged(int max);
301 
307  void
309 
310  protected:
312  void
313  initialize();
314 
315  using GLWindow::render;
316 
318  void
319  render();
320 
322  void
323  resize();
324 
332  void
333  mousePressEvent(QMouseEvent *event);
334 
342  void
343  mouseMoveEvent(QMouseEvent *event);
344 
352  void
353  timerEvent (QTimerEvent *event);
354 
355  private:
359  struct Camera
360  {
363  {
366  };
367 
368  Camera():
370  zoom(0),
371  xTran(0),
372  yTran(0),
373  zRot(0),
374  model(1.0f),
375  view(1.0f),
376  projection(1.0f)
377  {}
378 
382  int zoom;
384  int xTran;
386  int yTran;
388  int zRot;
390  glm::mat4 model;
392  glm::mat4 view;
394  glm::mat4 projection;
395 
404  float
405  zoomfactor() const
406  {
407  return std::pow(10.0f, static_cast<float>(zoom)/1024.0f);
408  }
409 
415  float
416  rotation() const
417  {
418  return glm::radians(-static_cast<float>(zRot)/16.0f);
419  }
420 
429  glm::mat4
430  mvp() const
431  {
432  return projection * view * model;
433  }
434  };
435 
441  QElapsedTimer etimer;
443  glm::vec3 cmin;
445  glm::vec3 cmax;
451  QPoint lastPos;
459  ome::compat::shared_ptr<ome::bioformats::FormatReader> reader;
462  };
463 
464  }
465 }
466 
467 #endif // OME_QTWIDGETS_GLVIEW2D_H
468 
469 /*
470  * Local Variables:
471  * mode:C++
472  * End:
473  */
glm::mat4 view
Current view.
Definition: GLView2D.h:392
ome::bioformats::dimension_size_type getSeries()
Get series.
Definition: GLView2D.cpp:124
int yTran
y translation.
Definition: GLView2D.h:386
Perspective projection.
Definition: GLView2D.h:365
void timerEvent(QTimerEvent *event)
Handle timer events.
Definition: GLView2D.cpp:371
glm::mat4 model
Current model.
Definition: GLView2D.h:390
void channelMaxChanged(int max)
Signal maximum value for linear contrast changed.
float zoomfactor() const
Get zoom factor.
Definition: GLView2D.h:405
Memory type substitution.
void mouseMoveEvent(QMouseEvent *event)
Handle mouse button movement events.
Definition: GLView2D.cpp:343
int getChannelMax() const
Get maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:160
2D (xy) axis renderer.
Definition: Axis2D.h:68
ProjectionType
Projection type.
Definition: GLView2D.h:362
glm::vec3 cmax
Maximum level for linear contrast.
Definition: GLView2D.h:445
void resize()
Resize the view.
Definition: GLView2D.cpp:319
ome::bioformats::dimension_size_type oldplane
Previous plane.
Definition: GLView2D.h:449
ProjectionType projectionType
Projection type.
Definition: GLView2D.h:380
int getXTranslation() const
Get x translation factor.
Definition: GLView2D.cpp:136
2D (xy) grid renderer.
Definition: Grid2D.h:66
Pan in x and y.
Definition: GLView2D.h:73
MouseMode getMouseMode() const
Get mouse behaviour mode.
Definition: GLView2D.cpp:219
ome::bioformats::dimension_size_type plane
Current plane.
Definition: GLView2D.h:447
QSize sizeHint() const
Get window size hint.
Definition: GLView2D.cpp:112
QSize minimumSizeHint() const
Get window minimum size hint.
Definition: GLView2D.cpp:107
int zRot
Rotation factor.
Definition: GLView2D.h:388
QPoint lastPos
Last mouse position.
Definition: GLView2D.h:451
glm::vec3 cmin
Minimum level for linear contrast.
Definition: GLView2D.h:443
ome::compat::shared_ptr< ome::bioformats::FormatReader > reader
The image reader.
Definition: GLView2D.h:459
2D GL view of an image with axes and gridlines.
Definition: GLView2D.h:64
Zoom in and out.
Definition: GLView2D.h:72
void setZRotation(int angle)
Set z rotation factor.
Definition: GLView2D.cpp:202
glm::mat4 projection
Current projection.
Definition: GLView2D.h:394
int xTran
x translation
Definition: GLView2D.h:384
ome::bioformats::dimension_size_type series
The image series.
Definition: GLView2D.h:461
ome::compat::shared_ptr< ome::bioformats::FormatReader > getReader()
Get reader.
Definition: GLView2D.cpp:118
int getChannelMin() const
Get minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:154
void setPlane(ome::bioformats::dimension_size_type plane)
Set plane to render.
Definition: GLView2D.cpp:255
void setChannelMax(int max)
Set maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:241
void zRotationChanged(int angle)
Signal z rotation changed.
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
bool event(QEvent *event)
Handle events.
Definition: GLWindow.cpp:113
int getZRotation() const
Get z rotation factor.
Definition: GLView2D.cpp:148
void zoomChanged(int zoom)
Signal zoom level changed.
QElapsedTimer etimer
Rendering timer.
Definition: GLView2D.h:441
glm::mat4 mvp() const
Get modelview projection matrix.
Definition: GLView2D.h:430
int getYTranslation() const
Get y translation factor.
Definition: GLView2D.cpp:142
Top level GL window.
Definition: GLWindow.h:65
ome::bioformats::dimension_size_type getPlane() const
Get plane to render.
Definition: GLView2D.cpp:166
virtual void render()
Render using OpenGL.
Definition: GLWindow.cpp:90
GLView2D(ome::compat::shared_ptr< ome::bioformats::FormatReader > reader, ome::bioformats::dimension_size_type series, QWidget *parent=0)
Create a 2D image view.
Definition: GLView2D.cpp:82
int zoom
Zoom factor.
Definition: GLView2D.h:382
float rotation() const
Get rotation factor.
Definition: GLView2D.h:416
void planeChanged(ome::bioformats::dimension_size_type plane)
Signal current plane changed.
void yTranslationChanged(int ytran)
Signal y translation changed.
int getZoom() const
Get zoom factor.
Definition: GLView2D.cpp:130
void setMouseMode(MouseMode mode)
Set mouse behaviour mode.
Definition: GLView2D.cpp:213
Camera (modelview projection matrix manipulation)
Definition: GLView2D.h:359
gl::Axis2D * axes
Axes to render.
Definition: GLView2D.h:455
gl::Image2D * image
Image to render.
Definition: GLView2D.h:453
Camera camera
Current projection.
Definition: GLView2D.h:437
void setYTranslation(int ytran)
Set y translation factor.
Definition: GLView2D.cpp:192
void setZoom(int zoom)
Set zoom factor.
Definition: GLView2D.cpp:172
void mousePressEvent(QMouseEvent *event)
Handle mouse button press events.
Definition: GLView2D.cpp:329
gl::Grid2D * grid
Grid to render.
Definition: GLView2D.h:457
Rotate around point in z.
Definition: GLView2D.h:74
void channelMinChanged(int min)
Signal minimum value for linear contrast changed.
void initialize()
Set up GL context and subsidiary objects.
Definition: GLView2D.cpp:266
MouseMode
Mouse behaviour.
Definition: GLView2D.h:70
void xTranslationChanged(int xtran)
Signal x translation changed.
void setChannelMin(int min)
Set minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:227
2D (xy) image renderer.
Definition: Image2D.h:69
Orthographic projection.
Definition: GLView2D.h:364
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
~GLView2D()
Destructor.
Definition: GLView2D.cpp:102
MouseMode mouseMode
Current mouse behaviour.
Definition: GLView2D.h:439
void setXTranslation(int xtran)
Set x translation factor.
Definition: GLView2D.cpp:182
void render()
Render the scene with the current view settings.
Definition: GLView2D.cpp:302