#include "TNode.h"
#include "TShape.h"
#include "TView.h"
#include "TVirtualPad.h"
#include "TGeometry.h"
#include "TMaterial.h"
#include "TFile.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualViewer3D.h"
#include "TClass.h"
#include <assert.h>
ClassImp(TShape)
//Begin_Html
/*
<img src="gif/tshape_classtree.gif">
*/
//End_Html
//Begin_Html
/*
<img src="gif/shapes.gif">
*/
//End_Html
TShape::TShape()
{
fVisibility = 1;
fMaterial = 0;
}
TShape::TShape(const char *name,const char *title, const char *materialname)
: TNamed (name, title), TAttLine(), TAttFill()
{
fVisibility = 1;
if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
fMaterial = gGeometry->GetMaterial(materialname);
fNumber = gGeometry->GetListOfShapes()->GetSize();
gGeometry->GetListOfShapes()->Add(this);
#ifdef WIN32
Color_t lcolor = 16;
SetLineColor(lcolor);
#endif
}
TShape::TShape(const TShape& ts) :
TNamed(ts),
TAttLine(ts),
TAttFill(ts),
TAtt3D(ts),
fNumber(ts.fNumber),
fVisibility(ts.fVisibility),
fMaterial(ts.fMaterial)
{
}
TShape& TShape::operator=(const TShape& ts)
{
if (this!=&ts) {
TNamed::operator=(ts);
TAttLine::operator=(ts);
TAttFill::operator=(ts);
TAtt3D::operator=(ts);
fNumber=ts.fNumber;
fVisibility=ts.fVisibility;
fMaterial=ts.fMaterial;
}
return *this;
}
TShape::~TShape()
{
if (gGeometry) gGeometry->GetListOfShapes()->Remove(this);
}
Int_t TShape::ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
{
Int_t dist = 9999;
TView *view = gPad->GetView();
if (!(numPoints && view)) return dist;
Double_t *points = new Double_t[3*numPoints];
SetPoints(points);
Double_t dpoint2, x1, y1, xndc[3];
for (Int_t i = 0; i < numPoints; i++) {
if (gGeometry) gGeometry->Local2Master(&points[3*i],&points[3*i]);
view->WCtoNDC(&points[3*i], xndc);
x1 = gPad->XtoAbsPixel(xndc[0]);
y1 = gPad->YtoAbsPixel(xndc[1]);
dpoint2= (px-x1)*(px-x1) + (py-y1)*(py-y1);
if (dpoint2 < dist) dist = (Int_t)dpoint2;
}
delete [] points;
return Int_t(TMath::Sqrt(Float_t(dist)));
}
void TShape::Paint(Option_t *)
{
TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
if (viewer3D) {
const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
viewer3D->AddObject(buffer);
}
}
void TShape::SetPoints(Double_t *) const
{
AbstractMethod("SetPoints(Double_t *buffer) const");
}
void TShape::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v > 1) {
TShape::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
return;
}
TNamed::Streamer(R__b);
TAttLine::Streamer(R__b);
TAttFill::Streamer(R__b);
TFile *file = (TFile*)R__b.GetParent();
if (file) {
if (file->GetVersion() > 22300) TAtt3D::Streamer(R__b);
} else {
TAtt3D::Streamer(R__b);
}
R__b >> fNumber;
R__b >> fVisibility;
R__b >> fMaterial;
R__b.CheckByteCount(R__s, R__c, TShape::IsA());
} else {
TShape::Class()->WriteBuffer(R__b,this);
}
}
void TShape::TransformPoints(Double_t *points, UInt_t NbPnts) const
{
if (gGeometry && points) {
Double_t dlocal[3];
Double_t dmaster[3];
for (UInt_t j=0; j<NbPnts; j++) {
dlocal[0] = points[3*j];
dlocal[1] = points[3*j+1];
dlocal[2] = points[3*j+2];
gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
points[3*j] = dmaster[0];
points[3*j+1] = dmaster[1];
points[3*j+2] = dmaster[2];
}
}
}
void TShape::FillBuffer3D(TBuffer3D & buffer, Int_t reqSections) const
{
if (reqSections & TBuffer3D::kRaw)
{
if (!(reqSections & TBuffer3D::kRawSizes) && !buffer.SectionsValid(TBuffer3D::kRawSizes))
{
assert(kFALSE);
}
}
if (reqSections & TBuffer3D::kCore) {
buffer.ClearSectionsValid();
buffer.fID = gNode;
buffer.fColor = GetLineColor();
buffer.fTransparency = 0;
buffer.fLocalFrame = kFALSE;
buffer.fReflection = kFALSE;
buffer.SetLocalMasterIdentity();
buffer.SetSectionsValid(TBuffer3D::kCore);
}
}
Int_t TShape::GetBasicColor() const
{
Int_t basicColor = ((GetLineColor() %8) -1) * 4;
if (basicColor < 0) basicColor = 0;
return basicColor;
}
const TBuffer3D &TShape::GetBuffer3D(Int_t ) const
{
static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
Warning("GetBuffer3D", "this must be implemented for shapes in a TNode::Paint hierarchy. This will become a pure virtual fn eventually.");
return buffer;
}
ROOT page - Class index - Class Hierarchy - Top of the page
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.