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 #ifndef _SO_WIN_VIEWER_
00026 #define _SO_WIN_VIEWER_
00027
00028 #include <Inventor/Win/SoWinBeginStrict.h>
00029
00030 #include <Inventor/SoType.h>
00031 #include <Inventor/Win/SoWinRenderArea.h>
00032 #include <Inventor/misc/SoCallbackList.h>
00033 #include <Inventor/SbElapsedTime.h>
00034 #include <Inventor/events/SoKeyboardEvent.h>
00035 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00036
00037 #include <Inventor/components/stereo/SoStereoViewer.h>
00038
00039
00040 class SoFieldSensor;
00041 class SoNode;
00042 class SoDirectionalLight;
00043 class SoGroup;
00044 class SoRotation;
00045 class SoCamera;
00046 class SoDrawStyle;
00047 class SoLightModel;
00048 class SoTimerSensor;
00049 class SoWinClipboard;
00050 class SoWinViewer;
00051 class SoGetBoundingBoxAction;
00052 class SbPList;
00053 class SoSeparator;
00054 class SoSwitch;
00055 class SoComplexity;
00056 class SoPackedColor;
00057 class SoMaterialBinding;
00058 class SoBaseColor;
00059 class SoSFTime;
00060 class SoAlarmSensor;
00061 class SoNodeSensor;
00062 class SoGetPrimitiveCountAction;
00063 class SoStereoViewer;
00064 class SoBaseStereo;
00065
00066 class SoType;
00067 class SbEventWrapperList;
00068
00069 class ScRayPickAction;
00070
00071
00072
00073 typedef void SoWinViewerCB( void* userData, SoWinViewer* viewer );
00074
00075 typedef void SoWinViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoWinViewer* viewer );
00076
00081 typedef void SoWinViewerFPSCB( float fps, void* userData, SoWinViewer* viewer );
00082
00083 typedef void SoWinViewerDecimationPercentageCB( float percentage, void* userData, SoWinViewer* viewer );
00084
00086
00087
00088
00089
00090
00091
00092
00094
00166 class SoWinViewer : public SoWinRenderArea, public SoStereoViewer {
00167
00168 public:
00169
00180 enum Type
00181 {
00185 BROWSER,
00189 EDITOR
00190 };
00191
00198 enum DrawStyle
00199 {
00203 VIEW_AS_IS,
00207 VIEW_HIDDEN_LINE,
00211 VIEW_NO_TEXTURE,
00215 VIEW_LOW_COMPLEXITY,
00219 VIEW_LINE,
00223 VIEW_POINT,
00227 VIEW_BBOX,
00231 VIEW_LOW_RES_LINE,
00235 VIEW_LOW_RES_POINT,
00239 VIEW_SAME_AS_STILL
00240 };
00242 enum DrawType
00243 {
00247 STILL,
00251 INTERACTIVE
00252 };
00253
00254
00256 enum BufferType
00257 {
00261 BUFFER_SINGLE,
00265 BUFFER_DOUBLE,
00269 BUFFER_INTERACTIVE
00270 };
00271
00272
00274 enum DecimationStrategy
00275 {
00279 NORMAL,
00283 FIXED_NUM_TRIANGLES,
00287 FRAMES_PER_SECOND,
00291 FIXED_PERCENTAGE
00292 };
00293
00299 enum CursorStyle
00300 {
00304 CLASSIC,
00308 XOR,
00312 SHADOW
00313 };
00314
00323 virtual void setSceneGraph( SoNode* newScene );
00324
00328 virtual SoNode* getSceneGraph();
00329
00330 #ifndef HIDDEN_FROM_DOC
00331 void saveSceneGraph( const char* fileName ) ;
00332 #endif //HIDDEN_FROM_DOC
00333
00339 virtual void setCamera(SoCamera *cam);
00340
00344 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00345
00354 virtual void setCameraType(SoType type);
00355
00360 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00361
00367 virtual void setPreserveCameraHeightAngle(SbBool flag)
00368 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00369
00375 virtual SbBool isCameraHeightAnglePreserved() const
00376 { return m_guiViewer->isCameraHeightAnglePreserved(); }
00377
00382 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00383
00388 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00389
00408 virtual void viewAll();
00409
00413 virtual void saveHomePosition();
00414
00418 virtual void resetToHomePosition();
00419
00424 void setCameraTypeChangeCallback( SoWinViewerCameraTypeChangeCB* callback, void* userdata );
00425
00432 void setHeadlight( SbBool onOrOff );
00433
00437 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00438
00442 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00443
00492 void setDrawStyle( SoWinViewer::DrawType type, SoWinViewer::DrawStyle style );
00493
00497 SoWinViewer::DrawStyle getDrawStyle( SoWinViewer::DrawType type );
00498
00503 void setBufferingType( SoWinViewer::BufferType type );
00504
00508 SoWinViewer::BufferType getBufferingType()
00509 { return (SoWinViewer::BufferType)m_guiViewer->getBufferingType(); }
00510
00511
00512 virtual void setDoubleBuffer( SbBool onOrOff );
00513
00526 virtual void setViewing( SbBool onOrOff );
00527
00532 virtual void enableDirectViz( SbBool onOrOff );
00533
00537 virtual void showDirectVizDialog( SbBool show );
00538
00542 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00543
00547 SbBool isDirectVizEnabled() const { return m_guiViewer->getDirectVizFlag(); }
00548
00557 virtual void setSeekMode(SbBool onOrOff);
00558
00563 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
00564
00576 virtual void setCursorEnabled( SbBool onOrOff );
00577
00583 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00584
00594 void setAutoClipping( SbBool onOrOff );
00595
00599 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00600
00626 virtual void setStereoViewing( SbBool onOrOff );
00627
00632 virtual SbBool isStereoViewing();
00633
00637 void setStereoOffset( float dist );
00638
00642 float getStereoOffset();
00643
00651 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00652
00656 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00657
00670 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00671
00675 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00676
00686 void addStartCallback( SoWinViewerCB* f, void* userData = NULL )
00687 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00688
00698 void addFinishCallback( SoWinViewerCB* f, void* userData = NULL )
00699 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00700
00707 void removeStartCallback( SoWinViewerCB* f, void* userData = NULL )
00708 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00709
00716 void removeFinishCallback( SoWinViewerCB *f, void* userData = NULL )
00717 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00718
00724 void copyView( Time eventTime );
00725
00731 void pasteView( Time eventTime );
00732
00733
00734
00735 virtual void setNormalVisual( XVisualInfo* i );
00736
00743 virtual void recomputeSceneSize();
00744
00745
00746
00755 void setDecimationStrategy( SoWinViewer::DecimationStrategy strategy );
00756
00760 SoWinViewer::DecimationStrategy getDecimationStrategy()
00761 { return (SoWinViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00762
00770 void setGoalNumberOfTriangles(int32_t goal);
00771
00775 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00776
00784 void setGoalFramesPerSecond( float goal );
00785
00789 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00790
00798 void setFixedPercentage( float percent );
00799
00803 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00804
00813 void enableFullRenderingWhenStill( SbBool onOff );
00814
00819 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00820
00824 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00825
00829 void setFramesPerSecondCallback( SoWinViewerFPSCB* callback, void* userData = NULL );
00830
00835 void setNumSamples( int numFrames );
00836
00841 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00842
00846 void setDecimationPercentageCallback( SoWinViewerDecimationPercentageCB *callback,
00847 void* userData = NULL );
00848
00852 float getCurrentDecimationPercentage();
00853
00858 void enableMouseWheelDolly( SbBool onOff ) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00859
00860
00870 void setPickRadius( float radius );
00871
00875 float getPickRadius() const;
00876
00877 public:
00878
00882 virtual SoCamera* getViewerCamera();
00883
00887 virtual SbBool isViewerDoubleBuffer();
00888
00895 virtual void actualRendering();
00896
00901 virtual const SbVec2s& getSize();
00902
00910 virtual const SbVec2s& getTopLeft() ;
00911
00919 virtual const SbVec2s& getBottomRight() ;
00920
00927 void setStereoViewType( SoBaseStereo* stereo );
00928
00932 SoBaseStereo* getStereoViewType();
00933
00937 void reverseStereoView( SbBool reverse );
00938
00942 SbBool isStereoViewReversed();
00943
00947 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00948
00952 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00953
00958 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00959
00963 virtual float getStereoBalance();
00964
00969 virtual SbBool isStereoBalanceNearFrac();
00970
00975 virtual void setStereoActive( SbBool activate ) ;
00976
00980 virtual SbBool isStereoActive() ;
00981
00985 void setViewport( short left, short bottom, short width, short height ) ;
00986
00990 void getViewport( short& left, short& bottom, short& width, short& height ) ;
00991
01006 virtual void setCursorStyle( SoWinViewer::CursorStyle style );
01007
01011 SoWinViewer::CursorStyle getCursorStyle()
01012 { return (SoWinViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
01013
01023 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
01024
01028 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
01029
01054 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
01055
01059 SoNode* getCameraSceneGraph();
01060
01070 virtual void toggleCameraType();
01071
01072 #if 1 SoDEPRECATED
01078 HDC getCurrentDC();
01079 SoDEPRECATED
01085 virtual void adjustClippingPlanes();
01086
01087 #endif
01094 SbBool getDepthValue(int x, int y, float &depth)
01095 {
01096 return m_guiViewer->getDepthValue(x, y, depth);
01097 }
01098
01099 private:
01100
01101 virtual ~SoWinViewer();
01102
01107 float getAntoClipTolerance() const { return m_guiViewer->getAutoClipTolerance(); }
01108
01109 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
01110
01111 virtual SbBool isInteractive() const;
01112
01113 SoGuiViewer* getGuiViewer() const;
01114
01115
01116
01117 SoCamera* camera;
01118 SbBool createdCursors, viewingFlag;
01119 CursorStyle cursorStyle;
01120 SoSeparator* sceneRoot;
01121 float sceneSize;
01122 SoBaseStereo* stereoViewType;
01123 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01124 float m_previousHeightAngle, viewerSpeed, seekDistance;
01125 SoWinViewer::Type type;
01126 SoNode* sceneGraph;
01127 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01128 SbRotation oldCamOrientation, newCamOrientation;
01129
01130 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01131 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01132
01133 private:
01134
01135 virtual void adjustCameraClippingPlanes();
01136
01137
01138 SbEventWrapperList* m_eventWrapperList;
01139
01140 void windowsKeyArrayConvert();
01141 SoKeyboardEvent::Key* m_windowsKeyArray;
01142
01143
01144 SoWinViewer( SoWidget parent,
01145 const char* name,
01146 SbBool buildInsideParent,
01147 SoWinViewer::Type type,
01148 SbBool buildNow,
01149 SbBool sync );
01150
01151 SoWinViewer( SoWidget parent,
01152 const char* name,
01153 SbBool buildInsideParent,
01154 SoWinViewer::Type type,
01155 SbBool buildNow,
01156 SbBool sync,
01157 SoGuiViewer* guiViewer );
01158
01159
01160 SbBool altSwitchBack;
01161
01162
01163
01164
01165
01166
01167 HCURSOR normalCursor,
01168 dollyCursor, panCursor, rollCursor, seekCursor,
01169 spinCursor, upCursor, flyCursor, walkCursor,
01170 pickCursor, manipCursor;
01171
01172
01173
01174
01175
01176 virtual void defineCursors();
01177
01178
01179
01180 virtual void updateCursor() {};
01181
01182 #ifdef __sgi
01183
01184
01185 SbBool useSGIStereoExt;
01186 #endif
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197 SbBool processCommonEvents(XAnyEvent *xe);
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 void interactiveCountInc();
01211 void interactiveCountDec();
01212 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 SbBool seekToPoint(const SbVec2s &mouseLocation);
01225
01226
01227
01228
01229
01230
01231
01232
01233 virtual void interpolateSeekAnimation(float t);
01234 virtual void computeSeekFinalOrientation();
01235
01236
01237
01238
01239 virtual void actualRedraw();
01240
01241
01242
01243
01244 virtual void changeCameraValues( SoCamera* newCamera );
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01259
01260
01261 static void restoreGLStateAfterFeedback();
01262
01263 static void drawViewerCrossFeedback( SbVec2s loc );
01264
01265 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275 virtual void widgetChanged( SoWidget );
01276
01277
01278 virtual void afterRealizeHook();
01279
01280
01281
01282 virtual void redraw();
01283
01284
01285
01286
01287
01288
01289
01290 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01291
01292
01293
01294
01295
01296
01297 virtual float decimationForNumTriangles(uint32_t numTris);
01298
01299 void setCurrentDrawStyle(SoWinViewer::DrawStyle style);
01300
01301 private:
01302
01303 void constructorCommon( SoWinViewer::Type t, SbBool buildNow );
01304 void constructorCommon2( SoWinViewer::Type t, SbBool buildNow );
01305
01306 SoGuiViewer* m_guiViewer;
01307
01308 SbBool m_firstRealize;
01309
01310
01311 SoWinClipboard* clipboard;
01312 static void pasteDoneCB( void* userData, SoPathList* pathList );
01313
01314
01315 SoFieldSensor* headlightSensor;
01316 static void headlightSensorCB( void* v, SoSensor* s );
01317
01318
01319 static void visibilityChangeCB( void* pt, SbBool visible );
01320
01321
01322 void setZbufferState();
01323 SbBool isZbufferOff();
01324 void arrowKeyPressed( KeySym key );
01325
01326
01327 SoAlarmSensor* stillSensor;
01328 static void alarmCB( void* thisp, SoSensor* s );
01329 void stillSensorCalled();
01330
01331
01332 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01333
01334
01350 static SbBool viewingEventCB( SoWinViewer* viewer, XAnyEvent* anyEvent );
01351
01352 private:
01353 void* getViewer() { return (void*)this; }
01354 };
01355
01356 inline void
01357 SoWinViewer::alarmCB( void* thisp, SoSensor* )
01358 {
01359 ((SoWinViewer*)thisp)->stillSensorCalled();
01360 }
01361
01362 #include <Inventor/Win/SoWinEndStrict.h>
01363
01364 #endif
01365
01366
01367
01368
01369