00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEveStraightLineSetGL.h"
00013 #include "TEveStraightLineSet.h"
00014
00015 #include "TGLIncludes.h"
00016 #include "TGLRnrCtx.h"
00017 #include "TGLSelectRecord.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 ClassImp(TEveStraightLineSetGL);
00029
00030
00031 TEveStraightLineSetGL::TEveStraightLineSetGL() : TGLObject(), fM(0)
00032 {
00033
00034
00035
00036 fMultiColor = kTRUE;
00037 }
00038
00039
00040
00041
00042 Bool_t TEveStraightLineSetGL::SetModel(TObject* obj, const Option_t* )
00043 {
00044
00045
00046 fM = SetModelDynCast<TEveStraightLineSet>(obj);
00047 return kTRUE;
00048 }
00049
00050
00051 void TEveStraightLineSetGL::SetBBox()
00052 {
00053
00054
00055 SetAxisAlignedBBox(((TEveStraightLineSet*)fExternalObj)->AssertBBox());
00056 }
00057
00058
00059 Bool_t TEveStraightLineSetGL::ShouldDLCache(const TGLRnrCtx& rnrCtx) const
00060 {
00061
00062
00063
00064
00065 if (rnrCtx.Selection()) return kFALSE;
00066 return TGLObject::ShouldDLCache(rnrCtx);
00067 }
00068
00069
00070
00071
00072 void TEveStraightLineSetGL::Draw(TGLRnrCtx& rnrCtx) const
00073 {
00074
00075
00076 if (rnrCtx.IsDrawPassOutlineLine())
00077 return;
00078
00079 TGLObject::Draw(rnrCtx);
00080 }
00081
00082
00083 void TEveStraightLineSetGL::DirectDraw(TGLRnrCtx& rnrCtx) const
00084 {
00085
00086
00087
00088
00089 TEveStraightLineSet& mL = * fM;
00090
00091 if (mL.GetDepthTest() == kFALSE)
00092 {
00093 glPushAttrib(GL_VIEWPORT_BIT);
00094 glDepthRange(0, 0.1);
00095 }
00096
00097
00098 if (mL.GetRnrLines() && mL.GetLinePlex().Size() > 0)
00099 {
00100 glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
00101 glDisable(GL_LIGHTING);
00102 TGLUtil::LineWidth(mL.GetLineWidth());
00103 if (mL.GetLineStyle() > 1) {
00104 Int_t fac = 1;
00105 UShort_t pat = 0xffff;
00106 switch (mL.GetLineStyle()) {
00107 case 2: pat = 0x3333; break;
00108 case 3: pat = 0x5555; break;
00109 case 4: pat = 0xf040; break;
00110 case 5: pat = 0xf4f4; break;
00111 case 6: pat = 0xf111; break;
00112 case 7: pat = 0xf0f0; break;
00113 case 8: pat = 0xff11; break;
00114 case 9: pat = 0x3fff; break;
00115 case 10: pat = 0x08ff; fac = 2; break;
00116 }
00117 glLineStipple(1, pat);
00118 glEnable(GL_LINE_STIPPLE);
00119 }
00120
00121
00122 Bool_t changePM = rnrCtx.Selection() && mL.GetLineWidth() > rnrCtx.GetPickRadius();
00123 if (changePM)
00124 TGLUtil::BeginExtendPickRegion((Float_t) rnrCtx.GetPickRadius() / mL.GetLineWidth());
00125
00126 TEveChunkManager::iterator li(mL.GetLinePlex());
00127 if (rnrCtx.SecSelection())
00128 {
00129 GLuint name = 0;
00130 glPushName(1);
00131 glPushName(0);
00132 while (li.next())
00133 {
00134 TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
00135 glLoadName(l.fId);
00136 {
00137 glBegin(GL_LINES);
00138 glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
00139 glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
00140 glEnd();
00141 }
00142 name ++;
00143 }
00144 glPopName();
00145 glPopName();
00146 }
00147 else
00148 {
00149 glBegin(GL_LINES);
00150 while (li.next())
00151 {
00152 TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
00153 glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
00154 glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
00155 }
00156 glEnd();
00157 }
00158
00159 if (changePM)
00160 TGLUtil::EndExtendPickRegion();
00161
00162 glPopAttrib();
00163 }
00164
00165
00166
00167 if (mL.GetRnrMarkers() && mL.GetMarkerPlex().Size() > 0)
00168 {
00169 TEveChunkManager::iterator mi(mL.GetMarkerPlex());
00170 Float_t* pnts = new Float_t[mL.GetMarkerPlex().Size()*3];
00171 Float_t* pnt = pnts;
00172 while (mi.next())
00173 {
00174 TEveStraightLineSet::Marker_t& m = * (TEveStraightLineSet::Marker_t*) mi();
00175 pnt[0] = m.fV[0];
00176 pnt[1] = m.fV[1];
00177 pnt[2] = m.fV[2];
00178 pnt += 3;
00179 }
00180 if (rnrCtx.SecSelection()) glPushName(2);
00181 TGLUtil::RenderPolyMarkers((TAttMarker&)mL, mL.GetMainTransparency(),
00182 pnts, mL.GetMarkerPlex().Size(),
00183 rnrCtx.GetPickRadius(),
00184 rnrCtx.Selection(),
00185 rnrCtx.SecSelection());
00186 if (rnrCtx.SecSelection()) glPopName();
00187 delete [] pnts;
00188 }
00189
00190 if (mL.GetDepthTest() == kFALSE)
00191 glPopAttrib();
00192 }
00193
00194
00195
00196
00197 void TEveStraightLineSetGL::ProcessSelection(TGLRnrCtx& ,
00198 TGLSelectRecord& rec)
00199 {
00200
00201
00202 if (rec.GetN() != 3) return;
00203 if (rec.GetItem(1) == 1)
00204 {
00205 printf("selected line %d\n", rec.GetItem(2));
00206 }
00207 else
00208 {
00209 TEveStraightLineSet::Marker_t& m = * (TEveStraightLineSet::Marker_t*) fM->GetMarkerPlex().Atom(rec.GetItem(2));
00210 printf("Selected point %d on line %d\n", rec.GetItem(2), m.fLineId);
00211 }
00212 }