ome-qtwidgets  5.3.1
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  {
77  };
78 
88  GLView2D(ome::compat::shared_ptr<ome::files::FormatReader> reader,
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
165 
171  void
172  setMouseMode(MouseMode mode);
173 
174  public:
180  ome::compat::shared_ptr<ome::files::FormatReader>
181  getReader();
182 
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 
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
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  {
365  {
368  };
369 
370  Camera():
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 
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 
443  QElapsedTimer etimer;
445  glm::vec3 cmin;
447  glm::vec3 cmax;
453  QPoint lastPos;
461  ome::compat::shared_ptr<ome::files::FormatReader> reader;
464  };
465 
466  }
467 }
468 
469 #endif // OME_QTWIDGETS_GLVIEW2D_H
470 
471 /*
472  * Local Variables:
473  * mode:C++
474  * End:
475  */
glm::mat4 view
Current view.
Definition: GLView2D.h:394
int yTran
y translation.
Definition: GLView2D.h:388
Perspective projection.
Definition: GLView2D.h:367
void timerEvent(QTimerEvent *event)
Handle timer events.
Definition: GLView2D.cpp:366
glm::mat4 model
Current model.
Definition: GLView2D.h:392
void channelMaxChanged(int max)
Signal maximum value for linear contrast changed.
float zoomfactor() const
Get zoom factor.
Definition: GLView2D.h:407
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:364
std::size_t dimension_size_type
glm::vec3 cmax
Maximum level for linear contrast.
Definition: GLView2D.h:447
void resize()
Resize the view.
Definition: GLView2D.cpp:314
ProjectionType projectionType
Projection type.
Definition: GLView2D.h:382
int getXTranslation() const
Get x translation factor.
Definition: GLView2D.cpp:131
2D (xy) grid renderer.
Definition: Grid2D.h:67
Pan in x and y.
Definition: GLView2D.h:75
ome::files::dimension_size_type plane
Current plane.
Definition: GLView2D.h:449
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:390
QPoint lastPos
Last mouse position.
Definition: GLView2D.h:453
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:445
2D GL view of an image with axes and gridlines.
Definition: GLView2D.h:66
ome::files::dimension_size_type oldplane
Previous plane.
Definition: GLView2D.h:451
Zoom in and out.
Definition: GLView2D.h:74
void setZRotation(int angle)
Set z rotation factor.
Definition: GLView2D.cpp:197
glm::mat4 projection
Current projection.
Definition: GLView2D.h:396
ome::files::dimension_size_type series
The image series.
Definition: GLView2D.h:463
ome::compat::shared_ptr< ome::files::FormatReader > getReader()
Get reader.
Definition: GLView2D.cpp:113
int xTran
x translation
Definition: GLView2D.h:386
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.
Open Microscopy Environment C++.
bool event(QEvent *event)
Handle events.
Definition: GLWindow.cpp:114
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:443
glm::mat4 mvp() const
Get modelview projection matrix.
Definition: GLView2D.h:432
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:91
int zoom
Zoom factor.
Definition: GLView2D.h:384
float rotation() const
Get rotation factor.
Definition: GLView2D.h:418
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:361
gl::Axis2D * axes
Axes to render.
Definition: GLView2D.h:457
gl::Image2D * image
Image to render.
Definition: GLView2D.h:455
Camera camera
Current projection.
Definition: GLView2D.h:439
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:459
Rotate around point in z.
Definition: GLView2D.h:76
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:72
ome::compat::shared_ptr< ome::files::FormatReader > reader
The image reader.
Definition: GLView2D.h:461
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:70
Orthographic projection.
Definition: GLView2D.h:366
~GLView2D()
Destructor.
Definition: GLView2D.cpp:97
MouseMode mouseMode
Current mouse behaviour.
Definition: GLView2D.h:441
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