TEveLine.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveLine.cxx 33955 2010-06-17 11:33:13Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveLine.h"
00013 #include "TEveProjectionManager.h"
00014 
00015 //==============================================================================
00016 //==============================================================================
00017 // TEveLine
00018 //==============================================================================
00019 
00020 //______________________________________________________________________________
00021 //
00022 // An arbitrary polyline with fixed line and marker attributes.
00023 
00024 ClassImp(TEveLine);
00025 
00026 Bool_t TEveLine::fgDefaultSmooth = kFALSE;
00027 
00028 //______________________________________________________________________________
00029 TEveLine::TEveLine(Int_t n_points, ETreeVarType_e tv_type) :
00030    TEvePointSet("Line", n_points, tv_type),
00031    fRnrLine   (kTRUE),
00032    fRnrPoints (kFALSE),
00033    fSmooth    (fgDefaultSmooth)
00034 {
00035    // Constructor.
00036 
00037    fMainColorPtr = &fLineColor;
00038    fMarkerColor  =  kGreen;
00039 }
00040 
00041 //______________________________________________________________________________
00042 TEveLine::TEveLine(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
00043    TEvePointSet(name, n_points, tv_type),
00044    fRnrLine   (kTRUE),
00045    fRnrPoints (kFALSE),
00046    fSmooth    (fgDefaultSmooth)
00047 {
00048    // Constructor.
00049 
00050    fMainColorPtr = &fLineColor;
00051    fMarkerColor = kGreen;
00052 }
00053 
00054 //______________________________________________________________________________
00055 const TGPicture* TEveLine::GetListTreeIcon(Bool_t)
00056 {
00057    // Returns list-tree icon for TEveLine.
00058 
00059    return fgListTreeIcons[8];
00060 }
00061 
00062 //______________________________________________________________________________
00063 void TEveLine::SetMarkerColor(Color_t col)
00064 {
00065    // Set marker color. Propagate to projected lines.
00066 
00067    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00068    while (pi != fProjectedList.end())
00069    {
00070       TEveLine* l = dynamic_cast<TEveLine*>(*pi);
00071       if (l && fMarkerColor == l->GetMarkerColor())
00072       {
00073          l->SetMarkerColor(col);
00074          l->StampObjProps();
00075       }
00076       ++pi;
00077    }
00078    TAttMarker::SetMarkerColor(col);
00079 }
00080 
00081 //______________________________________________________________________________
00082 void TEveLine::SetLineStyle(Style_t lstyle)
00083 {
00084    // Set line-style of the line.
00085    // The style is propagated to projecteds.
00086 
00087    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00088    while (pi != fProjectedList.end())
00089    {
00090       TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
00091       if (pt)
00092       {
00093          pt->SetLineStyle(lstyle);
00094          pt->StampObjProps();
00095       }
00096       ++pi;
00097    }
00098    TAttLine::SetLineStyle(lstyle);
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TEveLine::SetLineWidth(Width_t lwidth)
00103 {
00104    // Set line-style of the line.
00105    // The style is propagated to projecteds.
00106 
00107    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00108    while (pi != fProjectedList.end())
00109    {
00110       TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
00111       if (pt)
00112       {
00113          pt->SetLineWidth(lwidth);
00114          pt->StampObjProps();
00115       }
00116       ++pi;
00117    }
00118    TAttLine::SetLineWidth(lwidth);
00119 }
00120 
00121 //______________________________________________________________________________
00122 void TEveLine::SetRnrLine(Bool_t r)
00123 {
00124    // Set rendering of line. Propagate to projected lines.
00125 
00126    fRnrLine = r;
00127    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00128    while (pi != fProjectedList.end())
00129    {
00130       TEveLine* l = dynamic_cast<TEveLine*>(*pi);
00131       if (l)
00132       {
00133          l->SetRnrLine(r);
00134          l->ElementChanged();
00135       }
00136       ++pi;
00137    }
00138 }
00139 
00140 //______________________________________________________________________________
00141 void TEveLine::SetRnrPoints(Bool_t r)
00142 {
00143    // Set rendering of points. Propagate to projected lines.
00144 
00145    fRnrPoints = r;
00146    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00147    while (pi != fProjectedList.end())
00148    {
00149       TEveLine* l = dynamic_cast<TEveLine*>(*pi);
00150       if (l)
00151       {
00152          l->SetRnrPoints(r);
00153          l->ElementChanged();
00154       }
00155       ++pi;
00156    }
00157 }
00158 
00159 //______________________________________________________________________________
00160 void TEveLine::SetSmooth(Bool_t r)
00161 {
00162    // Set smooth rendering. Propagate to projected lines.
00163 
00164    fSmooth = r;
00165    std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00166    while (pi != fProjectedList.end())
00167    {
00168       TEveLine* l = dynamic_cast<TEveLine*>(*pi);
00169       if (l)
00170       {
00171          l->SetSmooth(r);
00172          l->ElementChanged();
00173       }
00174       ++pi;
00175    }
00176 }
00177 
00178 //==============================================================================
00179 
00180 //______________________________________________________________________________
00181 void TEveLine::ReduceSegmentLengths(Float_t max)
00182 {
00183    // Make sure that no segment is longer than max.
00184    // Per point references and integer ids are lost.
00185 
00186    const Float_t max2 = max*max;
00187 
00188    Float_t    *p = GetP();
00189    Int_t       s = Size();
00190    TEveVector  a, b, d;
00191 
00192    std::vector<TEveVector> q;
00193 
00194    b.Set(p);
00195    q.push_back(b);
00196    for (Int_t i = 1; i < s; ++i)
00197    {
00198       a = b; b.Set(&p[3*i]); d = b - a;
00199       Float_t m2 = d.Mag2();
00200       if (m2 > max2)
00201       {
00202          Float_t f = TMath::Sqrt(m2) / max;
00203          Int_t   n = TMath::FloorNint(f);
00204          d *= 1.0f / (n + 1);
00205          for (Int_t j = 0; j < n; ++j)
00206          {
00207             a += d;
00208             q.push_back(a);
00209          }
00210       }
00211       q.push_back(b);
00212    }
00213 
00214    s = q.size();
00215    Reset(s);
00216    for (std::vector<TEveVector>::iterator i = q.begin(); i != q.end(); ++i)
00217       SetNextPoint(i->fX, i->fY, i->fZ);
00218 }
00219 
00220 //______________________________________________________________________________
00221 TEveVector TEveLine::GetLineStart() const
00222 {
00223    // Return the first point of the line.
00224    // If there are no points (0,0,0) is returned.
00225 
00226    TEveVector v;
00227    GetPoint(0, v.fX, v.fY, v.fZ);
00228    return v;
00229 }
00230 
00231 //______________________________________________________________________________
00232 TEveVector TEveLine::GetLineEnd() const
00233 {
00234    // Return the last point of the line.
00235    // If there are no points (0,0,0) is returned.
00236 
00237    TEveVector v;
00238    GetPoint(fLastPoint, v.fX, v.fY, v.fZ);
00239    return v;
00240 }
00241 
00242 //==============================================================================
00243 
00244 //______________________________________________________________________________
00245 void TEveLine::CopyVizParams(const TEveElement* el)
00246 {
00247    // Copy visualization parameters from element el.
00248 
00249    const TEveLine* m = dynamic_cast<const TEveLine*>(el);
00250    if (m)
00251    {
00252       TAttLine::operator=(*m);
00253       fRnrLine   = m->fRnrLine;
00254       fRnrPoints = m->fRnrPoints;
00255       fSmooth    = m->fSmooth;
00256    }
00257 
00258    TEvePointSet::CopyVizParams(el);
00259 }
00260 
00261 //______________________________________________________________________________
00262 void TEveLine::WriteVizParams(ostream& out, const TString& var)
00263 {
00264    // Write visualization parameters.
00265 
00266    TEvePointSet::WriteVizParams(out, var);
00267 
00268    TString t = "   " + var + "->";
00269    TAttLine::SaveLineAttributes(out, var);
00270    out << t << "SetRnrLine("   << ToString(fRnrLine)   << ");\n";
00271    out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
00272    out << t << "SetSmooth("    << ToString(fSmooth)    << ");\n";
00273 }
00274 
00275 //______________________________________________________________________________
00276 TClass* TEveLine::ProjectedClass(const TEveProjection*) const
00277 {
00278    // Virtual from TEveProjectable, returns TEvePointSetProjected class.
00279 
00280    return TEveLineProjected::Class();
00281 }
00282 
00283 //------------------------------------------------------------------------------
00284 
00285 //______________________________________________________________________________
00286 Bool_t TEveLine::GetDefaultSmooth()
00287 {
00288    // Get default value for smooth-line drawing flag.
00289    // Static function.
00290 
00291    return fgDefaultSmooth;
00292 }
00293 
00294 //______________________________________________________________________________
00295 void TEveLine::SetDefaultSmooth(Bool_t r)
00296 {
00297    // Set default value for smooth-line drawing flag (default kFALSE).
00298    // Static function.
00299 
00300    fgDefaultSmooth = r;
00301 }
00302 
00303 
00304 
00305 //==============================================================================
00306 //==============================================================================
00307 // TEveLineProjected
00308 //==============================================================================
00309 
00310 //______________________________________________________________________________
00311 //
00312 // Projected copy of a TEvePointSet.
00313 
00314 ClassImp(TEveLineProjected);
00315 
00316 //______________________________________________________________________________
00317 TEveLineProjected::TEveLineProjected() :
00318    TEveLine      (),
00319    TEveProjected ()
00320 {
00321    // Default constructor.
00322 }
00323 
00324 //______________________________________________________________________________
00325 void TEveLineProjected::SetProjection(TEveProjectionManager* mng,
00326                                       TEveProjectable* model)
00327 {
00328    // Set projection manager and projection model.
00329    // Virtual from TEveProjected.
00330 
00331    TEveProjected::SetProjection(mng, model);
00332    CopyVizParams(dynamic_cast<TEveElement*>(model));
00333 }
00334 
00335 //______________________________________________________________________________
00336 void TEveLineProjected::SetDepthLocal(Float_t d)
00337 {
00338    // Set depth (z-coordinate) of the projected points.
00339 
00340    SetDepthCommon(d, this, fBBox);
00341 
00342    Int_t    n = Size();
00343    Float_t *p = GetP() + 2;
00344    for (Int_t i = 0; i < n; ++i, p+=3)
00345       *p = fDepth;
00346 }
00347 
00348 //______________________________________________________________________________
00349 void TEveLineProjected::UpdateProjection()
00350 {
00351    // Re-apply the projection.
00352    // Virtual from TEveProjected.
00353 
00354    TEveProjection& proj = * fManager->GetProjection();
00355    TEveLine      & als  = * dynamic_cast<TEveLine*>(fProjectable);
00356    TEveTrans      *tr   =   als.PtrMainTrans(kFALSE);
00357 
00358    Int_t n = als.Size();
00359    Reset(n);
00360    fLastPoint = n - 1;
00361    Float_t *o = als.GetP(), *p = GetP();
00362    for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
00363    {
00364       proj.ProjectPointfv(tr, o, p, fDepth);
00365    }
00366 }

Generated on Tue Jul 5 14:16:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1