25 ClassImp(TPolyLine3D);
99 TPolyLine3D::TPolyLine3D()
110 TPolyLine3D::TPolyLine3D(Int_t n, Option_t *option)
122 fP =
new Float_t[3*fN];
123 for (Int_t i=0; i<3*fN; i++) fP[i] = 0;
130 TPolyLine3D::TPolyLine3D(Int_t n, Float_t *p, Option_t *option)
142 fP =
new Float_t[3*fN];
143 for (Int_t i=0; i<3*n; i++) {
153 TPolyLine3D::TPolyLine3D(Int_t n, Double_t *p, Option_t *option)
165 fP =
new Float_t[3*fN];
166 for (Int_t i=0; i<3*n; i++) {
167 fP[i] = (Float_t) p[i];
176 TPolyLine3D::TPolyLine3D(Int_t n, Float_t *x, Float_t *y, Float_t *z, Option_t *option)
188 fP =
new Float_t[3*fN];
190 for (Int_t i=0; i<n;i++) {
204 TPolyLine3D::TPolyLine3D(Int_t n, Double_t *x, Double_t *y, Double_t *z, Option_t *option)
216 fP =
new Float_t[3*fN];
218 for (Int_t i=0; i<n;i++) {
219 fP[j] = (Float_t) x[i];
220 fP[j+1] = (Float_t) y[i];
221 fP[j+2] = (Float_t) z[i];
230 TPolyLine3D& TPolyLine3D::operator=(
const TPolyLine3D& pl)
233 TObject::operator=(pl);
234 TAttLine::operator=(pl);
235 TAtt3D::operator=(pl);
239 fLastPoint=pl.fLastPoint;
247 TPolyLine3D::~TPolyLine3D()
249 if (fP)
delete [] fP;
255 TPolyLine3D::TPolyLine3D(
const TPolyLine3D &polyline) : TObject(polyline), TAttLine(polyline), TAtt3D(polyline)
260 ((TPolyLine3D&)polyline).TPolyLine3D::Copy(*
this);
266 void TPolyLine3D::Copy(TObject &obj)
const
269 TAttLine::Copy(((TPolyLine3D&)obj));
270 ((TPolyLine3D&)obj).fN = fN;
271 if (((TPolyLine3D&)obj).fP)
272 delete [] ((TPolyLine3D&)obj).fP;
274 ((TPolyLine3D&)obj).fP =
new Float_t[3*fN];
275 for (Int_t i=0; i<3*fN;i++) {((TPolyLine3D&)obj).fP[i] = fP[i];}
277 ((TPolyLine3D&)obj).fP = 0;
279 ((TPolyLine3D&)obj).fOption = fOption;
280 ((TPolyLine3D&)obj).fLastPoint = fLastPoint;
290 Int_t TPolyLine3D::DistancetoPrimitive(Int_t px, Int_t py)
292 const Int_t inaxis = 7;
295 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
296 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
297 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
298 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
301 if (px < puxmin - inaxis)
return dist;
302 if (py > puymin + inaxis)
return dist;
303 if (px > puxmax + inaxis)
return dist;
304 if (py < puymax - inaxis)
return dist;
306 TView *view = gPad->GetView();
307 if (!view)
return dist;
310 Double_t x1,y1,x2,y2;
312 for (i=0;i<Size()-1;i++) {
313 view->WCtoNDC(&fP[3*i], xndc);
316 view->WCtoNDC(&fP[3*i+3], xndc);
319 dsegment = DistancetoLine(px,py,x1,y1,x2,y2);
320 if (dsegment < dist) dist = dsegment;
328 void TPolyLine3D::Draw(Option_t *option)
354 void TPolyLine3D::DrawOutlineCube(TList *outline, Double_t *rmin, Double_t *rmax)
356 Double_t xmin = rmin[0]; Double_t xmax = rmax[0];
357 Double_t ymin = rmin[1]; Double_t ymax = rmax[1];
358 Double_t zmin = rmin[2]; Double_t zmax = rmax[2];
360 TPolyLine3D *pl3d = (TPolyLine3D *)outline->First();
362 TView *view = gPad->GetView();
364 TPolyLine3D *p1 =
new TPolyLine3D(4);
365 TPolyLine3D *p2 =
new TPolyLine3D(4);
366 TPolyLine3D *p3 =
new TPolyLine3D(4);
367 TPolyLine3D *p4 =
new TPolyLine3D(4);
368 p1->SetLineColor(view->GetLineColor());
369 p1->SetLineStyle(view->GetLineStyle());
370 p1->SetLineWidth(view->GetLineWidth());
380 pl3d = (TPolyLine3D *)outline->First();
383 pl3d->SetPoint(0, xmin, ymin, zmin);
384 pl3d->SetPoint(1, xmax, ymin, zmin);
385 pl3d->SetPoint(2, xmax, ymax, zmin);
386 pl3d->SetPoint(3, xmin, ymax, zmin);
389 pl3d = (TPolyLine3D *)outline->After(pl3d);
392 pl3d->SetPoint(0, xmax, ymin, zmin);
393 pl3d->SetPoint(1, xmax, ymin, zmax);
394 pl3d->SetPoint(2, xmax, ymax, zmax);
395 pl3d->SetPoint(3, xmax, ymax, zmin);
398 pl3d = (TPolyLine3D *)outline->After(pl3d);
401 pl3d->SetPoint(0, xmax, ymin, zmax);
402 pl3d->SetPoint(1, xmin, ymin, zmax);
403 pl3d->SetPoint(2, xmin, ymax, zmax);
404 pl3d->SetPoint(3, xmax, ymax, zmax);
407 pl3d = (TPolyLine3D *)outline->After(pl3d);
410 pl3d->SetPoint(0, xmin, ymin, zmax);
411 pl3d->SetPoint(1, xmin, ymin, zmin);
412 pl3d->SetPoint(2, xmin, ymax, zmin);
413 pl3d->SetPoint(3, xmin, ymax, zmax);
422 void TPolyLine3D::DrawPolyLine(Int_t n, Float_t *p, Option_t *option)
424 TPolyLine3D *newpolyline =
new TPolyLine3D();
425 Int_t size = 3*Size();
427 newpolyline->fP =
new Float_t[size];
428 for (Int_t i=0; i<size;i++) { newpolyline->fP[i] = p[i];}
429 TAttLine::Copy(*newpolyline);
430 newpolyline->fOption = fOption;
431 newpolyline->fLastPoint = fLastPoint;
432 newpolyline->SetBit(kCanDelete);
433 newpolyline->AppendPad(option);
439 void TPolyLine3D::ExecuteEvent(Int_t event, Int_t px, Int_t py)
442 if (gPad->GetView()) gPad->GetView()->ExecuteRotateView(event, px, py);
448 void TPolyLine3D::ls(Option_t *option)
const
450 TROOT::IndentLevel();
451 std::cout <<
"PolyLine3D N=" <<fN<<
" Option="<<option<<std::endl;
457 Int_t TPolyLine3D::Merge(TCollection *li)
465 while ((pl = (TPolyLine3D*)next())) {
466 if (!pl->InheritsFrom(TPolyLine3D::Class())) {
467 Error(
"Add",
"Attempt to add object of class: %s to a %s",pl->ClassName(),this->ClassName());
470 npoints += pl->Size();
474 SetPoint(npoints-1,0,0,0);
478 while ((pl = (TPolyLine3D*)next())) {
479 Int_t np = pl->Size();
480 Float_t *p = pl->GetP();
481 for (Int_t i=0;i<np;i++) {
482 SetPoint(i,p[3*i],p[3*i+1],p[3*i+2]);
492 void TPolyLine3D::Paint(Option_t * )
497 if (Size() <= 0)
return;
499 static TBuffer3D buffer(TBuffer3DTypes::kLine);
504 buffer.ClearSectionsValid();
508 buffer.fColor = GetLineColor();
509 buffer.fTransparency = 0;
510 buffer.fLocalFrame = kFALSE;
511 buffer.SetSectionsValid(TBuffer3D::kCore);
514 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
515 if (!viewer3D)
return;
516 Int_t reqSections = viewer3D->AddObject(buffer);
517 if (reqSections == TBuffer3D::kNone) {
521 if (reqSections & TBuffer3D::kRawSizes) {
522 Int_t nbPnts = Size();
523 Int_t nbSegs = nbPnts-1;
524 if (!buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, 0, 0)) {
527 buffer.SetSectionsValid(TBuffer3D::kRawSizes);
530 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
532 for (i=0; i<3*buffer.NbPnts(); i++) {
533 buffer.fPnts[i] = (Double_t)fP[i];
537 if (gGeometry && !buffer.fLocalFrame) {
540 for (UInt_t j=0; j<buffer.NbPnts(); j++) {
541 dlocal[0] = buffer.fPnts[3*j];
542 dlocal[1] = buffer.fPnts[3*j+1];
543 dlocal[2] = buffer.fPnts[3*j+2];
544 gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
545 buffer.fPnts[3*j] = dmaster[0];
546 buffer.fPnts[3*j+1] = dmaster[1];
547 buffer.fPnts[3*j+2] = dmaster[2];
552 Int_t c = (((GetLineColor()) %8) -1) * 4;
556 for (i = 0; i < buffer.NbSegs(); i++) {
557 buffer.fSegs[3*i ] = c;
558 buffer.fSegs[3*i+1] = i;
559 buffer.fSegs[3*i+2] = i+1;
564 buffer.SetSectionsValid(TBuffer3D::kRaw);
567 viewer3D->AddObject(buffer);
573 void TPolyLine3D::Print(Option_t *option)
const
575 printf(
" TPolyLine3D N=%d, Option=%s\n",fN,option);
576 TString opt = option;
578 if (opt.Contains(
"all")) {
579 for (Int_t i=0;i<Size();i++) {
580 printf(
" x[%d]=%g, y[%d]=%g, z[%d]=%g\n",i,fP[3*i],i,fP[3*i+1],i,fP[3*i+2]);
588 void TPolyLine3D::SavePrimitive(std::ostream &out, Option_t * )
592 if (gROOT->ClassSaved(TPolyLine3D::Class())) {
595 out<<
" TPolyLine3D *";
598 out<<
"pline3D = new TPolyLine3D("<<fN<<
","<<quote<<fOption<<quote<<
");"<<std::endl;
600 SaveLineAttributes(out,
"pline3D",1,1,1);
603 for (Int_t i=0;i<size;i++)
604 out<<
" pline3D->SetPoint("<<i<<
","<<fP[3*i]<<
","<<fP[3*i+1]<<
","<<fP[3*i+2]<<
");"<<std::endl;
606 out<<
" pline3D->Draw();"<<std::endl;
613 Int_t TPolyLine3D::SetNextPoint(Double_t x, Double_t y, Double_t z)
616 SetPoint(fLastPoint, x, y, z);
625 void TPolyLine3D::SetPoint(Int_t n, Double_t x, Double_t y, Double_t z)
628 if (!fP || n >= fN) {
630 Int_t newN = TMath::Max(2*fN,n+1);
631 Float_t *savepoint =
new Float_t [3*newN];
633 memcpy(savepoint,fP,3*fN*
sizeof(Float_t));
634 memset(&savepoint[3*fN],0,(newN-fN)*
sizeof(Float_t));
643 fLastPoint = TMath::Max(fLastPoint,n);
650 void TPolyLine3D::SetPolyLine(Int_t n, Option_t *option)
661 if (fP)
delete [] fP;
662 fP =
new Float_t[3*fN];
663 memset(fP,0,3*fN*
sizeof(Float_t));
671 void TPolyLine3D::SetPolyLine(Int_t n, Float_t *p, Option_t *option)
682 if (fP)
delete [] fP;
683 fP =
new Float_t[3*fN];
685 for (Int_t i=0; i<fN;i++) {
687 fP[3*i+1] = p[3*i+1];
688 fP[3*i+2] = p[3*i+2];
691 memset(fP,0,3*fN*
sizeof(Float_t));
700 void TPolyLine3D::SetPolyLine(Int_t n, Double_t *p, Option_t *option)
711 if (fP)
delete [] fP;
712 fP =
new Float_t[3*fN];
714 for (Int_t i=0; i<fN;i++) {
715 fP[3*i] = (Float_t) p[3*i];
716 fP[3*i+1] = (Float_t) p[3*i+1];
717 fP[3*i+2] = (Float_t) p[3*i+2];
720 memset(fP,0,3*fN*
sizeof(Float_t));
728 void TPolyLine3D::Streamer(TBuffer &b)
732 b.ReadVersion(&R__s, &R__c);
733 b.ClassBegin(TPolyLine3D::IsA());
734 b.ClassMember(
"TObject");
735 TObject::Streamer(b);
736 b.ClassMember(
"TAttLine");
737 TAttLine::Streamer(b);
738 b.ClassMember(
"fN",
"Int_t");
741 fP =
new Float_t[3*fN];
742 b.ClassMember(
"fP",
"Float_t", 3 * fN);
743 b.ReadFastArray(fP, 3 * fN);
745 b.ClassMember(
"fOption",
"TString");
748 b.ClassEnd(TPolyLine3D::IsA());
749 b.CheckByteCount(R__s, R__c, TPolyLine3D::IsA());
751 R__c = b.WriteVersion(TPolyLine3D::IsA(), kTRUE);
752 b.ClassBegin(TPolyLine3D::IsA());
753 b.ClassMember(
"TObject");
754 TObject::Streamer(b);
755 b.ClassMember(
"TAttLine");
756 TAttLine::Streamer(b);
757 b.ClassMember(
"fN",
"Int_t");
761 b.ClassMember(
"fP",
"Float_t", 3 * size);
762 b.WriteFastArray(fP, 3 * size);
764 b.ClassMember(
"fOption",
"TString");
766 b.ClassEnd(TPolyLine3D::IsA());
767 b.SetByteCount(R__c, kTRUE);