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