ome-qtwidgets  5.2.0
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  {
74  };
75 
85  GLView2D(ome::compat::shared_ptr<ome::files::FormatReader> reader,
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
162 
168  void
169  setMouseMode(MouseMode mode);
170 
171  public:
177  ome::compat::shared_ptr<ome::files::FormatReader>
178  getReader();
179 
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 
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
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  {
362  {
365  };
366 
367  Camera():
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 
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 
440  QElapsedTimer etimer;
442  glm::vec3 cmin;
444  glm::vec3 cmax;
450  QPoint lastPos;
458  ome::compat::shared_ptr<ome::files::FormatReader> reader;
461  };
462 
463  }
464 }
465 
466 #endif // OME_QTWIDGETS_GLVIEW2D_H
467 
468 /*
469  * Local Variables:
470  * mode:C++
471  * End:
472  */
glm::mat4 view
Current view.
Definition: GLView2D.h:391
int yTran
y translation.
Definition: GLView2D.h:385
Perspective projection.
Definition: GLView2D.h:364
void timerEvent(QTimerEvent *event)
Handle timer events.
Definition: GLView2D.cpp:366
glm::mat4 model
Current model.
Definition: GLView2D.h:389
void channelMaxChanged(int max)
Signal maximum value for linear contrast changed.
float zoomfactor() const
Get zoom factor.
Definition: GLView2D.h:404
void mouseMoveEvent(QMouseEvent *event)
Handle mouse button movement events.
Definition: GLView2D.cpp:338
int getChannelMax() const
Get maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:155
void planeChanged(ome::files::dimension_size_type plane)
Signal current plane changed.
2D (xy) axis renderer.
Definition: Axis2D.h:67
ProjectionType
Projection type.
Definition: GLView2D.h:361
std::size_t dimension_size_type
glm::vec3 cmax
Maximum level for linear contrast.
Definition: GLView2D.h:444
void resize()
Resize the view.
Definition: GLView2D.cpp:314
ProjectionType projectionType
Projection type.
Definition: GLView2D.h:379
int getXTranslation() const
Get x translation factor.
Definition: GLView2D.cpp:131
2D (xy) grid renderer.
Definition: Grid2D.h:66
Pan in x and y.
Definition: GLView2D.h:72
ome::files::dimension_size_type plane
Current plane.
Definition: GLView2D.h:446
MouseMode getMouseMode() const
Get mouse behaviour mode.
Definition: GLView2D.cpp:214
QSize sizeHint() const
Get window size hint.
Definition: GLView2D.cpp:107
QSize minimumSizeHint() const
Get window minimum size hint.
Definition: GLView2D.cpp:102
int zRot
Rotation factor.
Definition: GLView2D.h:387
QPoint lastPos
Last mouse position.
Definition: GLView2D.h:450
void setPlane(ome::files::dimension_size_type plane)
Set plane to render.
Definition: GLView2D.cpp:250
glm::vec3 cmin
Minimum level for linear contrast.
Definition: GLView2D.h:442
2D GL view of an image with axes and gridlines.
Definition: GLView2D.h:63
ome::files::dimension_size_type oldplane
Previous plane.
Definition: GLView2D.h:448
Zoom in and out.
Definition: GLView2D.h:71
void setZRotation(int angle)
Set z rotation factor.
Definition: GLView2D.cpp:197
glm::mat4 projection
Current projection.
Definition: GLView2D.h:393
ome::files::dimension_size_type series
The image series.
Definition: GLView2D.h:460
ome::compat::shared_ptr< ome::files::FormatReader > getReader()
Get reader.
Definition: GLView2D.cpp:113
int xTran
x translation
Definition: GLView2D.h:383
int getChannelMin() const
Get minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:149
void setChannelMax(int max)
Set maximum value for linear contrast (all channels).
Definition: GLView2D.cpp:236
void zRotationChanged(int angle)
Signal z rotation changed.
bool event(QEvent *event)
Handle events.
Definition: GLWindow.cpp:113
int getZRotation() const
Get z rotation factor.
Definition: GLView2D.cpp:143
void zoomChanged(int zoom)
Signal zoom level changed.
QElapsedTimer etimer
Rendering timer.
Definition: GLView2D.h:440
glm::mat4 mvp() const
Get modelview projection matrix.
Definition: GLView2D.h:429
int getYTranslation() const
Get y translation factor.
Definition: GLView2D.cpp:137
Top level GL window.
Definition: GLWindow.h:65
virtual void render()
Render using OpenGL.
Definition: GLWindow.cpp:90
int zoom
Zoom factor.
Definition: GLView2D.h:381
float rotation() const
Get rotation factor.
Definition: GLView2D.h:415
void yTranslationChanged(int ytran)
Signal y translation changed.
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
int getZoom() const
Get zoom factor.
Definition: GLView2D.cpp:125
void setMouseMode(MouseMode mode)
Set mouse behaviour mode.
Definition: GLView2D.cpp:208
Camera (modelview projection matrix manipulation)
Definition: GLView2D.h:358
gl::Axis2D * axes
Axes to render.
Definition: GLView2D.h:454
gl::Image2D * image
Image to render.
Definition: GLView2D.h:452
Camera camera
Current projection.
Definition: GLView2D.h:436
void setYTranslation(int ytran)
Set y translation factor.
Definition: GLView2D.cpp:187
void setZoom(int zoom)
Set zoom factor.
Definition: GLView2D.cpp:167
void mousePressEvent(QMouseEvent *event)
Handle mouse button press events.
Definition: GLView2D.cpp:324
gl::Grid2D * grid
Grid to render.
Definition: GLView2D.h:456
Rotate around point in z.
Definition: GLView2D.h:73
void channelMinChanged(int min)
Signal minimum value for linear contrast changed.
ome::files::dimension_size_type getPlane() const
Get plane to render.
Definition: GLView2D.cpp:161
void initialize()
Set up GL context and subsidiary objects.
Definition: GLView2D.cpp:261
MouseMode
Mouse behaviour.
Definition: GLView2D.h:69
ome::compat::shared_ptr< ome::files::FormatReader > reader
The image reader.
Definition: GLView2D.h:458
void xTranslationChanged(int xtran)
Signal x translation changed.
void setChannelMin(int min)
Set minimum value for linear contrast (all channels).
Definition: GLView2D.cpp:222
2D (xy) image renderer.
Definition: Image2D.h:69
Orthographic projection.
Definition: GLView2D.h:363
~GLView2D()
Destructor.
Definition: GLView2D.cpp:97
MouseMode mouseMode
Current mouse behaviour.
Definition: GLView2D.h:438
ome::files::dimension_size_type getSeries()
Get series.
Definition: GLView2D.cpp:119
void setXTranslation(int xtran)
Set x translation factor.
Definition: GLView2D.cpp:177
void render()
Render the scene with the current view settings.
Definition: GLView2D.cpp:297