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_RENDER_AREA_H_
00027 #define _SO_WIN_MP_RENDER_AREA_H_
00028
00029 #if defined(_WIN32)
00030 # include <Inventor/Win/SoWinBeginStrict.h>
00031 # include <windows.h>
00032 # ifdef _SO_QT_
00033 # include <wingdi.h>
00034 # else
00035 # include <Inventor/Win/SoWinDef.h>
00036 # endif
00037 #else
00038 # include <X11/Intrinsic.h>
00039 # include <X11/Xlib.h>
00040 #endif // _WIN32
00041
00042 #include <Inventor/SbColor.h>
00043 #include <Inventor/sensors/SoNodeSensor.h>
00044 #include <Inventor/SoSceneManager.h>
00045 #include <Inventor/MP/Win/SoWinMPGLWidget.h>
00046 #include <Inventor/actions/SoGLRenderAction.h>
00047 #include <Inventor/threads/SbThreadBarrier.h>
00048 #include <Inventor/threads/SbThread.h>
00049
00050 #include <Inventor/nodes/SoCamera.h>
00051 #include <Inventor/components/stereo/SoStereoViewer.h>
00052 #include <Inventor/sensors/SoTimerSensor.h>
00053
00054 class SoHandleEventAction;
00055 class SoWinDevice;
00056 class SoNode;
00057 class SoWinMouse;
00058 class SoWinKeyboard;
00059 class SoSelection;
00060
00061
00062 typedef SbBool SoWinMPRenderAreaEventCB(void *userData, XAnyEvent *anyevent);
00063
00064
00065 class SoWinMPRenderArea;
00066
00067 typedef void SoWinMPRenderAreaThreadInitCB(void * userData, SoWinMPRenderArea *ra);
00068
00069
00070 typedef void SoWinMPRenderAreaThreadRenderCB(void * userData, SoWinMPRenderArea *ra);
00071
00073
00074
00075
00076
00077
00079
00137 class SoWinMPRenderArea : public SoWinMPGLWidget, public SoStereoViewer {
00138 public:
00148 SoWinMPRenderArea(SoWidget parent = NULL,
00149 const char *name = NULL,
00150 SbBool buildInsideParent = TRUE,
00151 SbBool getMouseInput = TRUE,
00152 SbBool getKeyboardInput = TRUE);
00153
00157 ~SoWinMPRenderArea();
00158
00162 virtual void setSceneGraph(SoNode *newScene);
00166 virtual SoNode * getSceneGraph();
00167
00173 void registerDevice(SoWinDevice *d);
00179 void unregisterDevice(SoWinDevice *d);
00180
00188 void setBackgroundColor(const SbColor &c)
00189 { sceneMgr->setBackgroundColor(c); }
00193 const SbColor & getBackgroundColor() const
00194 { return sceneMgr->getBackgroundColor(); }
00195
00200 void setBackgroundIndex(int index)
00201 { sceneMgr->setBackgroundIndex(index); }
00205 int getBackgroundIndex() const
00206 { return sceneMgr->getBackgroundIndex(); }
00207
00212 void setColorMap(int startIndex, int num, const SbColor *colors);
00213
00214
00218 void setViewportRegion(const SbViewportRegion &newRegion, int id)
00219 { sceneMgr->getGLRenderAction(id)->setViewportRegion(newRegion); }
00223 const SbViewportRegion &getViewportRegion(int id) const
00224 { return sceneMgr->getGLRenderAction(id)->getViewportRegion(); }
00228 void setViewportRegion(const SbViewportRegion &newRegion);
00232 const SbViewportRegion &getViewportRegion() const
00233 { return sceneMgr->getGLRenderAction(0)->getLogicalViewportRegion(); }
00234
00239 void setTransparencyType(SoGLRenderAction::TransparencyType type);
00244 SoGLRenderAction::TransparencyType getTransparencyType() const
00245 { return sceneMgr->getGLRenderAction()->getTransparencyType(); }
00246
00254 void setClearBeforeRender(SbBool trueOrFalse,
00255 SbBool zbTrueOrFalse = TRUE)
00256 { clearFirst = trueOrFalse;
00257 clearZBufferFirst = zbTrueOrFalse; }
00261 SbBool isClearBeforeRender() const
00262 { return clearFirst; }
00267 SbBool isClearZBufferBeforeRender() const
00268 { return clearZBufferFirst; }
00269
00277 void setAutoRedraw(SbBool trueOrFalse);
00282 SbBool isAutoRedraw() const { return autoRedraw; }
00283
00287 void setRedrawPriority(unsigned long priority)
00288 { sceneMgr->setRedrawPriority(priority);
00289 overlaySceneMgr->setRedrawPriority(priority); }
00293 unsigned long getRedrawPriority() const
00294 { return sceneMgr->getRedrawPriority(); }
00298 static unsigned long getDefaultRedrawPriority()
00299 { return SoSceneManager::getDefaultRedrawPriority(); }
00300
00305 void render() { redraw(); }
00306
00311 void scheduleRedraw();
00312
00319 void redrawOnSelectionChange(SoSelection *s);
00320
00332 void setEventCallback(
00333 SoWinMPRenderAreaEventCB *fcn,
00334 void *userData = NULL)
00335 { appEventHandler = fcn; appEventHandlerData = userData; }
00336
00343 void setSceneManager(SoSceneManager *sm);
00350 SoSceneManager * getSceneManager() const { return sceneMgr; }
00351
00357 void setGLRenderAction(SoGLRenderAction *ra)
00358 {
00359 sizeChanged(SbVec2s(166,363));
00360 sceneMgr->setGLRenderAction(ra);
00361 }
00367 SoGLRenderAction *getGLRenderAction() const
00368 { return sceneMgr->getGLRenderAction(); }
00374 void setGLRenderAction(SoGLRenderAction *ra, int i)
00375 { sceneMgr->setGLRenderAction(ra, i); }
00379 SoGLRenderAction *getGLRenderAction(int i) const
00380 { return sceneMgr->getGLRenderAction(i); }
00381
00382 #if 1 SoDEPRECATED
00388 void setOverlaySceneGraph( SoNode *newScene );
00389 SoDEPRECATED
00395 SoNode* getOverlaySceneGraph() { return overlaySceneMgr->getSceneGraph(); }
00396 SoDEPRECATED
00402 void setOverlayBackgroundIndex( int index ) { overlaySceneMgr->setBackgroundIndex( index ); }
00403 SoDEPRECATED
00408 int getOverlayBackgroundIndex() const { return overlaySceneMgr->getBackgroundIndex(); }
00409 SoDEPRECATED
00415 void setOverlayColorMap( int startIndex, int num, const SbColor *colors );
00416 SoDEPRECATED
00422 void setClearBeforeOverlayRender( SbBool trueOrFalse ) { clearOverlayFirst = trueOrFalse; }
00423 SoDEPRECATED
00428 SbBool isClearBeforeOverlayRender() const { return clearOverlayFirst; }
00429 SoDEPRECATED
00435 void renderOverlay();
00436 SoDEPRECATED
00442 void scheduleOverlayRedraw();
00443 SoDEPRECATED
00451 void redrawOverlayOnSelectionChange( SoSelection *s );
00452 SoDEPRECATED
00460 void setOverlaySceneManager( SoSceneManager *sm ) { overlaySceneMgr = sm; }
00461 SoDEPRECATED
00469 SoSceneManager* getOverlaySceneManager() const { return overlaySceneMgr; }
00470 SoDEPRECATED
00475 void setOverlayGLRenderAction(SoGLRenderAction *ra) { overlaySceneMgr->setGLRenderAction(ra); }
00476 SoDEPRECATED
00481 SoGLRenderAction* getOverlayGLRenderAction() const { return overlaySceneMgr->getGLRenderAction(); }
00482 #endif
00487 SoTimerSensor * getTrackerSensor()
00488 { return trackerSensor; }
00489
00494 void setInterEyeDistance(float value)
00495 { interEyeDistance = value;}
00496
00500 float getInterEyeDistance(void)
00501 { return interEyeDistance;}
00502
00503
00504 int changeZbuffer;
00505
00509 void setStereoOffset(float dist) { stereoOffset = dist; scheduleRedraw() ;}
00513 float getStereoOffset() { return stereoOffset; }
00514
00516 virtual SoGLContext* getViewerContext() { return getNormalContext(); }
00517
00519 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
00520
00521 #if 1 SoDEPRECATED
00538 void setAntialiasing(SbBool smoothing, int numPasses);
00539 SoDEPRECATED
00544 void getAntialiasing(SbBool &smoothing, int &numPasses) const;
00545
00546 #endif
00548 private:
00549
00550
00551
00552
00553
00554
00555 SoWinMPRenderArea(SoWidget parent,
00556 const char *name,
00557 SbBool buildInsideParent,
00558 SbBool getMouseInput,
00559 SbBool getKeyboardInput,
00560 SbBool buildNow);
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 void partialRedraw(int id);
00571 #if 1 SoDEPRECATED
00573 void partialRedrawOverlay( int id );
00574 #endif
00576 void swapBuffers(int);
00577
00578
00579 virtual void redraw();
00580 virtual void prepareRedraw();
00581 virtual void actualRedraw();
00582 virtual void endRedraw();
00583
00584 #if 1
00585 // drawing functions for the overlay layer
00586 SoDEPRECATED
00587 virtual void redrawOverlay();SoDEPRECATED
00589 virtual void prepareOverlayRedraw();SoDEPRECATED
00591 virtual void actualOverlayRedraw();SoDEPRECATED
00593 virtual void endOverlayRedraw();
00594 #endif
00596 //
00597
00598
00599 virtual void processEvent(XAnyEvent *anyevent);
00600 virtual void initGraphic();
00601 #if 1 SoDEPRECATED
00603 virtual void initOverlayGraphic();
00604 #endif
00606 virtual void sizeChanged(const SbVec2s &newSize);
00607 virtual void widgetChanged(SoWidget);
00608
00609 virtual void initViewportRegion(int);
00610
00611
00612 SoWidget buildWidget(SoWidget parent);
00613
00614
00615 virtual SbString getDefaultWidgetName() const;
00616 virtual SbString getDefaultTitle() const;
00617 virtual SbString getDefaultIconTitle() const;
00618
00619
00620 SbPList *deviceList;
00621
00622
00623 SoWinMPRenderAreaEventCB *appEventHandler;
00624 void *appEventHandlerData;
00625
00626 SbBool invokeAppCB(XAnyEvent *anyevent);
00627
00628
00629 void setDepthRange(float,float);
00630 float zNear;
00631 float zFar;
00632 void changeDepthRange(void);
00633 SbBool drawHiddenLineMode;
00634 void setHiddenLineSwap(SbBool);
00635 SbBool hiddenLineSwap;
00636
00637
00638 SbBool stereoAbsoluteAdjustments;
00639 float stereoOffset;
00640 float stereoBalance;
00641 SbBool stereoNearFrac;
00642 SoCamera::StereoMode stereoMode;
00643 float interEyeDistance;
00644
00645 private:
00646 void setDoSwapBuffers(SbBool);
00647 SbBool doSwapBuffers(void);
00648 void setLeftView(SbBool);
00649 void setRightView(SbBool);
00650 SbBool isLeftViewRendering(void);
00651 SbBool isRightViewRendering(void);
00652
00653 void setStereoMode(SoCamera::StereoMode stMode);
00654
00655 private:
00656
00657 void setModifyViewVolumeElementWall(int id,SoSceneManager * sceneManager);
00658 void setStereoElement(int);
00659
00660
00661 SbBool doSwap;
00662 SbBool doLeftViewRendering;
00663 SbBool doRightViewRendering;
00664
00665 SbThreadBarrier *swapBarrier;
00666
00667 SbThreadBarrier *synchroStartBarrier;
00668 SbThreadBarrier *synchroEndBarrier;
00669
00670 SbThreadBarrier *synchroOverlayStartBarrier;
00671 SbThreadBarrier *synchroOverlayEndBarrier;
00672
00673 {
00674 SoWinMPRenderArea *p;
00675 int id ;
00676 } ThreadFuncStruct ;
00677 ThreadFuncStruct *threadStruct;
00678
00679
00680 static unsigned int WINAPI threadRoutRedraw(LPVOID _userData);
00681 SbThread **threadHandle;
00682
00683 static unsigned int WINAPI threadRoutRedrawOverlay(LPVOID _userData);
00684 SbThread **threadHandleOverlay;
00685
00686
00687
00688 SbBool isRedrawing;
00689
00690
00691 SoSceneManager *sceneMgr;
00692 SoSceneManager *overlaySceneMgr;
00693
00694 SbBool clearFirst, clearOverlayFirst;
00695 SbBool clearZBufferFirst;
00696 SbBool autoRedraw;
00697 XColor *mapColors, *overlayMapColors;
00698 int mapColorNum, overlayMapColorNum;
00699
00700 SoWinMouse *mouseDevice;
00701 SoWinKeyboard *keybdDevice;
00702 void reinstallDevices(SoWidget newWidget);
00703
00704 static void selectionChangeCB(void *userData, SoSelection *s);
00705 static void overlaySelectionChangeCB(void *userData, SoSelection *s);
00706 SoSelection *selection, *overlaySelection;
00707 SoWidget deviceWidget;
00708
00709
00710
00711 SbBool firstEvent;
00712 private:
00713 static void windowEventCB(SoWidget, SoWinMPRenderArea *, XAnyEvent *, Boolean *);
00714 private:
00715 static void renderCB(void *, SoSceneManager *);
00716 static void renderOverlayCB(void *, SoSceneManager *);
00717
00718 static void visibilityChangeCB(void *pt, SbBool visible);
00719 void activate();
00720 void deactivate();
00721
00722
00723 void constructorCommon(
00724 SbBool getMouseInput,
00725 SbBool getKeyboardInput,
00726 SbBool buildNow);
00727 int inRedraw;
00728 int inOverlayRedraw;
00729
00730 void setModifyViewVolume(int, SoSceneManager *);
00731
00732 static SoCallbackList * threadInitCBList;
00733 static SoCallbackList * threadPreRenderCBList;
00734 static SoCallbackList * threadPostRenderCBList;
00735
00736 SbBool stereoActive;
00737 SoTimerSensor * trackerSensor;
00738
00739 public:
00740
00741 static void addThreadInitCB(SoWinMPRenderAreaThreadInitCB * fcn, void *userData);
00742 static void removeThreadInitCB(SoWinMPRenderAreaThreadInitCB * fcn, void *userData);
00743
00744 static void addThreadPreRenderCB(SoWinMPRenderAreaThreadRenderCB * fcn, void *userData);
00745 static void removeThreadPreRenderCB(SoWinMPRenderAreaThreadRenderCB * fcn, void *userData);
00746
00747 static void addThreadPostRenderCB(SoWinMPRenderAreaThreadRenderCB * fcn, void *userData);
00748 static void removeThreadPostRenderCB(SoWinMPRenderAreaThreadRenderCB * fcn, void *userData);
00749
00750
00751
00752 virtual SbBool isViewerDoubleBuffer();
00753 virtual void setStereoViewing(SbBool onOrOff);
00754 virtual SbBool isStereoViewing();
00755 virtual SoCamera * getViewerCamera();
00756 virtual const SbVec2s& getSize();
00757 virtual const SbVec2s& getTopLeft() ;
00758 virtual const SbVec2s& getBottomRight() ;
00759 void setStereoViewType(SoBaseStereo * stereo);
00760 SoBaseStereo * getStereoViewType();
00761 void reverseStereoView(SbBool reverse);
00762 SbBool isStereoViewReversed();
00763 virtual void setStereoAbsoluteAdjustments(SbBool absolute);
00764 virtual SbBool isStereoAbsoluteAdjustments() const {return stereoAbsoluteAdjustments;}
00765 virtual void setStereoBalance(float balance, SbBool nearFrac = false);
00766 virtual float getStereoBalance();
00767 virtual SbBool isStereoBalanceNearFrac();
00768 virtual void setStereoActive(SbBool activate) ;
00769 virtual SbBool isStereoActive() ;
00770 void setViewport(short left, short bottom, short width, short height) ;
00771 void getViewport(short &left, short &bottom, short &width, short &height) ;
00772 void * getViewer(void);
00773 virtual void actualRendering() {}
00774
00775 #if 1 SoDEPRECATED
00778 virtual void adjustClippingPlanes();
00779 SoDEPRECATED
00781 HDC getCurrentDC() {return NULL;}
00782
00783 #endif
00785 private:
00786 SoBaseStereo * stereoViewType;
00787
00788 };
00789
00790 #if defined(_WIN32)
00791 #include <Inventor/Win/SoWinEndStrict.h>
00792 #endif // _WIN32
00793
00794 #endif
00795
00796
00797