Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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,
42  kClipPlane,
43  kClipBox
44  };
45 
46 protected:
47  EMode fMode;
48  UInt_t fTimeStamp;
49  Bool_t fValid;
50 
51 public:
52  TGLClip(const TGLLogicalShape & logical, const TGLMatrix & transform, const float color[4]);
53  virtual ~TGLClip();
54 
55  virtual void Modified() { TGLPhysicalShape::Modified(); IncTimeStamp(); }
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 
139 class TGLClipSet : public TGLOverlayElement
140 {
141 private:
142  TGLClipSet(const TGLClipSet&); // Not implemented
143  TGLClipSet& operator=(const TGLClipSet&); // Not implemented
144 
145 protected:
146  TGLClipPlane *fClipPlane;
147  TGLClipBox *fClipBox;
148  TGLClip *fCurrentClip; //! the current clipping shape
149 
150  Bool_t fAutoUpdate;
151  Bool_t fShowClip;
152  Bool_t fShowManip;
153  TGLManipSet *fManip;
154 
155  TGLBoundingBox fLastBBox;
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;
185  void SetClipType(TGLClip::EType type);
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