24 class TGLClipPlaneLogical :
public TGLLogicalShape
27 virtual void DirectDraw(TGLRnrCtx & rnrCtx)
const
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());
39 TGLClipPlaneLogical() : TGLLogicalShape() { fDLCache = kFALSE; }
40 virtual ~TGLClipPlaneLogical() {}
42 void Resize(Double_t ext)
44 fBoundingBox.SetAligned(TGLVertex3(-ext, -ext, 0),
45 TGLVertex3( ext, ext, 0));
46 UpdateBoundingBoxesOfPhysicals();
52 class TGLClipBoxLogical :
public TGLLogicalShape
55 virtual void DirectDraw(TGLRnrCtx & rnrCtx)
const
57 glEnable(GL_NORMALIZE);
58 fBoundingBox.Draw(rnrCtx.IsDrawPassFilled());
59 glDisable(GL_NORMALIZE);
63 TGLClipBoxLogical() : TGLLogicalShape() { fDLCache = kFALSE; }
64 virtual ~TGLClipBoxLogical() {}
66 void Resize(
const TGLVertex3 & lowVertex,
const TGLVertex3 & highVertex)
68 fBoundingBox.SetAligned(lowVertex, highVertex);
69 UpdateBoundingBoxesOfPhysicals();
89 TGLClip::TGLClip(
const TGLLogicalShape & logical,
const TGLMatrix & transform,
const float color[4]) :
90 TGLPhysicalShape(0, logical, transform, kTRUE, color),
95 logical.StrongRef(kTRUE);
110 void TGLClip::Setup(
const TGLVector3&,
const TGLVector3&)
112 Warning(
"TGLClip::Setup",
"Called on base-class -- should be re-implemented in derived class.");
120 void TGLClip::Draw(TGLRnrCtx & rnrCtx)
const
122 glDepthMask(GL_FALSE);
124 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
125 glDisable(GL_CULL_FACE);
126 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
128 TGLPhysicalShape::Draw(rnrCtx);
130 glPolygonMode(GL_FRONT, GL_FILL);
131 glEnable(GL_CULL_FACE);
133 glDepthMask(GL_TRUE);
143 ClassImp(TGLClipPlane);
145 const float TGLClipPlane::fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
161 TGLClipPlane::TGLClipPlane() :
162 TGLClip(* new TGLClipPlaneLogical, TGLMatrix(), fgColor)
164 SetManip(EManip(kTranslateAll | kRotateX | kRotateY));
166 TGLPlane plane(0.0, -1.0, 0.0, 0.0);
174 TGLClipPlane::~TGLClipPlane()
181 void TGLClipPlane::Setup(
const TGLBoundingBox & bbox)
183 Double_t extents = bbox.Extents().Mag();
184 TGLClipPlaneLogical* cpl = (TGLClipPlaneLogical*) GetLogical();
185 cpl->Resize(extents);
187 SetTransform(TGLMatrix(bbox.Center(), BoundingBox().GetNearPlane().Norm()));
206 void TGLClipPlane::Setup(
const TGLVector3& point,
const TGLVector3& normal)
208 TGLVector3 n(normal);
209 Double_t extents = n.Mag();
213 TGLClipPlaneLogical* cpl = (TGLClipPlaneLogical*) GetLogical();
214 cpl->Resize(extents);
215 SetTransform(TGLMatrix(point, n));
222 Warning(
"TGLClipPlane::Setup",
"Normal with zero length passed.");
230 void TGLClipPlane::Set(
const TGLPlane& plane)
232 TGLVertex3 oldCenter = BoundingBox().Center();
233 TGLVertex3 newCenter = plane.NearestOn(oldCenter);
234 SetTransform(TGLMatrix(newCenter, plane.Norm()));
242 void TGLClipPlane::PlaneSet(TGLPlaneSet_t& set)
const
245 set[0] = BoundingBox().GetNearPlane();
255 ClassImp(TGLClipBox);
257 const float TGLClipBox::fgColor[4] = { 1.0, 0.6, 0.2, 0.3 };
264 TGLClipBox::TGLClipBox() :
265 TGLClip(* new TGLClipBoxLogical, TGLMatrix(), fgColor)
272 TGLClipBox::~TGLClipBox()
279 void TGLClipBox::Setup(
const TGLBoundingBox& bbox)
281 TGLVector3 halfLengths = bbox.Extents() * 0.2501;
282 TGLVertex3 center = bbox.Center() + halfLengths;
284 TGLClipBoxLogical* cbl = (TGLClipBoxLogical*) GetLogical();
285 cbl->Resize(center - halfLengths, center + halfLengths);
302 void TGLClipBox::Setup(
const TGLVector3& min_point,
const TGLVector3& max_point)
304 TGLClipBoxLogical* cbl = (TGLClipBoxLogical*) GetLogical();
305 cbl->Resize(min_point, max_point);
315 void TGLClipBox::PlaneSet(TGLPlaneSet_t& set)
const
317 BoundingBox().PlaneSet(set);
318 TGLPlaneSet_i i = set.begin();
319 while (i != set.end()) {
331 ClassImp(TGLClipSet);
336 TGLClipSet::TGLClipSet() :
337 TGLOverlayElement(kViewer),
338 fClipPlane (new TGLClipPlane),
339 fClipBox (new TGLClipBox),
344 fManip (new TGLManipSet)
351 TGLClipSet::~TGLClipSet()
362 Bool_t TGLClipSet::MouseEnter(TGLOvlSelectRecord& selRec)
364 return fManip->MouseEnter(selRec);
367 Bool_t TGLClipSet::MouseStillInside(TGLOvlSelectRecord& selRec)
372 return fManip->MouseStillInside(selRec);
379 Bool_t TGLClipSet::Handle(TGLRnrCtx& rnrCtx, TGLOvlSelectRecord& selRec,
382 return fManip->Handle(rnrCtx, selRec, event);
389 void TGLClipSet::MouseLeave()
391 return fManip->MouseLeave();
397 void TGLClipSet::Render(TGLRnrCtx& rnrCtx)
399 if (!fCurrentClip)
return;
401 rnrCtx.SetShapeLOD(TGLRnrCtx::kLODHigh);
402 rnrCtx.SetDrawPass(TGLRnrCtx::kPassFill);
403 if (fShowClip && ! rnrCtx.Selection())
405 fCurrentClip->Draw(rnrCtx);
409 fManip->Render(rnrCtx);
416 void TGLClipSet::FillPlaneSet(TGLPlaneSet_t& set)
const
419 fCurrentClip->PlaneSet(set);
425 void TGLClipSet::SetupClips(
const TGLBoundingBox& sceneBBox)
427 fLastBBox = sceneBBox;
428 fClipPlane->Setup(sceneBBox);
429 fClipBox ->Setup(sceneBBox);
435 void TGLClipSet::SetupCurrentClip(
const TGLBoundingBox& sceneBBox)
437 fLastBBox = sceneBBox;
439 fCurrentClip->Setup(sceneBBox);
445 void TGLClipSet::SetupCurrentClipIfInvalid(
const TGLBoundingBox& sceneBBox)
447 fLastBBox = sceneBBox;
448 if (fCurrentClip && ! fCurrentClip->IsValid())
449 fCurrentClip->Setup(sceneBBox);
455 void TGLClipSet::InvalidateClips()
457 fClipPlane->Invalidate();
458 fClipBox ->Invalidate();
464 void TGLClipSet::InvalidateCurrentClip()
467 fCurrentClip->Invalidate();
477 void TGLClipSet::GetClipState(TGLClip::EType type, Double_t data[6])
const
481 case TGLClip::kClipNone:
484 case TGLClip::kClipPlane:
486 if (!fClipPlane->IsValid())
487 fClipPlane->Setup(fLastBBox);
488 TGLPlaneSet_t planes;
489 fClipPlane->PlaneSet(planes);
490 data[0] = planes[0].A();
491 data[1] = planes[0].B();
492 data[2] = planes[0].C();
493 data[3] = planes[0].D();
496 case TGLClip::kClipBox:
498 if (!fClipBox->IsValid())
499 fClipBox->Setup(fLastBBox);
500 const TGLBoundingBox & box = fClipBox->BoundingBox();
501 TGLVector3 ext = box.Extents();
502 data[0] = box.Center().X();
503 data[1] = box.Center().Y();
504 data[2] = box.Center().Z();
505 data[3] = box.Extents().X();
506 data[4] = box.Extents().Y();
507 data[5] = box.Extents().Z();
511 Error(
"TGLClipSet::GetClipState",
"invalid clip type '%d'.", type);
524 void TGLClipSet::SetClipState(TGLClip::EType type,
const Double_t data[6])
527 case TGLClip::kClipNone: {
530 case TGLClip::kClipPlane: {
531 TGLPlane newPlane(-data[0], -data[1], -data[2], -data[3]);
532 fClipPlane->Set(newPlane);
535 case TGLClip::kClipBox: {
538 const TGLBoundingBox & currentBox = fClipBox->BoundingBox();
539 TGLVector3 shift(data[0] - currentBox.Center().X(),
540 data[1] - currentBox.Center().Y(),
541 data[2] - currentBox.Center().Z());
542 fClipBox->Translate(shift);
545 TGLVector3 currentScale = fClipBox->GetScale();
546 TGLVector3 newScale(data[3] / currentBox.Extents().X() * currentScale.X(),
547 data[4] / currentBox.Extents().Y() * currentScale.Y(),
548 data[5] / currentBox.Extents().Z() * currentScale.Z());
550 fClipBox->Scale(newScale);
560 TGLClip::EType TGLClipSet::GetClipType()
const
563 if (fCurrentClip == 0) {
564 type = TGLClip::kClipNone;
565 }
else if (fCurrentClip == fClipPlane) {
566 type = TGLClip::kClipPlane;
567 }
else if (fCurrentClip == fClipBox) {
568 type = TGLClip::kClipBox;
570 Error(
"TGLClipSet::GetClipType" ,
"Unknown clip type");
571 type = TGLClip::kClipNone;
580 void TGLClipSet::SetClipType(TGLClip::EType type)
583 case TGLClip::kClipNone: {
587 case TGLClip::kClipPlane: {
588 fCurrentClip = fClipPlane;
591 case TGLClip::kClipBox: {
592 fCurrentClip = fClipBox;
596 Error(
"TGLClipSet::SetClipType" ,
"Unknown clip type");
600 fManip->SetPShape(fCurrentClip);