VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgChannel.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2017 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/DtChannel.h>
13 #include <vrvOsg/DtOsgRenderer.h>
14 #include <vrvOsg/DtCameraNode.h>
15 
16 #include <osgViewer/View>
17 
18 namespace osg
19 {
20  class Matrixd;
21  class DatabaseRequestHandler;
22 }
23 
24 namespace makVrv
25 {
26  class DtLight;
27  class DtChannelSpecificGroup;
28  class DtOsgWindow;
29  class DtOsgChannelCreator;
30  class DtChannelManager;
31  class DtWindowConfiguration;
32  class DtSensorModule;
33  class DtSensor;
34  class DtOsgObserverObject;
35  class DtOsgCullVisitorParameters;
36 
38  class DtDatabasePagerCallback : public osg::DatabaseRequestHandlerCallback
39  {
40 
41  public:
43 
44  /* child under parent was loaded and added to the scenegraph */
45  virtual void childPagedIn(const osg::DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const;
46 
47  /* child under parent was un-loaded and removed from the scenegraph */
48  virtual void childAboutToPageOut(const osg::DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const;
49 
50  virtual osg::DatabaseRequestHandlerCallback* clone() const;
51 
53 
54  private:
55 
57  };
58 
66  {
67  protected:
68  friend class DtOsgChannelCreator;
69 
73  DtOsgChannel(DtDe& de, DtOsgWindow* window, DtChannelConfiguration& config);
74 
76 
77 
82  virtual bool initialize();
83 
85 
86  virtual void initializeNormalized2DCamera();
87  virtual void initialize2DCamera( int w, int h );
88  virtual void initializeSceneCamera( );
89  virtual void initializeRenderTexture( );
90  virtual void initializeRTTCamera( );
91 
92  void clearRttCamera();
93 
94  virtual void recreateRTTCamera( );
95 
97 
99  void setShadowState(bool enable);
100 
102  virtual void addOverlayDrawablesToCameras();
103 
109  virtual void initializeSignalConnections();
111 
112 
113  public:
115  virtual ~DtOsgChannel();
116 
121  void setSensorName( const std::string& sensorName );
122 
124  virtual void setClearColor(float r,float g,float b, float a);
125 
129  virtual void setWindow(DtWindow* view);
130 
132  virtual const DtWindow* window() const;
133 
135  virtual void setViewport(int x,int y,int width, int height);
136 
140  virtual void clearFrameBufferIfChanged();
141 
143  virtual void getViewport(int& x,int& y, int& width,int& height) const;
144 
146  virtual void setCameraPosition(double x, double y, double z);
147 
149  virtual void setCameraOrientation( double psi, double theta, double phi );
150 
155  virtual void setCameraPositionAndOrientation( double x, double y,
156  double z, double psi, double theta, double phi );
157  virtual void setCameraPositionAndOrientation( osg::Vec3d& pos,
158  osg::Quat& orient );
159 
161  virtual void getCameraPositionAndOrientation( osg::Vec3d& position,
162  osg::Quat& rotation ) const;
163 
164  virtual void update();
165 
167  virtual void connectToObserver();
168 
171  virtual void setProjectionMatrixAsPerspective(double fovy,
172  double aspectRatio, double zNear, double zFar);
173 
175  virtual void setProjectionMatrixAsFrustum (double left, double right,
176  double bottom, double top, double zNear, double zFar);
177 
179  virtual void setProjectionMatrix(const osg::Matrix& matrix);
180 
182  virtual osgViewer::View& view();
183 
185  virtual DtCameraNode* sceneCamera();
186  virtual const DtCameraNode* sceneCamera() const;
187 
189  virtual DtCameraNode* rttCamera() const;
190 
192  virtual DtCameraNode* overlayCamera();
193 
194 
196  virtual DtCameraNode* normalizedOverlayCamera();
197 
199  virtual void setRenderToTexture(bool enabled);
200 
204  virtual void setRenderToTextureFormat(int format, int sourceFormat, int sourceType);
205 
206 
209  virtual osg::ref_ptr<osg::Texture2D> getRenderTexture();
210  virtual osg::ref_ptr<osg::Texture2D> getOcculsionTexture();
211 
213  virtual osg::ref_ptr<osg::Texture2D> getDepthTexture() const;
214 
216  int shadowQuality() const;
217 
221  virtual std::vector<const osg::Camera*> getShadowableCameras() const;
222 
225  virtual void setProjectionResizePolicy(
227 
230  virtual void updateProjection();
231 
232  void projectionUnitsToFrustum( DtChannelConfiguration::ProjectionUnits units,
233  double &left, double zNear, double &right, double &top, double &bottom );
234 
236  virtual void connectChannelToScene();
237 
239  virtual bool processMouseEvent( const DtMouseEvent& ev);
240 
242  virtual bool processKeyboardEvent(const DtKeyEvent & ev);
243 
245  //virtual DtDynamicOverlay* overlay();
246 
248  void getWorldToWindowMatrix( osg::Matrix& worldToWindowMatrix ) const;
249 
251  virtual void moveMouseToScreenLocation(float screenX, float screenY);
252 
256  virtual void projectToScreen( double dbX, double dbY, double dbZ,
257  double& screenX, double& screenY, double& screenZ );
258 
260  virtual void projectToWorld( double screenX, double screenY,
261  double& dbX, double& dbY, double& dbZ );
262 
264  virtual const std::string& name();
265 
270  boost::signal<void (int, int, int, int)> signal_viewportChanged;
271 
272  typedef std::list<std::string> PostProcessorEffectList;
273 
277  virtual void addPostProcessEffect(const std::string& postProcessorEffect);
278 
282  virtual void removePostProcessEffect(const std::string& postProcessorEffect);
283 
285  virtual void set3DCullVisitorParams( DtOsgCullVisitorParameters* params );
286  virtual void set2DCullVisitorParams( DtOsgCullVisitorParameters* params );
288 
289  virtual void setEnablePostProcessors(bool enable);
290 
291  virtual bool getEnablePostProcessors();
292 
293  //getter/setter for flag to use old (pre 2.1) channel offset calculation
294  virtual bool useOldChannelOffsetCalcuation() const;
295  virtual void setUseOldChannelOffsetCalcuation( bool enable );
296 
299  virtual bool forceHdrLuminanceOverride();
300  virtual void setForceHdrLuminanceOverride(bool force);
301 
303  // structure to expedite culling. We need to clear any memory
304  // that this structure caches to decrement reference count of
305  // StateSets (and hence drawables, textures, etc) when scene
306  // changes completely (e.g. on post processor turned off/on)
307  // so that memory can be reclaimed
308  // This helper function accomplishes that
309  virtual void clearStateGraph(void);
310 
312  // should just pass through without applying any effects
313  // used by SensorFX to turn off HDR on a per channel basis.
314  virtual void setEnableHdrPassthrough(bool flag);
315  virtual bool enableHdrPassthrough();
316 
318  virtual void screenCapture();
319 
321  virtual void setOcclusionTextureEnabled(bool enabled);
322 
324  virtual void initOcclusionTexture();
325 
326 
327  protected:
328  //create observer to camera matricies both with and without
329  // channel offset applied.
330  // offsetObserverToCamera has channel offset applied and
331  // observerToCamera does not
332  virtual void makeObserverToCameraMatrix( osg::Vec3d& orient,
333  osg::Matrixd& offsetObserverToCamera, osg::Matrixd& observerToCamera );
334  virtual void makeObserverToCameraMatrix( osg::Quat& qObserverToWorld,
335  osg::Matrixd& offsetObserverToCamera, osg::Matrixd& observerToCamera );
336 
337 
339  virtual void calculateNearFar(double& zNear, double& zFar);
340 
344  virtual bool useAttachedForNearClip( double alt );
345 
347  virtual double calculateNearClip( double alt, double zFar );
348 
350  virtual double calculateFarClip( double alt );
351 
353  virtual void projectFor3D();
354 
356  virtual void projectFor2D();
357 
361  virtual void stopUsingModelSet( int modelSet );
362 
366  virtual void startUsingModelSet( int modelSet );
367 
369  virtual void stopUsingSensor( DtSensor* sensor );
370 
372  virtual void startUsingSensor( DtSensor* sensor );
373 
375  virtual void slot_sensorRemoved( DtSensor* sensor );
376 
378  virtual void slot_visualizerRootAdded( int modelSet, int visualType );
379 
381  virtual void slot_observerModelSetChanged( DtObserverObject* observer,
382  int modelSet );
383 
385  virtual void slot_observerSettingChanged( DtObserverObject* observer,
386  int setting, bool value );
387 
389  virtual void slot_observerSettingRemoved( DtObserverObject* observer,
390  int setting );
391 
393  virtual void slot_windowConfigurationModified( const std::string& deName,
394  const std::string& oldWindowName, const DtWindowConfiguration& config);
395 
397  virtual void slot_onCoordinateSystemChanged();
398 
399  protected:
401  void stopUsingModelSetWork( int modelSet );
402 
404  void startUsingModelSetWork( int modelSet );
405 
407  void initializeRenderTextureColor();
408 
410  void initializeRenderTextureDepth();
411 
412  void enableLighting(osg::ref_ptr<osg::Camera> camera, bool enable);
413 
414 
415 
416  protected:
417  typedef std::map< int, DtChannelSpecificGroup*> VisualTypeMap;
418 
419  osg::ref_ptr<osgViewer::View> myView;
422 
424 
426 
428 
430 
432 
433  osg::ref_ptr<osg::Group> myRoot;
434 
435  //The master 3D camera
436  osg::ref_ptr<DtCameraNode> mySceneCamera;
437 
438  //The 2D camera in screen space(0,0 - w,h)
439  osg::ref_ptr<DtCameraNode> my2DCamera;
440 
441  //The 2D camera in normalize screen space (0,0 - 1,1)
442  osg::ref_ptr<DtCameraNode> myNormalized2DCamera;
443 
445  osg::ref_ptr<osg::Texture2D> myRenderTexture;
446  osg::ref_ptr<osg::Texture2D> myDepthTexture;
447  osg::ref_ptr<osg::Texture2D> myOcclusionTexture;
448 
450  osg::ref_ptr<DtCameraNode> myRTTCamera;
451 
456 
457  // ex. { "dof", "rainsplash", "oceanspray" }
458  // list of post processor effect names to enable on update
460 
461  osg::Node::NodeMask myOldSceneCameraNodeMask;
462 
464 
466 
467  //flag to use old (pre 2.1) channel offset calculation
468  // set by creating a signal_channelCreated callback and
469  // setting it in there
471 
472  osg::ref_ptr<osg::DatabaseRequestHandlerCallback> myDatabasePagerCallback;
473 
476 
478  };
479 
483  {
484  public:
486  virtual DtChannel* create(DtDe& de, DtWindow* window, DtChannelConfiguration& config);
487  };
488 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)