VR-Forces 4.6 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 }
22 
23 namespace makVrv
24 {
25  class DtLight;
26  class DtChannelSpecificGroup;
27  class DtOsgWindow;
28  class DtOsgChannelCreator;
29  class DtChannelManager;
30  class DtWindowConfiguration;
31  class DtSensorModule;
32  class DtSensor;
33  class DtOsgObserverObject;
34  class DtOsgCullVisitorParameters;
35 
37  class DtDatabasePagerCallback : public osg::DatabaseRequestHandlerCallback
38  {
39 
40  public:
42 
43  /* child under parent was loaded and added to the scenegraph */
44  virtual void childPagedIn(const osg::NodeVisitor::DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const;
45 
46  /* child under parent was un-loaded and removed from the scenegraph */
47  virtual void childAboutToPageOut(const osg::NodeVisitor::DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const;
48 
49  virtual osg::DatabaseRequestHandlerCallback* clone() const;
50 
52 
53  private:
54 
56  };
57 
65  {
66  protected:
67  friend class DtOsgChannelCreator;
68 
72  DtOsgChannel(DtDe& de, DtOsgWindow* window, DtChannelConfiguration& config);
73 
75 
76 
81  virtual bool initialize();
82 
84 
85  virtual void initializeNormalized2DCamera();
86  virtual void initialize2DCamera( int w, int h );
87  virtual void initializeSceneCamera( );
88  virtual void initializeRenderTexture( );
89  virtual void initializeRTTCamera( );
90 
91  void clearRttCamera();
92 
93  virtual void recreateRTTCamera( );
94 
96 
98  void setShadowState(bool enable);
99 
101  virtual void addOverlayDrawablesToCameras();
102 
108  virtual void initializeSignalConnections();
110 
111 
112  public:
114  virtual ~DtOsgChannel();
115 
120  void setSensorName( const std::string& sensorName );
121 
123  virtual void setClearColor(float r,float g,float b, float a);
124 
128  virtual void setWindow(DtWindow* view);
129 
131  virtual const DtWindow* window() const;
132 
134  virtual void setViewport(int x,int y,int width, int height);
135 
139  virtual void clearFrameBufferIfChanged();
140 
142  virtual void getViewport(int& x,int& y, int& width,int& height) const;
143 
145  virtual void setCameraPosition(double x, double y, double z);
146 
148  virtual void setCameraOrientation( double psi, double theta, double phi );
149 
154  virtual void setCameraPositionAndOrientation( double x, double y,
155  double z, double psi, double theta, double phi );
156  virtual void setCameraPositionAndOrientation( osg::Vec3d& pos,
157  osg::Quat& orient );
158 
160  virtual void getCameraPositionAndOrientation( osg::Vec3d& position,
161  osg::Quat& rotation ) const;
162 
163  virtual void update();
164 
166  virtual void connectToObserver();
167 
170  virtual void setProjectionMatrixAsPerspective(double fovy,
171  double aspectRatio, double zNear, double zFar);
172 
174  virtual void setProjectionMatrixAsFrustum (double left, double right,
175  double bottom, double top, double zNear, double zFar);
176 
178  virtual void setProjectionMatrix(const osg::Matrix& matrix);
179 
181  virtual osgViewer::View& view();
182 
184  virtual DtCameraNode* sceneCamera();
185  virtual const DtCameraNode* sceneCamera() const;
186 
188  virtual DtCameraNode* rttCamera() const;
189 
191  virtual DtCameraNode* overlayCamera();
192 
193 
195  virtual DtCameraNode* normalizedOverlayCamera();
196 
198  virtual void setRenderToTexture(bool enabled);
199 
203  virtual void setRenderToTextureFormat(int format, int sourceFormat, int sourceType);
204 
205 
208  virtual osg::ref_ptr<osg::Texture2D> getRenderTexture();
209  virtual osg::ref_ptr<osg::Texture2D> getOcculsionTexture();
210 
212  virtual osg::ref_ptr<osg::Texture2D> getDepthTexture() const;
213 
215  int shadowQuality() const;
216 
220  virtual std::vector<const osg::Camera*> getShadowableCameras() const;
221 
224  virtual void setProjectionResizePolicy(
226 
229  virtual void updateProjection();
230 
231  void projectionUnitsToFrustum( DtChannelConfiguration::ProjectionUnits units,
232  double &left, double zNear, double &right, double &top, double &bottom );
233 
235  virtual void connectChannelToScene();
236 
238  virtual bool processMouseEvent( const DtMouseEvent& ev);
239 
241  virtual bool processKeyboardEvent(const DtKeyEvent & ev);
242 
244  //virtual DtDynamicOverlay* overlay();
245 
247  void getWorldToWindowMatrix( osg::Matrix& worldToWindowMatrix ) const;
248 
250  virtual void moveMouseToScreenLocation(float screenX, float screenY);
251 
255  virtual void projectToScreen( double dbX, double dbY, double dbZ,
256  double& screenX, double& screenY, double& screenZ );
257 
259  virtual void projectToWorld( double screenX, double screenY,
260  double& dbX, double& dbY, double& dbZ );
261 
263  virtual const std::string& name();
264 
269  boost::signal<void (int, int, int, int)> signal_viewportChanged;
270 
271  typedef std::list<std::string> PostProcessorEffectList;
272 
276  virtual void addPostProcessEffect(const std::string& postProcessorEffect);
277 
281  virtual void removePostProcessEffect(const std::string& postProcessorEffect);
282 
284  virtual void set3DCullVisitorParams( DtOsgCullVisitorParameters* params );
285  virtual void set2DCullVisitorParams( DtOsgCullVisitorParameters* params );
287 
288  virtual void setEnablePostProcessors(bool enable);
289 
290  virtual bool getEnablePostProcessors();
291 
292  //getter/setter for flag to use old (pre 2.1) channel offset calculation
293  virtual bool useOldChannelOffsetCalcuation() const;
294  virtual void setUseOldChannelOffsetCalcuation( bool enable );
295 
298  virtual bool forceHdrLuminanceOverride();
299  virtual void setForceHdrLuminanceOverride(bool force);
300 
302  // structure to expedite culling. We need to clear any memory
303  // that this structure caches to decrement reference count of
304  // StateSets (and hence drawables, textures, etc) when scene
305  // changes completely (e.g. on post processor turned off/on)
306  // so that memory can be reclaimed
307  // This helper function accomplishes that
308  virtual void clearStateGraph(void);
309 
311  // should just pass through without applying any effects
312  // used by SensorFX to turn off HDR on a per channel basis.
313  virtual void setEnableHdrPassthrough(bool flag);
314  virtual bool enableHdrPassthrough();
315 
317  virtual void screenCapture();
318 
320  virtual void setOcclusionTextureEnabled(bool enabled);
321 
323  virtual void initOcclusionTexture();
324 
325 
326  protected:
327  //create observer to camera matricies both with and without
328  // channel offset applied.
329  // offsetObserverToCamera has channel offset applied and
330  // observerToCamera does not
331  virtual void makeObserverToCameraMatrix( osg::Vec3d& orient,
332  osg::Matrixd& offsetObserverToCamera, osg::Matrixd& observerToCamera );
333  virtual void makeObserverToCameraMatrix( osg::Quat& qObserverToWorld,
334  osg::Matrixd& offsetObserverToCamera, osg::Matrixd& observerToCamera );
335 
336 
338  virtual void calculateNearFar(double& zNear, double& zFar);
339 
343  virtual bool useAttachedForNearClip( double alt );
344 
346  virtual double calculateNearClip( double alt, double zFar );
347 
349  virtual double calculateFarClip( double alt );
350 
352  virtual void projectFor3D();
353 
355  virtual void projectFor2D();
356 
360  virtual void stopUsingModelSet( int modelSet );
361 
365  virtual void startUsingModelSet( int modelSet );
366 
368  virtual void stopUsingSensor( DtSensor* sensor );
369 
371  virtual void startUsingSensor( DtSensor* sensor );
372 
374  virtual void slot_sensorRemoved( DtSensor* sensor );
375 
377  virtual void slot_visualizerRootAdded( int modelSet, int visualType );
378 
380  virtual void slot_observerModelSetChanged( DtObserverObject* observer,
381  int modelSet );
382 
384  virtual void slot_observerSettingChanged( DtObserverObject* observer,
385  int setting, bool value );
386 
388  virtual void slot_observerSettingRemoved( DtObserverObject* observer,
389  int setting );
390 
392  virtual void slot_windowConfigurationModified( const std::string& deName,
393  const std::string& oldWindowName, const DtWindowConfiguration& config);
394 
396  virtual void slot_onCoordinateSystemChanged();
397 
398  protected:
400  void stopUsingModelSetWork( int modelSet );
401 
403  void startUsingModelSetWork( int modelSet );
404 
406  void initializeRenderTextureColor();
407 
409  void initializeRenderTextureDepth();
410 
411  void enableLighting(osg::ref_ptr<osg::Camera> camera, bool enable);
412 
413 
414 
415  protected:
416  typedef std::map< int, DtChannelSpecificGroup*> VisualTypeMap;
417 
418  osg::ref_ptr<osgViewer::View> myView;
421 
423 
425 
427 
429 
431 
432  osg::ref_ptr<osg::Group> myRoot;
433 
434  //The master 3D camera
435  osg::ref_ptr<DtCameraNode> mySceneCamera;
436 
437  //The 2D camera in screen space(0,0 - w,h)
438  osg::ref_ptr<DtCameraNode> my2DCamera;
439 
440  //The 2D camera in normalize screen space (0,0 - 1,1)
441  osg::ref_ptr<DtCameraNode> myNormalized2DCamera;
442 
444  osg::ref_ptr<osg::Texture2D> myRenderTexture;
445  osg::ref_ptr<osg::Texture2D> myDepthTexture;
446  osg::ref_ptr<osg::Texture2D> myOcclusionTexture;
447 
449  osg::ref_ptr<DtCameraNode> myRTTCamera;
450 
455 
456  // ex. { "dof", "rainsplash", "oceanspray" }
457  // list of post processor effect names to enable on update
459 
460  osg::Node::NodeMask myOldSceneCameraNodeMask;
461 
463 
465 
466  //flag to use old (pre 2.1) channel offset calculation
467  // set by creating a signal_channelCreated callback and
468  // setting it in there
470 
471  osg::ref_ptr<osg::DatabaseRequestHandlerCallback> myDatabasePagerCallback;
472 
475 
477  };
478 
482  {
483  public:
485  virtual DtChannel* create(DtDe& de, DtWindow* window, DtChannelConfiguration& config);
486  };
487 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)