#include "TEvePointSet.h"
#include "TEveManager.h"
#include "TEveProjectionManager.h"
#include "TEveTrans.h"
#include "TTree.h"
#include "TTreePlayer.h"
#include "TF3.h"
#include "TColor.h"
#include "TCanvas.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualViewer3D.h"
ClassImp(TEvePointSet);
TEvePointSet::TEvePointSet(Int_t n_points, ETreeVarType_e tv_type) :
TEveElement(fMarkerColor),
TPointSet3D(n_points),
TEvePointSelectorConsumer(tv_type),
TEveProjectable(),
TQObject(),
fTitle (),
fIntIds (0),
fIntIdsPerPoint (0)
{
fMarkerStyle = 20;
fPickable = kTRUE;
}
TEvePointSet::TEvePointSet(const Text_t* name, Int_t n_points, ETreeVarType_e tv_type) :
TEveElement(fMarkerColor),
TPointSet3D(n_points),
TEvePointSelectorConsumer(tv_type),
TEveProjectable(),
TQObject(),
fTitle (),
fIntIds (0),
fIntIdsPerPoint (0)
{
fMarkerStyle = 20;
SetName(name);
fPickable = kTRUE;
}
TEvePointSet::TEvePointSet(const TEvePointSet& e) :
TEveElement(e),
TPointSet3D(e),
TEvePointSelectorConsumer(e),
TEveProjectable(),
TQObject(),
fTitle (e.fTitle),
fIntIds (e.fIntIds ? new TArrayI(*e.fIntIds) : 0),
fIntIdsPerPoint (e.fIntIdsPerPoint)
{
}
TEvePointSet::~TEvePointSet()
{
delete fIntIds;
}
const TGPicture* TEvePointSet::GetListTreeIcon(Bool_t)
{
return TEveElement::fgListTreeIcons[3];
}
void TEvePointSet::ComputeBBox()
{
TPointSet3D::ComputeBBox();
AssertBBoxExtents(0.1);
}
void TEvePointSet::Reset(Int_t n_points, Int_t n_int_ids)
{
delete [] fP; fP = 0;
fN = n_points;
if (fN) fP = new Float_t [3*fN];
memset(fP, 0, 3*fN*sizeof(Float_t));
fLastPoint = -1;
ClearIds();
delete fIntIds; fIntIds = 0;
fIntIdsPerPoint = n_int_ids;
if (fIntIdsPerPoint > 0) fIntIds = new TArrayI(fIntIdsPerPoint*fN);
ResetBBox();
}
Int_t TEvePointSet::GrowFor(Int_t n_points)
{
Int_t old_size = Size();
Int_t new_size = old_size + n_points;
SetPoint(new_size - 1, 0, 0, 0);
if (fIntIds)
fIntIds->Set(fIntIdsPerPoint * new_size);
return old_size;
}
inline void TEvePointSet::AssertIntIdsSize()
{
Int_t exp_size = GetN()*fIntIdsPerPoint;
if (fIntIds->GetSize() < exp_size)
fIntIds->Set(exp_size);
}
Int_t* TEvePointSet::GetPointIntIds(Int_t p) const
{
if (fIntIds)
return fIntIds->GetArray() + p*fIntIdsPerPoint;
return 0;
}
Int_t TEvePointSet::GetPointIntId(Int_t p, Int_t i) const
{
if (fIntIds)
return * (fIntIds->GetArray() + p*fIntIdsPerPoint + i);
return kMinInt;
}
void TEvePointSet::SetPointIntIds(Int_t* ids)
{
SetPointIntIds(fLastPoint, ids);
}
void TEvePointSet::SetPointIntIds(Int_t n, Int_t* ids)
{
if (!fIntIds) return;
AssertIntIdsSize();
Int_t* x = fIntIds->GetArray() + n*fIntIdsPerPoint;
for (Int_t i=0; i<fIntIdsPerPoint; ++i)
x[i] = ids[i];
}
void TEvePointSet::Paint(Option_t* )
{
static const TEveException eh("TEvePointSet::Paint ");
if (fRnrSelf == kFALSE) return;
TBuffer3D buff(TBuffer3DTypes::kGeneric);
buff.fID = this;
buff.fColor = GetMainColor();
buff.fTransparency = GetMainTransparency();
if (HasMainTrans())
RefMainTrans().SetBuffer3D(buff);
buff.SetSectionsValid(TBuffer3D::kCore);
Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
if (reqSections != TBuffer3D::kNone)
Error(eh, "only direct GL rendering supported.");
}
void TEvePointSet::InitFill(Int_t subIdNum)
{
if (subIdNum > 0) {
fIntIdsPerPoint = subIdNum;
if (!fIntIds)
fIntIds = new TArrayI(fIntIdsPerPoint*GetN());
else
fIntIds->Set(fIntIdsPerPoint*GetN());
} else {
delete fIntIds; fIntIds = 0;
fIntIdsPerPoint = 0;
}
}
void TEvePointSet::TakeAction(TEvePointSelector* sel)
{
static const TEveException eh("TEvePointSet::TakeAction ");
if(sel == 0)
throw(eh + "selector is <null>.");
Int_t n = sel->GetNfill();
Int_t beg = GrowFor(n);
Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
Float_t *p = fP + 3*beg;
switch(fSourceCS) {
case kTVT_XYZ:
while(n-- > 0) {
p[0] = *vx; p[1] = *vy; p[2] = *vz;
p += 3;
++vx; ++vy; ++vz;
}
break;
case kTVT_RPhiZ:
while(n-- > 0) {
p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
p += 3;
++vx; ++vy; ++vz;
}
break;
default:
throw(eh + "unknown tree variable type.");
}
if (fIntIds) {
Double_t** subarr = new Double_t* [fIntIdsPerPoint];
for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
subarr[i] = sel->GetVal(sel->GetDimension() - fIntIdsPerPoint + i);
if (subarr[i] == 0)
throw(eh + "sub-id array not available.");
}
Int_t* ids = fIntIds->GetArray() + fIntIdsPerPoint*beg;
n = sel->GetNfill();
while (n-- > 0) {
for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
ids[i] = TMath::Nint(*subarr[i]);
++subarr[i];
}
ids += fIntIdsPerPoint;
}
delete [] subarr;
}
}
void TEvePointSet::CopyVizParams(const TEveElement* el)
{
const TEvePointSet* m = dynamic_cast<const TEvePointSet*>(el);
if (m)
{
TAttMarker::operator=(*m);
fOption = m->fOption;
}
TEveElement::CopyVizParams(el);
}
void TEvePointSet::WriteVizParams(ostream& out, const TString& var)
{
TEveElement::WriteVizParams(out, var);
TAttMarker::SaveMarkerAttributes(out, var);
}
TClass* TEvePointSet::ProjectedClass() const
{
return TEvePointSetProjected::Class();
}
void TEvePointSet::PointSelected(Int_t id)
{
Emit("PointSelected(Int_t)", id);
TPointSet3D::PointSelected(id);
}
ClassImp(TEvePointSetArray);
TEvePointSetArray::TEvePointSetArray(const Text_t* name,
const Text_t* title) :
TEveElement(fMarkerColor),
TNamed(name, title),
fBins(0), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
fMin(0), fCurMin(0), fMax(0), fCurMax(0),
fBinWidth(0),
fQuantName()
{
}
TEvePointSetArray::~TEvePointSetArray()
{
delete [] fBins; fBins = 0;
}
void TEvePointSetArray::RemoveElementLocal(TEveElement* el)
{
for (Int_t i=0; i<fNBins; ++i) {
if (fBins[i] == el) {
fBins[i] = 0;
break;
}
}
}
void TEvePointSetArray::RemoveElementsLocal()
{
delete [] fBins; fBins = 0; fLastBin = -1;
}
void TEvePointSetArray::SetMarkerColor(Color_t tcolor)
{
static const TEveException eh("TEvePointSetArray::SetMarkerColor ");
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
if (m && m->GetMarkerColor() == fMarkerColor)
m->SetMarkerColor(tcolor);
}
TAttMarker::SetMarkerColor(tcolor);
}
void TEvePointSetArray::SetMarkerStyle(Style_t mstyle)
{
static const TEveException eh("TEvePointSetArray::SetMarkerStyle ");
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
if (m && m->GetMarkerStyle() == fMarkerStyle)
m->SetMarkerStyle(mstyle);
}
TAttMarker::SetMarkerStyle(mstyle);
}
void TEvePointSetArray::SetMarkerSize(Size_t msize)
{
static const TEveException eh("TEvePointSetArray::SetMarkerSize ");
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
if (m && m->GetMarkerSize() == fMarkerSize)
m->SetMarkerSize(msize);
}
TAttMarker::SetMarkerSize(msize);
}
void TEvePointSetArray::TakeAction(TEvePointSelector* sel)
{
static const TEveException eh("TEvePointSetArray::TakeAction ");
if (sel == 0)
throw(eh + "selector is <null>.");
Int_t n = sel->GetNfill();
Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
Double_t *qq = sel->GetV4();
if(qq == 0)
throw(eh + "requires 4-d varexp.");
switch(fSourceCS) {
case kTVT_XYZ:
while(n-- > 0) {
Fill(*vx, *vy, *vz, *qq);
++vx; ++vy; ++vz; ++qq;
}
break;
case kTVT_RPhiZ:
while(n-- > 0) {
Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
++vx; ++vy; ++vz; ++qq;
}
break;
default:
throw(eh + "unknown tree variable type.");
}
}
Int_t TEvePointSetArray::Size(Bool_t under, Bool_t over) const
{
Int_t size = 0;
const Int_t min = under ? 0 : 1;
const Int_t max = over ? fNBins : fNBins - 1;
for (Int_t i = min; i < max; ++i)
{
if (fBins[i])
size += fBins[i]->Size();
}
return size;
}
void TEvePointSetArray::InitBins(const Text_t* quant_name,
Int_t nbins, Double_t min, Double_t max)
{
static const TEveException eh("TEvePointSetArray::InitBins ");
if (nbins < 1) throw(eh + "nbins < 1.");
if (min > max) throw(eh + "min > max.");
RemoveElements();
fQuantName = quant_name;
fNBins = nbins + 2;
fLastBin = -1;
fMin = fCurMin = min;
fMax = fCurMax = max;
fBinWidth = (fMax - fMin)/(fNBins - 2);
fBins = new TEvePointSet* [fNBins];
for (Int_t i = 0; i < fNBins; ++i)
{
fBins[i] = new TEvePointSet
(Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
fDefPointSetCapacity);
fBins[i]->SetMarkerColor(fMarkerColor);
fBins[i]->SetMarkerStyle(fMarkerStyle);
fBins[i]->SetMarkerSize(fMarkerSize);
AddElement(fBins[i]);
}
fBins[0]->SetName("Underflow");
fBins[0]->SetRnrSelf(kFALSE);
fBins[fNBins-1]->SetName("Overflow");
fBins[fNBins-1]->SetRnrSelf(kFALSE);
}
Bool_t TEvePointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
{
fLastBin =TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
if (fLastBin < 0)
{
fLastBin = 0;
}
else if (fLastBin > fNBins - 1)
{
fLastBin = fNBins - 1;
}
if (fBins[fLastBin] != 0)
{
fBins[fLastBin]->SetNextPoint(x, y, z);
return kTRUE;
}
else
{
return kFALSE;
}
}
void TEvePointSetArray::SetPointId(TObject* id)
{
if (fLastBin >= 0)
fBins[fLastBin]->SetPointId(id);
}
void TEvePointSetArray::CloseBins()
{
for (Int_t i=0; i<fNBins; ++i) {
if (fBins[i] != 0) {
fBins[i]->SetTitle(Form("N=%d", fBins[i]->Size()));
fBins[i]->ComputeBBox();
}
}
fLastBin = -1;
}
void TEvePointSetArray::SetOwnIds(Bool_t o)
{
for (Int_t i=0; i<fNBins; ++i)
{
if (fBins[i] != 0)
fBins[i]->SetOwnIds(o);
}
}
void TEvePointSetArray::SetRange(Double_t min, Double_t max)
{
using namespace TMath;
fCurMin = min; fCurMax = max;
Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth));
Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
for (Int_t i = 1; i < fNBins - 1; ++i)
{
if (fBins[i] != 0)
fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
}
}
ClassImp(TEvePointSetProjected);
TEvePointSetProjected::TEvePointSetProjected() :
TEvePointSet (),
TEveProjected ()
{
}
void TEvePointSetProjected::SetProjection(TEveProjectionManager* proj,
TEveProjectable* model)
{
TEveProjected::SetProjection(proj, model);
* (TAttMarker*)this = * dynamic_cast<TAttMarker*>(fProjectable);
}
void TEvePointSetProjected::SetDepth(Float_t d)
{
SetDepthCommon(d, this, fBBox);
Int_t n = Size();
Float_t *p = GetP();
for (Int_t i = 0; i < n; ++i, p+=3)
p[2] = fDepth;
}
void TEvePointSetProjected::UpdateProjection()
{
TEveProjection& proj = * fManager->GetProjection();
TEvePointSet & ps = * dynamic_cast<TEvePointSet*>(fProjectable);
Int_t n = ps.Size();
Reset(n);
fLastPoint = n - 1;
Float_t *o = ps.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.ProjectPoint(p[0], p[1], p[2]);
p[2] = fDepth;
}
}
Last change: Mon Nov 24 08:18:47 2008
Last generated: 2008-11-24 08:18
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.