00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef SO_GUI_VIEWER
00025 #define SO_GUI_VIEWER
00026
00028
00029
00030
00031
00032
00033
00035
00036 #include <Inventor/Gui/SoGuiRenderArea.h>
00037 #include <Inventor/SbElapsedTime.h>
00038 #include <Inventor/fields/SoSFEnum.h>
00039 #include <Inventor/fields/SoSFBitMask.h>
00040 #include <Inventor/components/stereo/SoStereoViewer.h>
00041
00042 class SoCallbackList;
00043
00044
00045 class SoNode;
00046 class SoDirectionalLight;
00047 class SoGroup;
00048 class SoRotation;
00049 class SoCamera;
00050 class SoDrawStyle;
00051 class SoLightModel;
00052 class SoFieldSensor;
00053 class SoGuiViewer;
00054 class SoGetBoundingBoxAction;
00055 class SoSeparator;
00056 class SoShadowGroup;
00057 class SoSwitch;
00058 class SoComplexity;
00059 class SoColorMask;
00060 class SoMaterialBinding;
00061 class SoSFTime;
00062 class SoNodeSensor;
00063 class SoGetPrimitiveCountAction;
00064 class SoBaseStereo;
00065 class SoDepthBuffer;
00066 class SoPerfCounter;
00067
00068 #ifndef HIDDEN_FROM_DOC
00069
00070 typedef void SoGuiViewerCB( void* userData, void* viewer );
00071 typedef void SoGuiViewerCameraTypeChangeCB( void* userData, SoCamera* camera, void* viewer );
00072
00073
00074
00075 typedef void SoGuiViewerFPSCB( float fps, void* userData, void* viewer );
00076 typedef void SoGuiViewerDecimationPercentageCB( float percentage, void* userData, void* viewer );
00077 #endif
00078
00079
00080 class SoGuiViewer : public SoGuiRenderArea, virtual public SoStereoViewer
00081 {
00082 #ifndef HIDDEN_FROM_DOC
00083 SO_FIELDCONTAINER_HEADER( SoGuiViewer );
00084 #endif
00085
00086 private:
00087 SoSFBool stereoActive;
00088 SoSFEnum stereoType;
00089 SoSFBitMask stereoColorMask;
00090 SoSFBool hiddenLine;
00091
00092 enum StereoViewType
00093 {
00094
00095 NO_STEREO_VIEW = 0,
00096
00097 INTERLACED_STEREO = 1,
00098
00099 HALF_SCREEN_STEREO = 2,
00100
00101 RAW_STEREO = 3,
00102
00103 OPENGL_STEREO = 3,
00104
00105 ANAGLYPH_STEREO = 4,
00106
00107 ANAGLYPH = 4,
00108 #ifndef HIDDEN_FROM_DOC
00109
00110 SSDI_STEREO = 5,
00111 #endif
00112
00113 PASSIVE_STEREO = 6
00114 };
00115
00116
00117 enum Color
00118 {
00119 RED = 0x01,
00120 GREEN = 0x02,
00121 BLUE = 0x04
00122 };
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 enum Type
00133 {
00137 BROWSER,
00141 EDITOR
00142 };
00143
00144
00145
00146
00147
00148
00149
00150 enum DrawStyle
00151 {
00155 VIEW_AS_IS,
00159 VIEW_HIDDEN_LINE,
00163 VIEW_NO_TEXTURE,
00167 VIEW_LOW_COMPLEXITY,
00171 VIEW_LINE,
00175 VIEW_POINT,
00179 VIEW_BBOX,
00183 VIEW_LOW_RES_LINE,
00187 VIEW_LOW_RES_POINT,
00191 VIEW_SAME_AS_STILL
00192 };
00193
00194 enum DrawType
00195 {
00199 STILL,
00203 INTERACTIVE
00204 };
00205
00206
00207
00208
00209 enum BufferType
00210 {
00214 BUFFER_SINGLE,
00218 BUFFER_DOUBLE,
00222 BUFFER_INTERACTIVE
00223 };
00224
00225
00226
00227
00228 enum DecimationStrategy
00229 {
00233 NORMAL,
00237 FIXED_NUM_TRIANGLES,
00241 FRAMES_PER_SECOND,
00245 FIXED_PERCENTAGE
00246 };
00247
00248
00249
00250 enum CursorStyle
00251 {
00255 CLASSIC,
00259 XOR,
00263 SHADOW
00264 };
00265
00266
00267 enum Direction
00268 {
00269 AKP_UP,
00270 AKP_DOWN,
00271 AKP_RIGHT,
00272 AKP_LEFT
00273 };
00274
00278 SoGuiViewer();
00279
00288 virtual void setSceneGraph( SoNode* newScene );
00289
00293 virtual SoNode* getSceneGraph();
00294
00300 virtual void setCamera( SoCamera* newCamera );
00301
00305 SoCamera* getCamera();
00306
00312 SoNONUNICODE SbBool saveSceneGraph( const char* fileName );
00313
00314
00319 SbBool saveSceneGraph( const SbString& fileName );
00320
00329 virtual void setCameraType( SoType type );
00330
00335 SoType getCameraType();
00336
00342 virtual void setPreserveCameraHeightAngle( SbBool flag );
00343
00349 virtual SbBool isCameraHeightAnglePreserved() const;
00350
00355 virtual void enableSeekWithOrtho( SbBool flag );
00356
00361 virtual SbBool isSeekWithOrthoEnabled() const;
00362
00367 virtual void viewAll();
00368
00372 virtual void saveHomePosition();
00373
00377 virtual void resetToHomePosition();
00378
00385 virtual void setHeadlight( SbBool insertFlag );
00386
00390 SbBool isHeadlight();
00391
00395 SoDirectionalLight* getHeadlight();
00396
00445 virtual void setDrawStyle( DrawType type, DrawStyle style );
00446
00450 SoGuiViewer::DrawStyle getDrawStyle( SoGuiViewer::DrawType type );
00451
00456 virtual void setBufferingType( BufferType type );
00457
00461 SoGuiViewer::BufferType getBufferingType();
00462
00475 virtual void setViewing( SbBool flag );
00476
00480 SbBool isViewing() const;
00481
00492 virtual void setCursorEnabled( SbBool flag );
00493
00498 SbBool isCursorEnabled() const;
00499
00510 void setAutoClipping( SbBool flag );
00511
00516 virtual SbBool isStereoViewing();
00517
00521 SbBool isAutoClipping() const;
00522
00526 void setStereoOffset( float dist );
00527
00531 float getStereoOffset();
00532
00540 void setDetailSeek( SbBool onOrOff );
00541
00545 SbBool isDetailSeek();
00546
00559 void setSeekTime( float seconds );
00560
00564 float getSeekTime();
00565
00572 virtual void recomputeSceneSize();
00573
00574
00575
00581 void setDecimationStrategy( DecimationStrategy strategy );
00585 DecimationStrategy getDecimationStrategy() const;
00586
00594 void setGoalNumberOfTriangles( int32_t goal );
00595
00599 int32_t getGoalNumberOfTriangles();
00600
00608 void setGoalFramesPerSecond( float goal );
00609
00613 float getGoalFramesPerSecond();
00614
00622 void setFixedPercentage( float percent );
00623
00627 float getFixedPercentage();
00628
00637 void enableFullRenderingWhenStill( SbBool onOff );
00638
00643 SbBool isFullRenderingWhenStill();
00644
00645 void setStill( SbBool isStill );
00649 SbBool isStillNow();
00650
00656 void setNumSamples( int numFrames );
00657
00662 int getNumSamples();
00663
00667 float getCurrentDecimationPercentage();
00668
00669
00670 virtual void setStereoActive(SbBool activate);
00671 virtual SbBool isStereoActive();
00672 virtual void actualRendering();
00673 virtual SoCamera* getViewerCamera();
00674 virtual const SbVec2s& getSize();
00675 virtual const SbVec2s& getTopLeft();
00676 virtual const SbVec2s& getBottomRight();
00677 virtual SbBool isViewerDoubleBuffer();
00678 virtual void setStereoViewType( SoBaseStereo* stereo );
00679 virtual SoBaseStereo* getStereoViewType();
00680 virtual void reverseStereoView( SbBool reverse );
00681 virtual SbBool isStereoViewReversed();
00682 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00683 virtual SbBool isStereoAbsoluteAdjustments() const;
00684 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00685 virtual float getStereoBalance();
00686 virtual SbBool isStereoBalanceNearFrac();
00687 virtual void setViewport( short left, short bottom, short width, short height );
00688 virtual void getViewport(short& left, short& bottom, short& width, short& height);
00689 virtual SoGLContext* getViewerContext() { return NULL; }
00690 virtual SoSceneManager* getViewerSceneManager() { return this->getSceneManager(); }
00691
00692 SoSeparator* getSceneRoot();
00693 bool getFirstRedrawFlag() const
00694 { return m_isFirstRedraw; }
00695 void setFirstRedrawFlag(bool value)
00696 { m_isFirstRedraw = value; }
00697
00698
00713 virtual void setCursorStyle( CursorStyle style );
00714
00718 CursorStyle getCursorStyle() const;
00719
00729 void setAutoClipTolerance ( float tolerance );
00730
00734 float getAutoClipTolerance () const;
00735
00757 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00758
00762 SoNode* getCameraSceneGraph();
00763
00768 void enableShadows( bool onOrOff );
00769
00773 SbBool isEnableShadows();
00774
00778 SoShadowGroup* getShadowGroup();
00779
00785 void enableMouseWheelDolly( SbBool onOff );
00786 SbBool isMouseWheelEnabled() const;
00787
00788 SbBool isInteractive() const;
00789
00790
00791
00792 virtual void toggleCameraType();
00793
00802 virtual void setSeekMode( SbBool flag );
00803 SbBool isSeekMode() const;
00804
00805
00806 void setInteractiveFlag( SbBool flag );
00807 SbBool getInteractiveFlag() const;
00808
00809
00810 void setStillDrawStyle( DrawStyle style );
00811 DrawStyle getStillDrawStyle() const;
00812
00813
00814 void setInteractiveDrawStyle( DrawStyle style );
00815 DrawStyle getInteractiveDrawStyle() const;
00816
00817
00818 void setSeekStartTime( SbTime seekTime );
00819 SbTime getSeekStartTime() const;
00820
00821
00822 void setNewCamOrientation( SbRotation newOrientation );
00823 SbRotation getNewCamOrientation() const;
00824
00825
00826 void setSeekPoint( SbVec3f newOrientation );
00827 SbVec3f getSeekPoint() const;
00828
00829
00830 void setViewerSpeed( float speed );
00831 float getViewerSpeed() const;
00832
00833
00834 void setHeadLightFlag( SbBool flag );
00835
00836
00837 void setCreatedCursors( SbBool flag );
00838 SbBool getCreatedCursors() const;
00839
00840
00841 void setInteractiveCount( int count );
00842
00843
00844 SoCallbackList* getFinishCBList();
00845
00846
00847 void setCheckForDrawStyle( SbBool flag );
00848 SbBool getCheckForDrawStyle() const;
00849
00850
00851 void setType( Type type );
00852 Type getType() const;
00853
00854
00855 void setRealTime( SoSFTime* type );
00856 SoSFTime* getRealTime() const;
00857
00858
00859 void setSeekDistance( float seekDistance );
00860 float getSeekDistance();
00861
00862
00863 void setSceneSize( float size );
00864 float getSceneSize();
00865
00866
00867 SbBool getComputeSeekVariables() const { return m_computeSeekVariables; }
00868 float getPreviousHeightAngle() { return m_previousHeightAngle; }
00869 SbVec3f getSeekNormal() { return m_seekNormal; }
00870 SbVec3f getNewCamPosition() { return m_newCamPosition; }
00871
00872
00873 void setSeekSensor( SoFieldSensor* s );
00874 SoFieldSensor* getSeekSensor() const;
00875
00876
00877 SbBool getCreatedCamera() const;
00878
00879 void setViewer( void* viewer );
00880
00881
00882 virtual SbBool setDoubleBuffer( SbBool flag );
00883
00884
00885
00886
00887 SoNONUNICODE static void writeScene( SoNode* node, const char* filename );
00888
00889
00890 static void writeScene( SoNode* node, const SbString& filename );
00891
00892
00893 void setCameraTypeChangeCallback( SoGuiViewerCameraTypeChangeCB* callback, void* userdata );
00894 void addStartCallback( SoGuiViewerCB* f, void* userData = NULL );
00895 void addFinishCallback( SoGuiViewerCB* f, void* userData = NULL );
00896 void removeStartCallback( SoGuiViewerCB* f, void* userData = NULL );
00897 void removeFinishCallback( SoGuiViewerCB* f, void* userData = NULL );
00898
00903 void setFramesPerSecondCallback( SoGuiViewerFPSCB* callback, void* userData = NULL );
00904
00909 void setDecimationPercentageCallback( SoGuiViewerDecimationPercentageCB* callback, void* userData = NULL );
00910
00911 SbBool isZBufferOff();
00912
00913 void arrowKeyPressed( Direction direction );
00914
00915 SbBool getDepthValue(int x, int y, float &depth);
00916
00917 class CameraFields {
00918 public:
00919 CameraFields();
00920 SbBool isModified( SoCamera* cam );
00921 void setCameraFields( SoCamera* cam );
00922 static bool stereoDataMatchViewerState( SoCamera* cam, SoGuiViewer* viewer );
00923 static void setViewerStereoData( SoCamera* cam, SoGuiViewer* viewer );
00924 static void setCameraStereoData( SoCamera* cam, SoGuiViewer* viewer );
00925
00926 private:
00927 int m_viewportMapping;
00928 SbVec3f m_position;
00929 SbRotation m_orientation;
00930 float m_aspectRatio;
00931 float m_nearDistance;
00932 float m_farDistance;
00933 float m_focalDistance;
00934 float m_height;
00935
00936 bool m_stereoAbsoluteAdjustments;
00937 float m_stereoAdjustment;
00938 float m_balanceAdjustment;
00939 int m_stereoMode;
00940 bool m_balanceNearFrac;
00941 };
00942
00943
00944
00945 virtual void afterRealizeHook();
00946
00947 virtual void adjustCameraClippingPlanes();
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959 void interactiveCountInc();
00960 void interactiveCountDec();
00961 int getInteractiveCount();
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 SbBool seekToPoint( const SbVec2s& mouseLocation, SbBool allowChangeOrientation=TRUE, SbBool allowChangeDistance=TRUE );
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 SbBool seekToPoint( const SbVec3f& worldPoint, const SbVec3f& worldNormal, SbBool allowChangeOrientation=TRUE, SbBool allowChangeDistance=TRUE );
00989
00990
00991
00992
00993
00994
00995 virtual void interpolateSeekAnimation( float t );
00996 virtual void computeSeekFinalOrientation();
00997
00998
00999
01000
01001 virtual void actualRedraw();
01002
01003
01004
01005
01006 virtual void changeCameraValues( SoCamera* newCamera );
01007
01008
01009
01010 virtual void preViewerRedraw();
01011 virtual void postViewerRedraw();
01012
01013
01014
01015
01016
01017
01018
01019 virtual float decimationForFramesPerSecond( float fps,
01020 double lasttime,
01021 float lastDec );
01022
01023
01024
01025
01026
01027 virtual float decimationForNumTriangles( uint32_t numTris );
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040 static void setFeedbackOrthoProjection( const SbVec2s& size );
01041
01042
01043 static void restoreGLStateAfterFeedback();
01044
01045 static void drawViewerCrossFeedback( SbVec2s loc );
01046
01047 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01048
01049 void setCurrentDrawStyle( SoGuiViewer::DrawStyle style );
01050
01051 void doBoxZoom( int x1, int y1, int x2, int y2 );
01052 void setZoomMode( SbBool zoomMode );
01053 SbBool isZoomModeEnabled() const;
01054 void setSeekDistAsPercentage( SbBool seekDist );
01055
01056 #if 1 SoDEPRECATED
01058 virtual void adjustClippingPlanes();SoDEPRECATED
01060 virtual HDC getCurrentDC();
01061 #endif
01063 private:
01064
01068 virtual ~SoGuiViewer();
01069
01070 SoShadowGroup* getShadowGroup() const { return m_shadowGroup; };
01071
01072 SoGetBoundingBoxAction* m_sceneSizeBBoxAction;
01073 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01074
01075 void* getViewer() { return (void*)this; }
01076
01077
01078
01079 private:
01080
01081 void doRendering();
01082 static void drawStyleStartCallback( void* userData, void* v );
01083 static void drawStyleFinishCallback( void* userData, void* v );
01084 static void changeCB( void* thisp, SoSensor* sensor );
01085 void changeSensorCalled();
01086
01087 void setStereoOffsetP( float dist );
01088 void setStereoBalanceP( float balance, SbBool nearFrac );
01089 void setStereoAbsoluteAdjustmentsP( SbBool absolute );
01090
01091
01092 SoSeparator* m_sceneRoot;
01093 SoNode* m_sceneGraph;
01094 void* m_viewerPtr;
01095
01096
01097 SoNode* m_cameraSceneGraph;
01098 SoType m_cameraType;
01099 SoCamera* m_camera;
01100 SoGuiViewer::Type m_type;
01101 SbBool m_viewingFlag;
01102 SbBool m_interactiveFlag;
01103 BufferType m_bufferType;
01104 SbBool m_cursorEnabledFlag;
01105 float m_sceneSize;
01106 static SoSFTime* m_viewerRealTime;
01107 SbBool m_firstLeftRender;
01108 float m_viewerSpeed;
01109
01110
01111 SbBool m_createdCamera;
01112 SbVec3f m_origPosition;
01113 SbRotation m_origOrientation;
01114 float m_origNearDistance;
01115 float m_origFarDistance;
01116 float m_origFocalDistance;
01117 float m_origHeight;
01118
01119
01120 SbBool m_headlightFlag;
01121 SoGroup* m_headlightGroup;
01122 SoDirectionalLight* m_headlightNode;
01123 SoRotation* m_headlightRot;
01124
01125
01126 SbBool m_preserveHeightAngle;
01127 SbBool m_seekWithOrtho;
01128 SbBool m_mouseWheelEnable;
01129 float m_previousHeightAngle;
01130 CameraFields* m_prevCam;
01131 SoBaseStereo* m_stereoViewType;
01132 double m_farDistS;
01133 double m_nearDistS;
01134
01135
01136 SbBool m_checkForDrawStyle;
01137 DrawStyle m_stillDrawStyle, m_interactiveDrawStyle;
01138 SoSwitch* m_drawStyleSwitch;
01139 SoDrawStyle* m_drawStyleNode;
01140 SoLightModel* m_lightModelNode;
01141 SoComplexity* m_complexityNode;
01142 SoColorMask* m_colorMaskNode;
01143 SoMaterialBinding *m_matBindingNode;
01144 SoDepthBuffer *m_depthBuffer ;
01145
01146
01147 SoShadowGroup* m_shadowGroup;
01148 bool m_shadowGroupCurrState;
01149
01150
01151 SbBool m_autoClipFlag;
01152 float m_minimumNearPlane;
01153 SoGetBoundingBoxAction* m_autoClipBboxAction;
01154 bool m_autoClipPlaneViewVolumeCulling;
01155
01156
01157 SbBool m_detailSeekFlag;
01158 float m_seekAnimTime;
01159 SbBool m_seekModeFlag;
01160 SbBool m_seekAllowChangeOrientation;
01161 SbBool m_seekAllowChangeDistance;
01162 SoFieldSensor* m_seekAnimationSensor;
01163
01164
01165 DecimationStrategy m_decStrategy;
01166 SbBool m_isStill, m_doFullRendering, m_wasStill;
01167 int32_t m_goalTris;
01168 float m_goalFps;
01169 float m_decPercentage;
01170 float m_lastDecimationValue;
01171 double m_lastRenderTime;
01172
01173 SoPerfCounter* m_fpsCounter;
01174
01175 int m_lastDirection;
01176 SoGetPrimitiveCountAction* m_primCountAction;
01177 SoNodeSensor* m_motionSensor;
01178
01179
01180 int m_numSamples;
01181 SoGuiViewerFPSCB* m_fpsUserCallback;
01182 void* m_fpsUserData;
01183
01184
01185
01186
01187
01188
01189
01190 SoGuiViewer::CursorStyle m_cursorStyle;
01191
01192
01193
01194
01195
01196 SbBool m_createdCursors;
01197
01198
01199 SoCallbackList* m_startCBList;
01200 SoCallbackList* m_finishCBList;
01201
01202
01203 SbVec3f m_seekPoint, m_seekNormal;
01204 SbBool m_computeSeekVariables;
01205 SbTime m_seekStartTime;
01206 SbRotation m_oldCamOrientation, m_newCamOrientation;
01207 SbVec3f m_oldCamPosition, m_newCamPosition;
01208 float m_seekDistance;
01209 SbBool m_seekDistAsPercentage;
01210
01211
01212
01213 SbBool m_isWinRedrawing;
01214
01215
01216 SoGuiViewerCameraTypeChangeCB* m_viewerCameraTypeChangeCallback;
01217 void* m_viewerCameraTypeChangeCallbackUserData;
01218
01219
01220 SoGuiViewerDecimationPercentageCB* m_decimationUserCallback;
01221 void* m_decimationUserData;
01222
01223 SbBool m_zoomMode;
01224 static bool s_enableIgnoreScreenSpaceBBox;
01225
01226 bool m_isFirstRedraw;
01227 };
01228
01229 #endif // SO_GUI_VIEWER
01230
01231
01232