HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI_ViewState.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GUI_ViewState.h (Geometry Render Library, C++)
7  *
8  * COMMENTS:
9  * This class basically envelopes a DisplayOption and
10  * a ViewParameter. So it holds all the information
11  * that is relevant to viewing.
12  *
13  */
14 
15 #ifndef __GUI_ViewState__
16 #define __GUI_ViewState__
17 
18 #include "GUI_API.h"
19 #include "GUI_DisplayOption.h"
20 #include "GUI_RenderCommon.h"
21 #include "GUI_ViewParameter.h"
22 #include <UT/UT_Matrix3.h>
23 #include <UT/UT_Matrix4.h>
24 #include <UT/UT_Plane.h>
25 #include <UT/UT_Quaternion.h>
26 #include <UT/UT_Vector3.h>
27 
28 // Essentially a callback class to allow options from above GUI
29 // to be saved to the default file.
31 {
32 public:
34  virtual bool isDefaultToken(const char *token) = 0;
35  virtual bool parseDefaultOption(const char *token, UT_IStream &is) = 0;
36 
37  virtual bool save(std::ostream &os) = 0;
38 };
39 
40 
41 class UT_StringArray;
42 class TIL_Raster;
43 class GUI_SnapshotImage;
44 
46 {
47 public:
48  GUI_ViewState(bool for_lops);
49  ~GUI_ViewState();
50 
51  // member data accessors
53  { return myOption; }
55  { return myView; }
56  GUI_DisplayOption &getDisplayOptionRef() { return myOption; }
57  GUI_ViewParameter &getViewParameterRef() { return myView; }
58 
59  // sets the OpenGL state according to the view parameter
60  void setViewport(RE_Render *r, int x, int y, int w, int h)
61  { myView.setViewport(r, x, y, w, h); }
63  { myView.setProjection(r); }
64 
65  // methods for getting and setting the view point
66  void homeToBox(int w, int h, UT_BoundingBox &box,
67  const UT_Matrix3R *rot = NULL, bool centred = false,
68  bool zoom_in = false)
69  {
70  fpreal minh = getDisplayOptionRef().common()
71  .getMinHomeZoom();
72  myView.homeToBox(w, h, minh, box, rot,
73  centred, zoom_in);
74  myLeftView.homeToBox(w, h, minh, box, rot,
75  centred, zoom_in);
76  myRightView.homeToBox(w, h, minh, box, rot,
77  centred, zoom_in);
78  }
79  void getViewport(int &l, int &r, int &b, int &t) const
80  { myView.getViewport(l, r, b, t); }
81  UT_DimRect getViewport() const { return myView.getViewport(); }
82  void getView(int &l, int &r, int &b, int &t) const
83  { myView.getView(l, r, b, t); }
84  UT_DimRect getView() const { return myView.getView(); }
85  int getViewWidth() const { return myView.getViewWidth(); }
86  int getViewHeight() const { return myView.getViewHeight(); }
87 
89  { return myView.getItransformMatrix();}
91  { return myView.getTransformMatrix(); }
93  { return myView.getProjectionMatrix();}
95  { return myView.getRotateMatrix(); }
96  void setRotateMatrix(const UT_Matrix3R &mat)
97  { myView.setRotateMatrix(mat); }
98 
99  int initialized() const { return myView.initialized(); }
100 
101  void setOrthoFlag(int onoff)
102  {
103  myView.setOrthoFlag(onoff);
104  myLeftView.setOrthoFlag(onoff);
105  myRightView.setOrthoFlag(onoff);
106  }
107  int getOrthoFlag() const { return myView.getOrthoFlag(); }
108 
109  void setApplyAspectFlag(int onoff)
110  { myView.setApplyAspectFlag(onoff); }
111  int getApplyAspectFlag() const
112  {return myView.getApplyAspectFlag(); }
114  { myView.setAspectRatio(value); }
116  {return myView.getAspectRatio(); }
118  { myView.setLimits(n, f); }
119 
120  void rotate(UT_Axis3::axis axis, fpreal dx)
121  {
122  myView.rotate(axis, dx);
123  myLeftView.rotate(axis, dx);
124  myRightView.rotate(axis, dx);
125  }
126  void rotate(const UT_Vector3R &axis, fpreal dx)
127  {
128  myView.rotate(axis, dx);
129  myLeftView.rotate(axis, dx);
130  myRightView.rotate(axis, dx);
131  }
132  void rotate(const UT_Quaternion &quat)
133  {
134  myView.rotate(quat);
135  myLeftView.rotate(quat);
136  myRightView.rotate(quat);
137  }
138  void trackball(fpreal dx, fpreal dy)
139  {
140  myView.trackball(dx, dy);
141  myLeftView.trackball(dx, dy);
142  myRightView.trackball(dx, dy);
143  }
144  void dotumble(fpreal dx, fpreal dy, int changed)
145  {
146  myView.dotumble(dx, dy, changed);
147  myLeftView.dotumble(dx, dy, changed);
148  myRightView.dotumble(dx, dy, changed);
149  }
150  void scroll(fpreal dx, fpreal dy)
151  {
152  myView.scroll(dx, dy);
153  myLeftView.scroll(dx, dy);
154  myRightView.scroll(dx, dy);
155  }
156  void scroll(fpreal dx, fpreal dy,
157  const UT_InclusiveRect &viewport)
158  {
159  myView.scroll(dx, dy, viewport);
160  myLeftView.scroll(dx, dy, viewport);
161  myRightView.scroll(dx, dy, viewport);
162  }
163  void worldLockedScroll(const UT_Vector3R &locked_pos,
164  fpreal dx, fpreal dy)
165  {
166  // This method requires the projection
167  // matrix to be set correctly, which is
168  // not always the case for myLeftView
169  // and myRightView. Even if we could
170  // count on that, doing it individually
171  // for each view would tend to change
172  // the distance between the left and
173  // right views, which isn't what one
174  // wants. Instead, we just apply the
175  // same delta to the left and right
176  // views.
177  UT_Vector3D old_t = myView.getT();
178  UT_Vector3D old_p = myView.getP();
179 
180  myView.worldLockedScroll(
181  locked_pos, dx, dy);
182 
183  UT_Vector3D delta_t =
184  myView.getT() - old_t;
185  UT_Vector3D delta_p =
186  myView.getP() - old_p;
187  myLeftView.setT(
188  myLeftView.getT() + delta_t);
189  myLeftView.setP(
190  myLeftView.getP() + delta_p);
191  myRightView.setT(
192  myLeftView.getT() + delta_t);
193  myRightView.setP(
194  myLeftView.getP() + delta_p);
195  }
196  void dolly(fpreal dx,
197  bool precise_zoom = false,
198  bool smooth_dolly = false)
199  {
200  myView.dolly(dx, precise_zoom,
201  smooth_dolly);
202  myLeftView.dolly(dx, precise_zoom,
203  smooth_dolly);
204  myRightView.dolly(dx, precise_zoom,
205  smooth_dolly);
206  }
207  void directedDolly(const UT_Vector3R &unit_worldspace_dir,
208  fpreal dx,
209  bool precise_zoom = false,
210  bool smooth_dolly = false)
211  {
212  myView.directedDolly(
213  unit_worldspace_dir, dx,
214  precise_zoom,
215  smooth_dolly);
216  myLeftView.directedDolly(
217  unit_worldspace_dir, dx,
218  precise_zoom,
219  smooth_dolly);
220  myRightView.directedDolly(
221  unit_worldspace_dir, dx,
222  precise_zoom,
223  smooth_dolly);
224  }
226  bool precise_zoom = false)
227  {
228  myView.zoom(dx, item, precise_zoom);
229  myLeftView.zoom(dx, item, precise_zoom);
230  myRightView.zoom(dx, item,precise_zoom);
231  }
233  const UT_InclusiveRect &viewport,
234  bool precise_zoom = false)
235  {
236  myView.zoom(dx, item, viewport,
237  precise_zoom);
238  myLeftView.zoom(dx, item, viewport,
239  precise_zoom);
240  myRightView.zoom(dx, item, viewport,
241  precise_zoom);
242  }
243  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
245  bool precise_zoom = false)
246  {
247  myView.offsetZoom(sx, sy, dx, item,
248  precise_zoom);
249  myLeftView.offsetZoom(sx, sy, dx, item,
250  precise_zoom);
251  myRightView.offsetZoom(sx, sy, dx, item,
252  precise_zoom);
253  }
254  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
256  const UT_InclusiveRect &viewport,
257  bool precise_zoom = false)
258  {
259  myView.offsetZoom(sx, sy, dx, item,
260  viewport,
261  precise_zoom);
262  myLeftView.offsetZoom(sx, sy, dx, item,
263  viewport,
264  precise_zoom);
265  myRightView.offsetZoom(sx, sy, dx, item,
266  viewport,
267  precise_zoom);
268  }
269  void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx,
270  fpreal lasty, fpreal distance)
271  { myView.boxZoom(frstx,frsty,lastx,lasty, distance); }
272 
274  {
275  myView.screenScroll(dx, dy);
276  myLeftView.screenScroll(dx, dy);
277  myRightView.screenScroll(dx, dy);
278  }
279 
281  { myOption.common().primMask(m); }
283  { return myOption.common().primMask(); }
284 
285  // Enumeration of the types of view points:
287  {
291  GUI_IMAGE
292  };
293 
294  // type dependent view parameter accessor
296  {
297  if( view_type == GUI_MAIN )
298  return myView;
299  if( view_type == GUI_LEFT )
300  return myLeftView;
301  if( view_type == GUI_RIGHT )
302  return myRightView;
303  if( view_type == GUI_IMAGE )
304  return myImageView;
305  return myView;
306  }
307 
308  // for general synchronization of L/R view points with the main one
310  {
311  myLeftView = myView;
312  myRightView = myView;
313  }
314 
315  // type dependent versions
317  RE_Render *r, int x, int y, int w, int h)
318  { getViewParameter(vt).setViewport(r, x, y, w, h); }
320  { getViewParameter(vt).setProjection(r); }
321 
322  // The UT_Plane will be transformed with the inverted ViewState transform
323  // matrix
324  void alignPlaneWithView(UT_Plane *plane);
325 
326  const char *className() const;
327 
328  GUI_ViewState &operator=(const GUI_ViewState &src);
329 
330  // Method to override the default preference file name. In order to for
331  // the defaults to be loaded from this file, this must be called before
332  // the first instance of this class is created.
333  static void overridePrefFile(const char *filename);
334 
335  void saveAsDefault();
336  void resetToDefaults();
337 
338  // setting the image that overrides the regular rendering
339  void setSnapshotImage(TIL_Raster *texture);
340  TIL_Raster *getSnapshotImage() const;
341 
342  // setting the frame information of the snapshot image
343  void setSnapshotImageFrame( int frame );
344  int getSnapshotImageFrame() const;
345 
346  // the snapshot blending coefficient (alpha)
347  void setSnapshotFactor( float alpha);
348  float getSnapshotFactor() const;
349 
350  void setSnapshotBlendMode(GUI_SnapshotBlendMode mode);
351  GUI_SnapshotBlendMode getSnapshotBlendMode() const;
352 
353  // snapshot image flags
354  void setHideSnapshotAtSourceFrame( bool flag );
355  bool getHideSnapshotAtSourceFrame() const;
356 
357  void setTumbling(bool tumble) { myTumbleFlag = tumble; }
358  bool isTumbling() const { return myTumbleFlag; }
359 
360  bool isLopsView() const { return myIsLops; }
361 
362  // Returns the near and far clipping planes that have saved in the pref file
363  static void getDefaultNearFarLimits(fpreal &near_limit, fpreal &far_limit);
364 
365  // Methods to manipulate the external callback class for saving/loading
366  // defaults.
368  { return externalDefaultValues[for_lops?1:0]; }
370  bool for_lops)
371  { externalDefaultValues[for_lops?1:0] = cb; }
372 
373  static void ensureDefaultsLoaded(bool is_lops);
374 
375 private:
376  // 0 = reg, 1 = lops
377  static GUI_ViewState *defaultValues[2];
378  static GUI_ExternalDefaultCB *externalDefaultValues[2];
379  static UT_StringArray *defaultEnabledUserOptions[2];
380 
381  // Display options for the viewport
382  GUI_DisplayOption myOption;
383 
384  // Defines the point of view for simple cameras (non-stereoscopic).
385  GUI_ViewParameter myView;
386 
387  // For stereoscopic cameras we have two view points
388  GUI_ViewParameter myLeftView;
389  GUI_ViewParameter myRightView;
390 
391  // For the image view in LOPs, this is the camera view (myView is the 2D
392  // view)
393  GUI_ViewParameter myImageView;
394 
395  // data about the snapshot image that is displayed instead of showing
396  // the rendered scene (or is blended with the scene framebuffer)
397  GUI_SnapshotImage *mySnapshotImage;
398  bool myTumbleFlag;
399  bool myIsLops;
400 };
401 
402 #endif
const GUI_DisplayOption & getDisplayOptionRef() const
Definition: GUI_ViewState.h:52
GUI_ViewParameter & getViewParameterRef()
Definition: GUI_ViewState.h:57
virtual ~GUI_ExternalDefaultCB()
Definition: GUI_ViewState.h:33
GT_API const UT_StringHolder filename
GLenum src
Definition: glew.h:2410
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1520
void dotumble(fpreal dx, fpreal dy, int changed)
const UT_Matrix4D & getRotateMatrix() const
Definition: GUI_ViewState.h:94
GLenum mode
Definition: glew.h:2163
void setProjection(GUI_ViewState::GUI_ViewType vt, RE_Render *r)
void screenScroll(fpreal dx, fpreal dy)
const UT_Matrix4D & getProjectionMatrix() const
Definition: GUI_ViewState.h:92
GA_API const UT_StringHolder rot
void scroll(fpreal dx, fpreal dy, const UT_InclusiveRect &viewport)
void syncViewsWithMain()
const GLdouble * m
Definition: glew.h:9124
GLdouble l
Definition: glew.h:9122
void setPrimitiveMask(GA_PrimCompat::TypeMask m)
void dolly(fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
GA_PrimCompat::TypeMask getPrimitiveMask(void) const
void directedDolly(const UT_Vector3R &unit_worldspace_dir, fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
GUI_DisplayOption & getDisplayOptionRef()
Definition: GUI_ViewState.h:56
const UT_Matrix4D & getTransformMatrix()
Definition: GUI_ViewState.h:90
int getApplyAspectFlag() const
void setProjection(RE_Render *r)
Definition: GUI_ViewState.h:62
GLclampf f
Definition: glew.h:3499
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
void setViewport(GUI_ViewState::GUI_ViewType vt, RE_Render *r, int x, int y, int w, int h)
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
#define GUI_API
Definition: GUI_API.h:10
void setRotateMatrix(const UT_Matrix3R &mat)
Definition: GUI_ViewState.h:96
void setViewport(RE_Render *r, int x, int y, int w, int h)
Definition: GUI_ViewState.h:60
bool isLopsView() const
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
void scroll(fpreal dx, fpreal dy)
GLsizei n
Definition: glew.h:4040
int getViewWidth() const
Definition: GUI_ViewState.h:85
bool isTumbling() const
GLsizei GLsizei GLfloat distance
Definition: glew.h:13640
void rotate(const UT_Vector3R &axis, fpreal dx)
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
void worldLockedScroll(const UT_Vector3R &locked_pos, fpreal dx, fpreal dy)
UT_DimRect getViewport() const
Definition: GUI_ViewState.h:81
int initialized() const
Definition: GUI_ViewState.h:99
const GUI_ViewParameter & getViewParameterRef() const
Definition: GUI_ViewState.h:54
void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, const UT_InclusiveRect &viewport, bool precise_zoom=false)
UT_DimRect getView() const
Definition: GUI_ViewState.h:84
int getOrthoFlag() const
void getView(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:82
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, const UT_InclusiveRect &viewport, bool precise_zoom=false)
fpreal getAspectRatio() const
void setOrthoFlag(int onoff)
GUI_ViewParameter & getViewParameter(GUI_ViewState::GUI_ViewType view_type)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, bool precise_zoom=false)
double fpreal
Definition: SYS_Types.h:276
void setTumbling(bool tumble)
void rotate(const UT_Quaternion &quat)
int getViewHeight() const
Definition: GUI_ViewState.h:86
void setLimits(fpreal n, fpreal f)
const UT_Matrix4D & getItransformMatrix()
Definition: GUI_ViewState.h:88
GLenum GLuint texture
Definition: glew.h:2361
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
void rotate(UT_Axis3::axis axis, fpreal dx)
static GUI_ExternalDefaultCB * getExternalDefaultCB(bool for_lops)
void trackball(fpreal dx, fpreal dy)
void setAspectRatio(fpreal value)
void homeToBox(int w, int h, UT_BoundingBox &box, const UT_Matrix3R *rot=NULL, bool centred=false, bool zoom_in=false)
Definition: GUI_ViewState.h:66
static void setExternalDefaultCB(GUI_ExternalDefaultCB *cb, bool for_lops)
GUI_SnapshotBlendMode
void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, bool precise_zoom=false)
GLsizei const GLfloat * value
Definition: glew.h:1849
void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx, fpreal lasty, fpreal distance)
GLdouble GLdouble t
Definition: glew.h:1398
void getViewport(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:79
void setApplyAspectFlag(int onoff)