28 ClassImp(TMarker3DBox);
49 TMarker3DBox::TMarker3DBox()
60 SetBit(kTemporary,kFALSE);
66 TMarker3DBox::TMarker3DBox( Float_t x, Float_t y, Float_t z,
67 Float_t dx, Float_t dy, Float_t dz,
68 Float_t theta, Float_t phi)
69 :TAttLine(1,1,1), TAttFill(1,0)
80 SetBit(kTemporary,kFALSE);
86 TMarker3DBox::TMarker3DBox(
const TMarker3DBox& m3d) :
99 fRefObject(m3d.fRefObject)
106 TMarker3DBox& TMarker3DBox::operator=(
const TMarker3DBox& m3d)
109 TObject::operator=(m3d);
110 TAttLine::operator=(m3d);
111 TAttFill::operator=(m3d);
112 TAtt3D::operator=(m3d);
121 fRefObject=m3d.fRefObject;
129 TMarker3DBox::~TMarker3DBox()
140 Int_t TMarker3DBox::DistancetoPrimitive(Int_t px, Int_t py)
142 const Int_t numPoints = 8;
144 Double_t points[3*numPoints];
146 TView *view = gPad->GetView();
147 if (!view)
return dist;
148 const Int_t seg1[12] = {0,1,2,3,4,5,6,7,0,1,2,3};
149 const Int_t seg2[12] = {1,2,3,0,5,6,7,4,4,5,6,7};
153 Int_t i, i1, i2, dsegment;
154 Double_t x1,y1,x2,y2;
156 for (i = 0; i < 12; i++) {
158 view->WCtoNDC(&points[i1], xndc);
163 view->WCtoNDC(&points[i2], xndc);
166 dsegment = DistancetoLine(px,py,x1,y1,x2,y2);
167 if (dsegment < dist) dist = dsegment;
170 gPad->SetCursor(kCross);
171 if (fRefObject) {gPad->SetSelected(fRefObject);
return 0;}
182 void TMarker3DBox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
185 if (gPad->GetView()) gPad->GetView()->ExecuteRotateView(event, px, py);
191 void TMarker3DBox::Paint(Option_t * )
193 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
195 buffer.ClearSectionsValid();
201 if (TestBit(kTemporary)) {
206 buffer.fColor = GetLineColor();
207 buffer.fTransparency = 0;
208 buffer.fLocalFrame = kFALSE;
209 buffer.SetSectionsValid(TBuffer3D::kCore);
212 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
213 if (!viewer3D)
return;
214 Int_t reqSections = viewer3D->AddObject(buffer);
215 if (reqSections == TBuffer3D::kNone) {
219 if (reqSections & TBuffer3D::kRawSizes) {
223 if (!buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*nbPols)) {
226 buffer.SetSectionsValid(TBuffer3D::kRawSizes);
229 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
231 SetPoints(buffer.fPnts);
234 if (gGeometry && !buffer.fLocalFrame) {
237 for (UInt_t j=0; j<buffer.NbPnts(); j++) {
238 dlocal[0] = buffer.fPnts[3*j];
239 dlocal[1] = buffer.fPnts[3*j+1];
240 dlocal[2] = buffer.fPnts[3*j+2];
241 gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
242 buffer.fPnts[3*j] = dmaster[0];
243 buffer.fPnts[3*j+1] = dmaster[1];
244 buffer.fPnts[3*j+2] = dmaster[2];
249 Int_t c = (((GetLineColor()) %8) -1) * 4;
253 buffer.fSegs[ 0] = c ; buffer.fSegs[ 1] = 0 ; buffer.fSegs[ 2] = 1;
254 buffer.fSegs[ 3] = c+1 ; buffer.fSegs[ 4] = 1 ; buffer.fSegs[ 5] = 2;
255 buffer.fSegs[ 6] = c+1 ; buffer.fSegs[ 7] = 2 ; buffer.fSegs[ 8] = 3;
256 buffer.fSegs[ 9] = c ; buffer.fSegs[10] = 3 ; buffer.fSegs[11] = 0;
257 buffer.fSegs[12] = c+2 ; buffer.fSegs[13] = 4 ; buffer.fSegs[14] = 5;
258 buffer.fSegs[15] = c+2 ; buffer.fSegs[16] = 5 ; buffer.fSegs[17] = 6;
259 buffer.fSegs[18] = c+3 ; buffer.fSegs[19] = 6 ; buffer.fSegs[20] = 7;
260 buffer.fSegs[21] = c+3 ; buffer.fSegs[22] = 7 ; buffer.fSegs[23] = 4;
261 buffer.fSegs[24] = c ; buffer.fSegs[25] = 0 ; buffer.fSegs[26] = 4;
262 buffer.fSegs[27] = c+2 ; buffer.fSegs[28] = 1 ; buffer.fSegs[29] = 5;
263 buffer.fSegs[30] = c+1 ; buffer.fSegs[31] = 2 ; buffer.fSegs[32] = 6;
264 buffer.fSegs[33] = c+3 ; buffer.fSegs[34] = 3 ; buffer.fSegs[35] = 7;
267 buffer.fPols[ 0] = c ; buffer.fPols[ 1] = 4 ; buffer.fPols[ 2] = 0;
268 buffer.fPols[ 3] = 9 ; buffer.fPols[ 4] = 4 ; buffer.fPols[ 5] = 8;
269 buffer.fPols[ 6] = c+1 ; buffer.fPols[ 7] = 4 ; buffer.fPols[ 8] = 1;
270 buffer.fPols[ 9] = 10 ; buffer.fPols[10] = 5 ; buffer.fPols[11] = 9;
271 buffer.fPols[12] = c ; buffer.fPols[13] = 4 ; buffer.fPols[14] = 2;
272 buffer.fPols[15] = 11 ; buffer.fPols[16] = 6 ; buffer.fPols[17] = 10;
273 buffer.fPols[18] = c+1 ; buffer.fPols[19] = 4 ; buffer.fPols[20] = 3;
274 buffer.fPols[21] = 8 ; buffer.fPols[22] = 7 ; buffer.fPols[23] = 11;
275 buffer.fPols[24] = c+2 ; buffer.fPols[25] = 4 ; buffer.fPols[26] = 0;
276 buffer.fPols[27] = 3 ; buffer.fPols[28] = 2 ; buffer.fPols[29] = 1;
277 buffer.fPols[30] = c+3 ; buffer.fPols[31] = 4 ; buffer.fPols[32] = 4;
278 buffer.fPols[33] = 5 ; buffer.fPols[34] = 6 ; buffer.fPols[35] = 7;
280 buffer.SetSectionsValid(TBuffer3D::kRaw);
286 viewer3D->AddObject(buffer);
292 void TMarker3DBox::PaintH3(TH1 *h, Option_t *option)
295 Double_t xmin,xmax,ymin,ymax,zmin,zmax,wmin,wmax,w;
296 TAxis *xaxis = h->GetXaxis();
297 TAxis *yaxis = h->GetYaxis();
298 TAxis *zaxis = h->GetZaxis();
300 wmin = h->GetMinimum();
301 wmax = h->GetMaximum();
304 TView *view = gPad->GetView();
306 gPad->Range(-1,-1,1,1);
307 view = TView::CreateView(1,0,0);
310 view->SetRange(xaxis->GetBinLowEdge(xaxis->GetFirst()),
311 yaxis->GetBinLowEdge(yaxis->GetFirst()),
312 zaxis->GetBinLowEdge(zaxis->GetFirst()),
313 xaxis->GetBinUpEdge(xaxis->GetLast()),
314 yaxis->GetBinUpEdge(yaxis->GetLast()),
315 zaxis->GetBinUpEdge(zaxis->GetLast()));
317 view->PadRange(gPad->GetFrameFillColor());
321 m3.SetBit(kTemporary,kTRUE);
323 m3.SetDirection(0,0);
324 m3.SetLineColor(h->GetMarkerColor());
326 for (ix=xaxis->GetFirst();ix<=xaxis->GetLast();ix++) {
327 xmin = h->GetXaxis()->GetBinLowEdge(ix);
328 xmax = xmin + h->GetXaxis()->GetBinWidth(ix);
329 for (iy=yaxis->GetFirst();iy<=yaxis->GetLast();iy++) {
330 ymin = h->GetYaxis()->GetBinLowEdge(iy);
331 ymax = ymin + h->GetYaxis()->GetBinWidth(iy);
332 for (iz=zaxis->GetFirst();iz<=zaxis->GetLast();iz++) {
333 zmin = h->GetZaxis()->GetBinLowEdge(iz);
334 zmax = zmin + h->GetZaxis()->GetBinWidth(iz);
335 bin = h->GetBin(ix,iy,iz);
336 w = h->GetBinContent(bin);
337 if (w < wmin)
continue;
338 if (w > wmax) w = wmax;
339 scale = (TMath::Power((w-wmin)/(wmax-wmin),1./3.))/2.;
340 if (scale == 0)
continue;
341 m3.SetPosition(0.5*(xmin+xmax),0.5*(ymin+ymax),0.5*(zmin+zmax));
342 m3.SetSize(scale*(xmax-xmin),scale*(ymax-ymin),scale*(zmax-zmin));
352 void TMarker3DBox::SavePrimitive(std::ostream &out, Option_t * )
355 if (gROOT->ClassSaved(TMarker3DBox::Class())) {
358 out<<
" TMarker3DBox *";
360 out<<
"marker3DBox = new TMarker3DBox("<<fX<<
","
367 <<fPhi<<
");"<<std::endl;
369 SaveLineAttributes(out,
"marker3DBox",1,1,1);
370 SaveFillAttributes(out,
"marker3DBox",1,0);
372 out<<
" marker3DBox->Draw();"<<std::endl;
378 void TMarker3DBox::SetDirection(Float_t theta, Float_t phi)
387 void TMarker3DBox::SetSize(Float_t dx, Float_t dy, Float_t dz)
397 void TMarker3DBox::SetPosition(Float_t x, Float_t y, Float_t z)
407 void TMarker3DBox::SetPoints(Double_t *points)
const
410 points[ 0] = -fDx ; points[ 1] = -fDy ; points[ 2] = -fDz;
411 points[ 3] = -fDx ; points[ 4] = fDy ; points[ 5] = -fDz;
412 points[ 6] = fDx ; points[ 7] = fDy ; points[ 8] = -fDz;
413 points[ 9] = fDx ; points[10] = -fDy ; points[11] = -fDz;
414 points[12] = -fDx ; points[13] = -fDy ; points[14] = fDz;
415 points[15] = -fDx ; points[16] = fDy ; points[17] = fDz;
416 points[18] = fDx ; points[19] = fDy ; points[20] = fDz;
417 points[21] = fDx ; points[22] = -fDy ; points[23] = fDz;
420 const Double_t kPI = TMath::Pi();
421 Double_t theta = fTheta*kPI/180;
422 Double_t phi = fPhi*kPI/180;
423 Double_t sinth = TMath::Sin(theta);
424 Double_t costh = TMath::Cos(theta);
425 Double_t sinfi = TMath::Sin(phi);
426 Double_t cosfi = TMath::Cos(phi);
430 m[0] = costh * cosfi; m[1] = -sinfi; m[2] = sinth*cosfi;
431 m[3] = costh * sinfi; m[4] = cosfi; m[5] = sinth*sinfi;
432 m[6] = -sinth; m[7] = 0; m[8] = costh;
433 for (Int_t i = 0; i < 8; i++) {
438 points[3*i] = fX + m[0] * x + m[1] * y + m[2] * z;
439 points[3*i+1] = fY + m[3] * x + m[4] * y + m[5] * z;
440 points[3*i+2] = fZ + m[6] * x + m[7] * y + m[8] * z;
448 void TMarker3DBox::Streamer(TBuffer &R__b)
450 if (R__b.IsReading()) {
452 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
454 R__b.ReadClassBuffer(TMarker3DBox::Class(),
this, R__v, R__s, R__c);
458 TObject::Streamer(R__b);
459 TAttLine::Streamer(R__b);
460 TAttFill::Streamer(R__b);
461 TAtt3D::Streamer(R__b);
471 R__b.CheckByteCount(R__s, R__c, TMarker3DBox::IsA());
475 R__b.WriteClassBuffer(TMarker3DBox::Class(),
this);