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 SoPackedColor;
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
00584 void setDecimationStrategy( DecimationStrategy strategy );
00588 DecimationStrategy getDecimationStrategy() const;
00589
00597 void setGoalNumberOfTriangles( int32_t goal );
00598
00602 int32_t getGoalNumberOfTriangles();
00603
00611 void setGoalFramesPerSecond( float goal );
00612
00616 float getGoalFramesPerSecond();
00617
00625 void setFixedPercentage( float percent );
00626
00630 float getFixedPercentage();
00631
00640 void enableFullRenderingWhenStill( SbBool onOff );
00641
00646 SbBool isFullRenderingWhenStill();
00647
00648 void setStill( SbBool isStill );
00652 SbBool isStillNow();
00653
00659 void setNumSamples( int numFrames );
00660
00665 int getNumSamples();
00666
00670 float getCurrentDecimationPercentage();
00671
00672
00673 virtual void setStereoActive(SbBool activate);
00674 virtual SbBool isStereoActive();
00675 virtual void actualRendering();
00676 virtual SoCamera* getViewerCamera();
00677 virtual const SbVec2s& getSize();
00678 virtual const SbVec2s& getTopLeft();
00679 virtual const SbVec2s& getBottomRight();
00680 virtual SbBool isViewerDoubleBuffer();
00681 virtual void setStereoViewType( SoBaseStereo* stereo );
00682 virtual SoBaseStereo* getStereoViewType();
00683 virtual void reverseStereoView( SbBool reverse );
00684 virtual SbBool isStereoViewReversed();
00685 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00686 virtual SbBool isStereoAbsoluteAdjustments() const;
00687 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00688 virtual float getStereoBalance();
00689 virtual SbBool isStereoBalanceNearFrac();
00690 virtual void setViewport( short left, short bottom, short width, short height );
00691 virtual void getViewport(short& left, short& bottom, short& width, short& height);
00692 virtual SoGLContext* getViewerContext() { return NULL; }
00693 virtual SoSceneManager* getViewerSceneManager() { return this->getSceneManager(); }
00694
00695 SoSeparator* getSceneRoot();
00696
00711 virtual void setCursorStyle( CursorStyle style );
00712
00716 CursorStyle getCursorStyle() const;
00717
00727 void setAutoClipTolerance ( float tolerance );
00728
00732 float getAutoClipTolerance () const;
00733
00755 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00756
00760 SoNode* getCameraSceneGraph();
00761
00766 void enableShadows( bool onOrOff );
00767
00771 SbBool isEnableShadows();
00772
00776 SoShadowGroup* getShadowGroup();
00777
00783 void enableMouseWheelDolly( SbBool onOff );
00784 SbBool isMouseWheelEnabled() const;
00785
00786 SbBool isInteractive() const;
00787
00788
00789
00790 virtual void toggleCameraType();
00791
00800 virtual void setSeekMode( SbBool flag );
00801 SbBool isSeekMode() const;
00802
00803
00804 void setInteractiveFlag( SbBool flag );
00805 SbBool getInteractiveFlag() const;
00806
00807
00808 void setStillDrawStyle( DrawStyle style );
00809 DrawStyle getStillDrawStyle() const;
00810
00811
00812 void setInteractiveDrawStyle( DrawStyle style );
00813 DrawStyle getInteractiveDrawStyle() const;
00814
00815
00816 void setSeekStartTime( SbTime seekTime );
00817 SbTime getSeekStartTime() const;
00818
00819
00820 void setNewCamOrientation( SbRotation newOrientation );
00821 SbRotation getNewCamOrientation() const;
00822
00823
00824 void setSeekPoint( SbVec3f newOrientation );
00825 SbVec3f getSeekPoint() const;
00826
00827
00828 void setViewerSpeed( float speed );
00829 float getViewerSpeed() const;
00830
00831
00832 void setHeadLightFlag( SbBool flag );
00833
00834
00835 void setCreatedCursors( SbBool flag );
00836 SbBool getCreatedCursors() const;
00837
00838
00839 void setInteractiveCount( int count );
00840
00841
00842 SoCallbackList* getFinishCBList();
00843
00844
00845 void setCheckForDrawStyle( SbBool flag );
00846 SbBool getCheckForDrawStyle() const;
00847
00848
00849 void setType( Type type );
00850 Type getType() const;
00851
00852
00853 void setRealTime( SoSFTime* type );
00854 SoSFTime* getRealTime() const;
00855
00856
00857 virtual void enableDirectViz( SbBool flag );
00858
00859 virtual void internalEnableDirectViz( SbBool flag );
00860
00861
00862 void setDirectVizFlag( SbBool enable );
00863 SbBool getDirectVizFlag() const;
00864
00865
00866 void setSeekDistance( float seekDistance );
00867 float getSeekDistance();
00868
00869
00870 void setSceneSize( float size );
00871 float getSceneSize();
00872
00873
00874 SbBool getComputeSeekVariables() const { return m_computeSeekVariables; }
00875 float getPreviousHeightAngle() { return m_previousHeightAngle; }
00876 SbVec3f getSeekNormal() { return m_seekNormal; }
00877 SbVec3f getNewCamPosition() { return m_newCamPosition; }
00878
00879
00880 void setSeekSensor( SoFieldSensor* s );
00881 SoFieldSensor* getSeekSensor() const;
00882
00883
00884 SbBool getCreatedCamera() const;
00885
00886 void setViewer( void* viewer );
00887
00888
00889 virtual void setDoubleBuffer( SbBool flag );
00890
00891
00892
00893
00894 SoNONUNICODE static void writeScene( SoNode* node, const char* filename );
00895
00896
00897 static void writeScene( SoNode* node, const SbString& filename );
00898
00899
00900 void setCameraTypeChangeCallback( SoGuiViewerCameraTypeChangeCB* callback, void* userdata );
00901 void addStartCallback( SoGuiViewerCB* f, void* userData = NULL );
00902 void addFinishCallback( SoGuiViewerCB* f, void* userData = NULL );
00903 void removeStartCallback( SoGuiViewerCB* f, void* userData = NULL );
00904 void removeFinishCallback( SoGuiViewerCB* f, void* userData = NULL );
00905
00910 void setFramesPerSecondCallback( SoGuiViewerFPSCB* callback, void* userData = NULL );
00911
00916 void setDecimationPercentageCallback( SoGuiViewerDecimationPercentageCB* callback, void* userData = NULL );
00917
00918 SbBool isZBufferOff();
00919
00920 void arrowKeyPressed( Direction direction );
00921
00922 SbBool getDepthValue(int x, int y, float &depth);
00923
00924 class CameraFields {
00925 public:
00926 CameraFields();
00927 SbBool isModified( SoCamera* cam );
00928 void setCameraFields( SoCamera* cam );
00929 static bool stereoDataMatchViewerState( SoCamera* cam, SoGuiViewer* viewer );
00930 static void setViewerStereoData( SoCamera* cam, SoGuiViewer* viewer );
00931 static void setCameraStereoData( SoCamera* cam, SoGuiViewer* viewer );
00932
00933 private:
00934 int m_viewportMapping;
00935 SbVec3f m_position;
00936 SbRotation m_orientation;
00937 float m_aspectRatio;
00938 float m_nearDistance;
00939 float m_farDistance;
00940 float m_focalDistance;
00941 float m_height;
00942
00943 bool m_stereoAbsoluteAdjustments;
00944 float m_stereoAdjustment;
00945 float m_balanceAdjustment;
00946 int m_stereoMode;
00947 bool m_balanceNearFrac;
00948 };
00949
00950
00951
00952 virtual void afterRealizeHook();
00953
00954 virtual void adjustCameraClippingPlanes();
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966 void interactiveCountInc();
00967 void interactiveCountDec();
00968 int getInteractiveCount();
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 SbBool seekToPoint( const SbVec2s& mouseLocation, SbBool allowChangeOrientation=TRUE, SbBool allowChangeDistance=TRUE );
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995 SbBool seekToPoint( const SbVec3f& worldPoint, const SbVec3f& worldNormal, SbBool allowChangeOrientation=TRUE, SbBool allowChangeDistance=TRUE );
00996
00997
00998
00999
01000
01001
01002 virtual void interpolateSeekAnimation( float t );
01003 virtual void computeSeekFinalOrientation();
01004
01005
01006
01007
01008 virtual void actualRedraw();
01009
01010
01011
01012
01013 virtual void changeCameraValues( SoCamera* newCamera );
01014
01015
01016
01017 virtual void preViewerRedraw();
01018 virtual void postViewerRedraw();
01019
01020
01021
01022
01023
01024
01025
01026 virtual float decimationForFramesPerSecond( float fps,
01027 double lasttime,
01028 float lastDec );
01029
01030
01031
01032
01033
01034 virtual float decimationForNumTriangles( uint32_t numTris );
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047 static void setFeedbackOrthoProjection( const SbVec2s& size );
01048
01049
01050 static void restoreGLStateAfterFeedback();
01051
01052 static void drawViewerCrossFeedback( SbVec2s loc );
01053
01054 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01055
01056 void setCurrentDrawStyle( SoGuiViewer::DrawStyle style );
01057
01058 void doBoxZoom( int x1, int y1, int x2, int y2 );
01059 void setZoomMode( SbBool zoomMode );
01060 SbBool isZoomModeEnabled() const;
01061 void setSeekDistAsPercentage( SbBool seekDist );
01062
01063 #if 1 SoDEPRECATED
01065 virtual void adjustClippingPlanes();SoDEPRECATED
01067 virtual HDC getCurrentDC();
01068 #endif
01070 private:
01071
01075 virtual ~SoGuiViewer();
01076
01077 SoShadowGroup* getShadowGroup() const { return m_shadowGroup; };
01078
01079 SoGetBoundingBoxAction* m_sceneSizeBBoxAction;
01080 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01081
01082
01083
01084 private:
01085
01086 void doRendering();
01087 static void drawStyleStartCallback( void* userData, void* v );
01088 static void drawStyleFinishCallback( void* userData, void* v );
01089 static void changeCB( void* thisp, SoSensor* sensor );
01090 void changeSensorCalled();
01091
01092 void setStereoOffsetP( float dist );
01093 void setStereoBalanceP( float balance, SbBool nearFrac );
01094 void setStereoAbsoluteAdjustmentsP( SbBool absolute );
01095
01096
01097 SoSeparator* m_sceneRoot;
01098 SoNode* m_sceneGraph;
01099 void* m_viewerPtr;
01100
01101
01102 SoNode* m_cameraSceneGraph;
01103 SoType m_cameraType;
01104 SoCamera* m_camera;
01105 SoGuiViewer::Type m_type;
01106 SbBool m_viewingFlag;
01107 SbBool m_directVizFlag;
01108 SbBool m_interactiveFlag;
01109 BufferType m_bufferType;
01110 SbBool m_cursorEnabledFlag;
01111 float m_sceneSize;
01112 static SoSFTime* m_viewerRealTime;
01113 SbBool m_firstLeftRender;
01114 float m_viewerSpeed;
01115
01116
01117 SbBool m_createdCamera;
01118 SbVec3f m_origPosition;
01119 SbRotation m_origOrientation;
01120 float m_origNearDistance;
01121 float m_origFarDistance;
01122 float m_origFocalDistance;
01123 float m_origHeight;
01124
01125
01126 SbBool m_headlightFlag;
01127 SoGroup* m_headlightGroup;
01128 SoDirectionalLight* m_headlightNode;
01129 SoRotation* m_headlightRot;
01130
01131
01132 SbBool m_preserveHeightAngle;
01133 SbBool m_seekWithOrtho;
01134 SbBool m_mouseWheelEnable;
01135 float m_previousHeightAngle;
01136 CameraFields* m_prevCam;
01137 SoBaseStereo* m_stereoViewType;
01138 double m_farDistS;
01139 double m_nearDistS;
01140
01141
01142 SbBool m_checkForDrawStyle;
01143 DrawStyle m_stillDrawStyle, m_interactiveDrawStyle;
01144 SoSwitch* m_drawStyleSwitch;
01145 SoDrawStyle* m_drawStyleNode;
01146 SoLightModel* m_lightModelNode;
01147 SoComplexity* m_complexityNode;
01148 SoPackedColor* m_colorNode;
01149 SoMaterialBinding *m_matBindingNode;
01150 SoDepthBuffer *m_depthBuffer ;
01151
01152
01153 SoShadowGroup* m_shadowGroup;
01154 bool m_shadowGroupCurrState;
01155
01156
01157 SbBool m_autoClipFlag;
01158 float m_minimumNearPlane;
01159 SoGetBoundingBoxAction* m_autoClipBboxAction;
01160 bool m_autoClipPlaneViewVolumeCulling;
01161
01162
01163 SbBool m_detailSeekFlag;
01164 float m_seekAnimTime;
01165 SbBool m_seekModeFlag;
01166 SbBool m_seekAllowChangeOrientation;
01167 SbBool m_seekAllowChangeDistance;
01168 SoFieldSensor* m_seekAnimationSensor;
01169
01170
01171 DecimationStrategy m_decStrategy;
01172 SbBool m_isStill, m_doFullRendering, m_wasStill;
01173 int32_t m_goalTris;
01174 float m_goalFps;
01175 float m_decPercentage;
01176 float m_lastDecimationValue;
01177 double m_lastRenderTime;
01178
01179 SoPerfCounter* m_fpsCounter;
01180
01181 int m_lastDirection;
01182 SoGetPrimitiveCountAction* m_primCountAction;
01183 SoNodeSensor* m_motionSensor;
01184
01185
01186 int m_numSamples;
01187 SoGuiViewerFPSCB* m_fpsUserCallback;
01188 void* m_fpsUserData;
01189
01190
01191
01192
01193
01194
01195
01196 SoGuiViewer::CursorStyle m_cursorStyle;
01197
01198
01199
01200
01201
01202 SbBool m_createdCursors;
01203
01204
01205 SoCallbackList* m_startCBList;
01206 SoCallbackList* m_finishCBList;
01207
01208
01209 SbVec3f m_seekPoint, m_seekNormal;
01210 SbBool m_computeSeekVariables;
01211 SbTime m_seekStartTime;
01212 SbRotation m_oldCamOrientation, m_newCamOrientation;
01213 SbVec3f m_oldCamPosition, m_newCamPosition;
01214 float m_seekDistance;
01215 SbBool m_seekDistAsPercentage;
01216
01217
01218
01219 SbBool m_isWinRedrawing;
01220
01221
01222 SoGuiViewerCameraTypeChangeCB* m_viewerCameraTypeChangeCallback;
01223 void* m_viewerCameraTypeChangeCallbackUserData;
01224
01225
01226 SoGuiViewerDecimationPercentageCB* m_decimationUserCallback;
01227 void* m_decimationUserData;
01228
01229 SbBool m_zoomMode;
01230 static bool s_enableIgnoreScreenSpaceBBox;
01231
01232
01233 };
01234
01235 #endif // SO_GUI_VIEWER
01236
01237
01238