Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLClip.cxx
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#include "TGLClip.h"
13#include "TGLIncludes.h"
14#include "TGLRnrCtx.h"
15#include "TGLManipSet.h"
16
17#include "TGLFaceSet.h"
18#include "TBuffer3D.h"
19#include "TBuffer3DTypes.h"
20
21namespace
22{
23
24class TGLClipPlaneLogical : public TGLLogicalShape
25{
26protected:
27 void DirectDraw(TGLRnrCtx & rnrCtx) const override
28 {
29 glBegin(rnrCtx.IsDrawPassFilled() ? GL_QUADS : GL_LINE_LOOP);
30 glNormal3d (0.0, 0.0, 1.0);
31 glVertex3dv(fBoundingBox[4].CArr());
32 glVertex3dv(fBoundingBox[7].CArr());
33 glVertex3dv(fBoundingBox[6].CArr());
34 glVertex3dv(fBoundingBox[5].CArr());
35 glEnd();
36 }
37
38public:
39 TGLClipPlaneLogical() : TGLLogicalShape() { fDLCache = kFALSE; }
40 ~TGLClipPlaneLogical() override {}
41
42 void Resize(Double_t ext)
43 {
44 fBoundingBox.SetAligned(TGLVertex3(-ext, -ext, 0),
45 TGLVertex3( ext, ext, 0));
46 UpdateBoundingBoxesOfPhysicals();
47 }
48
49};
50
51
52class TGLClipBoxLogical : public TGLLogicalShape
53{
54protected:
55 void DirectDraw(TGLRnrCtx & rnrCtx) const override
56 {
58 fBoundingBox.Draw(rnrCtx.IsDrawPassFilled());
60 }
61
62public:
63 TGLClipBoxLogical() : TGLLogicalShape() { fDLCache = kFALSE; }
64 ~TGLClipBoxLogical() override {}
65
66 void Resize(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex)
67 {
68 fBoundingBox.SetAligned(lowVertex, highVertex);
69 UpdateBoundingBoxesOfPhysicals();
70 }
71};
72
73}
74
75
76/** \class TGLClip
77\ingroup opengl
78Abstract clipping shape - derives from TGLPhysicalShape
79Adds clip mode (inside/outside) and pure virtual method to
80approximate shape as set of planes. This plane set is used to perform
81interactive clipping using OpenGL clip planes.
82*/
83
84
85////////////////////////////////////////////////////////////////////////////////
86/// Construct a stand-alone physical clipping object.
87
88TGLClip::TGLClip(const TGLLogicalShape & logical, const TGLMatrix & transform, const float color[4]) :
90 fMode (kInside),
91 fTimeStamp (1),
92 fValid (kFALSE)
93{
94 logical.StrongRef(kTRUE);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Destroy clip object.
99
103
104////////////////////////////////////////////////////////////////////////////////
105/// Setup the clipping object with two vectors.
106/// The interpretation of the two is different for plane and box
107/// clipping objects.
108
110{
111 Warning("TGLClip::Setup", "Called on base-class -- should be re-implemented in derived class.");
112
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Draw out clipping object with blending and back + front filling.
117/// Some clip objects are single face which we want to see both sides of.
118
134
135/** \class TGLClipPlane
136\ingroup opengl
137Concrete clip plane object. This can be translated in all directions
138rotated about the Y/Z local axes (the in-plane axes). It cannot be
139scaled.
140*/
141
142
143const float TGLClipPlane::fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
144
145////////////////////////////////////////////////////////////////////////////////
146/// Construct a clip plane object, based on supplied 'plane', with
147/// initial manipulation pivot at 'center', with drawn extents (in
148/// local x/y axes) of 'extents'
149///
150/// Plane can have center pivot translated in all directions, and
151/// rotated round center in X/Y axes , the in-plane axes. It cannot
152/// be scaled
153///
154/// Note theoretically a plane is of course infinite - however we
155/// want to draw the object in viewer - so we fake it with a single
156/// GL face (polygon) - extents defines the width/depth of this -
157/// should be several times scene extents - see Setup().
158
160 TGLClip(* new TGLClipPlaneLogical, TGLMatrix(), fgColor)
161{
163
164 TGLPlane plane(0.0, -1.0, 0.0, 0.0);
165 Set(plane);
166 fValid = kFALSE;
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Destroy clip plane object
171
175
176////////////////////////////////////////////////////////////////////////////////
177/// Setup the clip object for scene encompassed by bbox.
178
180{
181 Double_t extents = bbox.Extents().Mag();
182 TGLClipPlaneLogical* cpl = (TGLClipPlaneLogical*) GetLogical();
183 cpl->Resize(extents);
184 if (!fValid) {
185 SetTransform(TGLMatrix(bbox.Center(), BoundingBox().GetNearPlane().Norm()));
186 }
187 IncTimeStamp();
188 fValid = kTRUE;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Setup the clipping plane by point and normal.
193/// Length of the normal determines the size of the plane drawn in
194/// GL viewer. The normal points into the direction of visible half-plane.
195///
196/// This only makes sense if you disable auto-update of the
197/// clip-object:
198///
199/// gl_viewer->SetClipAutoUpdate(kFALSE).
200///
201/// After calling this also call gl_viewer->RefreshPadEditor(gl_viewer)
202/// and gl_viewer->RequestDraw().
203
205{
207 Double_t extents = n.Mag();
208 if (extents > 0)
209 {
210 n /= extents;
211 TGLClipPlaneLogical* cpl = (TGLClipPlaneLogical*) GetLogical();
212 cpl->Resize(extents);
213 SetTransform(TGLMatrix(point, n));
214
215 IncTimeStamp();
216 fValid = kTRUE;
217 }
218 else
219 {
220 Warning("TGLClipPlane::Setup", "Normal with zero length passed.");
221 }
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Update clip plane object to follow passed 'plane' equation. Center pivot
226/// is shifted to nearest point on new plane.
227
229{
230 TGLVertex3 oldCenter = BoundingBox().Center();
231 TGLVertex3 newCenter = plane.NearestOn(oldCenter);
233 IncTimeStamp();
234 fValid = kTRUE;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Return set of planes (actually a single one) describing this clip plane.
239
241{
242 set.resize(1);
243 set[0] = BoundingBox().GetNearPlane();
244 set[0].Negate();
245}
246
247/** \class TGLClipBox
248\ingroup opengl
249Concrete clip box object. Can be translated, rotated and scaled in
250all (xyz) axes. By default inside of the box is clipped away.
251*/
252
253
254const float TGLClipBox::fgColor[4] = { 1.0, 0.6, 0.2, 0.3 };
255
256////////////////////////////////////////////////////////////////////////////////
257/// Construct an (initially) axis aligned clip pbox object, extents
258/// 'halfLengths', centered on 'center' vertex.
259/// Box can be translated, rotated and scaled in all (xyz) local axes.
260
262 TGLClip(* new TGLClipBoxLogical, TGLMatrix(), fgColor)
263{
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Destroy clip box object.
268
272
273////////////////////////////////////////////////////////////////////////////////
274/// Setup the clip object for scene encompassed by bbox.
275
277{
278 TGLVector3 halfLengths = bbox.Extents() * 0.2501;
279 TGLVertex3 center = bbox.Center() + halfLengths;
280
281 TGLClipBoxLogical* cbl = (TGLClipBoxLogical*) GetLogical();
282 cbl->Resize(center - halfLengths, center + halfLengths);
283
284 IncTimeStamp();
285 fValid = kTRUE;
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Setup the clip box with min/max points directly.
290///
291/// This only makes sense if you disable auto-update of the
292/// clip-object:
293///
294/// gl_viewer->SetClipAutoUpdate(kFALSE).
295///
296/// After calling this also call gl_viewer->RefreshPadEditor(gl_viewer)
297/// and gl_viewer->RequestDraw().
298
300{
301 TGLClipBoxLogical* cbl = (TGLClipBoxLogical*) GetLogical();
302 cbl->Resize(min_point, max_point);
303
304 IncTimeStamp();
305 fValid = kTRUE;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Return set of 6 planes describing faces of the box but invert them
310/// so that they point inside of box.
311
313{
314 BoundingBox().PlaneSet(set);
315 TGLPlaneSet_i i = set.begin();
316 while (i != set.end()) {
317 i->Negate();
318 ++i;
319 }
320}
321
322
323/** \class TGLClipSet
324\ingroup opengl
325A collection of concrete TGLClip objects to be selected from.
326*/
327
328
329////////////////////////////////////////////////////////////////////////////////
330/// Constructor.
331
333 TGLOverlayElement(kViewer),
334 fClipPlane (new TGLClipPlane),
335 fClipBox (new TGLClipBox),
336 fCurrentClip (nullptr),
337 fAutoUpdate (kTRUE),
338 fShowClip (kFALSE),
339 fShowManip (kFALSE),
340 fManip (new TGLManipSet)
341{
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Destructor.
346
348{
349 delete fClipPlane;
350 delete fClipBox;
351 delete fManip;
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Mouse has entered this element.
356/// Forward to ManipSet.
357
362
364{
365 // A new overlay hit is about to be processed.
366 // Forward to ManipSet.
367
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Handle overlay event.
373/// Forward to ManipSet.
374
380
381////////////////////////////////////////////////////////////////////////////////
382/// Mouse has left the element.
383/// Forward to ManipSet.
384
386{
387 return fManip->MouseLeave();
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Render clip-shape and manipulator.
392
394{
395 if (!fCurrentClip) return;
396
397 rnrCtx.SetShapeLOD(TGLRnrCtx::kLODHigh);
398 rnrCtx.SetDrawPass(TGLRnrCtx::kPassFill);
399 if (fShowClip && ! rnrCtx.Selection())
400 {
402 }
403 if (fShowManip)
404 {
406 }
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Forward request to fill the plane-set to the current clip.
411
413{
414 if (fCurrentClip)
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Setup clipping objects for given scene bounding box.
420
427
428////////////////////////////////////////////////////////////////////////////////
429/// Setup current clipping object for given scene bounding box.
430
437
438////////////////////////////////////////////////////////////////////////////////
439/// Setup current clipping object for given scene bounding box.
440
447
448////////////////////////////////////////////////////////////////////////////////
449/// Invalidate clip objects.
450
456
457////////////////////////////////////////////////////////////////////////////////
458/// Invalidate current clip object.
459
465
466////////////////////////////////////////////////////////////////////////////////
467/// Get state of clip object 'type' into data vector:
468///
469/// 'type' requested - 'data' contents returned
470/// kClipPlane 4 components - A,B,C,D - of plane eq : Ax+By+CZ+D = 0
471/// kBoxPlane 6 components - Box Center X/Y/Z - Box Extents X/Y/Z
472
474{
475 switch (type)
476 {
478 break;
479
481 {
482 if (!fClipPlane->IsValid())
486 data[0] = planes[0].A();
487 data[1] = planes[0].B();
488 data[2] = planes[0].C();
489 data[3] = planes[0].D();
490 break;
491 }
493 {
494 if (!fClipBox->IsValid())
497 TGLVector3 ext = box.Extents();
498 data[0] = box.Center().X();
499 data[1] = box.Center().Y();
500 data[2] = box.Center().Z();
501 data[3] = box.Extents().X();
502 data[4] = box.Extents().Y();
503 data[5] = box.Extents().Z();
504 break;
505 }
506 default:
507 Error("TGLClipSet::GetClipState", "invalid clip type '%d'.", type);
508 break;
509 }
510}
511
512////////////////////////////////////////////////////////////////////////////////
513/// Set state of clip object 'type' into data vector:
514///
515/// 'type' specified 'data' contents interpretation
516/// kClipNone ignored
517/// kClipPlane 4 components - A,B,C,D - of plane eq : Ax+By+CZ+D = 0
518/// kBoxPlane 6 components - Box Center X/Y/Z - Box Extents X/Y/Z
519
521{
522 switch (type) {
523 case TGLClip::kClipNone: {
524 break;
525 }
526 case TGLClip::kClipPlane: {
527 TGLPlane newPlane(-data[0], -data[1], -data[2], -data[3]);
529 break;
530 }
531 case TGLClip::kClipBox: {
532 //TODO: Pull these inside TGLPhysicalShape
533 // Update clip box center
535 TGLVector3 shift(data[0] - currentBox.Center().X(),
536 data[1] - currentBox.Center().Y(),
537 data[2] - currentBox.Center().Z());
538 fClipBox->Translate(shift);
539 // Update clip box extents
540
542 TGLVector3 newScale(data[3] / currentBox.Extents().X() * currentScale.X(),
543 data[4] / currentBox.Extents().Y() * currentScale.Y(),
544 data[5] / currentBox.Extents().Z() * currentScale.Z());
545
547 break;
548 }
549 }
550}
551
552////////////////////////////////////////////////////////////////////////////////
553/// Get current type active in viewer - returns one of kClipNone
554/// kClipPlane or kClipBox.
555
557{
559 if (fCurrentClip == nullptr) {
561 } else if (fCurrentClip == fClipPlane) {
563 } else if (fCurrentClip == fClipBox) {
565 } else {
566 Error("TGLClipSet::GetClipType" , "Unknown clip type");
568 }
569 return type;
570}
571
572////////////////////////////////////////////////////////////////////////////////
573/// Set current clip active in viewer - 'type' is one of kClipNone
574/// kClipPlane or kClipBox.
575
577{
578 switch (type) {
579 case TGLClip::kClipNone: {
580 fCurrentClip = nullptr;
581 break;
582 }
583 case TGLClip::kClipPlane: {
585 break;
586 }
587 case TGLClip::kClipBox: {
589 break;
590 }
591 default: {
592 Error("TGLClipSet::SetClipType" , "Unknown clip type");
593 break;
594 }
595 }
597}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
std::vector< TGLPlane > TGLPlaneSet_t
Definition TGLUtil.h:571
std::vector< TGLPlane >::iterator TGLPlaneSet_i
Definition TGLUtil.h:572
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
TGLVector3 Extents() const
TGLVertex3 Center() const
Concrete clip box object.
Definition TGLClip.h:114
~TGLClipBox() override
Destroy clip box object.
Definition TGLClip.cxx:269
void Setup(const TGLBoundingBox &bbox) override
Setup the clip object for scene encompassed by bbox.
Definition TGLClip.cxx:276
void PlaneSet(TGLPlaneSet_t &set) const override
Return set of 6 planes describing faces of the box but invert them so that they point inside of box.
Definition TGLClip.cxx:312
TGLClipBox()
Fixed color of clip box.
Definition TGLClip.cxx:261
static const float fgColor[4]
Definition TGLClip.h:254
Concrete clip plane object.
Definition TGLClip.h:86
static const float fgColor[4]
Definition TGLClip.h:143
void Set(const TGLPlane &plane)
Update clip plane object to follow passed 'plane' equation.
Definition TGLClip.cxx:228
void PlaneSet(TGLPlaneSet_t &set) const override
Return set of planes (actually a single one) describing this clip plane.
Definition TGLClip.cxx:240
~TGLClipPlane() override
Destroy clip plane object.
Definition TGLClip.cxx:172
void Setup(const TGLBoundingBox &bbox) override
Setup the clip object for scene encompassed by bbox.
Definition TGLClip.cxx:179
TGLClipPlane()
Fixed color of clip plane.
Definition TGLClip.cxx:159
~TGLClipSet() override
Destructor.
Definition TGLClip.cxx:347
void InvalidateClips()
Invalidate clip objects.
Definition TGLClip.cxx:451
TGLClip * fCurrentClip
Definition TGLClip.h:148
Bool_t fShowManip
Definition TGLClip.h:152
TGLManipSet * fManip
Definition TGLClip.h:153
void GetClipState(TGLClip::EType type, Double_t data[6]) const
Get state of clip object 'type' into data vector:
Definition TGLClip.cxx:473
void SetClipState(TGLClip::EType type, const Double_t data[6])
Set state of clip object 'type' into data vector:
Definition TGLClip.cxx:520
TGLClipBox * fClipBox
Definition TGLClip.h:147
void FillPlaneSet(TGLPlaneSet_t &set) const
Forward request to fill the plane-set to the current clip.
Definition TGLClip.cxx:412
void SetupCurrentClip(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition TGLClip.cxx:431
void SetClipType(TGLClip::EType type)
Set current clip active in viewer - 'type' is one of kClipNone kClipPlane or kClipBox.
Definition TGLClip.cxx:576
Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event) override
Handle overlay event.
Definition TGLClip.cxx:375
void MouseLeave() override
Mouse has left the element.
Definition TGLClip.cxx:385
TGLClipSet()
Constructor.
Definition TGLClip.cxx:332
Bool_t MouseStillInside(TGLOvlSelectRecord &selRec) override
Definition TGLClip.cxx:363
TGLClipPlane * fClipPlane
Definition TGLClip.h:146
Bool_t MouseEnter(TGLOvlSelectRecord &selRec) override
Mouse has entered this element.
Definition TGLClip.cxx:358
TGLBoundingBox fLastBBox
Definition TGLClip.h:155
Bool_t fShowClip
Definition TGLClip.h:151
void SetupCurrentClipIfInvalid(const TGLBoundingBox &sceneBBox)
Setup current clipping object for given scene bounding box.
Definition TGLClip.cxx:441
TGLClip::EType GetClipType() const
Get current type active in viewer - returns one of kClipNone kClipPlane or kClipBox.
Definition TGLClip.cxx:556
void SetupClips(const TGLBoundingBox &sceneBBox)
Setup clipping objects for given scene bounding box.
Definition TGLClip.cxx:421
void Render(TGLRnrCtx &rnrCtx) override
Render clip-shape and manipulator.
Definition TGLClip.cxx:393
void InvalidateCurrentClip()
Invalidate current clip object.
Definition TGLClip.cxx:460
Abstract clipping shape - derives from TGLPhysicalShape Adds clip mode (inside/outside) and pure virt...
Definition TGLClip.h:32
@ kClipBox
Definition TGLClip.h:43
@ kClipPlane
Definition TGLClip.h:42
@ kClipNone
Definition TGLClip.h:41
~TGLClip() override
Destroy clip object.
Definition TGLClip.cxx:100
void IncTimeStamp()
Definition TGLClip.h:64
virtual void Setup(const TGLBoundingBox &bbox)=0
void Invalidate()
Definition TGLClip.h:67
TGLClip(const TGLLogicalShape &logical, const TGLMatrix &transform, const float color[4])
Construct a stand-alone physical clipping object.
Definition TGLClip.cxx:88
virtual void PlaneSet(TGLPlaneSet_t &set) const =0
Bool_t fValid
Definition TGLClip.h:49
Bool_t IsValid() const
Definition TGLClip.h:66
void Draw(TGLRnrCtx &rnrCtx) const override
Draw out clipping object with blending and back + front filling.
Definition TGLClip.cxx:119
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
Combine all available manipulators in a collection.
Definition TGLManipSet.h:22
void MouseLeave() override
Mouse has left the element.
Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event) override
Handle overlay event.
Bool_t MouseEnter(TGLOvlSelectRecord &selRec) override
Mouse has entered this element.
void Render(TGLRnrCtx &rnrCtx) override
Render the manipulator and bounding-box.
void SetPShape(TGLPhysicalShape *shape) override
Set phys-shape, override of virtual from TGLPShapeRef.
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition TGLUtil.h:598
An overlay element.
Definition TGLOverlay.h:23
virtual Bool_t MouseStillInside(TGLOvlSelectRecord &selRec)
Selection record for overlay objects.
Concrete physical shape - a GL drawable.
void Scale(const TGLVector3 &scale)
void SetTransform(const TGLMatrix &transform)
const TGLBoundingBox & BoundingBox() const
void SetManip(EManip manip)
TGLVector3 GetScale() const
const TGLLogicalShape * GetLogical() const
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw physical shape, using LOD flags, potential from display list cache.
void Translate(const TGLVector3 &vect)
3D plane class - of format Ax + By + Cz + D = 0
Definition TGLUtil.h:525
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
Double_t Mag() const
Definition TGLUtil.h:298
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
const Int_t n
Definition legend1.C:16
Event structure.
Definition GuiTypes.h:174