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(SOWX)
00054 # include <Inventor/Wx/viewers/SoWxViewer.h>
00055 #elif defined _WIN32
00056 # include <Inventor/Win/viewers/SoWinViewer.h>
00057 #else
00058
00059 #ifndef _SO_XT_VIEWER_
00060 #define _SO_XT_VIEWER_
00061
00062 #include <Inventor/SoType.h>
00063 #include <Inventor/Xt/SoXtRenderArea.h>
00064 #include <Inventor/misc/SoCallbackList.h>
00065 #include <Inventor/SbElapsedTime.h>
00066 #include <Inventor/events/SoKeyboardEvent.h>
00067 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00068 #include <Inventor/components/stereo/SoStereoViewer.h>
00069
00070
00071 class SoNode;
00072 class SoDirectionalLight;
00073 class SoGroup;
00074 class SoRotation;
00075 class SoCamera;
00076 class SoDrawStyle;
00077 class SoLightModel;
00078 class SoFieldSensor;
00079 class SoXtClipboard;
00080 class SoXtViewer;
00081 class SoGetBoundingBoxAction;
00082 class SbPList;
00083 class SoSeparator;
00084 class SoSwitch;
00085 class SoComplexity;
00086 class SoPackedColor;
00087 class SoMaterialBinding;
00088 class SoSFTime;
00089 class SoXtInputFocus;
00090 class SoAlarmSensor;
00091 class SoNodeSensor;
00092 class SoGetPrimitiveCountAction;
00093 class SoStereoViewer;
00094 class SoBaseStereo;
00095 class ScRayPickAction;
00096
00097
00098 typedef void SoXtViewerCB( void* userData, SoXtViewer* viewer );
00099 typedef void SoXtViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoXtViewer* viewer );
00100
00101
00102
00103 typedef void SoXtViewerFPSCB( float fps, void* userData, SoXtViewer* viewer );
00104 typedef void SoXtViewerDecimationPercentageCB( float percentage, void* userData, SoXtViewer* viewer );
00105
00107
00108
00109
00110
00111
00112
00113
00115
00186 class SoXtViewer : public SoXtRenderArea, public SoStereoViewer
00187 {
00188 public:
00199 enum Type
00200 {
00204 BROWSER,
00208 EDITOR
00209 };
00210
00217 enum DrawStyle
00218 {
00222 VIEW_AS_IS,
00226 VIEW_HIDDEN_LINE,
00230 VIEW_NO_TEXTURE,
00234 VIEW_LOW_COMPLEXITY,
00238 VIEW_LINE,
00242 VIEW_POINT,
00246 VIEW_BBOX,
00250 VIEW_LOW_RES_LINE,
00254 VIEW_LOW_RES_POINT,
00258 VIEW_SAME_AS_STILL
00259 };
00260
00262 enum DrawType
00263 {
00267 STILL,
00271 INTERACTIVE
00272 };
00273
00275 enum BufferType
00276 {
00280 BUFFER_SINGLE,
00284 BUFFER_DOUBLE,
00288 BUFFER_INTERACTIVE
00289 };
00290
00292 enum DecimationStrategy
00293 {
00297 NORMAL,
00301 FIXED_NUM_TRIANGLES,
00305 FRAMES_PER_SECOND,
00309 FIXED_PERCENTAGE
00310 };
00311
00317 enum CursorStyle
00318 {
00322 CLASSIC,
00326 XOR,
00330 SHADOW
00331 };
00332
00333
00342 virtual void setSceneGraph(SoNode *newScene);
00343
00347 virtual SoNode* getSceneGraph();
00348
00354 virtual void setCamera( SoCamera* cam );
00355
00359 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00360
00369 virtual void setCameraType( SoType type );
00370
00375 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00376
00382 virtual void setPreserveCameraHeightAngle( SbBool flag )
00383 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00384
00390 virtual SbBool isCameraHeightAnglePreserved() const { return m_guiViewer->isCameraHeightAnglePreserved(); }
00391
00396 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00397
00402 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00403
00422 virtual void viewAll();
00423
00427 virtual void saveHomePosition();
00428
00432 virtual void resetToHomePosition();
00433
00438 void setCameraTypeChangeCallback( SoXtViewerCameraTypeChangeCB* callback, void* userdata );
00439
00446 virtual void setHeadlight( SbBool onOrOff );
00447
00451 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00452
00456 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00457
00506 virtual void setDrawStyle( SoXtViewer::DrawType type, SoXtViewer::DrawStyle style );
00507
00511 SoXtViewer::DrawStyle getDrawStyle( SoXtViewer::DrawType type );
00512
00517 virtual void setBufferingType( SoXtViewer::BufferType type) ;
00518
00522 SoXtViewer::BufferType getBufferingType()
00523 { return (SoXtViewer::BufferType)m_guiViewer->getBufferingType(); }
00524
00537 virtual void setViewing( SbBool onOrOff );
00538
00542 SbBool isViewing() const { return m_guiViewer->isViewing(); };
00543
00554 virtual void setCursorEnabled( SbBool onOrOff );
00555
00560 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00561
00572 void setAutoClipping( SbBool onOrOff );
00573
00577 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00578
00586 virtual void setStereoViewing( SbBool onOrOff );
00587
00592 virtual SbBool isStereoViewing();
00593
00597 void setStereoOffset( float dist );
00598
00602 float getStereoOffset();
00603
00611 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); };
00612
00616 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00617
00630 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00631
00635 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00636
00645 void addStartCallback( SoXtViewerCB* f, void* userData = NULL )
00646 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00647
00656 void addFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00657 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00658
00664 void removeStartCallback( SoXtViewerCB* f, void* userData = NULL )
00665 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00666
00672 void removeFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00673 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00674
00680 void copyView( Time eventTime );
00681
00687 void pasteView( Time eventTime );
00688
00695 virtual void recomputeSceneSize();
00696
00697
00698
00704 void setDecimationStrategy( SoXtViewer::DecimationStrategy strategy );
00705
00709 SoXtViewer::DecimationStrategy getDecimationStrategy()
00710 { return (SoXtViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00711
00719 void setGoalNumberOfTriangles( int32_t goal );
00720
00724 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); };
00725
00733 void setGoalFramesPerSecond( float goal );
00734
00738 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); };
00739
00747 void setFixedPercentage( float percent );
00748
00752 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); };
00753
00762 void enableFullRenderingWhenStill( SbBool onOff );
00763
00768 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); };
00769
00773 SbBool isStillNow() { return m_guiViewer->isStillNow(); };
00774
00778 void setFramesPerSecondCallback( SoXtViewerFPSCB* callback, void* userData = NULL );
00779
00784 void setNumSamples( int numFrames );
00789 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00790
00794 void setDecimationPercentageCallback( SoXtViewerDecimationPercentageCB* callback, void* userData = NULL );
00795
00799 float getCurrentDecimationPercentage();
00800
00801
00802
00803 virtual SoCamera* getViewerCamera();
00804 virtual SbBool isViewerDoubleBuffer();
00805 virtual void actualRendering();
00806 virtual const SbVec2s& getSize();
00807 virtual const SbVec2s& getTopLeft() ;
00808 virtual const SbVec2s& getBottomRight() ;
00809 void setStereoViewType( SoBaseStereo* stereo );
00810 SoBaseStereo* getStereoViewType();
00811 void reverseStereoView( SbBool reverse );
00812 SbBool isStereoViewReversed();
00813 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00814 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00815 virtual void setStereoBalance( float balance, SbBool nearFrac );
00816 virtual float getStereoBalance();
00817 virtual SbBool isStereoBalanceNearFrac();
00818 virtual void setStereoActive( SbBool activate );
00819 virtual SbBool isStereoActive();
00820 void setViewport( short left, short bottom, short width, short height );
00821 void getViewport( short &left, short &bottom, short &width, short &height );
00822
00823
00838 virtual void setCursorStyle( SoXtViewer::CursorStyle style );
00839
00843 SoXtViewer::CursorStyle getCursorStyle()
00844 { return (SoXtViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00845
00846
00847 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00848
00858 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); };
00859
00863 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); };
00864
00889 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00890
00894 SoNode* getCameraSceneGraph();
00895
00905 virtual void toggleCameraType();
00906
00914 virtual void setSeekMode( SbBool onOrOff );
00915
00925 void setPickRadius( float radius );
00926
00930 float getPickRadius() const;
00931
00932 #if 1 SoDEPRECATED
00935 virtual void adjustClippingPlanes();
00936
00937 #endif
00944 SbBool getDepthValue(int x, int y, float &depth)
00945 {
00946 return m_guiViewer->getDepthValue(x, y, depth);
00947 }
00948
00949 private:
00950 virtual ~SoXtViewer();
00951
00952
00953
00954 virtual void setNormalVisual( XVisualInfo* v );
00955
00956 #ifndef HIDDEN_FROM_DOC
00957 void saveSceneGraph( const char* fileName ) ;
00958 #endif //HIDDEN_FROM_DOC
00959
00960 SbBool isInteractive() const;
00961
00962 SoGuiViewer* getGuiViewer() const;
00963
00964
00965
00966 SoCamera* camera;
00967 SbBool createdCursors, viewingFlag;
00968 CursorStyle cursorStyle;
00969 SoSeparator* sceneRoot;
00970 float sceneSize;
00971 SoBaseStereo* stereoViewType;
00972 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
00973 float m_previousHeightAngle, viewerSpeed, seekDistance;
00974 SoXtViewer::Type type;
00975 SoNode* sceneGraph;
00976 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
00977 SbRotation oldCamOrientation, newCamOrientation;
00978
00979 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
00980 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
00981
00982 private:
00983
00984
00985 SoXtViewer( SoWidget parent,
00986 const char* name,
00987 SbBool buildInsideParent,
00988 SoXtViewer::Type type,
00989 SbBool buildNow,
00990 SbBool sync = TRUE );
00991
00992 SoXtViewer( SoWidget parent,
00993 const char* name,
00994 SbBool buildInsideParent,
00995 SoXtViewer::Type type,
00996 SbBool buildNow,
00997 SbBool sync,
00998 SoGuiViewer* guiViewer );
00999
01000
01001
01002
01003 virtual void updateCursor() {};
01004
01005
01006 SbBool altSwitchBack;
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017 SbBool processCommonEvents( XAnyEvent* xe );
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 void interactiveCountInc();
01031 void interactiveCountDec();
01032 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044 SbBool seekToPoint( const SbVec2s& mouseLocation );
01045
01046
01047
01048
01049
01050
01051
01052
01053 virtual void interpolateSeekAnimation( float t );
01054 virtual void computeSeekFinalOrientation();
01055
01056 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
01057
01058
01059
01060
01061 virtual void actualRedraw();
01062
01063
01064
01065
01066 virtual void changeCameraValues( SoCamera* newCamera );
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01081
01082
01083
01084 static void restoreGLStateAfterFeedback();
01085
01086
01087 static void drawViewerCrossFeedback( SbVec2s loc );
01088
01089
01090 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01091
01092
01093 virtual void afterRealizeHook();
01094
01095 virtual void widgetChanged( SoWidget );
01096
01097
01098 SbBool autoClipFlag;
01099 float minimumNearPlane;
01100 SoGetBoundingBoxAction* autoClipBboxAction;
01101 virtual void adjustCameraClippingPlanes();
01102
01103
01104
01105 virtual void redraw();
01106
01107
01108
01109
01110
01111
01112
01113 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01114
01115
01116
01117
01118
01119
01120 virtual float decimationForNumTriangles( uint32_t numTris );
01121
01122
01123 void* getViewer() { return (void*)this; }
01124
01125 private:
01126 void constructorCommon( SoXtViewer::Type t, SbBool buildNow );
01127
01128 void constructorCommon2( SoXtViewer::Type t, SbBool buildNow );
01129
01130 SoGuiViewer* m_guiViewer;
01131
01132 SbBool m_firstRealize;
01133
01134
01135 SoXtInputFocus* inputFocus;
01136
01137
01138 void setCurrentDrawStyle( SoXtViewer::DrawStyle style );
01139
01140
01141 SoXtClipboard* clipboard;
01142 static void pasteDoneCB( void* userData, SoPathList* pathList );
01143
01144
01145 void setZbufferState();
01146 SbBool isZbufferOff();
01147 void arrowKeyPressed( KeySym key );
01148
01149
01150 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01151 SoAlarmSensor* stillSensor;
01152 static void alarmCB( void* thisp, SoSensor* )
01153 { ((SoXtViewer*)thisp)->stillSensorCalled(); }
01154
01155
01171 static SbBool viewingEventCB( SoXtViewer* viewer, XAnyEvent* anyEvent );
01172
01173 void stillSensorCalled();
01174
01175
01176 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01177 };
01178
01179 #endif
01180
01181 #endif
01182
01183
01184