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 #ifndef _SO_WIN_MP_VIEWER_
00027 #define _SO_WIN_MP_VIEWER_
00028
00029 #if defined(_WIN32)
00030 # include <Inventor/Win/SoWinBeginStrict.h>
00031 #endif
00032 #include <Inventor/SoType.h>
00033 #include <Inventor/MP/Win/SoWinMPRenderArea.h>
00034 #include <Inventor/misc/SoCallbackList.h>
00035 #include <Inventor/SbTime.h>
00036
00037
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 SoWinMPViewer;
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
00064
00065
00066 class SoTransform;
00067
00068
00069
00070 typedef void SoWinMPViewerCB(void *userData, SoWinMPViewer *viewer);
00071 typedef void SoWinMPViewerCameraTypeChangeCB(void *userData, SoCamera *camera, SoWinMPViewer *viewer);
00072
00073
00074
00075 typedef void SoWinMPViewerFPSCB(float fps, void *userData, SoWinMPViewer *viewer);
00076 typedef void SoWinMPViewerDecimationPercentageCB(float percentage,
00077 void *userData, SoWinMPViewer *viewer);
00078
00080
00081
00082
00083
00084
00085
00086
00088
00105
00106 class SoWinMPViewer : public SoWinMPRenderArea {
00107
00108 public:
00109
00110
00111
00122 enum Type {
00126 BROWSER,
00130 EDITOR,
00131 };
00132
00138 enum DrawStyle {
00142 VIEW_AS_IS,
00146 VIEW_HIDDEN_LINE,
00150 VIEW_NO_TEXTURE,
00154 VIEW_LOW_COMPLEXITY,
00158 VIEW_LINE,
00162 VIEW_POINT,
00166 VIEW_BBOX,
00170 VIEW_LOW_RES_LINE,
00174 VIEW_LOW_RES_POINT,
00178 VIEW_SAME_AS_STILL,
00179 };
00181 enum DrawType {
00185 STILL,
00189 INTERACTIVE,
00190 };
00191
00193 enum BufferType {
00197 BUFFER_SINGLE,
00201 BUFFER_DOUBLE,
00205 BUFFER_INTERACTIVE,
00206 };
00207
00209 enum DecimationStrategy {
00213 NORMAL,
00217 FIXED_NUM_TRIANGLES,
00221 FRAMES_PER_SECOND,
00225 FIXED_PERCENTAGE
00226 };
00227
00233 enum CursorStyle {
00237 CLASSIC,
00241 XOR,
00245 SHADOW
00246 };
00247
00248
00249
00250
00251
00252
00253
00254 virtual void setSceneGraph(SoNode *newScene);
00255 virtual SoNode *getSceneGraph();
00256
00257 #ifndef HIDDEN_FROM_DOC
00258 void saveSceneGraph(const char *fileName) ;
00259 #endif //HIDDEN_FROM_DOC
00260
00266 virtual void setCamera(SoCamera *cam);
00270 SoCamera *getCamera() { return camera; }
00271
00280 virtual void setCameraType(SoType type);
00285 SoType getCameraType() { return cameraType; }
00286
00292 virtual void setPreserveCameraHeightAngle(SbBool flag)
00293 {m_preserveHeightAngle = flag; }
00294
00300 virtual SbBool isCameraHeightAnglePreserved() const
00301 {return m_preserveHeightAngle; }
00302
00307 virtual void enableSeekWithOrtho(SbBool flag)
00308 {m_seekWithOrtho = flag; }
00309
00314 virtual SbBool isSeekWithOrthoEnabled() const
00315 {return m_seekWithOrtho; }
00316
00317
00322 virtual void viewAll();
00326 virtual void saveHomePosition();
00330 virtual void resetToHomePosition();
00331
00336 void setCameraTypeChangeCallback(SoWinMPViewerCameraTypeChangeCB *callback,
00337 void *userdata);
00338
00342 void setHeadlight(SbBool onOrOff);
00346 SbBool isHeadlight() { return headlightFlag; }
00350 SoDirectionalLight *getHeadlight() { return headlightNode; }
00351
00393 void setDrawStyle(SoWinMPViewer::DrawType type,
00394 SoWinMPViewer::DrawStyle style);
00398 SoWinMPViewer::DrawStyle getDrawStyle(SoWinMPViewer::DrawType type);
00399
00404 void setBufferingType(SoWinMPViewer::BufferType type);
00408 SoWinMPViewer::BufferType getBufferingType() { return bufferType; }
00409
00410
00411 virtual void setDoubleBuffer(SbBool onOrOff);
00424 virtual void setViewing(SbBool onOrOff);
00428 SbBool isViewing() const { return viewingFlag; };
00429
00440 virtual void setCursorEnabled(SbBool onOrOff);
00445 SbBool isCursorEnabled() const { return cursorEnabledFlag; }
00446
00452 void setAutoClipping(SbBool onOrOff);
00456 SbBool isAutoClipping() const { return autoClipFlag; }
00457
00483
00488
00492
00496
00497
00505 void setDetailSeek(SbBool onOrOff) { detailSeekFlag = onOrOff; };
00509 SbBool isDetailSeek() { return detailSeekFlag; }
00510
00520 void setSeekTime(float seconds) { seekAnimTime = seconds; }
00524 float getSeekTime() { return seekAnimTime; }
00525
00534 void addStartCallback(SoWinMPViewerCB *f, void *userData = NULL)
00535 { startCBList->addCallback((SoCallbackListCB *)f, userData); }
00536
00545 void addFinishCallback(SoWinMPViewerCB *f, void *userData = NULL)
00546 { finishCBList->addCallback((SoCallbackListCB *)f, userData); }
00547
00553 void removeStartCallback(SoWinMPViewerCB *f, void *userData = NULL)
00554 { startCBList->removeCallback((SoCallbackListCB *)f, userData); }
00555
00561 void removeFinishCallback(SoWinMPViewerCB *f, void *userData = NULL)
00562 { finishCBList->removeCallback((SoCallbackListCB *)f, userData); }
00563
00569 void copyView(Time eventTime);
00575 void pasteView(Time eventTime);
00576
00577
00578
00579 virtual void setNormalVisual(XVisualInfo *);
00580
00587 virtual void recomputeSceneSize();
00588
00589
00590
00591
00595 void setDecimationStrategy(DecimationStrategy strategy);
00599 DecimationStrategy getDecimationStrategy() { return decStrategy; };
00600
00604 void setGoalNumberOfTriangles(int32_t goal);
00608 int32_t getGoalNumberOfTriangles() { return goalTris; };
00609
00613 void setGoalFramesPerSecond(float goal);
00617 float getGoalFramesPerSecond() { return goalFps; };
00618
00622 void setFixedPercentage(float percent);
00626 float getFixedPercentage() { return decPercentage; };
00627
00632 void enableFullRenderingWhenStill(SbBool onOff);
00637 SbBool isFullRenderingWhenStill() { return doFullRendering; };
00638
00642 SbBool isStillNow() { return isStill; };
00643
00647 void setFramesPerSecondCallback(SoWinMPViewerFPSCB *callback,
00648 void *userData = NULL);
00649
00654 void setNumSamples(int numFrames);
00659 int getNumSamples() { return numSamples; };
00660
00664 void setDecimationPercentageCallback(SoWinMPViewerDecimationPercentageCB *callback,
00665 void *userData = NULL);
00666
00670 float getCurrentDecimationPercentage();
00671
00675 void insertSceneTransform(void);
00676
00680 SoTransform * getSceneTransform(void);
00681
00685 SoTransform * getWandTransform(void);
00686
00690 void setWandGeometryFile(SbString wandFile);
00691
00696 void setHeadTracking(int value);
00697
00698 virtual void navigate(void);
00699
00700
00701
00702 public:
00703 HDC getCurrentDC( int id );
00704
00719 virtual void setCursorStyle( SoWinMPViewer::CursorStyle style );
00723 SoWinMPViewer::CursorStyle getCursorStyle() { return cursorStyle; };
00724
00734 virtual void toggleCameraType();
00735
00736 #if 1 SoDEPRECATED
00739 HDC getCurrentDC();
00740
00741 #endif
00743 private:
00744 virtual ~SoWinMPViewer();
00745
00746
00747 void useWand(SbBool flag)
00748 { addWandGroup = flag;};
00749
00750 private:
00751
00752 SoWinMPViewer(SoWidget parent,
00753 const char *name,
00754 SbBool buildInsideParent,
00755 Type type,
00756 SbBool buildNow);
00757
00758
00759 SoWinMPViewer::Type type;
00760 SoCamera *camera;
00761 SbBool viewingFlag;
00762 SbBool m_preserveHeightAngle;
00763 float m_previousHeightAngle;
00764
00765
00766 SbBool altSwitchBack;
00767 SbBool cursorEnabledFlag;
00768 static SoSFTime *viewerRealTime;
00769 float sceneSize;
00770 float viewerSpeed;
00771
00772
00773
00774
00775
00776
00777
00778 SoWinMPViewer::CursorStyle cursorStyle;
00779
00780
00781
00782
00783
00784
00785 SbBool createdCursors;
00786 HCURSOR normalCursor,
00787 dollyCursor, panCursor, rollCursor, seekCursor,
00788 spinCursor, upCursor, flyCursor, walkCursor;
00789
00790
00791
00792
00793
00794 virtual void defineCursors();
00795
00796
00797
00798 virtual void updateCursor() {};
00799
00800 #ifdef __sgi
00801
00802
00803 SbBool useSGIStereoExt;
00804 #endif
00805
00806
00807 SoSeparator *sceneRoot;
00808 SoNode *sceneGraph;
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 SbBool processCommonEvents(XAnyEvent *xe);
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832 void interactiveCountInc();
00833 void interactiveCountDec();
00834 int getInteractiveCount() { return interactiveCount; }
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 SbBool seekToPoint(const SbVec2s &mouseLocation);
00847
00848
00849
00850
00851
00852
00853
00854
00855 virtual void interpolateSeekAnimation(float t);
00856 virtual void computeSeekFinalOrientation();
00857
00858
00859 float seekDistance;
00860 SbBool seekDistAsPercentage;
00861 SbBool computeSeekVariables;
00862 SbVec3f seekPoint, seekNormal;
00863 SbRotation oldCamOrientation, newCamOrientation;
00864 SbVec3f oldCamPosition, newCamPosition;
00865
00866
00867
00868
00869
00870
00871 virtual void setSeekMode(SbBool onOrOff);
00872 SbBool isSeekMode() { return seekModeFlag; }
00873
00874
00875
00876
00877 virtual void prepareRedraw();
00878 virtual void actualRedraw();
00879 virtual void endRedraw();
00880
00881
00882
00883
00884 virtual void changeCameraValues(SoCamera *newCamera);
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898 static void setFeedbackOrthoProjection(const SbVec2s &glxSize);
00899
00900
00901 static void restoreGLStateAfterFeedback();
00902
00903 static void drawViewerCrossFeedback(SbVec2s loc);
00904
00905 static void drawViewerRollFeedback(SbVec2s center, SbVec2s loc);
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915 virtual void widgetChanged(SoWidget);
00916
00917
00918 virtual void afterRealizeHook();
00919
00920
00921 SbBool autoClipFlag;
00922 float minimumNearPlane;
00923 SoGetBoundingBoxAction *autoClipBboxAction;
00924 virtual void adjustCameraClippingPlanes();
00925
00926
00927
00928
00929 virtual void redraw();
00930
00931
00932
00933
00934
00935
00936
00937 virtual float decimationForFramesPerSecond(float fps,
00938 double timeTaken, float decimation);
00939
00940
00941
00942
00943
00944 virtual float decimationForNumTriangles(uint32_t numTris);
00945
00946 SbBool m_seekWithOrtho;
00947
00948
00949
00950 private:
00951
00952 SoType cameraType;
00953 BufferType bufferType;
00954 SbBool interactiveFlag;
00955
00956
00957 DrawStyle stillDrawStyle, interactiveDrawStyle;
00958 SbBool checkForDrawStyle;
00959 SoSwitch *drawStyleSwitch;
00960 SoDrawStyle *drawStyleNode;
00961 SoLightModel *lightModelNode;
00962 SoPackedColor *colorNode;
00963
00964 SoMaterialBinding *matBindingNode;
00965
00966 SoComplexity *complexityNode;
00967 void setCurrentDrawStyle(SoWinMPViewer::DrawStyle style);
00968 void doRendering();
00969
00970
00971 SoWinClipboard *clipboard;
00972 static void pasteDoneCB(void *userData, SoPathList *pathList);
00973
00974
00975 SbBool createdCamera;
00976 SbVec3f origPosition;
00977 SbRotation origOrientation;
00978 float origNearDistance;
00979 float origFarDistance;
00980 float origFocalDistance;
00981 float origHeight;
00982
00983
00984 SbBool seekModeFlag;
00985 SoFieldSensor *seekAnimationSensor;
00986 SbBool detailSeekFlag;
00987 float seekAnimTime;
00988 SbTime seekStartTime;
00989 static void seekAnimationSensorCB(void *p, SoSensor *);
00990
00991
00992 SoFieldSensor *headlightSensor;
00993 SoDirectionalLight *headlightNode;
00994 SoGroup *headlightGroup;
00995 SoRotation *headlightRot;
00996 SbBool headlightFlag;
00997 static void headlightSensorCB(void *, SoSensor *);
00998
00999
01000 int interactiveCount;
01001 SoCallbackList *startCBList;
01002 SoCallbackList *finishCBList;
01003 static void drawStyleStartCallback(void *, SoWinMPViewer *v);
01004 static void drawStyleFinishCallback(void *, SoWinMPViewer *v);
01005 static void bufferStartCallback(void *, SoWinMPViewer *v);
01006 static void bufferFinishCallback(void *, SoWinMPViewer *v);
01007
01008
01009 static void visibilityChangeCB(void *pt, SbBool visible);
01010
01011
01012 void setZbufferState();
01013 SbBool isZbufferOff();
01014 void arrowKeyPressed(KeySym key);
01015
01016
01017 DecimationStrategy decStrategy;
01018 int32_t goalTris;
01019 float goalFps;
01020 float decPercentage;
01021 float lastDecimationValue;
01022 double lastRenderTime;
01023 int lastDirection;
01024 SoGetPrimitiveCountAction *primCountAction, *userCountAction;
01025 SbBool isStill, doFullRendering;
01026 SoAlarmSensor *stillSensor;
01027 static void alarmCB(void* thisp, SoSensor*)
01028 { ((SoWinMPViewer*)thisp)->stillSensorCalled(); };
01029 void stillSensorCalled();
01030 SoNodeSensor *motionSensor;
01031 static void changeCB(void* thisp, SoSensor*)
01032 { ((SoWinMPViewer*)thisp)->changeSensorCalled(); };
01033 void changeSensorCalled();
01034
01035
01036 SoWinMPViewerCameraTypeChangeCB *viewerCameraTypeChangeCallback;
01037 void *viewerCameraTypeChangeCallbackUserData;
01038
01039
01040 int numSamples, curNumSamples;
01041 double curTotalTime;
01042 SoWinMPViewerFPSCB *fpsUserCallback;
01043 void *fpsUserData;
01044
01045
01046 SoWinMPViewerDecimationPercentageCB *decimationUserCallback;
01047 void *decimationUserData;
01048
01049
01050
01051 SbBool isWinRedrawing;
01052
01053
01054
01055
01056 SoTransform * sceneTransform;
01057
01058 SbBool addSceneTransform;
01059
01060
01061 SoSeparator * wandGroup;
01062 SoTransform * wandTransform;
01063 SoSeparator * wandGeometry;
01064 static const char * defaultWandGeometry;
01065 SbString wandFileStr;
01066 SbBool addWandGroup;
01067 void createWandGroup(void);
01068 void insertWandGroup(void);
01069
01070 void scaleScene(SoNode * scene);
01071 };
01072
01073 #if defined(_WIN32)
01074 # include <Inventor/Win/SoWinEndStrict.h>
01075 #endif
01076
01077 #endif
01078
01079