Logo ROOT  
Reference Guide
TGLClip.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Richard Maunder 16/09/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGLClip
13 #define ROOT_TGLClip
14 
15 #include "TGLPhysicalShape.h"
16 #include "TGLOverlay.h"
17 
18 class TGLRnrCtx;
19 class TGLManipSet;
20 
21 //////////////////////////////////////////////////////////////////////////
22 // //
23 // TGLClip //
24 // //
25 // Abstract clipping shape - derives from TGLPhysicalShape //
26 // Adds clip mode (inside/outside) and pure virtual method to //
27 // approximate shape as set of planes. This plane set is used to perform//
28 // interactive clipping using OpenGL clip planes. //
29 //////////////////////////////////////////////////////////////////////////
30 
31 class TGLClip : public TGLPhysicalShape
32 {
33 public:
34  enum EMode
35  {
36  kOutside, // Clip away what's outside
37  kInside // Clip away what's inside
38  };
39  enum EType
40  {
41  kClipNone = 0,
43  kClipBox
44  };
45 
46 protected:
50 
51 public:
52  TGLClip(const TGLLogicalShape & logical, const TGLMatrix & transform, const float color[4]);
53  virtual ~TGLClip();
54 
56 
57  virtual void Setup(const TGLBoundingBox & bbox) = 0;
58  virtual void Setup(const TGLVector3&, const TGLVector3&);
59 
60  EMode GetMode() const { return fMode; }
61  void SetMode(EMode mode) { if (mode != fMode) { fMode = mode; ++fTimeStamp; } }
62 
63  UInt_t TimeStamp() const { return fTimeStamp; }
64  void IncTimeStamp() { ++fTimeStamp; }
65 
66  Bool_t IsValid() const { return fValid; }
67  void Invalidate() { fValid = kFALSE; }
68 
69  virtual void Draw(TGLRnrCtx & rnrCtx) const;
70  virtual void PlaneSet(TGLPlaneSet_t & set) const = 0;
71 
72  ClassDef(TGLClip,0); // abstract clipping object
73 };
74 
75 //////////////////////////////////////////////////////////////////////////
76 // //
77 // TGLClipPlane //
78 // //
79 // Concrete clip plane object. This can be translated in all directions //
80 // rotated about the Y/Z local axes (the in-plane axes). It cannot be //
81 // scaled. //
82 // //
83 //////////////////////////////////////////////////////////////////////////
84 
85 class TGLClipPlane : public TGLClip
86 {
87 private:
88  static const float fgColor[4]; //! Fixed color of clip plane
89 
90 public:
91  TGLClipPlane();
92  virtual ~TGLClipPlane();
93 
94  virtual void Setup(const TGLBoundingBox & bbox);
95  virtual void Setup(const TGLVector3& point, const TGLVector3& normal);
96 
97  void Set(const TGLPlane & plane);
98 
99  virtual void PlaneSet(TGLPlaneSet_t & set) const;
100 
101  ClassDef(TGLClipPlane, 0); // clipping plane
102 };
103 
104 //////////////////////////////////////////////////////////////////////////
105 // //
106 // TGLClipBox //
107 // //
108 // Concrete clip box object. Can be translated, rotated and scaled in //
109 // all (xyz) axes. //
110 // //
111 //////////////////////////////////////////////////////////////////////////
112 
113 class TGLClipBox : public TGLClip
114 {
115 private:
116  static const float fgColor[4]; //! Fixed color of clip box
117 
118 public:
119  TGLClipBox();
120  virtual ~TGLClipBox();
121 
122  virtual void Setup(const TGLBoundingBox & bbox);
123  virtual void Setup(const TGLVector3& min_point, const TGLVector3& max_point);
124 
125  virtual void PlaneSet(TGLPlaneSet_t & set) const;
126 
127  ClassDef(TGLClipBox, 0); // clipping box
128 };
129 
130 //////////////////////////////////////////////////////////////////////////
131 //
132 // TGLClipSet
133 //
134 // A collection of all available clipping objects, to be used by higher
135 // level objects. For the time being by TGLViewer/Scene.
136 //
137 //////////////////////////////////////////////////////////////////////////
138 
140 {
141 private:
142  TGLClipSet(const TGLClipSet&); // Not implemented
143  TGLClipSet& operator=(const TGLClipSet&); // Not implemented
144 
145 protected:
148  TGLClip *fCurrentClip; //! the current clipping shape
149 
154 
156 
157 public:
158  TGLClipSet();
159  virtual ~TGLClipSet();
160 
161  virtual Bool_t MouseEnter(TGLOvlSelectRecord& selRec);
162  virtual Bool_t MouseStillInside(TGLOvlSelectRecord& selRec);
163  virtual Bool_t Handle(TGLRnrCtx& rnrCtx, TGLOvlSelectRecord& selRec,
164  Event_t* event);
165  virtual void MouseLeave();
166 
167  virtual void Render(TGLRnrCtx& rnrCtx);
168 
169  Bool_t IsClipping() const { return fCurrentClip != 0; }
170  TGLClip* GetCurrentClip() const { return fCurrentClip; }
171  void FillPlaneSet(TGLPlaneSet_t& set) const;
172 
173  // Clipping
174  void SetupClips(const TGLBoundingBox& sceneBBox);
175  void SetupCurrentClip(const TGLBoundingBox& sceneBBox);
176  void SetupCurrentClipIfInvalid(const TGLBoundingBox& sceneBBox);
177 
178  void InvalidateClips();
179  void InvalidateCurrentClip();
180 
181  void GetClipState(TGLClip::EType type, Double_t data[6]) const;
182  void SetClipState(TGLClip::EType type, const Double_t data[6]);
183 
184  TGLClip::EType GetClipType() const;
186 
187  // Clip control flags
188  Bool_t GetAutoUpdate() const { return fAutoUpdate; }
189  void SetAutoUpdate(Bool_t aup) { fAutoUpdate = aup; }
190  Bool_t GetShowManip() const { return fShowManip; }
191  void SetShowManip(Bool_t show) { fShowManip = show; }
192  Bool_t GetShowClip() const { return fShowClip; }
193  void SetShowClip(Bool_t show) { fShowClip = show; }
194 
195  ClassDef(TGLClipSet, 0); // A collection of supported clip-objects
196 };
197 
198 #endif
TGLOverlay.h
TGLClipPlane::PlaneSet
virtual void PlaneSet(TGLPlaneSet_t &set) const
Return set of planes (actually a single one) describing this clip plane.
Definition: TGLClip.cxx:242
TGLClipSet::SetupCurrentClip
void SetupCurrentClip(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition: TGLClip.cxx:435
TGLClipSet::MouseEnter
virtual Bool_t MouseEnter(TGLOvlSelectRecord &selRec)
Mouse has entered this element.
Definition: TGLClip.cxx:362
TGLClipSet::GetClipState
void GetClipState(TGLClip::EType type, Double_t data[6]) const
Get state of clip object 'type' into data vector:
Definition: TGLClip.cxx:477
TGLClipSet::SetAutoUpdate
void SetAutoUpdate(Bool_t aup)
Definition: TGLClip.h:189
TGLClip::GetMode
EMode GetMode() const
Definition: TGLClip.h:60
TGLClipSet::InvalidateCurrentClip
void InvalidateCurrentClip()
Invalidate current clip object.
Definition: TGLClip.cxx:464
TGLClipSet::TGLClipSet
TGLClipSet()
Constructor.
Definition: TGLClip.cxx:336
TGLClipSet::fCurrentClip
TGLClip * fCurrentClip
Definition: TGLClip.h:148
TGLClip::~TGLClip
virtual ~TGLClip()
Destroy clip object.
Definition: TGLClip.cxx:101
TGLOverlayElement
An overlay element.
Definition: TGLOverlay.h:23
TGLClip::Modified
virtual void Modified()
Definition: TGLClip.h:55
TGLClip::kOutside
@ kOutside
Definition: TGLClip.h:36
TGLClipBox::~TGLClipBox
virtual ~TGLClipBox()
Destroy clip box object.
Definition: TGLClip.cxx:272
TGLClipSet::fManip
TGLManipSet * fManip
Definition: TGLClip.h:153
TGLClipSet::Handle
virtual Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event)
Handle overlay event.
Definition: TGLClip.cxx:379
TGLClipPlane::TGLClipPlane
TGLClipPlane()
Fixed color of clip plane.
Definition: TGLClip.cxx:161
TGLClipSet::GetAutoUpdate
Bool_t GetAutoUpdate() const
Definition: TGLClip.h:188
TGLPhysicalShape.h
TGLClipSet
A collection of concrete TGLClip objects to be selected from.
Definition: TGLClip.h:140
TGLClipSet::GetShowManip
Bool_t GetShowManip() const
Definition: TGLClip.h:190
TGLClipPlane::Setup
virtual void Setup(const TGLBoundingBox &bbox)
Setup the clip object for scene encompassed by bbox.
Definition: TGLClip.cxx:181
TGLClip::fValid
Bool_t fValid
Definition: TGLClip.h:49
TGLClipSet::GetClipType
TGLClip::EType GetClipType() const
Get current type active in viewer - returns one of kClipNone kClipPlane or kClipBox.
Definition: TGLClip.cxx:560
TGLOvlSelectRecord
Selection record for overlay objects.
Definition: TGLSelectRecord.h:140
TGLManipSet
Combine all available manipulators in a collection.
Definition: TGLManipSet.h:22
TGLClip::kClipBox
@ kClipBox
Definition: TGLClip.h:43
TGLClip::fTimeStamp
UInt_t fTimeStamp
Definition: TGLClip.h:48
TGLClipSet::~TGLClipSet
virtual ~TGLClipSet()
Destructor.
Definition: TGLClip.cxx:351
TGLClip::fMode
EMode fMode
Definition: TGLClip.h:47
TGLClipSet::MouseLeave
virtual void MouseLeave()
Mouse has left the element.
Definition: TGLClip.cxx:389
TGLClipPlane::~TGLClipPlane
virtual ~TGLClipPlane()
Destroy clip plane object.
Definition: TGLClip.cxx:174
TGLClipBox::TGLClipBox
TGLClipBox()
Fixed color of clip box.
Definition: TGLClip.cxx:264
TGLClipSet::SetClipState
void SetClipState(TGLClip::EType type, const Double_t data[6])
Set state of clip object 'type' into data vector:
Definition: TGLClip.cxx:524
TGLClipSet::Render
virtual void Render(TGLRnrCtx &rnrCtx)
Render clip-shape and manipulator.
Definition: TGLClip.cxx:397
TGLClipSet::fClipBox
TGLClipBox * fClipBox
Definition: TGLClip.h:147
TGLClipSet::SetupCurrentClipIfInvalid
void SetupCurrentClipIfInvalid(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition: TGLClip.cxx:445
TGLClip::EMode
EMode
Definition: TGLClip.h:35
TGLMatrix
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:598
TGLClip::IncTimeStamp
void IncTimeStamp()
Definition: TGLClip.h:64
TGLClipBox::fgColor
static const float fgColor[4]
Definition: TGLClip.h:116
TGLClipPlane::fgColor
static const float fgColor[4]
Definition: TGLClip.h:88
TGLBoundingBox
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Definition: TGLBoundingBox.h:33
TGLClip::TGLClip
TGLClip(const TGLLogicalShape &logical, const TGLMatrix &transform, const float color[4])
Construct a stand-alone physical clipping object.
Definition: TGLClip.cxx:89
TGLClipSet::IsClipping
Bool_t IsClipping() const
Definition: TGLClip.h:169
bool
TGLClipSet::fAutoUpdate
Bool_t fAutoUpdate
the current clipping shape
Definition: TGLClip.h:150
TGLClipSet::GetCurrentClip
TGLClip * GetCurrentClip() const
Definition: TGLClip.h:170
TGLClip::Draw
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw out clipping object with blending and back + front filling.
Definition: TGLClip.cxx:120
TGLPlane
3D plane class - of format Ax + By + Cz + D = 0
Definition: TGLUtil.h:525
TGLClip::Invalidate
void Invalidate()
Definition: TGLClip.h:67
TGLClipSet::fShowManip
Bool_t fShowManip
Definition: TGLClip.h:152
TGLClipSet::operator=
TGLClipSet & operator=(const TGLClipSet &)
TGLClipSet::SetShowManip
void SetShowManip(Bool_t show)
Definition: TGLClip.h:191
TGLVector3
3 component (x/y/z) vector class.
Definition: TGLUtil.h:248
TGLClip::Setup
virtual void Setup(const TGLBoundingBox &bbox)=0
TGLClipSet::SetClipType
void SetClipType(TGLClip::EType type)
Set current clip active in viewer - 'type' is one of kClipNone kClipPlane or kClipBox.
Definition: TGLClip.cxx:580
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGLClipSet::GetShowClip
Bool_t GetShowClip() const
Definition: TGLClip.h:192
TGLClip::SetMode
void SetMode(EMode mode)
Definition: TGLClip.h:61
TGLClipBox::PlaneSet
virtual void PlaneSet(TGLPlaneSet_t &set) const
Return set of 6 planes describing faces of the box but invert them so that they point inside of box.
Definition: TGLClip.cxx:315
TGLClip::IsValid
Bool_t IsValid() const
Definition: TGLClip.h:66
TGLClip::TimeStamp
UInt_t TimeStamp() const
Definition: TGLClip.h:63
TGLClip::EType
EType
Definition: TGLClip.h:40
TGLClipPlane::Set
void Set(const TGLPlane &plane)
Update clip plane object to follow passed 'plane' equation.
Definition: TGLClip.cxx:230
TGLPlaneSet_t
std::vector< TGLPlane > TGLPlaneSet_t
Definition: TGLUtil.h:571
TGLClipSet::FillPlaneSet
void FillPlaneSet(TGLPlaneSet_t &set) const
Forward request to fill the plane-set to the current clip.
Definition: TGLClip.cxx:416
TGLClipPlane
Concrete clip plane object.
Definition: TGLClip.h:86
TGLClip::PlaneSet
virtual void PlaneSet(TGLPlaneSet_t &set) const =0
unsigned int
TGLClip
Abstract clipping shape - derives from TGLPhysicalShape Adds clip mode (inside/outside) and pure virt...
Definition: TGLClip.h:32
TGLClipSet::fLastBBox
TGLBoundingBox fLastBBox
Definition: TGLClip.h:155
Double_t
double Double_t
Definition: RtypesCore.h:59
TGLClip::kClipNone
@ kClipNone
Definition: TGLClip.h:41
TGLClipSet::TGLClipSet
TGLClipSet(const TGLClipSet &)
TGLClipBox::Setup
virtual void Setup(const TGLBoundingBox &bbox)
Setup the clip object for scene encompassed by bbox.
Definition: TGLClip.cxx:279
TGLClipSet::SetShowClip
void SetShowClip(Bool_t show)
Definition: TGLClip.h:193
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGLClipBox
Concrete clip box object.
Definition: TGLClip.h:114
Event_t
Definition: GuiTypes.h:173
TGLLogicalShape
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
Definition: TGLLogicalShape.h:30
TGLPhysicalShape
Concrete physical shape - a GL drawable.
Definition: TGLPhysicalShape.h:32
TGLClipSet::fClipPlane
TGLClipPlane * fClipPlane
Definition: TGLClip.h:146
TGLClip::kInside
@ kInside
Definition: TGLClip.h:37
TGLClipSet::MouseStillInside
virtual Bool_t MouseStillInside(TGLOvlSelectRecord &selRec)
Definition: TGLClip.cxx:367
type
int type
Definition: TGX11.cxx:121
TGLClipSet::SetupClips
void SetupClips(const TGLBoundingBox &sceneBBox)
Setup clipping objects for given scene bounding box.
Definition: TGLClip.cxx:425
TGLPhysicalShape::Modified
void Modified()
Call this after modifying the physical so that the information can be propagated to the object refere...
Definition: TGLPhysicalShape.cxx:180
TGLClipSet::InvalidateClips
void InvalidateClips()
Invalidate clip objects.
Definition: TGLClip.cxx:455
TGLRnrCtx
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:41
TGLClipSet::fShowClip
Bool_t fShowClip
Definition: TGLClip.h:151
TGLClip::kClipPlane
@ kClipPlane
Definition: TGLClip.h:42