#include "TEveBoxSetGL.h"
#include "TEveBoxSet.h"
#include "TGLIncludes.h"
#include "TGLRnrCtx.h"
#include "TGLScene.h"
#include "TGLSelectRecord.h"
#include "TGLContext.h"
#include "TGLQuadric.h"
ClassImp(TEveBoxSetGL);
TEveBoxSetGL::TEveBoxSetGL() : fM(0), fBoxDL(0)
{
fMultiColor = kTRUE;
}
TEveBoxSetGL::~TEveBoxSetGL()
{
DLCachePurge();
}
Int_t TEveBoxSetGL::PrimitiveType() const
{
return (fM->fRenderMode != TEveDigitSet::kRM_Line) ? GL_QUADS : GL_LINE_LOOP;
}
inline Bool_t TEveBoxSetGL::SetupColor(const TEveDigitSet::DigitBase_t& q) const
{
if (fM->fValueIsColor)
{
TGLUtil::Color4ubv((UChar_t*) & q.fValue);
return kTRUE;
}
else
{
UChar_t c[4];
Bool_t visible = fM->fPalette->ColorFromValue(q.fValue, fM->fDefaultValue, c);
if (visible)
TGLUtil::Color3ubv(c);
return visible;
}
}
void TEveBoxSetGL::MakeOriginBox(Float_t p[24], Float_t dx, Float_t dy, Float_t dz) const
{
p[0] = 0; p[1] = dy; p[2] = 0; p += 3;
p[0] = dx; p[1] = dy; p[2] = 0; p += 3;
p[0] = dx; p[1] = 0; p[2] = 0; p += 3;
p[0] = 0; p[1] = 0; p[2] = 0; p += 3;
p[0] = 0; p[1] = dy; p[2] = dz; p += 3;
p[0] = dx; p[1] = dy; p[2] = dz; p += 3;
p[0] = dx; p[1] = 0; p[2] = dz; p += 3;
p[0] = 0; p[1] = 0; p[2] = dz;
}
inline void TEveBoxSetGL::RenderBox(const Float_t p[24]) const
{
glNormal3f(0, 0, -1);
glVertex3fv(p); glVertex3fv(p + 3);
glVertex3fv(p + 6); glVertex3fv(p + 9);
glNormal3f(0, 0, 1);
glVertex3fv(p + 21); glVertex3fv(p + 18);
glVertex3fv(p + 15); glVertex3fv(p + 12);
glNormal3f(0, 1, 0);
glVertex3fv(p); glVertex3fv(p + 12);
glVertex3fv(p + 15); glVertex3fv(p + 3);
glNormal3f(0, -1, 0);
glVertex3fv(p + 9); glVertex3fv(p + 6);
glVertex3fv(p + 18); glVertex3fv(p + 21);
glNormal3f(-1, 0, 0);
glVertex3fv(p); glVertex3fv(p + 9);
glVertex3fv(p + 21); glVertex3fv(p + 12);
glNormal3f(1, 0, 0);
glVertex3fv(p + 3); glVertex3fv(p + 15);
glVertex3fv(p + 18); glVertex3fv(p + 6);
}
void TEveBoxSetGL::MakeDisplayList() const
{
if (fM->fBoxType == TEveBoxSet::kBT_AABox ||
fM->fBoxType == TEveBoxSet::kBT_AABoxFixedDim ||
fM->fBoxType == TEveBoxSet::kBT_Cone ||
fM->fBoxType == TEveBoxSet::kBT_EllipticCone)
{
if (fBoxDL == 0)
fBoxDL = glGenLists(1);
glNewList(fBoxDL, GL_COMPILE);
if (fM->fBoxType < TEveBoxSet::kBT_Cone)
{
glBegin(PrimitiveType());
Float_t p[24];
if (fM->fBoxType == TEveBoxSet::kBT_AABox)
MakeOriginBox(p, 1.0f, 1.0f, 1.0f);
else
MakeOriginBox(p, fM->fDefWidth, fM->fDefHeight, fM->fDefDepth);
RenderBox(p);
glEnd();
}
else
{
static TGLQuadric quad;
Int_t nt = 15;
gluCylinder(quad.Get(), 0, 1, 1, nt, 1);
if (fM->fDrawConeCap)
{
glPushMatrix();
glTranslatef(0, 0, 1);
gluDisk(quad.Get(), 0, 1, nt, 1);
glPopMatrix();
}
}
glEndList();
}
}
Bool_t TEveBoxSetGL::ShouldDLCache(const TGLRnrCtx & rnrCtx) const
{
MakeDisplayList();
return TGLObject::ShouldDLCache(rnrCtx);
}
void TEveBoxSetGL::DLCacheDrop()
{
fBoxDL = 0;
TGLObject::DLCacheDrop();
}
void TEveBoxSetGL::DLCachePurge()
{
if (fBoxDL != 0)
{
PurgeDLRange(fBoxDL, 1);
fBoxDL = 0;
}
TGLObject::DLCachePurge();
}
Bool_t TEveBoxSetGL::SetModel(TObject* obj, const Option_t* )
{
Bool_t isok = SetModelCheckClass(obj, TEveBoxSet::Class());
fM = isok ? dynamic_cast<TEveBoxSet*>(obj) : 0;
return isok;
}
void TEveBoxSetGL::SetBBox()
{
SetAxisAlignedBBox(fM->AssertBBox());
}
void TEveBoxSetGL::DirectDraw(TGLRnrCtx & rnrCtx) const
{
static const TEveException eH("TEveBoxSetGL::DirectDraw ");
TEveBoxSet& mB = * fM;
if(mB.fPlex.Size() == 0)
return;
if ( ! mB.fValueIsColor && mB.fPalette == 0)
{
mB.AssertPalette();
}
glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
if (mB.fRenderMode == TEveDigitSet::kRM_Fill)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
else if (mB.fRenderMode == TEveDigitSet::kRM_Line)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (mB.fBoxType == TEveBoxSet::kBT_Cone ||
mB.fBoxType == TEveBoxSet::kBT_EllipticCone)
{
glDisable(GL_CULL_FACE);
}
if (mB.fDisableLigting) glDisable(GL_LIGHTING);
if (rnrCtx.SecSelection()) glPushName(0);
Int_t boxSkip = 0;
if (rnrCtx.ShapeLOD() < 50)
boxSkip = 6 - (rnrCtx.ShapeLOD()+1)/10;
TEveChunkManager::iterator bi(mB.fPlex);
switch (mB.fBoxType)
{
case TEveBoxSet::kBT_FreeBox:
{
GLenum primitiveType = PrimitiveType();
while (bi.next())
{
TEveBoxSet::BFreeBox_t& b = * (TEveBoxSet::BFreeBox_t*) bi();
if (SetupColor(b))
{
if (rnrCtx.SecSelection()) glLoadName(bi.index());
glBegin(primitiveType);
RenderBox(b.fVertices);
glEnd();
}
if (boxSkip) { Int_t s = boxSkip; while (s--) bi.next(); }
}
break;
}
case TEveBoxSet::kBT_AABox:
{
glEnable(GL_NORMALIZE);
while (bi.next())
{
TEveBoxSet::BAABox_t& b = * (TEveBoxSet::BAABox_t*) bi();
if (SetupColor(b))
{
if (rnrCtx.SecSelection()) glLoadName(bi.index());
glPushMatrix();
glTranslatef(b.fA, b.fB, b.fC);
glScalef (b.fW, b.fH, b.fD);
glCallList(fBoxDL);
glPopMatrix();
}
if (boxSkip) { Int_t s = boxSkip; while (s--) bi.next(); }
}
break;
}
case TEveBoxSet::kBT_AABoxFixedDim:
{
while (bi.next())
{
TEveBoxSet::BAABoxFixedDim_t& b = * (TEveBoxSet::BAABoxFixedDim_t*) bi();
if (SetupColor(b))
{
if (rnrCtx.SecSelection()) glLoadName(bi.index());
glTranslatef(b.fA, b.fB, b.fC);
glCallList(fBoxDL);
glTranslatef(-b.fA, -b.fB, -b.fC);
}
if (boxSkip) { Int_t s = boxSkip; while (s--) bi.next(); }
}
break;
}
case TEveBoxSet::kBT_Cone:
{
using namespace TMath;
glEnable(GL_NORMALIZE);
Float_t theta=0, phi=0, h=0;
while (bi.next())
{
TEveBoxSet::BCone_t& b = * (TEveBoxSet::BCone_t*) bi();
if (SetupColor(b))
{
if (rnrCtx.SecSelection()) glLoadName(bi.index());
h = b.fDir.Mag();
phi = ATan2(b.fDir.fY, b.fDir.fX)*RadToDeg();
theta = ATan (b.fDir.fZ / Sqrt(b.fDir.fX*b.fDir.fX + b.fDir.fY*b.fDir.fY))*RadToDeg();
glPushMatrix();
glTranslatef(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
glRotatef(phi, 0, 0, 1);
glRotatef(90 - theta, 0, 1, 0);
glScalef (b.fR, b.fR, h);
glCallList(fBoxDL);
glPopMatrix();
}
if (boxSkip) { Int_t s = boxSkip; while (s--) bi.next(); }
}
break;
}
case TEveBoxSet::kBT_EllipticCone:
{
using namespace TMath;
glEnable(GL_NORMALIZE);
Float_t theta=0, phi=0, h=0;
while (bi.next())
{
TEveBoxSet::BEllipticCone_t& b = * (TEveBoxSet::BEllipticCone_t*) bi();
if (SetupColor(b))
{
if (rnrCtx.SecSelection()) glLoadName(bi.index());
h = b.fDir.Mag();
phi = ATan2(b.fDir.fY, b.fDir.fX)*RadToDeg();
theta = ATan (b.fDir.fZ / Sqrt(b.fDir.fX*b.fDir.fX + b.fDir.fY*b.fDir.fY))*RadToDeg();
glPushMatrix();
glTranslatef(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
glRotatef(phi, 0, 0, 1);
glRotatef(90 - theta, 0, 1, 0);
glRotatef(b.fAngle, 0, 0, 1);
glScalef (b.fR, b.fR2, h);
glCallList(fBoxDL);
glPopMatrix();
}
if (boxSkip) { Int_t s = boxSkip; while (s--) bi.next(); }
}
break;
}
default:
{
throw(eH + "unsupported box-type.");
}
}
if (rnrCtx.SecSelection()) glPopName();
glPopAttrib();
}
void TEveBoxSetGL::ProcessSelection(TGLRnrCtx & , TGLSelectRecord & rec)
{
if (rec.GetN() < 2) return;
fM->DigitSelected(rec.GetItem(1));
}
void TEveBoxSetGL::Render(TGLRnrCtx & rnrCtx)
{
MakeDisplayList();
DirectDraw(rnrCtx);
glDeleteLists(fBoxDL, 1);
fBoxDL = 0;
}
Last change: Mon Nov 24 08:18:25 2008
Last generated: 2008-11-24 08:18
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.