00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifdef SOQT
00052 # include <Inventor/Qt/viewers/SoQtViewer.h>
00053 #elif defined _WIN32
00054 # include <Inventor/Win/viewers/SoWinViewer.h>
00055 #else
00056
00057 #ifndef _SO_XT_VIEWER_
00058 #define _SO_XT_VIEWER_
00059
00060 #include <Inventor/SoType.h>
00061 #include <Inventor/Xt/SoXtRenderArea.h>
00062 #include <Inventor/misc/SoCallbackList.h>
00063 #include <Inventor/SbElapsedTime.h>
00064 #include <Inventor/events/SoKeyboardEvent.h>
00065 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00066 #include <Inventor/components/stereo/SoStereoViewer.h>
00067
00068
00069 class SoNode;
00070 class SoDirectionalLight;
00071 class SoGroup;
00072 class SoRotation;
00073 class SoCamera;
00074 class SoDrawStyle;
00075 class SoLightModel;
00076 class SoFieldSensor;
00077 class SoXtClipboard;
00078 class SoXtViewer;
00079 class SoGetBoundingBoxAction;
00080 class SbPList;
00081 class SoSeparator;
00082 class SoSwitch;
00083 class SoComplexity;
00084 class SoPackedColor;
00085 class SoMaterialBinding;
00086 class SoSFTime;
00087 class SoXtInputFocus;
00088 class SoAlarmSensor;
00089 class SoNodeSensor;
00090 class SoGetPrimitiveCountAction;
00091 class SoStereoViewer;
00092 class SoBaseStereo;
00093 class ScRayPickAction;
00094
00095
00096 typedef void SoXtViewerCB( void* userData, SoXtViewer* viewer );
00097 typedef void SoXtViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoXtViewer* viewer );
00098
00099
00100
00101 typedef void SoXtViewerFPSCB( float fps, void* userData, SoXtViewer* viewer );
00102 typedef void SoXtViewerDecimationPercentageCB( float percentage, void* userData, SoXtViewer* viewer );
00103
00105
00106
00107
00108
00109
00110
00111
00113
00184 class SoXtViewer : public SoXtRenderArea, public SoStereoViewer
00185 {
00186 public:
00197 enum Type
00198 {
00202 BROWSER,
00206 EDITOR
00207 };
00208
00215 enum DrawStyle
00216 {
00220 VIEW_AS_IS,
00224 VIEW_HIDDEN_LINE,
00228 VIEW_NO_TEXTURE,
00232 VIEW_LOW_COMPLEXITY,
00236 VIEW_LINE,
00240 VIEW_POINT,
00244 VIEW_BBOX,
00248 VIEW_LOW_RES_LINE,
00252 VIEW_LOW_RES_POINT,
00256 VIEW_SAME_AS_STILL
00257 };
00258
00260 enum DrawType
00261 {
00265 STILL,
00269 INTERACTIVE
00270 };
00271
00273 enum BufferType
00274 {
00278 BUFFER_SINGLE,
00282 BUFFER_DOUBLE,
00286 BUFFER_INTERACTIVE
00287 };
00288
00290 enum DecimationStrategy
00291 {
00295 NORMAL,
00299 FIXED_NUM_TRIANGLES,
00303 FRAMES_PER_SECOND,
00307 FIXED_PERCENTAGE
00308 };
00309
00315 enum CursorStyle
00316 {
00320 CLASSIC,
00324 XOR,
00328 SHADOW
00329 };
00330
00331
00340 virtual void setSceneGraph(SoNode *newScene);
00341
00345 virtual SoNode* getSceneGraph();
00346
00352 virtual void setCamera( SoCamera* cam );
00353
00357 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00358
00367 virtual void setCameraType( SoType type );
00368
00373 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00374
00380 virtual void setPreserveCameraHeightAngle( SbBool flag )
00381 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00382
00388 virtual SbBool isCameraHeightAnglePreserved() const { return m_guiViewer->isCameraHeightAnglePreserved(); }
00389
00394 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00395
00400 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00401
00420 virtual void viewAll();
00421
00425 virtual void saveHomePosition();
00426
00430 virtual void resetToHomePosition();
00431
00436 void setCameraTypeChangeCallback( SoXtViewerCameraTypeChangeCB* callback, void* userdata );
00437
00444 virtual void setHeadlight( SbBool onOrOff );
00445
00449 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00450
00454 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00455
00504 virtual void setDrawStyle( SoXtViewer::DrawType type, SoXtViewer::DrawStyle style );
00505
00509 SoXtViewer::DrawStyle getDrawStyle( SoXtViewer::DrawType type );
00510
00515 virtual void setBufferingType( SoXtViewer::BufferType type) ;
00516
00520 SoXtViewer::BufferType getBufferingType()
00521 { return (SoXtViewer::BufferType)m_guiViewer->getBufferingType(); }
00522
00535 virtual void setViewing( SbBool onOrOff );
00536
00540 SbBool isViewing() const { return m_guiViewer->isViewing(); };
00541
00552 virtual void setCursorEnabled( SbBool onOrOff );
00553
00558 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00559
00570 void setAutoClipping( SbBool onOrOff );
00571
00575 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00576
00584 virtual void setStereoViewing( SbBool onOrOff );
00585
00590 virtual SbBool isStereoViewing();
00591
00595 void setStereoOffset( float dist );
00596
00600 float getStereoOffset();
00601
00609 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); };
00610
00614 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00615
00628 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00629
00633 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00634
00643 void addStartCallback( SoXtViewerCB* f, void* userData = NULL )
00644 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00645
00654 void addFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00655 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00656
00662 void removeStartCallback( SoXtViewerCB* f, void* userData = NULL )
00663 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00664
00670 void removeFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00671 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00672
00678 void copyView( Time eventTime );
00679
00685 void pasteView( Time eventTime );
00686
00693 virtual void recomputeSceneSize();
00694
00695
00696
00702 void setDecimationStrategy( SoXtViewer::DecimationStrategy strategy );
00703
00707 SoXtViewer::DecimationStrategy getDecimationStrategy()
00708 { return (SoXtViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00709
00717 void setGoalNumberOfTriangles( int32_t goal );
00718
00722 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); };
00723
00731 void setGoalFramesPerSecond( float goal );
00732
00736 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); };
00737
00745 void setFixedPercentage( float percent );
00746
00750 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); };
00751
00760 void enableFullRenderingWhenStill( SbBool onOff );
00761
00766 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); };
00767
00771 SbBool isStillNow() { return m_guiViewer->isStillNow(); };
00772
00776 void setFramesPerSecondCallback( SoXtViewerFPSCB* callback, void* userData = NULL );
00777
00782 void setNumSamples( int numFrames );
00787 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00788
00792 void setDecimationPercentageCallback( SoXtViewerDecimationPercentageCB* callback, void* userData = NULL );
00793
00797 float getCurrentDecimationPercentage();
00798
00799
00800
00801 virtual SoCamera* getViewerCamera();
00802 virtual SbBool isViewerDoubleBuffer();
00803 virtual void actualRendering();
00804 virtual const SbVec2s& getSize();
00805 virtual const SbVec2s& getTopLeft() ;
00806 virtual const SbVec2s& getBottomRight() ;
00807 void setStereoViewType( SoBaseStereo* stereo );
00808 SoBaseStereo* getStereoViewType();
00809 void reverseStereoView( SbBool reverse );
00810 SbBool isStereoViewReversed();
00811 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00812 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00813 virtual void setStereoBalance( float balance, SbBool nearFrac );
00814 virtual float getStereoBalance();
00815 virtual SbBool isStereoBalanceNearFrac();
00816 virtual void setStereoActive( SbBool activate );
00817 virtual SbBool isStereoActive();
00818 void setViewport( short left, short bottom, short width, short height );
00819 void getViewport( short &left, short &bottom, short &width, short &height );
00820
00821
00836 virtual void setCursorStyle( SoXtViewer::CursorStyle style );
00837
00841 SoXtViewer::CursorStyle getCursorStyle()
00842 { return (SoXtViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00843
00844
00845 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00846
00856 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); };
00857
00861 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); };
00862
00887 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00888
00892 SoNode* getCameraSceneGraph();
00893
00903 virtual void toggleCameraType();
00904
00912 virtual void setSeekMode( SbBool onOrOff );
00913
00923 void setPickRadius( float radius );
00924
00928 float getPickRadius() const;
00929
00930 #if 1 SoDEPRECATED
00933 virtual void adjustClippingPlanes();
00934
00935 #endif
00942 SbBool getDepthValue(int x, int y, float &depth)
00943 {
00944 return m_guiViewer->getDepthValue(x, y, depth);
00945 }
00946
00947 private:
00948 virtual ~SoXtViewer();
00949
00950
00951
00952 virtual void setNormalVisual( XVisualInfo* v );
00953
00954 #ifndef HIDDEN_FROM_DOC
00955 void saveSceneGraph( const char* fileName ) ;
00956 #endif //HIDDEN_FROM_DOC
00957
00958 SbBool isInteractive() const;
00959
00960 SoGuiViewer* getGuiViewer() const;
00961
00962
00963
00964 SoCamera* camera;
00965 SbBool createdCursors, viewingFlag;
00966 CursorStyle cursorStyle;
00967 SoSeparator* sceneRoot;
00968 float sceneSize;
00969 SoBaseStereo* stereoViewType;
00970 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
00971 float m_previousHeightAngle, viewerSpeed, seekDistance;
00972 SoXtViewer::Type type;
00973 SoNode* sceneGraph;
00974 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
00975 SbRotation oldCamOrientation, newCamOrientation;
00976
00977 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
00978 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
00979
00980 private:
00981
00982
00983 SoXtViewer( SoWidget parent,
00984 const char* name,
00985 SbBool buildInsideParent,
00986 SoXtViewer::Type type,
00987 SbBool buildNow,
00988 SbBool sync = TRUE );
00989
00990 SoXtViewer( SoWidget parent,
00991 const char* name,
00992 SbBool buildInsideParent,
00993 SoXtViewer::Type type,
00994 SbBool buildNow,
00995 SbBool sync,
00996 SoGuiViewer* guiViewer );
00997
00998
00999
01000
01001 virtual void updateCursor() {};
01002
01003
01004 SbBool altSwitchBack;
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015 SbBool processCommonEvents( XAnyEvent* xe );
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028 void interactiveCountInc();
01029 void interactiveCountDec();
01030 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042 SbBool seekToPoint( const SbVec2s& mouseLocation );
01043
01044
01045
01046
01047
01048
01049
01050
01051 virtual void interpolateSeekAnimation( float t );
01052 virtual void computeSeekFinalOrientation();
01053
01054 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
01055
01056
01057
01058
01059 virtual void actualRedraw();
01060
01061
01062
01063
01064 virtual void changeCameraValues( SoCamera* newCamera );
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01079
01080
01081
01082 static void restoreGLStateAfterFeedback();
01083
01084
01085 static void drawViewerCrossFeedback( SbVec2s loc );
01086
01087
01088 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01089
01090
01091 virtual void afterRealizeHook();
01092
01093 virtual void widgetChanged( SoWidget );
01094
01095
01096 SbBool autoClipFlag;
01097 float minimumNearPlane;
01098 SoGetBoundingBoxAction* autoClipBboxAction;
01099 virtual void adjustCameraClippingPlanes();
01100
01101
01102
01103 virtual void redraw();
01104
01105
01106
01107
01108
01109
01110
01111 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01112
01113
01114
01115
01116
01117
01118 virtual float decimationForNumTriangles( uint32_t numTris );
01119
01120
01121 void* getViewer() { return (void*)this; }
01122
01123 private:
01124 void constructorCommon( SoXtViewer::Type t, SbBool buildNow );
01125
01126 void constructorCommon2( SoXtViewer::Type t, SbBool buildNow );
01127
01128 SoGuiViewer* m_guiViewer;
01129
01130 SbBool m_firstRealize;
01131
01132
01133 SoXtInputFocus* inputFocus;
01134
01135
01136 void setCurrentDrawStyle( SoXtViewer::DrawStyle style );
01137
01138
01139 SoXtClipboard* clipboard;
01140 static void pasteDoneCB( void* userData, SoPathList* pathList );
01141
01142
01143 void setZbufferState();
01144 SbBool isZbufferOff();
01145 void arrowKeyPressed( KeySym key );
01146
01147
01148 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01149 SoAlarmSensor* stillSensor;
01150 static void alarmCB( void* thisp, SoSensor* )
01151 { ((SoXtViewer*)thisp)->stillSensorCalled(); }
01152
01153
01169 static SbBool viewingEventCB( SoXtViewer* viewer, XAnyEvent* anyEvent );
01170
01171 void stillSensorCalled();
01172
01173
01174 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01175 };
01176
01177 #endif
01178
01179 #endif
01180
01181
01182