14#include "TGLIncludes.h"
101 Int_t zeroMagAxisInd = -1;
102 for (
UInt_t i = 0; i<3; i++) {
108 if (!fixZeroMagAxis && zeroMagAxisInd == -1) {
110 fixZeroMagAxis =
kTRUE;
111 }
else if (fixZeroMagAxis) {
119 if (fixZeroMagAxis) {
201 if (diff.
X() < 0.0 || diff.
Y() < 0.0 || diff.
Z() < 0.0) {
202 Error(
"TGLBoundingBox::SetAligned",
"low/high vertex range error");
222 if (nbPnts < 1 || !pnts) {
232 for (
UInt_t i = 0; i < 3; i++) {
233 if (pnts[3*
p + i] < low[i]) {
234 low[i] = pnts[3*
p + i] ;
236 if (pnts[3*
p + i] > high[i]) {
237 high[i] = pnts[3*
p + i] ;
287 Scale(factor, factor, factor);
314 fVertex[0] += -xOffset - yOffset - zOffset;
315 fVertex[1] += xOffset - yOffset - zOffset;
316 fVertex[2] += xOffset + yOffset - zOffset;
317 fVertex[3] += -xOffset + yOffset - zOffset;
319 fVertex[4] += -xOffset - yOffset + zOffset;
320 fVertex[5] += xOffset - yOffset + zOffset;
321 fVertex[6] += xOffset + yOffset + zOffset;
322 fVertex[7] += -xOffset + yOffset + zOffset;
370 static std::vector<UInt_t> faceIndexes[
kFaceCount];
404 return faceIndexes[face];
413 assert(planeSet.empty());
457 Int_t verticesInsidePlane = 8;
460 verticesInsidePlane--;
464 if ( verticesInsidePlane == 0 ) {
466 }
else if ( verticesInsidePlane == 8 ) {
498 Double_t aSphereRadius = aHL[0] < aHL[1] ? aHL[0] : aHL[1];
499 if (aHL[2] < aSphereRadius) {
500 aSphereRadius = aHL[2];
507 if (bSphereRadius + parentT.
Mag() < aSphereRadius) {
520 for (i=0 ; i<3 ; i++) {
521 for (k=0; k<3; k++) {
522 roaT[i][k] =
Dot(
a.Axis(i),
b.Axis(k));
524 if (fabs(roaT[i][k]) < 1
e-14) {
529 Double_t norm = sqrt(roaT[i][0]*roaT[i][0] + roaT[i][1]*roaT[i][1] + roaT[i][2]*roaT[i][2]);
530 roaT[i][0] /= norm; roaT[i][1] /= norm; roaT[i][2] /= norm;
538 for (i=0; i<3; i++) {
540 rb = bHL[0]*fabs(roaT[i][0]) + bHL[1]*fabs(roaT[i][1]) + bHL[2]*fabs(roaT[i][2]);
544 else if (ra < t + rb)
549 for (k=0; k<3; k++) {
550 ra = aHL[0]*fabs(roaT[0][k]) + aHL[1]*fabs(roaT[1][k]) + aHL[2]*fabs(roaT[2][k]);
552 t = fabs(aT[0]*roaT[0][k] + aT[1]*roaT[1][k] + aT[2]*roaT[2][k]);
555 else if (ra < t + rb)
562 ra = aHL[1]*fabs(roaT[2][0]) + aHL[2]*fabs(roaT[1][0]);
563 rb = bHL[1]*fabs(roaT[0][2]) + bHL[2]*fabs(roaT[0][1]);
564 t = fabs(aT[2]*roaT[1][0] - aT[1]*roaT[2][0]);
567 else if (ra < t + rb)
571 ra = aHL[1]*fabs(roaT[2][1]) + aHL[2]*fabs(roaT[1][1]);
572 rb = bHL[0]*fabs(roaT[0][2]) + bHL[2]*fabs(roaT[0][0]);
573 t = fabs(aT[2]*roaT[1][1] - aT[1]*roaT[2][1]);
576 else if (ra < t + rb)
580 ra = aHL[1]*fabs(roaT[2][2]) + aHL[2]*fabs(roaT[1][2]);
581 rb = bHL[0]*fabs(roaT[0][1]) + bHL[1]*fabs(roaT[0][0]);
582 t = fabs(aT[2]*roaT[1][2] - aT[1]*roaT[2][2]);
585 else if (ra < t + rb)
589 ra = aHL[0]*fabs(roaT[2][0]) + aHL[2]*fabs(roaT[0][0]);
590 rb = bHL[1]*fabs(roaT[1][2]) + bHL[2]*fabs(roaT[1][1]);
591 t = fabs(aT[0]*roaT[2][0] - aT[2]*roaT[0][0]);
594 else if (ra < t + rb)
598 ra = aHL[0]*fabs(roaT[2][1]) + aHL[2]*fabs(roaT[0][1]);
599 rb = bHL[0]*fabs(roaT[1][2]) + bHL[2]*fabs(roaT[1][0]);
600 t = fabs(aT[0]*roaT[2][1] - aT[2]*roaT[0][1]);
603 else if (ra < t + rb)
607 ra = aHL[0]*fabs(roaT[2][2]) + aHL[2]*fabs(roaT[0][2]);
608 rb = bHL[0]*fabs(roaT[1][1]) + bHL[1]*fabs(roaT[1][0]);
609 t = fabs(aT[0]*roaT[2][2] - aT[2]*roaT[0][2]);
612 else if (ra < t + rb)
616 ra = aHL[0]*fabs(roaT[1][0]) + aHL[1]*fabs(roaT[0][0]);
617 rb = bHL[1]*fabs(roaT[2][2]) + bHL[2]*fabs(roaT[2][1]);
618 t = fabs(aT[1]*roaT[0][0] - aT[0]*roaT[1][0]);
621 else if (ra < t + rb)
625 ra = aHL[0]*fabs(roaT[1][1]) + aHL[1]*fabs(roaT[0][1]);
626 rb = bHL[0]*fabs(roaT[2][2]) + bHL[2]*fabs(roaT[2][0]);
627 t = fabs(aT[1]*roaT[0][1] - aT[0]*roaT[1][1]);
630 else if (ra < t + rb)
634 ra = aHL[0]*fabs(roaT[1][2]) + aHL[1]*fabs(roaT[0][2]);
635 rb = bHL[0]*fabs(roaT[2][1]) + bHL[1]*fabs(roaT[2][0]);
636 t = fabs(aT[1]*roaT[0][2] - aT[0]*roaT[1][2]);
639 else if (ra < t + rb)
654 glVertex3dv(
fVertex[0].CArr());
655 glVertex3dv(
fVertex[1].CArr());
656 glVertex3dv(
fVertex[2].CArr());
657 glVertex3dv(
fVertex[3].CArr());
658 glVertex3dv(
fVertex[7].CArr());
659 glVertex3dv(
fVertex[6].CArr());
660 glVertex3dv(
fVertex[5].CArr());
661 glVertex3dv(
fVertex[4].CArr());
664 glVertex3dv(
fVertex[1].CArr());
665 glVertex3dv(
fVertex[5].CArr());
666 glVertex3dv(
fVertex[2].CArr());
667 glVertex3dv(
fVertex[6].CArr());
668 glVertex3dv(
fVertex[0].CArr());
669 glVertex3dv(
fVertex[3].CArr());
670 glVertex3dv(
fVertex[4].CArr());
671 glVertex3dv(
fVertex[7].CArr());
688 glVertex3dv(
fVertex[4].CArr());
689 glVertex3dv(
fVertex[7].CArr());
690 glVertex3dv(
fVertex[6].CArr());
691 glVertex3dv(
fVertex[5].CArr());
694 glVertex3dv(
fVertex[0].CArr());
695 glVertex3dv(
fVertex[1].CArr());
696 glVertex3dv(
fVertex[2].CArr());
697 glVertex3dv(
fVertex[3].CArr());
700 glVertex3dv(
fVertex[0].CArr());
701 glVertex3dv(
fVertex[3].CArr());
702 glVertex3dv(
fVertex[7].CArr());
703 glVertex3dv(
fVertex[4].CArr());
706 glVertex3dv(
fVertex[6].CArr());
707 glVertex3dv(
fVertex[2].CArr());
708 glVertex3dv(
fVertex[1].CArr());
709 glVertex3dv(
fVertex[5].CArr());
712 glVertex3dv(
fVertex[3].CArr());
713 glVertex3dv(
fVertex[2].CArr());
714 glVertex3dv(
fVertex[6].CArr());
715 glVertex3dv(
fVertex[7].CArr());
718 glVertex3dv(
fVertex[4].CArr());
719 glVertex3dv(
fVertex[5].CArr());
720 glVertex3dv(
fVertex[1].CArr());
721 glVertex3dv(
fVertex[0].CArr());
777 for (
UInt_t i = 0; i<8; i++) {
778 std::cout <<
"[" << i <<
"] (" <<
fVertex[i].
X() <<
"," <<
fVertex[i].
Y() <<
"," <<
fVertex[i].
Z() <<
")" << std::endl;
782 std::cout <<
"Volume: " <<
Volume() << std::endl;
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
std::vector< TGLPlane > TGLPlaneSet_t
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
winID h TVirtualViewer3D TVirtualGLPainter p
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 offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Double_t Min(UInt_t index) const
Find minimum vertex value for axis of index X(0), Y(1), Z(2)
Double_t fDiagonal
box volume - cached for speed
TGLPlane GetNearPlane() const
Return the near-plane.
TGLVector3 Extents() const
TGLVertex3 Center() const
void Set(const TGLVertex3 vertex[8])
Set a bounding box from provided 8 vertices.
void SetEmpty()
Set bounding box empty - all vertices at (0,0,0)
void PlaneSet(TGLPlaneSet_t &planeSet) const
Fill out supplied plane set vector with TGLPlane objects representing six faces of box.
const std::vector< UInt_t > & FaceVertices(EFace face) const
return a vector of face vertices y | | |________x / 3----—2 / /| /| z 7----—6 | | 0--—|-1 |/ |/ 4----...
void Transform(const TGLMatrix &matrix)
Transform all vertices with matrix.
TGLVector3 fAxesNorm[3]
box axes in global frame - cached for speed
void MergeAligned(const TGLBoundingBox &other)
Expand current bbox so that it includes other's bbox.
void Translate(const TGLVector3 &offset)
Translate all vertices by offset.
TGLVertex3 MinAAVertex() const
Find minimum vertex values.
TGLBoundingBox()
Construct an empty bounding box.
void Scale(Double_t factor)
Isotropically scale bounding box along it's LOCAL axes, preserving center.
TGLVector3 fAxes[3]
max box diagonal - cached for speed
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
TGLVertex3 MaxAAVertex() const
Find maximum vertex values.
void UpdateCache()
normalised box axes in global frame - cached for speed
Double_t Max(UInt_t index) const
Find maximum vertex value for axis of index X(0), Y(1), Z(2)
const TGLVector3 & Axis(UInt_t i, Bool_t normalised=kTRUE) const
void ExpandAligned(const TGLVertex3 &point)
Expand current bbox so that it includes the point.
Double_t fVolume
the 8 bounding box vertices
virtual ~TGLBoundingBox()
Destroy bounding box.
void Dump() const
Output to std::cout the vertices, center and volume of box.
Rgl::EOverlap Overlap(const TGLPlane &plane) const
Find overlap (Inside, Outside, Partial) of plane c.f. bounding box.
void Draw(Bool_t solid=kFALSE) const
Draw the bounding box as either wireframe (default) of solid using current GL color.
16 component (4x4) transform matrix - column MAJOR as per GL.
void TransformVertex(TGLVertex3 &vertex) const
Transform passed 'vertex' by this matrix - converts local frame to parent.
3D plane class - of format Ax + By + Cz + D = 0
Double_t DistanceTo(const TGLVertex3 &vertex) const
Distance from plane to vertex.
3 component (x/y/z) vector class.
3 component (x/y/z) vertex class.
void Dump() const
Output vertex component values to std::cout.
void Minimum(const TGLVertex3 &other)
void Maximum(const TGLVertex3 &other)
void Set(Double_t x, Double_t y, Double_t z)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.