MorphoGraphX
MorphoViewer.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef VIEWER_H
12 #define VIEWER_H
13 
14 #include <Config.hpp>
15 #include <GL.hpp>
16 
17 #include <ClipRegion.hpp>
18 #include <CutSurf.hpp>
19 #include <EdgeData.hpp>
20 #include <ImageData.hpp>
21 #include <MGXViewer/qglviewer.h>
22 #include <Shader.hpp>
23 #include <VertexData.hpp>
24 #include <Geometry.hpp>
25 
26 #include <QtGui>
27 
28 class QDomElement;
29 class QShowEvent;
30 class MorphoGraphX;
31 class MGXCamera;
32 
34 public:
36  virtual void interpolateAtTime(float time);
37 
38  std::vector<float> zooms;
39 };
40 
42 public:
44 
45  void wheelEvent(QWheelEvent* const event, qglviewer::Camera* const camera);
46 
47  float zoom() const
48  {
49  return _zoom;
50  }
51 
52  void setZoom(float z)
53  {
54  _zoom = z;
55  }
56 
57 protected:
58  float _zoom;
59 };
60 
62 {
63 public:
64  MGXCamera();
65 
66  void getOrthoWidthHeight(GLdouble& halfWidth, GLdouble& halfHeight) const;
67 
68  void resetZoom();
69 
70  void fitSphere(const qglviewer::Vec& center, float radius);
71 
72  virtual void addKeyFrameToPath(int i);
73 
74  virtual void playPath(int i);
75 
76  virtual void deletePath(int i);
77 
78  virtual void resetPath(int i);
79 
80  virtual void drawAllPaths();
81 
82  float zoom() const
83  {
84  return _frame->zoom();
85  }
86 
87  void setZoom(float z)
88  {
89  _frame->setZoom(z);
90  }
91 
92  MGXCameraFrame* frame()
93  {
94  return _frame;
95  }
96 
97  const MGXCameraFrame* frame() const
98  {
99  return _frame;
100  }
101 
102 protected:
103  MGXCameraFrame* _frame;
104 };
105 
106 class MorphoViewer : public QGLViewer
107 {
108  Q_OBJECT
109 public:
110  enum FrameIdentity {
111  FI_BACKGROUND,
112  FI_FULL_IMG1,
113  FI_FULL_IMG2,
114  FI_CUR_PEEL,
115  FI_VOLUME1,
116  FI_VOLUME2,
117  FI_OCCLUSION,
118  NB_FRAMES
119  };
120 
121  bool quitting;
122  bool DrawCellMap;
123  bool DrawClipBox;
124  std::set<mgx::vertex::identity_t> selectV;
125  mgx::Point3f oldVPos;
126  QPoint oldPos;
127  QRect selectRect;
128  bool pixelEditCursor;
129  float pixelRadius;
130  QPoint mousePos;
131  mgx::Shader raycasting_shader1, raycasting_shader2;
132  mgx::Shader colormap2_shader, index2_shader;
133  mgx::Shader final_combine_shader, combine_shader, render_depth_shader;
134  mgx::Shader texture_surf_shader, index_surf_shader;
135  mgx::Shader volume_surf_shader1, volume_surf_shader2;
136  mgx::Shader post_process_shader;
137  mgx::Shader occlusion_shader;
138 
139  GLuint baseFboId, fboId, fboCopyId;
140  GLuint depthTexId[NB_FRAMES];
141  GLuint colorTexId[NB_FRAMES];
142  GLuint depthBuffer;
143  std::vector<GLfloat> depthTexture;
144  int drawWidth, drawHeight;
145  int prevWidth, prevHeight;
146 
147  enum SelectMode { NONE, MOVE, SELRECT };
148  SelectMode selectMode;
149 
150  bool shiftPressed;
151  bool altPressed;
152  bool controlPressed;
153  bool leftButton;
154 
155  bool pixelEdit;
156  bool pickVolLabel;
157  bool deleteVolLabel;
158  bool deletePckdLabel;
159  bool fillVolLabel;
160  bool meshSelect;
161 
162  bool addNewSeed;
163  bool addCurrentSeed;
164  bool pickLabel;
165  bool selectLabel;
166  bool selectConnected;
167  bool grabSeed;
168  bool fillLabel;
169 
170  QList<float> pickedLabels;
171 
172  // Clipping planes
173  mgx::ClipRegion clip1, clip2, clip3;
174  mgx::Clip* c1, *c2, *c3;
175 
176  // Confocal stack objects
177  QPointer<mgx::ImgData> stack1, stack2;
178 
179  // Cutting surface
180  mgx::CutSurf* cutSurf;
181 
182  float FlySpeed;
183  int selectedLabel;
184  float sampling;
185  bool fast_draw;
186  int texWidth, texHeight;
187  int show_slice;
188  int slice_type;
189 
190  int MaxNbPeels;
191  float Specular;
192  float Shininess;
193  float GlobalBrightness;
194  float GlobalContrast;
195  float UnsharpStrength;
196  float Spinning;
197  float ZoomFactor() const;
198  void setZoomFactor(float f);
199  mgx::Matrix4d CameraFrame;
200  MGXCamera* _camera;
201 
202  MorphoGraphX* mainWindow();
203 
204  void setSceneBoundingBox(const mgx::Point3f& bbox);
205  float getSceneRadius() const {
206  return SceneRadius;
207  }
208 
209  void processRunning(bool state)
210  {
211  _processRunning = state;
212  }
213 
214  bool processRunning()
215  {
216  return _processRunning;
217  }
218 
219 private:
220  float SceneRadius;
221 
222  QString fullSnapshotFileName();
223  void initObject(QWidget* parent);
224  bool initialized;
225  qglviewer::Camera* lastInitCamera;
226  bool _processRunning;
227 
228  void initCamera();
229 
230 public:
231  MorphoViewer(QWidget* parent);
232  MorphoViewer(QGLContext* context, QWidget* parent);
233  MorphoViewer(const QGLFormat& format, QWidget* parent);
234  virtual ~MorphoViewer();
235 
236  static void initFormat();
237 
238  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
239 
240  void drawSelectRect();
241  void drawPixelCursor();
242  void checkPixelCursor(bool altPressed);
243  void drawColorBar();
244  void drawScaleBar();
245  void setLighting(bool isStack1);
246  void readParms(mgx::util::Parms& parms, QString section);
247  void writeParms(QTextStream& pout, QString section);
248  void updateAll();
249  mgx::Point3f pointUnderPixel(const QPoint& pos, bool& found);
250  void startScreenCoordinatesSystem(bool upward = false) const;
251 
252 protected:
253  void preDraw();
254  void draw();
255  void draw(QPaintDevice* device);
256  void fastDraw();
257  virtual void postDraw();
258  virtual void init();
259  void showEvent(QShowEvent* event);
260  void resizeGL(int width, int height);
261  void updateFBOTex(int width, int height, bool fast_draw = false);
262  void drawColorTexture(int i, bool draw_depth = false);
263  void alternatePeels(int& curPeelId, int& prevPeelId, int fullImgId);
264  void combinePeels(int& fullImgId, int curPeelId, int volume1, int volume2);
265  void setupCopyFB(GLuint depth, GLint color);
266  void setupFramebuffer(GLuint depth, GLuint color, GLbitfield clear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
267  void resetupFramebuffer(GLuint depth, GLuint color, GLbitfield clear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
268  void resetFramebuffer();
269  void leaveEvent(QEvent* e);
270  void enterEvent(QEvent* e);
271  void keyReleaseEvent(QKeyEvent* e);
272  void keyPressEvent(QKeyEvent* e);
273  void mouseMoveEvent(QMouseEvent* e);
274  void mousePressEvent(QMouseEvent* e);
275  void mouseReleaseEvent(QMouseEvent* e);
276  void mouseDoubleClickEvent(QMouseEvent* e);
277 
278 private:
279  mgx::ImgData* findSelectStack(bool printMsg);
280  mgx::ImgData* findSelectSurf(bool printMsg);
281  mgx::ImgData* findSelectMesh(bool printMsg);
282  void findSelectTriangle(mgx::ImgData* stk, uint x, uint y, std::vector<uint>& vlist, int& label,
283  bool useParentLabel = true);
284 
285  void getGUIFlags(QMouseEvent* e);
286  void drawCellMap();
287 
288  Qt::MouseButtons lastButtons;
289 
290  void clipEnable();
291  void clipDisable();
292  void pixelEditStart(QMouseEvent* e);
293  void pixelEditMove(QMouseEvent* e);
294  void pixelEditStop();
295  int findLabel(const mgx::Store* store, mgx::Point3f start, mgx::Point3f dir) const;
296  void pickVolumeLabelStart(QMouseEvent* e);
297  void deleteVolumeLabel(QMouseEvent* e);
298  void deletePickedLabelStart(QMouseEvent* e);
299  void deletePickedLabelMove(QMouseEvent* e, bool replace = false);
300  void deletePickedLabel();
301  void fillVolumeLabel(QMouseEvent* e);
302  void pickVolumeLabelMove(QMouseEvent* e);
303  void pickVolumeLabelStop();
304  void meshEditStart(QMouseEvent* e);
305  void meshEditMove(QMouseEvent* e);
306  void meshEditStop();
307  void labelEditStart(QMouseEvent* e);
308  void labelEditMove(QMouseEvent* e);
309  void labelEditStop();
310 
311  QPaintDevice* current_device;
312 
313  void ClipEnableSlot(mgx::Clip* c, bool _val);
314  void ClipGridSlot(mgx::Clip* c, bool _val);
315  void ClipWidthSlot(mgx::Clip* c, int _val);
316 
317 public slots:
318  void setLabel(int label);
319  void selectMeshLabel(int label, bool replace = true);
320  void selectMeshLabel(int label, int repeat, bool replace = true);
321  void unselectMeshLabel(int label);
322  void ReloadShaders();
323  void UpdateSlot() {
324  updateAll();
325  }
326  void editMainTransferFunction1();
327  void editWorkTransferFunction1();
328  void editSurfTransferFunction1();
329  void editHeatTransferFunction1();
330  void editMainTransferFunction2();
331  void editWorkTransferFunction2();
332  void editSurfTransferFunction2();
333  void editHeatTransferFunction2();
334  void loadFile(const QString& pth, bool stack2, bool load_work);
335  void UpdateLabels();
336 
337  // Takes care of GUI clips
338  void Clip1EnableSlot(bool _val) {
339  ClipEnableSlot(c1, _val);
340  }
341  void Clip1GridSlot(bool _val) {
342  ClipGridSlot(c1, _val);
343  }
344  void Clip1WidthSlot(int _val) {
345  ClipWidthSlot(c1, _val);
346  }
347  void Clip2EnableSlot(bool _val) {
348  ClipEnableSlot(c2, _val);
349  }
350  void Clip2GridSlot(bool _val) {
351  ClipGridSlot(c2, _val);
352  }
353  void Clip2WidthSlot(int _val) {
354  ClipWidthSlot(c2, _val);
355  }
356  void Clip3EnableSlot(bool _val) {
357  ClipEnableSlot(c3, _val);
358  }
359  void Clip3GridSlot(bool _val) {
360  ClipGridSlot(c3, _val);
361  }
362  void Clip3WidthSlot(int _val) {
363  ClipWidthSlot(c3, _val);
364  }
365 
366  void FlySpeedSlot(int val) {
367  FlySpeed = float(val) / 10000.0;
368  }
369  void DrawCellMapSlot(bool val)
370  {
371  DrawCellMap = val;
372  updateAll();
373  }
374  void SlicesSlot(int val)
375  {
376  mgx::ImgData::Slices = val;
377  updateAll();
378  }
379  void ScreenSamplingSlot(int val);
380  void Surf1BrightSlot(int val)
381  {
382  stack1->mesh->setBrightness(float(val) / 10000.0);
383  updateAll();
384  }
385  void Surf2BrightSlot(int val)
386  {
387  stack2->mesh->setBrightness(float(val) / 10000.0);
388  updateAll();
389  }
390  void LabelColorSlot();
391  void ResetViewSlot();
392 
393  void recordMovie(bool on);
394 
395  void saveScreenshot(bool automatic = false, bool overwrite = false)
396  {
397  return QGLViewer::saveSnapshot(automatic, overwrite);
398  }
399  void saveScreenshot(const QString& fileName, bool overwrite = false)
400  {
401  return QGLViewer::saveSnapshot(fileName, overwrite);
402  }
403  void setScreenshotFileName(const QString& name) {
404  return QGLViewer::setSnapshotFileName(name);
405  }
406  void setScreenshotFormat(const QString& format) {
407  return QGLViewer::setSnapshotFormat(format);
408  }
409  void setScreenshotCounter(int counter) {
410  return QGLViewer::setSnapshotCounter(counter);
411  }
412  void setScreenshotQuality(int quality) {
413  return QGLViewer::setSnapshotQuality(quality);
414  }
415  bool openScreenshotFormatDialog() {
417  }
418 
419  virtual void initFromDOMElement(const QDomElement& element);
420 
421  void ViewerUpdateSlot() {
422  updateAll();
423  }
424  void ToggleHeatMapSlot();
425 
426  virtual bool saveImageSnapshot(const QString& fileName, QSize finalSize, double oversampling = 1.0,
427  bool expand = false, bool has_gui = false);
428 
429  bool saveImageSnapshot(const QString& fileName, QSize finalSize, double oversampling, bool expand, bool has_gui,
430  QString* error);
431 
432  void showEntireScene() {
433  camera()->showEntireScene();
434  }
435 
436 signals:
437  void deleteSelection();
438  void modified();
439  void stepDrawFinished(bool);
440  void setLabelColor(QIcon&);
441  void recordingMovie(bool);
442  void changeSceneRadius(float);
443  void selectLabelChanged(int);
444 };
445 
446 #endif /*VIEWER_H*/
setSnapshotQuality(int quality)
saveSnapshot(bool automatic=true, bool overwrite=false)
setSnapshotFormat(const QString &format)
Definition: MorphoViewer.hpp:33
This file contains the definition of a clipping region.
This file contains the definition of a vertex.
Definition: MorphoViewer.hpp:61
setSnapshotCounter(int counter)
setSnapshotFileName(const QString &name)
Definition: MorphoViewer.hpp:106
Class to handle rotatable pair of clipping planes.
Definition: ClipRegion.hpp:38
Definition: MorphoViewer.hpp:41
Definition: Shader.hpp:279
openSnapshotFormatDialog()
The Store class holds the actual 3D data and properties specific to it.
Definition: Store.hpp:35
Definition: MorphoGraphX.hpp:53
This file contains the definition of an edge data.
Common definitions and utilities for all geometry algorithms This file is shared by cuda...
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:115
Definition: CutSurf.hpp:31
Definition: ImageData.hpp:47
Definition: Clip.hpp:21