00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEveStraightLineSet.h"
00013
00014 #include "TRandom.h"
00015 #include "TEveProjectionManager.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 ClassImp(TEveStraightLineSet);
00028
00029
00030 TEveStraightLineSet::TEveStraightLineSet(const char* n, const char* t):
00031 TEveElement (),
00032 TNamed (n, t),
00033
00034 fLinePlex (sizeof(Line_t), 4),
00035 fMarkerPlex (sizeof(Marker_t), 8),
00036 fOwnLinesIds (kFALSE),
00037 fOwnMarkersIds (kFALSE),
00038 fRnrMarkers (kTRUE),
00039 fRnrLines (kTRUE),
00040 fDepthTest (kTRUE),
00041 fLastLine (0)
00042 {
00043
00044
00045 InitMainTrans();
00046 fPickable = kTRUE;
00047
00048 fMainColorPtr = &fLineColor;
00049 fLineColor = 4;
00050 fMarkerColor = 2;
00051 fMarkerStyle = 20;
00052 }
00053
00054
00055
00056
00057 TEveStraightLineSet::Line_t*
00058 TEveStraightLineSet::AddLine(Float_t x1, Float_t y1, Float_t z1,
00059 Float_t x2, Float_t y2, Float_t z2)
00060 {
00061
00062
00063 fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
00064 fLastLine->fId = fLinePlex.Size() - 1;
00065 return fLastLine;
00066 }
00067
00068
00069 TEveStraightLineSet::Line_t*
00070 TEveStraightLineSet::AddLine(const TEveVector& p1, const TEveVector& p2)
00071 {
00072
00073
00074 return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
00075 }
00076
00077
00078 void
00079 TEveStraightLineSet::SetLine(int idx,
00080 Float_t x1, Float_t y1, Float_t z1,
00081 Float_t x2, Float_t y2, Float_t z2)
00082 {
00083
00084
00085 Line_t* l = (Line_t*) fLinePlex.Atom(idx);
00086
00087 l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
00088 l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
00089 }
00090
00091
00092 void
00093 TEveStraightLineSet::SetLine(int idx, const TEveVector& p1, const TEveVector& p2)
00094 {
00095
00096
00097 SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
00098 }
00099
00100
00101 TEveStraightLineSet::Marker_t*
00102 TEveStraightLineSet::AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id)
00103 {
00104
00105
00106 Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
00107 return marker;
00108 }
00109
00110
00111 TEveStraightLineSet::Marker_t*
00112 TEveStraightLineSet::AddMarker(const TEveVector& p, Int_t line_id)
00113 {
00114
00115
00116 return AddMarker(p.fX, p.fY, p.fZ, line_id);
00117 }
00118
00119
00120 TEveStraightLineSet::Marker_t*
00121 TEveStraightLineSet::AddMarker(Int_t line_id, Float_t pos)
00122 {
00123
00124
00125 Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
00126 return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
00127 l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
00128 l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
00129 line_id);
00130 }
00131
00132
00133
00134
00135 void TEveStraightLineSet::CopyVizParams(const TEveElement* el)
00136 {
00137
00138
00139 const TEveStraightLineSet* m = dynamic_cast<const TEveStraightLineSet*>(el);
00140 if (m)
00141 {
00142 TAttLine::operator=(*m);
00143 TAttMarker::operator=(*m);
00144 fRnrMarkers = m->fRnrMarkers;
00145 fRnrLines = m->fRnrLines;
00146 fDepthTest = m->fDepthTest;
00147 }
00148
00149 TEveElement::CopyVizParams(el);
00150 }
00151
00152
00153 void TEveStraightLineSet::WriteVizParams(ostream& out, const TString& var)
00154 {
00155
00156
00157 TEveElement::WriteVizParams(out, var);
00158
00159 TString t = " " + var + "->";
00160 TAttMarker::SaveMarkerAttributes(out, var);
00161 TAttLine ::SaveLineAttributes (out, var);
00162 out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
00163 out << t << "SetRnrLines(" << ToString(fRnrLines) << ");\n";
00164 out << t << "SetDepthTest(" << ToString(fDepthTest) << ");\n";
00165 }
00166
00167
00168
00169
00170 TClass* TEveStraightLineSet::ProjectedClass(const TEveProjection*) const
00171 {
00172
00173
00174
00175 return TEveStraightLineSetProjected::Class();
00176 }
00177
00178
00179
00180
00181 void TEveStraightLineSet::ComputeBBox()
00182 {
00183
00184
00185
00186 if(fLinePlex.Size() == 0) {
00187 BBoxZero();
00188 return;
00189 }
00190
00191 BBoxInit();
00192
00193 TEveChunkManager::iterator li(fLinePlex);
00194 while (li.next()) {
00195 BBoxCheckPoint(((Line_t*)li())->fV1);
00196 BBoxCheckPoint(((Line_t*)li())->fV2);
00197 }
00198
00199 TEveChunkManager::iterator mi(fMarkerPlex);
00200 while (mi.next())
00201 {
00202 BBoxCheckPoint(((Marker_t*)mi())->fV);
00203 }
00204 }
00205
00206
00207
00208
00209 void TEveStraightLineSet::Paint(Option_t*)
00210 {
00211
00212
00213 PaintStandard(this);
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 ClassImp(TEveStraightLineSetProjected);
00227
00228
00229 TEveStraightLineSetProjected::TEveStraightLineSetProjected() :
00230 TEveStraightLineSet(), TEveProjected ()
00231 {
00232
00233 }
00234
00235
00236
00237
00238 void TEveStraightLineSetProjected::SetProjection(TEveProjectionManager* mng,
00239 TEveProjectable* model)
00240 {
00241
00242
00243 TEveProjected::SetProjection(mng, model);
00244
00245 CopyVizParams(dynamic_cast<TEveElement*>(model));
00246 }
00247
00248
00249 void TEveStraightLineSetProjected::SetDepthLocal(Float_t d)
00250 {
00251
00252
00253 SetDepthCommon(d, this, fBBox);
00254
00255 TEveChunkManager::iterator li(fLinePlex);
00256 while (li.next())
00257 {
00258 TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
00259 l.fV1[2] = fDepth;
00260 l.fV2[2] = fDepth;
00261 }
00262
00263 TEveChunkManager::iterator mi(fMarkerPlex);
00264 while (mi.next())
00265 {
00266 Marker_t& m = * (Marker_t*) mi();
00267 m.fV[2] = fDepth;
00268 }
00269 }
00270
00271
00272 void TEveStraightLineSetProjected::UpdateProjection()
00273 {
00274
00275
00276
00277 TEveProjection& proj = * fManager->GetProjection();
00278 TEveStraightLineSet& orig = * dynamic_cast<TEveStraightLineSet*>(fProjectable);
00279
00280 TEveTrans *trans = orig.PtrMainTrans(kFALSE);
00281
00282 BBoxClear();
00283
00284
00285 Int_t num_lines = orig.GetLinePlex().Size();
00286 if (proj.HasSeveralSubSpaces())
00287 num_lines += TMath::Max(1, num_lines/10);
00288 fLinePlex.Reset(sizeof(Line_t), num_lines);
00289 TEveVector p1, p2;
00290 TEveChunkManager::iterator li(orig.GetLinePlex());
00291 while (li.next())
00292 {
00293 Line_t *l = (Line_t*) li();
00294
00295 proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
00296 proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
00297
00298 if (proj.AcceptSegment(p1, p2, 0.1f))
00299 {
00300 AddLine(p1, p2)->fId = l->fId;
00301 }
00302 else
00303 {
00304 TEveVector bp1(l->fV1), bp2(l->fV2);
00305 if (trans) {
00306 trans->MultiplyIP(bp1);
00307 trans->MultiplyIP(bp2);
00308 }
00309 proj.BisectBreakPoint(bp1, bp2, 1e-10f);
00310 proj.ProjectVector(bp1, fDepth);
00311 proj.ProjectVector(bp2, fDepth);
00312
00313 AddLine(p1, bp1)->fId = l->fId;
00314 AddLine(bp2, p2)->fId = l->fId;
00315 }
00316 }
00317 if (proj.HasSeveralSubSpaces())
00318 fLinePlex.Refit();
00319
00320
00321 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
00322 TEveChunkManager::iterator mi(orig.GetMarkerPlex());
00323 TEveVector pp;
00324 while (mi.next())
00325 {
00326 Marker_t &m = * (Marker_t*) mi();
00327
00328 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
00329 AddMarker(pp, m.fLineId);
00330 }
00331 }