3 #include "StraightLineSetGL.h"
4 #include <Reve/StraightLineSet.h>
5 #include <Reve/GLUtilNS.h>
8 #include <TGLSelectRecord.h>
10 #include <TGLIncludes.h>
14 //______________________________________________________________________
18 ClassImp(StraightLineSetGL)
20 StraightLineSetGL::StraightLineSetGL() : TGLObject(), fM(0)
22 // fDLCache = false; // Disable display list.
25 StraightLineSetGL::~StraightLineSetGL()
28 /**************************************************************************/
30 Bool_t StraightLineSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
32 if(SetModelCheckClass(obj, StraightLineSet::Class())) {
33 fM = dynamic_cast<StraightLineSet*>(obj);
39 void StraightLineSetGL::SetBBox()
41 // !! This ok if master sub-classed from TAttBBox
42 SetAxisAlignedBBox(((StraightLineSet*)fExternalObj)->AssertBBox());
45 //______________________________________________________________________________
46 Bool_t StraightLineSetGL::ShouldCache(TGLRnrCtx & rnrCtx) const
48 // Override from TGLDrawable.
49 // To account for large point-sizes we modify the projection matrix
50 // during selection and thus we need a direct draw.
52 if (rnrCtx.Selection()) return kFALSE;
56 /**************************************************************************/
58 void StraightLineSetGL::DirectDraw(TGLRnrCtx & rnrCtx) const
60 // printf("StraightLineSetGL::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD());
62 StraightLineSet& mL = * fM;
64 glPushAttrib(GL_POINT_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
67 GLUtilNS::GL_Capability_Switch lights_off(GL_LIGHTING, false);
68 if(mL.GetRnrLines() && mL.GetLinePlex().Size() > 0)
70 glDisable(GL_LIGHTING);
71 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
72 glEnable(GL_COLOR_MATERIAL);
74 Reve::ColorFromIdx(mL.GetLineColor(), color);
76 glLineWidth(mL.GetLineWidth());
77 if (mL.GetLineStyle() > 1) {
79 UShort_t pat = 0xffff;
80 switch (mL.GetLineStyle()) {
81 case 2: pat = 0x3333; break;
82 case 3: pat = 0x5555; break;
83 case 4: pat = 0xf040; break;
84 case 5: pat = 0xf4f4; break;
85 case 6: pat = 0xf111; break;
86 case 7: pat = 0xf0f0; break;
87 case 8: pat = 0xff11; break;
88 case 9: pat = 0x3fff; break;
89 case 10: pat = 0x08ff; fac = 2; break;
91 glLineStipple(1, pat);
92 glEnable(GL_LINE_STIPPLE);
95 VoidCPlex::iterator li(mL.GetLinePlex());
96 if(rnrCtx.SecSelection())
103 StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
107 glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
108 glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
121 StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
122 glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
123 glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
132 if(mL.GetRnrMarkers() && mL.GetMarkerPlex().Size() > 0)
134 VoidCPlex::iterator mi(mL.GetMarkerPlex());
135 Float_t* pnts = new Float_t[mL.GetMarkerPlex().Size()*3];
140 StraightLineSet::Marker& m = * (StraightLineSet::Marker*) mi();
142 StraightLineSet::Line& l = * (StraightLineSet::Line*) mL.GetLinePlex().Atom(lidx);
143 pnt[0] = l.fV1[0] + (l.fV2[0] - l.fV1[0])*m.fPos;
144 pnt[1] = l.fV1[1] + (l.fV2[1] - l.fV1[1])*m.fPos;
145 pnt[2] = l.fV1[2] + (l.fV2[2] - l.fV1[2])*m.fPos;;
148 if(rnrCtx.SecSelection()) glPushName(2);
149 GLUtilNS::RenderPolyMarkers((TAttMarker&)mL, pnts, mL.GetMarkerPlex().Size(),
150 rnrCtx.Selection(), rnrCtx.SecSelection());
151 if(rnrCtx.SecSelection()) glPopName();
157 /**************************************************************************/
159 void StraightLineSetGL::ProcessSelection(TGLRnrCtx & /*rnrCtx*/,
160 TGLSelectRecord & rec)
162 if (rec.GetN() != 3) return;
163 if(rec.GetItem(1) == 1)
165 printf("selected line %d\n", rec.GetItem(2));
169 StraightLineSet::Marker& m = * (StraightLineSet::Marker*) fM->GetMarkerPlex().Atom(rec.GetItem(2));
170 printf("Selected point %d on line %d\n", rec.GetItem(2), m.fLineID);