#include "TEveLine.h"
#include "TEveProjectionManager.h"
ClassImp(TEveLine);
Bool_t TEveLine::fgDefaultSmooth = kFALSE;
TEveLine::TEveLine(Int_t n_points, ETreeVarType_e tv_type) :
TEvePointSet("Line", n_points, tv_type),
fRnrLine (kTRUE),
fRnrPoints (kFALSE),
fSmooth (fgDefaultSmooth)
{
fMainColorPtr = &fLineColor;
fMarkerColor = kGreen;
}
TEveLine::TEveLine(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
TEvePointSet(name, n_points, tv_type),
fRnrLine (kTRUE),
fRnrPoints (kFALSE),
fSmooth (fgDefaultSmooth)
{
fMainColorPtr = &fLineColor;
fMarkerColor = kGreen;
}
void TEveLine::SetMarkerColor(Color_t col)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l && fMarkerColor == l->GetMarkerColor())
{
l->SetMarkerColor(col);
l->StampObjProps();
}
++pi;
}
TAttMarker::SetMarkerColor(col);
}
void TEveLine::SetLineStyle(Style_t lstyle)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
if (pt)
{
pt->SetLineStyle(lstyle);
pt->StampObjProps();
}
++pi;
}
TAttLine::SetLineStyle(lstyle);
}
void TEveLine::SetLineWidth(Width_t lwidth)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
if (pt)
{
pt->SetLineWidth(lwidth);
pt->StampObjProps();
}
++pi;
}
TAttLine::SetLineWidth(lwidth);
}
void TEveLine::SetRnrLine(Bool_t r)
{
fRnrLine = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetRnrLine(r);
l->ElementChanged();
}
++pi;
}
}
void TEveLine::SetRnrPoints(Bool_t r)
{
fRnrPoints = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetRnrPoints(r);
l->ElementChanged();
}
++pi;
}
}
void TEveLine::SetSmooth(Bool_t r)
{
fSmooth = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetSmooth(r);
l->ElementChanged();
}
++pi;
}
}
void TEveLine::ReduceSegmentLengths(Float_t max)
{
const Float_t max2 = max*max;
Float_t *p = GetP();
Int_t s = Size();
TEveVector a, b, d;
std::vector<TEveVector> q;
b.Set(p);
q.push_back(b);
for (Int_t i = 1; i < s; ++i)
{
a = b; b.Set(&p[3*i]); d = b - a;
Float_t m2 = d.Mag2();
if (m2 > max2)
{
Float_t f = TMath::Sqrt(m2) / max;
Int_t n = TMath::FloorNint(f);
d *= 1.0f / (n + 1);
for (Int_t j = 0; j < n; ++j)
{
a += d;
q.push_back(a);
}
}
q.push_back(b);
}
s = q.size();
Reset(s);
for (std::vector<TEveVector>::iterator i = q.begin(); i != q.end(); ++i)
SetNextPoint(i->fX, i->fY, i->fZ);
}
TEveVector TEveLine::GetLineStart() const
{
TEveVector v;
GetPoint(0, v.fX, v.fY, v.fZ);
return v;
}
TEveVector TEveLine::GetLineEnd() const
{
TEveVector v;
GetPoint(fLastPoint, v.fX, v.fY, v.fZ);
return v;
}
void TEveLine::CopyVizParams(const TEveElement* el)
{
const TEveLine* m = dynamic_cast<const TEveLine*>(el);
if (m)
{
TAttLine::operator=(*m);
fRnrLine = m->fRnrLine;
fRnrPoints = m->fRnrPoints;
fSmooth = m->fSmooth;
}
TEvePointSet::CopyVizParams(el);
}
void TEveLine::WriteVizParams(ostream& out, const TString& var)
{
TEvePointSet::WriteVizParams(out, var);
TString t = " " + var + "->";
TAttLine::SaveLineAttributes(out, var);
out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
}
TClass* TEveLine::ProjectedClass(const TEveProjection*) const
{
return TEveLineProjected::Class();
}
ClassImp(TEveLineProjected);
TEveLineProjected::TEveLineProjected() :
TEveLine (),
TEveProjected ()
{
}
void TEveLineProjected::SetProjection(TEveProjectionManager* mng,
TEveProjectable* model)
{
TEveProjected::SetProjection(mng, model);
* (TAttMarker*)this = * dynamic_cast<TAttMarker*>(fProjectable);
* (TAttLine*) this = * dynamic_cast<TAttLine*> (fProjectable);
}
void TEveLineProjected::SetDepthLocal(Float_t d)
{
SetDepthCommon(d, this, fBBox);
Int_t n = Size();
Float_t *p = GetP() + 2;
for (Int_t i = 0; i < n; ++i, p+=3)
*p = fDepth;
}
void TEveLineProjected::UpdateProjection()
{
TEveProjection& proj = * fManager->GetProjection();
TEveLine & als = * dynamic_cast<TEveLine*>(fProjectable);
Int_t n = als.Size();
Reset(n);
fLastPoint = n - 1;
Float_t *o = als.GetP(), *p = GetP();
for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
{
p[0] = o[0]; p[1] = o[1]; p[2] = o[2];
proj.ProjectPointfv(p, fDepth);
}
}