Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:58

0001 // @(#)root/gl:$Id$
0002 // Author:  Richard Maunder  16/09/2005
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGLClip
0013 #define ROOT_TGLClip
0014 
0015 #include "TGLPhysicalShape.h"
0016 #include "TGLOverlay.h"
0017 
0018 class TGLRnrCtx;
0019 class TGLManipSet;
0020 
0021 //////////////////////////////////////////////////////////////////////////
0022 //                                                                      //
0023 // TGLClip                                                              //
0024 //                                                                      //
0025 // Abstract clipping shape - derives from TGLPhysicalShape              //
0026 // Adds clip mode (inside/outside) and pure virtual method to           //
0027 // approximate shape as set of planes. This plane set is used to perform//
0028 // interactive clipping using OpenGL clip planes.                       //
0029 //////////////////////////////////////////////////////////////////////////
0030 
0031 class TGLClip : public TGLPhysicalShape
0032 {
0033 public:
0034    enum EMode
0035    {
0036       kOutside, // Clip away what's outside
0037       kInside   // Clip away what's inside
0038    };
0039    enum EType
0040    {
0041       kClipNone = 0,
0042       kClipPlane,
0043       kClipBox
0044    };
0045 
0046 protected:
0047    EMode  fMode;
0048    UInt_t fTimeStamp;
0049    Bool_t fValid;
0050 
0051 public:
0052    TGLClip(const TGLLogicalShape & logical, const TGLMatrix & transform, const float color[4]);
0053    ~TGLClip() override;
0054 
0055    virtual void Modified() { TGLPhysicalShape::Modified(); IncTimeStamp(); }
0056 
0057    virtual void Setup(const TGLBoundingBox & bbox) = 0;
0058    virtual void Setup(const TGLVector3&, const TGLVector3&);
0059 
0060    EMode GetMode() const      { return fMode; }
0061    void  SetMode(EMode mode)  { if (mode != fMode) { fMode = mode; ++fTimeStamp; } }
0062 
0063    UInt_t TimeStamp() const { return fTimeStamp; }
0064    void   IncTimeStamp()    { ++fTimeStamp; }
0065 
0066    Bool_t IsValid() const { return fValid;   }
0067    void   Invalidate()    { fValid = kFALSE; }
0068 
0069    void Draw(TGLRnrCtx & rnrCtx) const override;
0070    virtual void PlaneSet(TGLPlaneSet_t & set) const = 0;
0071 
0072    ClassDefOverride(TGLClip,0); // abstract clipping object
0073 };
0074 
0075 //////////////////////////////////////////////////////////////////////////
0076 //                                                                      //
0077 // TGLClipPlane                                                         //
0078 //                                                                      //
0079 // Concrete clip plane object. This can be translated in all directions //
0080 // rotated about the Y/Z local axes (the in-plane axes). It cannot be   //
0081 // scaled.                                                              //
0082 //                                                                      //
0083 //////////////////////////////////////////////////////////////////////////
0084 
0085 class TGLClipPlane : public TGLClip
0086 {
0087 private:
0088    static const float fgColor[4];   //! Fixed color of clip plane
0089 
0090 public:
0091    TGLClipPlane();
0092    ~TGLClipPlane() override;
0093 
0094    void Setup(const TGLBoundingBox & bbox) override;
0095    void Setup(const TGLVector3& point, const TGLVector3& normal) override;
0096 
0097    void Set(const TGLPlane & plane);
0098 
0099    void PlaneSet(TGLPlaneSet_t & set) const override;
0100 
0101    ClassDefOverride(TGLClipPlane, 0); // clipping plane
0102 };
0103 
0104 //////////////////////////////////////////////////////////////////////////
0105 //                                                                      //
0106 // TGLClipBox                                                           //
0107 //                                                                      //
0108 // Concrete clip box object. Can be translated, rotated and scaled in   //
0109 // all (xyz) axes.                                                      //
0110 //                                                                      //
0111 //////////////////////////////////////////////////////////////////////////
0112 
0113 class TGLClipBox : public TGLClip
0114 {
0115 private:
0116    static const float fgColor[4];   //! Fixed color of clip box
0117 
0118 public:
0119    TGLClipBox();
0120    ~TGLClipBox() override;
0121 
0122    void Setup(const TGLBoundingBox & bbox) override;
0123    void Setup(const TGLVector3& min_point, const TGLVector3& max_point) override;
0124 
0125    void PlaneSet(TGLPlaneSet_t & set) const override;
0126 
0127    ClassDefOverride(TGLClipBox, 0); // clipping box
0128 };
0129 
0130 //////////////////////////////////////////////////////////////////////////
0131 //
0132 // TGLClipSet
0133 //
0134 // A collection of all available clipping objects, to be used by higher
0135 // level objects. For the time being by TGLViewer/Scene.
0136 //
0137 //////////////////////////////////////////////////////////////////////////
0138 
0139 class TGLClipSet : public TGLOverlayElement
0140 {
0141 private:
0142    TGLClipSet(const TGLClipSet&) = delete;
0143    TGLClipSet& operator=(const TGLClipSet&) = delete;
0144 
0145 protected:
0146    TGLClipPlane          *fClipPlane;
0147    TGLClipBox            *fClipBox;
0148    TGLClip               *fCurrentClip;  //! the current clipping shape
0149 
0150    Bool_t                 fAutoUpdate;
0151    Bool_t                 fShowClip;
0152    Bool_t                 fShowManip;
0153    TGLManipSet           *fManip;
0154 
0155    TGLBoundingBox         fLastBBox;
0156 
0157 public:
0158    TGLClipSet();
0159    ~TGLClipSet() override;
0160 
0161    Bool_t MouseEnter(TGLOvlSelectRecord& selRec) override;
0162    Bool_t MouseStillInside(TGLOvlSelectRecord& selRec) override;
0163    Bool_t Handle(TGLRnrCtx& rnrCtx, TGLOvlSelectRecord& selRec,
0164                          Event_t* event) override;
0165    void   MouseLeave() override;
0166 
0167    void Render(TGLRnrCtx& rnrCtx) override;
0168 
0169    Bool_t    IsClipping()     const { return fCurrentClip != nullptr; }
0170    TGLClip*  GetCurrentClip() const { return fCurrentClip; }
0171    void      FillPlaneSet(TGLPlaneSet_t& set) const;
0172 
0173    // Clipping
0174    void  SetupClips(const TGLBoundingBox& sceneBBox);
0175    void  SetupCurrentClip(const TGLBoundingBox& sceneBBox);
0176    void  SetupCurrentClipIfInvalid(const TGLBoundingBox& sceneBBox);
0177 
0178    void  InvalidateClips();
0179    void  InvalidateCurrentClip();
0180 
0181    void  GetClipState(TGLClip::EType type, Double_t data[6]) const;
0182    void  SetClipState(TGLClip::EType type, const Double_t data[6]);
0183 
0184    TGLClip::EType GetClipType() const;
0185    void           SetClipType(TGLClip::EType type);
0186 
0187    // Clip control flags
0188    Bool_t GetAutoUpdate()     const { return fAutoUpdate; }
0189    void   SetAutoUpdate(Bool_t aup) { fAutoUpdate = aup;  }
0190    Bool_t GetShowManip()      const { return fShowManip; }
0191    void   SetShowManip(Bool_t show) { fShowManip = show; }
0192    Bool_t GetShowClip()       const { return fShowClip; }
0193    void   SetShowClip(Bool_t show)  { fShowClip = show; }
0194 
0195    ClassDefOverride(TGLClipSet, 0); // A collection of supported clip-objects
0196 };
0197 
0198 #endif