VAPoR  3.0.0
mappingframe.h
Go to the documentation of this file.
1 //--mappingframe.h ---------------------------------------------------------
2 //
3 // Copyright (C) 2006 Kenny Gruchalla. All rights reserved.
4 //
5 // A QLGWidget that provides 1D transfer function interface. This frame can
6 // be used to map color and/or opacity to data values.
7 //
8 // Note: The interface can map either opacity, color, or both opacity and
9 // color. The enabledness of these mappings needs to be set BEFORE
10 // initializeGL is called. Since QtDesigner does not provide a way to pass
11 // in constructor arguments, these are being set as properties in designer.
12 // If designer is not being used call setOpacityMapping and setColorMapping
13 // immediately after construction.
14 //
15 //----------------------------------------------------------------------------
16 
17 #ifndef MappingFrame_H
18 #define MappingFrame_H
19 
20 #include <GL/glew.h>
21 #ifdef Darwin
22 #include <OpenGL/gl.h>
23 #include <OpenGL/glu.h>
24 #else
25 #include <GL/gl.h>
26 #include <GL/glu.h>
27 #endif
28 
29 #include <qgl.h>
30 
31 #include <QContextMenuEvent>
32 #include <QPaintEvent>
33 #include <QMouseEvent>
34 #include "visualizer.h"
35 
36 #include <qpoint.h>
37 #include <list>
38 #include <map>
39 #include <set>
40 
41 
42 class QAction;
43 class QLabel;
44 class QMenu;
45 class QPushButton;
46 class QSlider;
47 
48 
49 
50 
51 namespace VAPoR {
52  class MapperFunction;
53  class RenderParams;
54  class Histo;
55  class DomainWidget;
56  class IsoSlider;
57  class GLWidget;
58  class OpacityWidget;
59  class OpacityMapBase;
60  class ColorbarWidget;
61  class EventRouter;
62 };
63 
64 using namespace VAPoR;
75 
76 class MappingFrame : public QGLWidget
77 {
78  Q_OBJECT
79 
80  Q_PROPERTY(bool colorMapping READ colorMapping WRITE setColorMapping)
81  Q_PROPERTY(bool opacityMapping READ opacityMapping WRITE setOpacityMapping)
82 
83  enum
84  {
85  BOOLEAN=0,
86  LINEAR=1,
87  LOG=2
88  };
89 
90  enum
91  {
92  ENABLED=0,
93  DISABLED=1
94  };
95 
96  enum
97  {
98  OPACITY_WIDGETS,
99  DOMAIN_WIDGET,
100  COLORBAR_WIDGET,
101  ISO_WIDGET
102  };
103 
104 public:
105 
106  MappingFrame(QWidget* parent, const char* name = 0);
107  virtual ~MappingFrame();
108 
120  void hookup(EventRouter* evrouter, QPushButton* editButton, QPushButton* ZoomPan, QPushButton* fitToView, QPushButton* histoButton,
121  QPushButton* fitData, QPushButton* bindColorToOpac, QPushButton* bindOpacToColor, QSlider* opacityScaleSlider);
122 
126  void setColorMapping(bool flag);
127 
131  void setOpacityMapping(bool flag);
132 
136  void setIsoSlider(bool flag) {_isoSliderEnabled = flag;}
137 
141  void setIsolineSliders(bool flag) {_isolineSlidersEnabled = flag;}
142 
146  void setIsolineSliders(const vector<double>& slidervals);
147 
151  void updateTab(RenderParams* rp);
152 
156  void setMapperFunction(MapperFunction *mapper);
157 
159  void updateParams();
160 
162  void setVariableName(std::string name);
163 
165  void update(){
166  QGLWidget::update();
167  }
168 
172  MapperFunction* mapperFunction() { return _mapper; }
173 
177  float minDataValue() { return _minValue; }
178 
182  float maxDataValue() { return _maxValue; }
183 
184 signals:
185 
190  void startChange(QString description);
191 
195  void endChange();
196  //
199  //
200  void mappingChanged();
201 
202 #ifndef DOXYGEN_SKIP_THIS
203 
204 public slots:
205  void fitToView();
206 
207 private:
208  bool colorMapping() const { return _colorMappingEnabled; }
209  bool opacityMapping() const { return _opacityMappingEnabled; }
210  bool isoSliderEnabled() const { return _isoSliderEnabled; }
211  bool isolineSlidersEnabled() const { return _isolineSlidersEnabled; }
212  void setIsoValue(float val){_isoVal = val;}
213  QString tipText(const QPoint &pos, bool isIso=false);
214  int histoValue(const QPoint &pos);
215  float xVariable(const QPoint &pos);
216  float yVariable(const QPoint &pos);
217  bool canBind();
218 
219 protected slots:
220  void setEditMode(bool);
221  void setNavigateMode(bool mode);
222  void setHistogramScale(QAction*);
223  void setCompositionType(QAction*);
224  void setWidgetEnabled(QAction*);
225  void updateMap();
226  void newHsv(int h, int s, int v);
227  void bindColorToOpacity();
228  void bindOpacityToColor();
229  void updateGL();
230 
231 
232 signals:
233  //
234  // Signals that a color control point has been selected
235  //
236  void sendRgb(QRgb color);
237 
238  //
239  // Signals that one color control point and one opacity control point have
240  // been selected.
241  //
242  void canBindControlPoints(bool);
243 
244 private:
245 
246  void initWidgets();
247  void initConnections();
248 
249  OpacityWidget* createOpacityWidget(OpacityMapBase *map);
250  void deleteOpacityWidgets();
251 
252  void initializeGL();
253  void paintGL();
254  void resizeGL( int w, int h );
255  //Virtual, Reimplemented here:
256  void paintEvent(QPaintEvent* event);
257 
258  void drawOpacityCurve();
259  void drawOpacityWidgets();
260  void drawDomainSlider();
261  void drawIsoSlider();
262  void drawIsolineSliders();
263  void drawColorbar();
264 
265  void updateTexture();
266 
267  void updateAxisLabels();
268  void addAxisLabel(int x, int y, const QString &text);
269 
270  void select(int x, int y, Qt::KeyboardModifiers);
271  void select(int hits, GLuint *selectionBuffer, Qt::KeyboardModifiers);
272 
273  void deselectWidgets();
274 
275  int totalFixedHeight();
276  void resize();
277 
278  virtual void mousePressEvent(QMouseEvent *event);
279  virtual void mouseMoveEvent(QMouseEvent *event);
280  virtual void mouseReleaseEvent(QMouseEvent *event);
281  virtual void mouseDoubleClickEvent(QMouseEvent *event);
282  virtual void contextMenuEvent(QContextMenuEvent *e);
283 
284  float xDataToWorld(float x);
285  float xWorldToData(float x);
286  float xViewToWorld(float x);
287  float xWorldToView(float x);
288 
289  float yDataToWorld(float y);
290  float yWorldToData(float y);
291  float yViewToWorld(float y);
292  float yWorldToView(float y);
293 
294  virtual float getMinEditBound();
295  virtual float getMaxEditBound();
296  virtual void setMinEditBound(float v);
297  virtual void setMaxEditBound(float v);
298 
299  virtual float getMinDomainBound();
300  virtual float getMaxDomainBound();
301 
302  virtual float getOpacity(float val);
303  virtual RenderParams* getParams();
304  virtual Histo* getHistogram();
305 
306 protected slots:
307 
308  void fitToData();
309  void refreshHisto();
310  void addOpacityWidget(QAction*);
311  void deleteOpacityWidget();
312 
313  void addColorControlPoint();
314 
315  void addOpacityControlPoint();
316  void editControlPoint();
317  void deleteControlPoint();
318 
319  void setDomain();
320  void setIsoSlider();
321  void setIsolineSlider(int sliderIndex);
322 
323 private:
324 
325  const int _NUM_BINS;
326 
327  MapperFunction *_mapper;
328  Histo *_histogram;
329 
330  bool _opacityMappingEnabled;
331  bool _colorMappingEnabled;
332  bool _isoSliderEnabled;
333  bool _isolineSlidersEnabled;
334  vector<IsoSlider*> _isolineSliders;
335  int _lastSelectedIndex;
336  QPushButton* navigateButton;
337  QPushButton* _editButton;
338  EventRouter* _eventRouter;
339 
340 
341  std::string _variableName;
342 
343  std::map<int, OpacityWidget*> _opacityWidgets;
344  DomainWidget *_domainSlider;
345  IsoSlider *_isoSlider;
346  ColorbarWidget *_colorbarWidget;
347  GLWidget *_lastSelected;
348  std::set<GLWidget*> _selectedWidgets;
349 
350  unsigned int _texid;
351  unsigned char *_texture;
352  bool _updateTexture;
353  int _histogramScale;
354 
355 
356  QPoint _contextPoint;
357  QMenu *_contextMenu;
358  QMenu *_addOpacityWidgetSubMenu;
359  QMenu *_histogramScalingSubMenu;
360  QMenu *_compTypeSubMenu;
361  QMenu *_widgetEnabledSubMenu;
362  QAction *_editOpacityWidgetAction;
363  QAction *_deleteOpacityWidgetAction;
364  QAction *_addColorControlPointAction;
365  QAction *_addOpacityControlPointAction;
366  QAction *_editControlPointAction;
367  QAction *_deleteControlPointAction;
368 
369  float _lastx;
370  float _lasty;
371 
372  bool _editMode;
373  QPoint _clickedPos;
374 
375  float _minValueStart;
376  float _maxValueStart;
377  float _isoVal;
378 
379  Qt::MouseButtons _button;
380 
381  float _minX;
382  float _maxX;
383  float _minY;
384  float _maxY;
385 
386  float _minValue;
387  float _maxValue;
388 
389  const int _colorbarHeight;
390  const int _domainBarHeight;
391  const int _domainLabelHeight;
392  const int _domainHeight;
393  int _axisRegionHeight;
394  const int _opacityGap;
395  const int _bottomGap;
396 
397  QStringList _axisTexts;
398  QList<QPoint*> _axisTextPos;
399 #endif //DOXYGEN_SKIP_THIS
400 
401 };
402 
403 #endif // MappingFrame_H
A Params subclass for managing parameters used by Renderers.
Definition: renderparams.h:57
float maxDataValue()
Definition: mappingframe.h:182
MapperFunction * mapperFunction()
Definition: mappingframe.h:172
A pure virtual class specifying the common properties of all the parameter tabs in the VAPOR GUI...
Definition: eventrouter.h:101
float minDataValue()
Definition: mappingframe.h:177
A QGLWidget that displays a Transfer Function Editor, or an Iso Selection Window. ...
Definition: mappingframe.h:76
void setIsoSlider(bool flag)
Definition: mappingframe.h:136
Definition: DC.h:10
void setIsolineSliders(bool flag)
Definition: mappingframe.h:141
void update()
Update the display of the MappingFrame. Invoked in EventRouter::setEditorDirty()
Definition: mappingframe.h:165