TGLClip.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLClip.h 32465 2010-03-04 20:29:52Z matevz $
00002 // Author:  Richard Maunder  16/09/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGLClip
00013 #define ROOT_TGLClip
00014 
00015 #include "TGLPhysicalShape.h"
00016 #include "TGLOverlay.h"
00017 
00018 class TGLRnrCtx;
00019 class TGLManipSet;
00020 
00021 //////////////////////////////////////////////////////////////////////////
00022 //                                                                      //
00023 // TGLClip                                                              //
00024 //                                                                      //
00025 // Abstract clipping shape - derives from TGLPhysicalShape              //
00026 // Adds clip mode (inside/outside) and pure virtual method to           //
00027 // approximate shape as set of planes. This plane set is used to perform//
00028 // interactive clipping using OpenGL clip planes.                       //
00029 //////////////////////////////////////////////////////////////////////////
00030 
00031 class TGLClip : public TGLPhysicalShape
00032 {
00033 public:
00034    enum EMode { kOutside, // Clip away what's outside
00035                 kInside   // Clip away what's inside
00036    };
00037 
00038 protected:
00039    EMode  fMode;
00040    UInt_t fTimeStamp;
00041    Bool_t fValid;
00042 
00043 public:
00044    TGLClip(const TGLLogicalShape & logical, const TGLMatrix & transform, const float color[4]);
00045    virtual ~TGLClip();
00046 
00047    virtual void Modified() { TGLPhysicalShape::Modified(); IncTimeStamp(); }
00048 
00049    virtual void Setup(const TGLBoundingBox & bbox) = 0;
00050    virtual void Setup(const TGLVector3&, const TGLVector3&);
00051 
00052    EMode GetMode() const      { return fMode; }
00053    void  SetMode(EMode mode)  { if (mode != fMode) { fMode = mode; ++fTimeStamp; } }
00054 
00055    UInt_t TimeStamp() const { return fTimeStamp; }
00056    void   IncTimeStamp()    { ++fTimeStamp; }
00057 
00058    Bool_t IsValid() const { return fValid;   }
00059    void   Invalidate()    { fValid = kFALSE; }
00060 
00061    virtual void Draw(TGLRnrCtx & rnrCtx) const;
00062    virtual void PlaneSet(TGLPlaneSet_t & set) const = 0;
00063 
00064    ClassDef(TGLClip,0); // abstract clipping object
00065 };
00066 
00067 //////////////////////////////////////////////////////////////////////////
00068 //                                                                      //
00069 // TGLClipPlane                                                         //
00070 //                                                                      //
00071 // Concrete clip plane object. This can be translated in all directions //
00072 // rotated about the Y/Z local axes (the in-plane axes). It cannot be   //
00073 // scaled.                                                              //
00074 //                                                                      //
00075 //////////////////////////////////////////////////////////////////////////
00076 
00077 class TGLClipPlane : public TGLClip
00078 {
00079 private:
00080    static const float fgColor[4];   //! Fixed color of clip plane
00081 
00082 public:
00083    TGLClipPlane();
00084    virtual ~TGLClipPlane();
00085 
00086    virtual void Setup(const TGLBoundingBox & bbox);
00087    virtual void Setup(const TGLVector3& point, const TGLVector3& normal);
00088 
00089    void Set(const TGLPlane & plane);
00090 
00091    virtual void PlaneSet(TGLPlaneSet_t & set) const;
00092 
00093    ClassDef(TGLClipPlane, 0); // clipping plane
00094 };
00095 
00096 //////////////////////////////////////////////////////////////////////////
00097 //                                                                      //
00098 // TGLClipBox                                                           //
00099 //                                                                      //
00100 // Concrete clip box object. Can be translated, rotated and scaled in   //
00101 // all (xyz) axes.                                                      //
00102 //                                                                      //
00103 //////////////////////////////////////////////////////////////////////////
00104 
00105 class TGLClipBox : public TGLClip
00106 {
00107 private:
00108    static const float fgColor[4];   //! Fixed color of clip box
00109 
00110 public:
00111    TGLClipBox();
00112    virtual ~TGLClipBox();
00113 
00114    virtual void Setup(const TGLBoundingBox & bbox);
00115    virtual void Setup(const TGLVector3& min_point, const TGLVector3& max_point);
00116 
00117    virtual void PlaneSet(TGLPlaneSet_t & set) const;
00118 
00119    ClassDef(TGLClipBox, 0); // clipping box
00120 };
00121 
00122 //////////////////////////////////////////////////////////////////////////
00123 //
00124 // TGLClipSet
00125 //
00126 // A collection of all available clipping objects, to be used by higher
00127 // level objects. For the time being by TGLViewer/Scene.
00128 //
00129 //////////////////////////////////////////////////////////////////////////
00130 
00131 class TGLClipSet : public TGLOverlayElement
00132 {
00133 private:
00134    TGLClipSet(const TGLClipSet&);            // Not implemented
00135    TGLClipSet& operator=(const TGLClipSet&); // Not implemented
00136 
00137 protected:
00138    TGLClipPlane          *fClipPlane;
00139    TGLClipBox            *fClipBox;
00140    TGLClip               *fCurrentClip;  //! the current clipping shape
00141 
00142    Bool_t                 fAutoUpdate;
00143    Bool_t                 fShowClip;
00144    Bool_t                 fShowManip;
00145    TGLManipSet           *fManip;
00146 
00147    TGLBoundingBox         fLastBBox;
00148 
00149 public:
00150    TGLClipSet();
00151    virtual ~TGLClipSet();
00152 
00153    virtual Bool_t MouseEnter(TGLOvlSelectRecord& selRec);
00154    virtual Bool_t MouseStillInside(TGLOvlSelectRecord& selRec);
00155    virtual Bool_t Handle(TGLRnrCtx& rnrCtx, TGLOvlSelectRecord& selRec,
00156                          Event_t* event);
00157    virtual void   MouseLeave();
00158 
00159    virtual void Render(TGLRnrCtx& rnrCtx);
00160 
00161    Bool_t    IsClipping()     const { return fCurrentClip != 0; }
00162    TGLClip*  GetCurrentClip() const { return fCurrentClip; }
00163    void      FillPlaneSet(TGLPlaneSet_t& set) const;
00164 
00165    // Clipping
00166    void  SetupClips(const TGLBoundingBox& sceneBBox);
00167    void  SetupCurrentClip(const TGLBoundingBox& sceneBBox);
00168    void  SetupCurrentClipIfInvalid(const TGLBoundingBox& sceneBBox);
00169 
00170    void  InvalidateClips();
00171    void  InvalidateCurrentClip();
00172 
00173    void  GetClipState(EClipType type, Double_t data[6]) const;
00174    void  SetClipState(EClipType type, const Double_t data[6]);
00175 
00176    EClipType GetClipType() const;
00177    void      SetClipType(EClipType type);
00178 
00179    // Clip control flags
00180    Bool_t GetAutoUpdate()     const { return fAutoUpdate; }
00181    void   SetAutoUpdate(Bool_t aup) { fAutoUpdate = aup;  }
00182    Bool_t GetShowManip()      const { return fShowManip; }
00183    void   SetShowManip(Bool_t show) { fShowManip = show; }
00184    Bool_t GetShowClip()       const { return fShowClip; }
00185    void   SetShowClip(Bool_t show)  { fShowClip = show; }
00186 
00187    ClassDef(TGLClipSet, 0); // A collection of supported clip-objects
00188 };
00189 
00190 #endif

Generated on Tue Jul 5 14:16:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1