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 #if defined(_WIN32)
00026 # include <Inventor/MP/Win/viewers/SoWinMPViewer.h>
00027 #else // _WIN32
00028
00029 #ifndef _SO_XT_MP_VIEWER_
00030 #define _SO_XT_MP_VIEWER_
00031
00032 #include <Inventor/SoType.h>
00033 #include <Inventor/MP/Xt/SoXtMPRenderArea.h>
00034 #include <Inventor/misc/SoCallbackList.h>
00035 #include <Inventor/SbElapsedTime.h>
00036
00037
00038 class SoNode;
00039 class SoDirectionalLight;
00040 class SoGroup;
00041 class SoRotation;
00042 class SoCamera;
00043 class SoDrawStyle;
00044 class SoLightModel;
00045 class SoFieldSensor;
00046 class SoXtClipboard;
00047 class SoXtMPViewer;
00048 class SoGetBoundingBoxAction;
00049 class SbPList;
00050 class SoSeparator;
00051 class SoSwitch;
00052 class SoComplexity;
00053 class SoPackedColor;
00054 class SoMaterialBinding;
00055 class SoSFTime;
00056 class SoXtInputFocus;
00057 class SoAlarmSensor;
00058 class SoNodeSensor;
00059 class SoGetPrimitiveCountAction;
00060 class SoStereoViewer;
00061 class SoBaseStereo;
00062 class SoTransform;
00063
00064
00065 typedef void SoXtMPViewerCB(void *userData, SoXtMPViewer *viewer);
00066 typedef void SoXtMPViewerCameraTypeChangeCB(void *userData, SoCamera *camera, SoXtMPViewer *viewer);
00067
00068
00069
00070 typedef void SoXtMPViewerFPSCB(float fps, void *userData, SoXtMPViewer *viewer);
00071 typedef void SoXtMPViewerDecimationPercentageCB(float percentage, void *userData, SoXtMPViewer *viewer);
00072
00074
00075
00076
00077
00078
00079
00080
00082
00152 class SoXtMPViewer : public SoXtMPRenderArea
00153 {
00154 public:
00155
00166 enum Type {
00170 BROWSER,
00174 EDITOR
00175 };
00176
00183 enum DrawStyle {
00187 VIEW_AS_IS,
00191 VIEW_HIDDEN_LINE,
00195 VIEW_NO_TEXTURE,
00199 VIEW_LOW_COMPLEXITY,
00203 VIEW_LINE,
00207 VIEW_POINT,
00211 VIEW_BBOX,
00215 VIEW_LOW_RES_LINE,
00219 VIEW_LOW_RES_POINT,
00223 VIEW_SAME_AS_STILL
00224 };
00225
00227 enum DrawType {
00231 STILL,
00235 INTERACTIVE
00236 };
00237
00239 enum BufferType {
00243 BUFFER_SINGLE,
00247 BUFFER_DOUBLE,
00251 BUFFER_INTERACTIVE
00252 };
00253
00255 enum DecimationStrategy {
00259 NORMAL,
00263 FIXED_NUM_TRIANGLES,
00267 FRAMES_PER_SECOND,
00271 FIXED_PERCENTAGE
00272 };
00273
00279 virtual void setSceneGraph(SoNode *newScene);
00283 virtual SoNode *getSceneGraph();
00284
00290 virtual void setCamera(SoCamera *cam);
00294 SoCamera *getCamera() { return camera; }
00295
00304 virtual void setCameraType(SoType type);
00309 SoType getCameraType() { return cameraType; }
00310
00316 virtual void setPreserveCameraHeightAngle(SbBool flag)
00317 {m_preserveHeightAngle = flag; }
00318
00324 virtual SbBool isCameraHeightAnglePreserved() const
00325 {return m_preserveHeightAngle; }
00326
00331 virtual void enableSeekWithOrtho(SbBool flag)
00332 {m_seekWithOrtho = flag; }
00333
00338 virtual SbBool isSeekWithOrthoEnabled() const
00339 {return m_seekWithOrtho; }
00340
00345 virtual void viewAll();
00349 virtual void saveHomePosition();
00353 virtual void resetToHomePosition();
00354
00359 void setCameraTypeChangeCallback(SoXtMPViewerCameraTypeChangeCB *callback,
00360 void *userdata);
00361
00365 virtual void setHeadlight(SbBool onOrOff);
00369 SbBool isHeadlight() { return headlightFlag; }
00373 SoDirectionalLight *getHeadlight() { return headlightNode; }
00374
00416 virtual void setDrawStyle(SoXtMPViewer::DrawType type,
00417 SoXtMPViewer::DrawStyle style);
00421 SoXtMPViewer::DrawStyle getDrawStyle(SoXtMPViewer::DrawType type);
00422
00427 virtual void setBufferingType( SoXtMPViewer::BufferType type);
00431 SoXtMPViewer::BufferType getBufferingType() { return bufferType; }
00444 virtual void setViewing(SbBool onOrOff);
00448 SbBool isViewing() const { return viewingFlag; };
00449
00460 virtual void setCursorEnabled(SbBool onOrOff);
00465 SbBool isCursorEnabled() const { return cursorEnabledFlag; }
00466
00473 void setAutoClipping(SbBool onOrOff);
00477 SbBool isAutoClipping() const { return autoClipFlag; }
00478
00486
00491
00492
00500 void setDetailSeek(SbBool onOrOff) { detailSeekFlag = onOrOff; };
00504 SbBool isDetailSeek() { return detailSeekFlag; }
00505
00510 void setSeekTime(float seconds) { seekAnimTime = seconds; }
00514 float getSeekTime() { return seekAnimTime; }
00515
00524 void addStartCallback(SoXtMPViewerCB *f, void *userData = NULL)
00525 { startCBList->addCallback((SoCallbackListCB *)f, userData); }
00534 void addFinishCallback(SoXtMPViewerCB *f, void *userData = NULL)
00535 { finishCBList->addCallback((SoCallbackListCB *)f, userData); }
00541 void removeStartCallback(SoXtMPViewerCB *f, void *userData = NULL)
00542 { startCBList->removeCallback((SoCallbackListCB *)f, userData); }
00548 void removeFinishCallback(SoXtMPViewerCB *f, void *userData = NULL)
00549 { finishCBList->removeCallback((SoCallbackListCB *)f, userData); }
00550
00556 void copyView(Time eventTime);
00562 void pasteView(Time eventTime);
00563
00570 virtual void recomputeSceneSize();
00571
00572
00573
00577 void setDecimationStrategy(DecimationStrategy strategy);
00581 DecimationStrategy getDecimationStrategy() {return decStrategy; };
00582
00586 void setGoalNumberOfTriangles(int32_t goal);
00590 int32_t getGoalNumberOfTriangles() { return goalTris; };
00591
00595 void setGoalFramesPerSecond(float goal);
00599 float getGoalFramesPerSecond() { return goalFps; };
00600
00604 void setFixedPercentage(float percent);
00608 float getFixedPercentage() { return decPercentage; };
00609
00614 void enableFullRenderingWhenStill(SbBool onOff);
00619 SbBool isFullRenderingWhenStill() { return doFullRendering; };
00620
00624 SbBool isStillNow() { return isStill; };
00625
00629 void setFramesPerSecondCallback(SoXtMPViewerFPSCB *callback,
00630 void *userData = NULL);
00631
00636 void setNumSamples(int numFrames);
00641 int getNumSamples() { return numSamples; };
00642
00646 void setDecimationPercentageCallback(
00647 SoXtMPViewerDecimationPercentageCB *callback,
00648 void *userData = NULL);
00649
00653 float getCurrentDecimationPercentage();
00654
00658
00659
00663 void insertSceneTransform(void);
00664
00668 SoTransform * getSceneTransform(void);
00669
00673 SoTransform * getWandTransform(void);
00674
00678 void setWandGeometryFile(SbString wandFile);
00679
00684 void setHeadTracking(int value);
00685
00686 virtual void navigate(void);
00687
00688
00689 private:
00690 virtual ~SoXtMPViewer();
00691
00692
00693 virtual void setDoubleBuffer(SbBool onOrOff);
00694
00695
00696
00697 virtual void setNormalVisual(XVisualInfo *);
00698
00699
00700
00701 void useWand(SbBool flag)
00702 { addWandGroup = flag;};
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728 public:
00735 void setAutoClipTolerance ( float tolerance ) {
00736 minimumNearPlane = tolerance; };
00737
00741 float getAutoClipTolerance () const
00742 { return minimumNearPlane; };
00743
00744 SoNode * getViewAllScene() { return viewAllScene;}
00745 void setViewAllScene(SoNode* node)
00746 {
00747 viewAllScene = node;
00748 }
00749
00759 virtual void toggleCameraType();
00760
00761 private:
00762
00763 SbBool m_preserveHeightAngle;
00764 float m_previousHeightAngle;
00765 SbBool m_seekWithOrtho;
00766
00767
00768 SoXtMPViewer(SoWidget parent,
00769 const char *name,
00770 SbBool buildInsideParent,
00771 Type type,
00772 SbBool buildNow);
00773
00774
00775 SoXtMPViewer::Type type;
00776 SoCamera *camera;
00777 SbBool viewingFlag;
00778 SbBool altSwitchBack;
00779 SbBool cursorEnabledFlag;
00780 static SoSFTime *viewerRealTime;
00781 float sceneSize;
00782 float viewerSpeed;
00783
00784
00785 SoSeparator *sceneRoot;
00786 SoNode *sceneGraph;
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 SbBool processCommonEvents(XAnyEvent *xe);
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 void interactiveCountInc();
00811 void interactiveCountDec();
00812 int getInteractiveCount() { return interactiveCount; }
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 SbBool seekToPoint(const SbVec2s &mouseLocation);
00825
00826
00827
00828
00829
00830
00831
00832
00833 virtual void interpolateSeekAnimation(float t);
00834 virtual void computeSeekFinalOrientation();
00835
00836
00837 float seekDistance;
00838 SbBool seekDistAsPercentage;
00839 SbBool computeSeekVariables;
00840 SbVec3f seekPoint, seekNormal;
00841 SbRotation oldCamOrientation, newCamOrientation;
00842 SbVec3f oldCamPosition, newCamPosition;
00843
00844
00845
00846
00847
00848
00849 virtual void setSeekMode(SbBool onOrOff);
00850 SbBool isSeekMode() { return seekModeFlag; }
00851
00852
00853
00854
00855 virtual void prepareRedraw();
00856 virtual void actualRedraw();
00857 virtual void endRedraw();
00858
00859
00860
00861
00862 virtual void changeCameraValues(SoCamera *newCamera);
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876 static void setFeedbackOrthoProjection(const SbVec2s &glxSize);
00877
00878
00879 static void restoreGLStateAfterFeedback();
00880
00881 static void drawViewerCrossFeedback(SbVec2s loc);
00882
00883 static void drawViewerRollFeedback(SbVec2s center, SbVec2s loc);
00884
00885
00886 virtual void afterRealizeHook();
00887
00888
00889 SbBool autoClipFlag;
00890 float minimumNearPlane;
00891 SoGetBoundingBoxAction *autoClipBboxAction;
00892 virtual void adjustCameraClippingPlanes();
00893
00894
00895
00896 virtual void redraw();
00897
00898
00899
00900
00901
00902
00903
00904 virtual float decimationForFramesPerSecond(float fps,
00905 double timeTaken,
00906 float decimation);
00907
00908
00909
00910
00911
00912 virtual float decimationForNumTriangles(uint32_t numTris);
00913
00914 private:
00915
00916 SoType cameraType;
00917 BufferType bufferType;
00918 SbBool interactiveFlag;
00919 SoXtInputFocus *inputFocus;
00920
00921
00922
00923
00924
00925
00926 SoNode * viewAllScene;
00927
00928
00929 DrawStyle stillDrawStyle, interactiveDrawStyle;
00930 SbBool checkForDrawStyle;
00931 SoSwitch *drawStyleSwitch;
00932 SoDrawStyle *drawStyleNode;
00933 SoLightModel *lightModelNode;
00934 SoPackedColor *colorNode;
00935 SoMaterialBinding *matBindingNode;
00936 SoComplexity *complexityNode;
00937 void setCurrentDrawStyle(SoXtMPViewer::DrawStyle style);
00938 void doRendering();
00939
00940
00941 SoXtClipboard *clipboard;
00942 static void pasteDoneCB(void *userData, SoPathList *pathList);
00943
00944
00945 SbBool createdCamera;
00946 SbVec3f origPosition;
00947 SbRotation origOrientation;
00948 float origNearDistance;
00949 float origFarDistance;
00950 float origFocalDistance;
00951 float origHeight;
00952
00953
00954 SbBool seekModeFlag;
00955 SoFieldSensor *seekAnimationSensor;
00956 SbBool detailSeekFlag;
00957 float seekAnimTime;
00958 SbTime seekStartTime;
00959 static void seekAnimationSensorCB(void *p, SoSensor *);
00960
00961
00962 SoDirectionalLight *headlightNode;
00963 SoGroup *headlightGroup;
00964 SoRotation *headlightRot;
00965 SbBool headlightFlag;
00966
00967
00968 int interactiveCount;
00969 SoCallbackList *startCBList;
00970 SoCallbackList *finishCBList;
00971 static void drawStyleStartCallback(void *, SoXtMPViewer *v);
00972 static void drawStyleFinishCallback(void *, SoXtMPViewer *v);
00973 static void bufferStartCallback(void *, SoXtMPViewer *v);
00974 static void bufferFinishCallback(void *, SoXtMPViewer *v);
00975
00976
00977 void setZbufferState();
00978 SbBool isZbufferOff();
00979 void arrowKeyPressed(KeySym key);
00980
00981
00982 DecimationStrategy decStrategy;
00983 int32_t goalTris;
00984 float goalFps;
00985 float decPercentage;
00986 float lastDecimationValue;
00987 int lastDirection;
00988 double lastRenderTime;
00989 SoGetPrimitiveCountAction *primCountAction;
00990 static SoGLRenderAction::AbortCode renderAbortCB(void *data);
00991 SbBool isStill, doFullRendering;
00992 SoAlarmSensor *stillSensor;
00993 static void alarmCB(void* thisp, SoSensor*) { ((SoXtMPViewer*)thisp)->stillSensorCalled(); };
00994 void stillSensorCalled();
00995 SoNodeSensor *motionSensor;
00996 static void changeCB(void* thisp, SoSensor*) { ((SoXtMPViewer*)thisp)->changeSensorCalled(); };
00997 void changeSensorCalled();
00998
00999
01000 SoXtMPViewerCameraTypeChangeCB *viewerCameraTypeChangeCallback;
01001 void *viewerCameraTypeChangeCallbackUserData;
01002
01003
01004 int numSamples, curNumSamples;
01005 double curTotalTime;
01006 SoXtMPViewerFPSCB *fpsUserCallback;
01007 void *fpsUserData;
01008 SbElapsedTime fpsTimer;
01009
01010
01011 SoXtMPViewerDecimationPercentageCB *decimationUserCallback;
01012 void *decimationUserData;
01013
01014
01015
01016
01017 SoTransform * sceneTransform;
01018
01019 SbBool addSceneTransform;
01020
01021
01022 SoSeparator * wandGroup;
01023 SoTransform * wandTransform;
01024 SoSeparator * wandGeometry;
01025 static const char * defaultWandGeometry;
01026 SbString wandFileStr;
01027 SbBool addWandGroup;
01028 void createWandGroup(void);
01029 void insertWandGroup(void);
01030
01031 void scaleScene(SoNode * scene);
01032
01033 private:
01034 void * getViewer() {return (void*) this;}
01035
01036
01037 };
01038
01039 #endif
01040
01041 #endif // _WIN32
01042
01043
01044