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.setDefaultFOV(value); }
120  { return myView.getDefaultFOV(); }
122  { myView.setLimits(n, f); }
123 
124  void rotate(UT_Axis3::axis axis, fpreal dx)
125  {
126  myView.rotate(axis, dx);
127  myLeftView.rotate(axis, dx);
128  myRightView.rotate(axis, dx);
129  }
130  void rotate(const UT_Vector3R &axis, fpreal dx)
131  {
132  myView.rotate(axis, dx);
133  myLeftView.rotate(axis, dx);
134  myRightView.rotate(axis, dx);
135  }
136  void rotate(const UT_Quaternion &quat)
137  {
138  myView.rotate(quat);
139  myLeftView.rotate(quat);
140  myRightView.rotate(quat);
141  }
142  void trackball(fpreal dx, fpreal dy)
143  {
144  myView.trackball(dx, dy);
145  myLeftView.trackball(dx, dy);
146  myRightView.trackball(dx, dy);
147  }
148  void dotumble(fpreal dx, fpreal dy, int changed)
149  {
150  myView.dotumble(dx, dy, changed);
151  myLeftView.dotumble(dx, dy, changed);
152  myRightView.dotumble(dx, dy, changed);
153  }
154  void scroll(fpreal dx, fpreal dy)
155  {
156  myView.scroll(dx, dy);
157  myLeftView.scroll(dx, dy);
158  myRightView.scroll(dx, dy);
159  }
160  void scroll(fpreal dx, fpreal dy,
161  const UT_InclusiveRect &viewport)
162  {
163  myView.scroll(dx, dy, viewport);
164  myLeftView.scroll(dx, dy, viewport);
165  myRightView.scroll(dx, dy, viewport);
166  }
167  void worldLockedScroll(const UT_Vector3R &locked_pos,
168  fpreal dx, fpreal dy)
169  {
170  // This method requires the projection
171  // matrix to be set correctly, which is
172  // not always the case for myLeftView
173  // and myRightView. Even if we could
174  // count on that, doing it individually
175  // for each view would tend to change
176  // the distance between the left and
177  // right views, which isn't what one
178  // wants. Instead, we just apply the
179  // same delta to the left and right
180  // views.
181  UT_Vector3D old_t = myView.getT();
182  UT_Vector3D old_p = myView.getP();
183 
184  myView.worldLockedScroll(
185  locked_pos, dx, dy);
186 
187  UT_Vector3D delta_t =
188  myView.getT() - old_t;
189  UT_Vector3D delta_p =
190  myView.getP() - old_p;
191  myLeftView.setT(
192  myLeftView.getT() + delta_t);
193  myLeftView.setP(
194  myLeftView.getP() + delta_p);
195  myRightView.setT(
196  myLeftView.getT() + delta_t);
197  myRightView.setP(
198  myLeftView.getP() + delta_p);
199  }
200  void dolly(fpreal dx,
201  bool precise_zoom = false,
202  bool smooth_dolly = false)
203  {
204  myView.dolly(dx, precise_zoom,
205  smooth_dolly);
206  myLeftView.dolly(dx, precise_zoom,
207  smooth_dolly);
208  myRightView.dolly(dx, precise_zoom,
209  smooth_dolly);
210  }
211  void directedDolly(const UT_Vector3R &unit_worldspace_dir,
212  fpreal dx,
213  bool precise_zoom = false,
214  bool smooth_dolly = false)
215  {
216  myView.directedDolly(
217  unit_worldspace_dir, dx,
218  precise_zoom,
219  smooth_dolly);
220  myLeftView.directedDolly(
221  unit_worldspace_dir, dx,
222  precise_zoom,
223  smooth_dolly);
224  myRightView.directedDolly(
225  unit_worldspace_dir, dx,
226  precise_zoom,
227  smooth_dolly);
228  }
230  bool precise_zoom = false)
231  {
232  myView.zoom(dx, item, precise_zoom);
233  myLeftView.zoom(dx, item, precise_zoom);
234  myRightView.zoom(dx, item,precise_zoom);
235  }
237  const UT_InclusiveRect &viewport,
238  bool precise_zoom = false)
239  {
240  myView.zoom(dx, item, viewport,
241  precise_zoom);
242  myLeftView.zoom(dx, item, viewport,
243  precise_zoom);
244  myRightView.zoom(dx, item, viewport,
245  precise_zoom);
246  }
247  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
249  bool precise_zoom = false)
250  {
251  myView.offsetZoom(sx, sy, dx, item,
252  precise_zoom);
253  myLeftView.offsetZoom(sx, sy, dx, item,
254  precise_zoom);
255  myRightView.offsetZoom(sx, sy, dx, item,
256  precise_zoom);
257  }
258  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
260  const UT_InclusiveRect &viewport,
261  bool precise_zoom = false)
262  {
263  myView.offsetZoom(sx, sy, dx, item,
264  viewport,
265  precise_zoom);
266  myLeftView.offsetZoom(sx, sy, dx, item,
267  viewport,
268  precise_zoom);
269  myRightView.offsetZoom(sx, sy, dx, item,
270  viewport,
271  precise_zoom);
272  }
273  void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx,
274  fpreal lasty, fpreal distance)
275  { myView.boxZoom(frstx,frsty,lastx,lasty, distance); }
276 
278  {
279  myView.screenScroll(dx, dy);
280  myLeftView.screenScroll(dx, dy);
281  myRightView.screenScroll(dx, dy);
282  }
283 
285  { myOption.common().primMask(m); }
287  { return myOption.common().primMask(); }
288 
289  // Enumeration of the types of view points:
291  {
295  GUI_IMAGE
296  };
297 
298  // type dependent view parameter accessor
300  {
301  if( view_type == GUI_MAIN )
302  return myView;
303  if( view_type == GUI_LEFT )
304  return myLeftView;
305  if( view_type == GUI_RIGHT )
306  return myRightView;
307  if( view_type == GUI_IMAGE )
308  return myImageView;
309  return myView;
310  }
311 
312  // for general synchronization of L/R view points with the main one
314  {
315  myLeftView = myView;
316  myRightView = myView;
317  }
318 
319  // type dependent versions
321  RE_Render *r, int x, int y, int w, int h)
322  { getViewParameter(vt).setViewport(r, x, y, w, h); }
324  { getViewParameter(vt).setProjection(r); }
325 
326  // The UT_Plane will be transformed with the inverted ViewState transform
327  // matrix
328  void alignPlaneWithView(UT_Plane *plane);
329 
330  const char *className() const;
331 
332  GUI_ViewState &operator=(const GUI_ViewState &src);
333 
334  // Method to override the default preference file name. In order to for
335  // the defaults to be loaded from this file, this must be called before
336  // the first instance of this class is created.
337  static void overridePrefFile(const char *filename);
338 
339  void saveAsDefault();
340  void resetToDefaults();
341 
342  // setting the image that overrides the regular rendering
343  void setSnapshotImage(TIL_Raster *texture);
344  TIL_Raster *getSnapshotImage() const;
345 
346  // setting the frame information of the snapshot image
347  void setSnapshotImageFrame( int frame );
348  int getSnapshotImageFrame() const;
349 
350  // the snapshot blending coefficient (alpha)
351  void setSnapshotFactor( float alpha);
352  float getSnapshotFactor() const;
353 
354  void setSnapshotBlendMode(GUI_SnapshotBlendMode mode);
355  GUI_SnapshotBlendMode getSnapshotBlendMode() const;
356 
357  // snapshot image flags
358  void setHideSnapshotAtSourceFrame( bool flag );
359  bool getHideSnapshotAtSourceFrame() const;
360 
361  void setTumbling(bool tumble) { myTumbleFlag = tumble; }
362  bool isTumbling() const { return myTumbleFlag; }
363 
364  bool isLopsView() const { return myIsLops; }
365 
366  // Returns the near and far clipping planes that have saved in the pref file
367  static void getDefaultNearFarLimits(fpreal &near_limit, fpreal &far_limit);
368 
369  // Automatic near/far clip adapt is disabled when looking through a camera.
370  void allowNearFarClipAdapt(bool allow)
371  {
372  myView.allowNearFarClipAdapt(allow);
373  myLeftView.allowNearFarClipAdapt(false); //allow);
374  myRightView.allowNearFarClipAdapt(false); //allow);
375  // No Image view
376  }
377  void setSceneBounds(const UT_BoundingBoxD &bbox)
378  {
379  myView.setSceneBounds(bbox);
380  myLeftView.setSceneBounds(bbox);
381  myRightView.setSceneBounds(bbox);
382  }
383 
385  {
386  myView.setSelectedObjectBounds(bbox);
387  myLeftView.setSelectedObjectBounds(bbox);
388  myRightView.setSelectedObjectBounds(bbox);
389  }
391  {
392  return myView.getSceneBounds();
393  }
394 
395  // Methods to manipulate the external callback class for saving/loading
396  // defaults.
398  { return externalDefaultValues[for_lops?1:0]; }
400  bool for_lops)
401  { externalDefaultValues[for_lops?1:0] = cb; }
402 
403  static void ensureDefaultsLoaded(bool is_lops);
404 
405 private:
406  // 0 = reg, 1 = lops
407  static GUI_ViewState *defaultValues[2];
408  static GUI_ExternalDefaultCB *externalDefaultValues[2];
409  static UT_StringArray *defaultEnabledUserOptions[2];
410 
411  // Display options for the viewport
412  GUI_DisplayOption myOption;
413 
414  // Defines the point of view for simple cameras (non-stereoscopic).
415  GUI_ViewParameter myView;
416 
417  // For stereoscopic cameras we have two view points
418  GUI_ViewParameter myLeftView;
419  GUI_ViewParameter myRightView;
420 
421  // For the image view in LOPs, this is the camera view (myView is the 2D
422  // view)
423  GUI_ViewParameter myImageView;
424 
425  // data about the snapshot image that is displayed instead of showing
426  // the rendered scene (or is blended with the scene framebuffer)
427  GUI_SnapshotImage *mySnapshotImage;
428  bool myTumbleFlag;
429  bool myIsLops;
430 };
431 
432 #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
void dotumble(fpreal dx, fpreal dy, int changed)
const UT_Matrix4D & getRotateMatrix() const
Definition: GUI_ViewState.h:94
void setProjection(GUI_ViewState::GUI_ViewType vt, RE_Render *r)
void setDefaultFOV(fpreal value)
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 allowNearFarClipAdapt(bool allow)
void syncViewsWithMain()
void setSceneBounds(const UT_BoundingBoxD &bbox)
GLint y
Definition: glcorearb.h:103
void setPrimitiveMask(GA_PrimCompat::TypeMask m)
void dolly(fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
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
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
void setSelectedObjectBounds(const UT_BoundingBoxD &bbox)
void setProjection(RE_Render *r)
Definition: GUI_ViewState.h:62
void setViewport(GUI_ViewState::GUI_ViewType vt, RE_Render *r, int x, int y, int w, int h)
#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
void scroll(fpreal dx, fpreal dy)
int getViewWidth() const
Definition: GUI_ViewState.h:85
bool isTumbling() const
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
void rotate(const UT_Vector3R &axis, fpreal dx)
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)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
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)
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
fpreal getAspectRatio() const
void setOrthoFlag(int onoff)
GUI_ViewParameter & getViewParameter(GUI_ViewState::GUI_ViewType view_type)
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, bool precise_zoom=false)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void setTumbling(bool tumble)
void rotate(const UT_Quaternion &quat)
fpreal getDefaultFOV() const
int getViewHeight() const
Definition: GUI_ViewState.h:86
fpreal64 fpreal
Definition: SYS_Types.h:277
void setLimits(fpreal n, fpreal f)
const UT_Matrix4D & getItransformMatrix()
Definition: GUI_ViewState.h:88
void rotate(UT_Axis3::axis axis, fpreal dx)
static GUI_ExternalDefaultCB * getExternalDefaultCB(bool for_lops)
void trackball(fpreal dx, fpreal dy)
GLuint texture
Definition: glcorearb.h:415
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void setAspectRatio(fpreal value)
Definition: core.h:1131
GLboolean r
Definition: glcorearb.h:1222
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
SIM_API const UT_StringHolder distance
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)
void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx, fpreal lasty, fpreal distance)
void getViewport(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:79
GA_PrimCompat::TypeMask getPrimitiveMask() const
void setApplyAspectFlag(int onoff)
GLenum src
Definition: glcorearb.h:1793
UT_BoundingBox getSceneBounds() const