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/SoWinMPRenderArea.h>
00027 #else // _WIN32
00028
00029 #ifndef _SO_XT_MP_RENDER_AREA_H_
00030 #define _SO_XT_MP_RENDER_AREA_H_
00031
00032 #include <Inventor/SbColor.h>
00033 #include <Inventor/sensors/SoNodeSensor.h>
00034 #include <Inventor/SoSceneManager.h>
00035 #include <Inventor/MP/Xt/SoXtMPGLWidget.h>
00036
00037 #include <Inventor/actions/SoGLRenderAction.h>
00038
00039 #include <Inventor/threads/SbThreadMutex.h>
00040 #include <Inventor/threads/SbThreadBarrier.h>
00041 #include <Inventor/threads/SbThread.h>
00042 #include <Inventor/nodes/SoCamera.h>
00043
00044 #include <Inventor/misc/SoCallbackList.h>
00045 #include <Inventor/components/stereo/SoStereoViewer.h>
00046
00047 #include <Inventor/sensors/SoTimerSensor.h>
00048
00049
00050 class SoHandleEventAction;
00051 class SoXtDevice;
00052 class SoNode;
00053 class SoXtMouse;
00054 class SoXtKeyboard;
00055 class SoSelection;
00056
00057
00058
00059 typedef SbBool SoXtMPRenderAreaEventCB(void *userData, XAnyEvent *anyevent);
00060
00061
00062 class SoXtMPRenderArea;
00063
00064 typedef void SoXtMPRenderAreaThreadInitCB(void * userData, SoXtMPRenderArea *ra);
00065
00066
00067 typedef void SoXtMPRenderAreaThreadRenderCB(void * userData, SoXtMPRenderArea *ra);
00068
00070
00071
00072
00073
00074
00076
00148 class SoXtMPRenderArea : public SoXtMPGLWidget, public SoStereoViewer
00149 {
00150 public:
00155 SoXtMPRenderArea(
00156 SoWidget parent = NULL,
00157 const char *name = NULL,
00158 SbBool buildInsideParent = TRUE,
00159 SbBool getMouseInput = TRUE,
00160 SbBool getKeyboardInput = TRUE);
00164 ~SoXtMPRenderArea();
00165
00169 virtual void setSceneGraph(SoNode *newScene);
00173 virtual SoNode * getSceneGraph();
00174
00180 void registerDevice(SoXtDevice *d);
00186 void unregisterDevice(SoXtDevice *d);
00187
00195 void setBackgroundColor(const SbColor &c)
00196 { sceneMgr->setBackgroundColor(c); }
00200 const SbColor & getBackgroundColor() const
00201 { return sceneMgr->getBackgroundColor(); }
00202
00207 void setBackgroundIndex(int index)
00208 { sceneMgr->setBackgroundIndex(index); }
00212 int getBackgroundIndex() const
00213 { return sceneMgr->getBackgroundIndex(); }
00214
00219 void setColorMap(int startIndex, int num, const SbColor *colors);
00220
00224 void setViewportRegion(const SbViewportRegion &newRegion, int id)
00225 { sceneMgr->getGLRenderAction(id)->setViewportRegion(newRegion); }
00229 const SbViewportRegion &getViewportRegion(int id) const
00230 { return sceneMgr->getGLRenderAction(id)->getViewportRegion(); }
00231
00235
00239 const SbViewportRegion &getViewportRegion() const;
00240
00245 void setTransparencyType(SoGLRenderAction::TransparencyType type);
00250 SoGLRenderAction::TransparencyType getTransparencyType() const
00251 { return sceneMgr->getGLRenderAction()->getTransparencyType(); }
00252
00260 void setClearBeforeRender(SbBool trueOrFalse,SbBool zbTrueOrFalse = TRUE)
00261 { clearFirst = trueOrFalse; clearZBufferFirst = zbTrueOrFalse;}
00265 SbBool isClearBeforeRender() const
00266 { return clearFirst; }
00271 SbBool isClearZBufferBeforeRender() const
00272 { return clearZBufferFirst; }
00273
00278 void setAutoRedraw(SbBool trueOrFalse);
00283 SbBool isAutoRedraw() const { return autoRedraw; }
00284
00288 void setRedrawPriority(uint32_t priority)
00289 { sceneMgr->setRedrawPriority(priority);
00290 overlaySceneMgr->setRedrawPriority(priority); }
00294 uint32_t getRedrawPriority() const
00295 { return sceneMgr->getRedrawPriority(); }
00299 static uint32_t getDefaultRedrawPriority()
00300 { return SoSceneManager::getDefaultRedrawPriority(); }
00301
00306 void render() { redraw(); }
00307
00312 void scheduleRedraw();
00313
00320 void redrawOnSelectionChange(SoSelection *s);
00321
00333 void setEventCallback(
00334 SoXtMPRenderAreaEventCB *fcn,
00335 void *userData = NULL)
00336 { appEventHandler = fcn; appEventHandlerData = userData; }
00337
00344 void setSceneManager(SoSceneManager *sm);
00351 SoSceneManager * getSceneManager() const { return sceneMgr; }
00352
00358 void setGLRenderAction(SoGLRenderAction *ra);
00359
00365 SoGLRenderAction *getGLRenderAction() const
00366 { return sceneMgr->getGLRenderAction(); }
00367
00373 void setGLRenderAction(SoGLRenderAction *ra, int id)
00374 { sceneMgr->setGLRenderAction(ra,id); }
00380 SoGLRenderAction *getGLRenderAction(int id) const
00381 { return sceneMgr->getGLRenderAction(id); }
00382
00383 #if 1
00384 #if defined(sun) || defined(__linux__)
00385 SoDEPRECATED
00386 virtual void setSunOverlayBackgroundIndex();
00387 #endif
00388 SoDEPRECATED
00394 void setOverlaySceneGraph(SoNode *newScene);
00395 SoDEPRECATED
00401 SoNode* getOverlaySceneGraph() { return overlaySceneMgr->getSceneGraph();}
00402 SoDEPRECATED
00408 void setOverlayBackgroundIndex(int index) { overlaySceneMgr->setBackgroundIndex(index); }
00409 SoDEPRECATED
00414 int getOverlayBackgroundIndex() const { return overlaySceneMgr->getBackgroundIndex(); }
00415 SoDEPRECATED
00421 void setOverlayColorMap(int startIndex, int num, const SbColor *colors);
00422 SoDEPRECATED
00428 void setClearBeforeOverlayRender(SbBool trueOrFalse) { clearOverlayFirst = trueOrFalse; }
00429 SoDEPRECATED
00434 SbBool isClearBeforeOverlayRender() const { return clearOverlayFirst; }
00435 SoDEPRECATED
00441 void renderOverlay() { redrawOverlay(); }
00442 SoDEPRECATED
00448 void scheduleOverlayRedraw();
00449 SoDEPRECATED
00457 void redrawOverlayOnSelectionChange(SoSelection *s);
00458 SoDEPRECATED
00466 void setOverlaySceneManager(SoSceneManager *sm) { overlaySceneMgr = sm; }
00467 SoDEPRECATED
00475 SoSceneManager* getOverlaySceneManager() const { return overlaySceneMgr; }
00476 SoDEPRECATED
00481 void setOverlayGLRenderAction(SoGLRenderAction *ra) { overlaySceneMgr->setGLRenderAction(ra); }
00482 SoDEPRECATED
00487 SoGLRenderAction* getOverlayGLRenderAction() const { return overlaySceneMgr->getGLRenderAction(); }
00488 #endif
00490 void show(void);
00491
00495 SoTimerSensor * getTrackerSensor()
00496 { return trackerSensor; }
00497
00502 void setInterEyeDistance(float value)
00503 { interEyeDistance = value;}
00504
00508 float getInterEyeDistance(void)
00509 { return interEyeDistance;}
00510
00511
00513 virtual SoGLContext* getViewerContext() { return getNormalContext(); }
00514
00516 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
00517
00518 #if 1 SoDEPRECATED
00535 void setAntialiasing(SbBool smoothing, int numPasses);
00536 SoDEPRECATED
00541 void getAntialiasing(SbBool &smoothing, int &numPasses) const;
00542
00543 #endif
00545 private:
00546
00547
00548
00549
00550
00551
00552 SoXtMPRenderArea(
00553 SoWidget parent,
00554 const char *name,
00555 SbBool buildInsideParent,
00556 SbBool getMouseInput,
00557 SbBool getKeyboardInput,
00558 SbBool buildNow);
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 void partialRedraw(int id);
00570 #if 1 SoDEPRECATED
00572 void partialRedrawOverlay(int id);
00573 #endif
00575 void swapBuffers(int);
00576
00577 virtual void redraw();
00578 virtual void prepareRedraw();
00579 virtual void actualRedraw();
00580 virtual void endRedraw();
00581
00582 #if 1 SoDEPRECATED
00584 virtual void prepareOverlayRedraw();SoDEPRECATED
00586 virtual void redrawOverlay();SoDEPRECATED
00588 virtual void endOverlayRedraw();SoDEPRECATED
00590 virtual void actualOverlayRedraw();
00591 #endif
00593 //
00594
00595
00596 virtual void processEvent(XAnyEvent *anyevent);
00597 virtual void initGraphic();
00598 #if 1 SoDEPRECATED
00600 virtual void initOverlayGraphic();
00601 #endif
00602 virtual void sizeChanged(const SbVec2s &newSize);
00603 virtual void widgetChanged(SoWidget);
00604
00605 virtual void initViewportRegion(int);
00606
00607 SoWidget buildWidget(SoWidget parent);
00608
00609
00610 virtual SbString getDefaultWidgetName() const;
00611 virtual SbString getDefaultTitle() const;
00612 virtual SbString getDefaultIconTitle() const;
00613
00614
00615 SbPList *deviceList;
00616
00617
00618 SoXtMPRenderAreaEventCB *appEventHandler;
00619 void *appEventHandlerData;
00620
00621 SbBool invokeAppCB(XAnyEvent *anyevent);
00622
00623
00624 void setDepthRange(float,float);
00625 float zNear;
00626 float zFar;
00627 void changeDepthRange(void);
00628 SbBool drawHiddenLineMode;
00629 void setHiddenLineSwap(SbBool);
00630 SbBool hiddenLineSwap;
00631
00632
00633 SbBool stereoAbsoluteAdjustments;
00634 float stereoOffset;
00635 float stereoBalance;
00636 SbBool stereoNearFrac;
00637 SoCamera::StereoMode stereoMode;
00638 float interEyeDistance;
00639
00640 private:
00641
00642 void setDoSwapBuffers(SbBool);
00643 SbBool doSwapBuffers(void);
00644 void setLeftView(SbBool);
00645 void setRightView(SbBool);
00646 SbBool isLeftViewRendering(void);
00647 SbBool isRightViewRendering(void);
00648
00649 void setStereoMode(SoCamera::StereoMode stMode);
00650
00651 private:
00652
00653 char * pixels;
00654 SoTimerSensor * trackerSensor;
00655
00656 SbBool stereoActive;
00657
00658 void setModifyViewVolume(int, SoSceneManager *);
00659 void setModifyViewVolumeElementWall(int id,SoSceneManager * sceneManager);
00660
00661 void setStereoElement(int);
00662
00663
00664 SbBool doSwap;
00665 SbBool doLeftViewRendering;
00666 SbBool doRightViewRendering;
00667
00668
00669 int * frameCounter;
00670
00671
00672
00673 SbThreadBarrier *swapBarrier;
00674 SbThreadBarrier *synchroStartBarrier;
00675 SbThreadBarrier *synchroEndBarrier;
00676
00677 SbThreadBarrier *synchroOverlayStartBarrier;
00678 SbThreadBarrier *synchroOverlayEndBarrier;
00679
00680 {
00681 SoXtMPRenderArea *p;
00682 int id;
00683 int numScreen;
00684 } ThreadFuncStruct;
00685 ThreadFuncStruct * threadStruct;
00686
00687 static void * threadRoutRedraw(void *);
00688 static void * threadRoutRedrawOverlay(void *);
00689
00690 SbThread ** thread;
00691 SbThread ** overlayThread;
00692
00693
00694 SoSceneManager *sceneMgr;
00695 SoSceneManager *overlaySceneMgr;
00696 SbBool clearFirst, clearOverlayFirst;
00697 SbBool clearZBufferFirst;
00698 SbBool autoRedraw;
00699 XColor *mapColors, *overlayMapColors;
00700 int mapColorNum, overlayMapColorNum;
00701
00702 SoXtMouse *mouseDevice;
00703 SoXtKeyboard *keybdDevice;
00704 void reinstallDevices(SoWidget newWidget);
00705
00706 static void selectionChangeCB(void *userData, SoSelection *s);
00707 static void overlaySelectionChangeCB(void *userData, SoSelection *s);
00708 SoSelection *selection, *overlaySelection;
00709 SoWidget * deviceWidget;
00710
00711
00712 SbBool firstEvent;
00713 static void windowEventCB(SoWidget, SoXtMPRenderArea *, XAnyEvent *, Boolean *);
00714 static void renderCB(void *, SoSceneManager *);
00715 static void renderOverlayCB(void *, SoSceneManager *);
00716
00717 static void visibilityChangeCB(void *pt, SbBool visible);
00718 void activate();
00719 void deactivate();
00720
00721
00722 void constructorCommon(
00723 SbBool getMouseInput,
00724 SbBool getKeyboardInput,
00725 SbBool buildNow);
00726
00727 static SoCallbackList * threadInitCBList;
00728 static SoCallbackList * threadPreRenderCBList;
00729 static SoCallbackList * threadPostRenderCBList;
00730
00731 public:
00732
00733 static void addThreadInitCB(SoXtMPRenderAreaThreadInitCB * fcn, void *userData);
00734 static void removeThreadInitCB(SoXtMPRenderAreaThreadInitCB * fcn, void *userData);
00735
00736 static void addThreadPreRenderCB(SoXtMPRenderAreaThreadRenderCB * fcn, void *userData);
00737 static void removeThreadPreRenderCB(SoXtMPRenderAreaThreadRenderCB * fcn, void *userData);
00738
00739 static void addThreadPostRenderCB(SoXtMPRenderAreaThreadRenderCB * fcn, void *userData);
00740 static void removeThreadPostRenderCB(SoXtMPRenderAreaThreadRenderCB * fcn, void *userData);
00741
00742
00743
00744 virtual SbBool isViewerDoubleBuffer();
00745 virtual void setStereoViewing(SbBool onOrOff);
00746 virtual SbBool isStereoViewing();
00747 virtual SoCamera * getViewerCamera();
00748 virtual const SbVec2s& getSize();
00749 virtual const SbVec2s& getTopLeft() ;
00750 virtual const SbVec2s& getBottomRight() ;
00751 void setStereoViewType(SoBaseStereo * stereo);
00752 SoBaseStereo * getStereoViewType();
00753 void reverseStereoView(SbBool reverse);
00754 SbBool isStereoViewReversed();
00755 virtual void setStereoAbsoluteAdjustments(SbBool absolute);
00756 virtual SbBool isStereoAbsoluteAdjustments() const {return stereoAbsoluteAdjustments;}
00757 virtual void setStereoBalance(float balance, SbBool nearFrac = false);
00758 virtual float getStereoBalance();
00759 virtual SbBool isStereoBalanceNearFrac();
00760 virtual void setStereoActive(SbBool activate) ;
00761 virtual SbBool isStereoActive() ;
00762 void setViewport(short left, short bottom, short width, short height) ;
00763 void getViewport(short &left, short &bottom, short &width, short &height) ;
00764 void * getViewer(void);
00765
00769 void setStereoOffset(float dist);
00773 float getStereoOffset() { return stereoOffset; }
00774
00775 virtual void actualRendering() {}
00776
00777 #if 1 SoDEPRECATED
00780 virtual void adjustClippingPlanes();
00781 SoDEPRECATED
00783 HDC getCurrentDC() { return NULL; }
00784
00785 #endif
00787 private:
00788 SoBaseStereo * stereoViewType;
00789
00790 };
00791
00792
00793 #endif
00794
00795 #endif // _WIN32
00796
00797
00798
00799