4 #include "RGBAPalette.h"
9 #include <TBuffer3DTypes.h>
10 #include <TGeometry.h>
11 #include <TVirtualPad.h>
12 #include <TVirtualViewer3D.h>
20 /**************************************************************************/
22 /**************************************************************************/
25 void Quad::ColorFromIdx(Color_t ci)
27 TColor* c = gROOT->GetColor(ci);
29 UChar_t *x = (UChar_t*) &color;
30 x[0] = (UChar_t)(255*c->GetRed()); x[1] = (UChar_t)(255*c->GetGreen());
31 x[2] = (UChar_t)(255*c->GetBlue()); x[3] = 255;
35 Quad::Quad(TRandom& rnd, Float_t origin, Float_t size) : color(0)
37 ColorFromIdx(Int_t(30*rnd.Rndm()));
38 Float_t x = 2*origin*(rnd.Rndm() - 0.5);
39 Float_t y = 2*origin*(rnd.Rndm() - 0.5);
40 Float_t z = 2*origin*(rnd.Rndm() - 0.5);
41 Float_t* p = vertices;
42 for(int i=0; i<4; ++i) {
43 p[0] = x + 2*size*(rnd.Rndm() - 0.5);
44 p[1] = y + 2*size*(rnd.Rndm() - 0.5);
45 p[2] = z + 2*size*(rnd.Rndm() - 0.5);
50 /**************************************************************************/
52 /**************************************************************************/
53 ClassImp(Reve::OldQuadSet)
56 OldQuadSet::OldQuadSet(const Text_t* n, const Text_t* t) :
62 void OldQuadSet::Test(Int_t nquads)
65 fQuads.resize(nquads);
66 for(Int_t i=0; i<nquads; ++i) {
67 new (&fQuads[i]) Quad(rnd, 10, 2);
71 void OldQuadSet::Paint(Option_t* )
73 TBuffer3D buffer(TBuffer3DTypes::kGeneric);
78 buffer.fTransparency = 0;
79 buffer.fLocalFrame = fTrans;
81 memcpy(buffer.fLocalMaster, fMatrix, 16*sizeof(Double_t));
82 buffer.SetSectionsValid(TBuffer3D::kCore);
84 // We fill kCore on first pass and try with viewer
85 Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
86 if (reqSections == TBuffer3D::kNone) {
87 // printf("OldQuadSet::Paint viewer was happy with Core buff3d.\n");
91 if (reqSections & TBuffer3D::kRawSizes) {
92 Int_t nbPnts = fQuads.size()*4;
93 Int_t nbSegs = nbPnts;
94 if (!buffer.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, fQuads.size(), fQuads.size()*6)) {
97 buffer.SetSectionsValid(TBuffer3D::kRawSizes);
100 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
103 for (std::vector<Quad>::iterator i=fQuads.begin(); i!=fQuads.end(); ++i) {
104 for (Int_t k = 0; k < 12; k++ ){
105 buffer.fPnts[pidx] = (*i).vertices[k];
112 for (Int_t q = 0; q < (Int_t)fQuads.size(); ++q) {
113 for (Int_t s = 0; s < 4; ++s ) {
114 buffer.fSegs[3*sidx ] = 4;
115 buffer.fSegs[3*sidx+1] = sidx;
117 buffer.fSegs[3*sidx+2] = q*4;
119 buffer.fSegs[3*sidx+2] = sidx + 1;
125 for (Int_t q = 0; q < (Int_t)fQuads.size(); ++q) {
126 buffer.fPols[6*q] = fQuads[q].color;
127 buffer.fPols[6*q +1] = 4;
128 buffer.fPols[6*q +2] = 4*q +0;
129 buffer.fPols[6*q +3] = 4*q +1;
130 buffer.fPols[6*q +4] = 4*q +2;
131 buffer.fPols[6*q +5] = 4*q +3;
134 buffer.SetSectionsValid(TBuffer3D::kRaw);
138 gPad->GetViewer3D()->AddObject(buffer);
141 /**************************************************************************/
143 void OldQuadSet::ComputeBBox()
150 for(std::vector<Quad>::iterator q=fQuads.begin(); q!=fQuads.end(); ++q) {
151 Float_t* p = q->vertices;
152 for(int i=0; i<4; ++i, p+=3)
156 // printf("%s BBox is x(%f,%f), y(%f,%f), z(%f,%f)\n", GetName(),
157 // fBBox[0], fBBox[1], fBBox[2], fBBox[3], fBBox[4], fBBox[5]);
160 /**************************************************************************/
161 /**************************************************************************/
162 /**************************************************************************/
163 /**************************************************************************/
165 //__________________________________________________________________________
168 // Supports various internal formats that result in rendering of a
169 // set of rectangular objects.
171 // Names of internal structures and their variables use fixed
172 // assignment to x, z, y coordinates; the render types can override
173 // this convention and impose Y as a fixed coordinate.
174 // For quad modes the deltas are expected to be positive.
175 // For line modes negative deltas are ok.
177 ClassImp(Reve::QuadSet)
179 QuadSet::QuadSet(const Text_t* n, const Text_t* t) :
184 fValueIsColor(kFALSE),
185 fDefaultValue(kMinInt),
189 fDefWidth(1), fDefHeight(1), fDefCoord(0),
193 fRenderMode(RM_AsIs),
197 QuadSet::QuadSet(QuadType_e quadType, Bool_t valIsCol, Int_t chunkSize,
198 const Text_t* n, const Text_t* t) :
203 fValueIsColor(valIsCol),
204 fDefaultValue(valIsCol ? 0 : kMinInt),
205 fPlex(SizeofAtom(quadType), chunkSize),
208 fDefWidth(1), fDefHeight(1), fDefCoord(0),
212 fRenderMode(RM_AsIs),
222 /**************************************************************************/
224 Int_t QuadSet::SizeofAtom(QuadSet::QuadType_e qt)
227 case QT_Undef: return 0;
228 case QT_FreeQuad: return sizeof(FreeQuad);
229 case QT_AxisAligned: return sizeof(AAQuad);
230 case QT_AxisAlignedFixedDim: return sizeof(AAFixDimQuad);
231 case QT_AxisAlignedFixedY:
232 case QT_AxisAlignedFixedZ: return sizeof(AAFixZQuad);
233 case QT_AxisAlignedFixedDimY:
234 case QT_AxisAlignedFixedDimZ: return sizeof(AAFixDimZQuad);
236 case QT_LineFixedZ: return sizeof(LineFixedZ);
241 /**************************************************************************/
243 void QuadSet::Reset(QuadSet::QuadType_e quadType, Bool_t valIsCol, Int_t chunkSize)
245 fQuadType = quadType;
246 fValueIsColor = valIsCol;
247 fDefaultValue = valIsCol ? 0 : kMinInt;
248 fPlex.Reset(SizeofAtom(fQuadType), chunkSize);
251 void QuadSet::RefitPlex()
253 // Instruct underlying memory allocator to regroup itself into a
254 // contiguous memory chunk.
259 /**************************************************************************/
261 void QuadSet::ScanMinMaxValues(Int_t& min, Int_t& max)
263 if (fValueIsColor || fPlex.Size() == 0) return;
266 for (Int_t c=0; c<fPlex.VecSize(); ++c)
268 Char_t* a = fPlex.Chunk(c);
269 Int_t n = fPlex.NAtoms(c);
272 Int_t v = ((QuadBase*)a)->fValue;
273 if (v < min) min = v;
274 if (v > max) max = v;
282 /**************************************************************************/
284 void QuadSet::SetFrame(FrameBox* b)
286 if (fFrame == b) return;
287 if (fFrame) fFrame->DecRefCount();
290 fFrame->IncRefCount();
291 SetMainColorPtr(fFrame->PtrFrameColor());
297 void QuadSet::SetPalette(RGBAPalette* p)
299 if (fPalette == p) return;
300 if (fPalette) fPalette->DecRefCount();
303 fPalette->IncRefCount();
304 SetMainColorPtr(fPalette->PtrDefaultColor());
310 /**************************************************************************/
312 QuadSet::QuadBase* QuadSet::NewQuad()
314 fLastQuad = new (fPlex.NewAtom()) QuadBase(fDefaultValue);
318 void QuadSet::AddQuad(Float_t* verts)
320 static const Exc_t eH("QuadSet::AddQuad ");
321 if (fQuadType != QT_FreeQuad)
322 throw(eH + "expect free quad-type.");
324 FreeQuad* fq = (FreeQuad*) NewQuad();
325 memcpy(fq->fVertices, verts, sizeof(fq->fVertices));
328 void QuadSet::AddQuad(Float_t x, Float_t y)
330 AddQuad(x, y, fDefCoord, fDefWidth, fDefHeight);
333 void QuadSet::AddQuad(Float_t x, Float_t y, Float_t z)
335 AddQuad(x, y, z, fDefWidth, fDefHeight);
338 void QuadSet::AddQuad(Float_t x, Float_t y, Float_t w, Float_t h)
340 AddQuad(x, y, fDefCoord, w, h);
343 void QuadSet::AddQuad(Float_t x, Float_t y, Float_t z, Float_t w, Float_t h)
345 static const Exc_t eH("QuadSet::AddAAQuad ");
347 AAFixDimZQuad& fq = * (AAFixDimZQuad*) NewQuad();
348 fq.fX = x; fq.fY = y;
351 case QT_AxisAligned: {
352 AAQuad& q = (AAQuad&) fq;
353 q.fZ = z; q.fW = w; q.fH = h;
356 case QT_AxisAlignedFixedDim: {
357 AAFixDimQuad& q = (AAFixDimQuad&) fq;
361 case QT_AxisAlignedFixedY:
362 case QT_AxisAlignedFixedZ: {
363 AAFixZQuad& q = (AAFixZQuad&) fq;
367 case QT_AxisAlignedFixedDimY:
368 case QT_AxisAlignedFixedDimZ: {
372 case QT_LineFixedZ: {
373 LineFixedZ& q = (LineFixedZ&) fq;
374 q.fDx = w; q.fDy = h;
378 throw(eH + "expect axis-aligned quad-type.");
382 /**************************************************************************/
384 void QuadSet::QuadValue(Int_t value)
386 fLastQuad->fValue = value;
389 void QuadSet::QuadColor(Color_t ci)
391 ColorFromIdx(ci, (UChar_t*) & fLastQuad->fValue, kTRUE);
394 void QuadSet::QuadColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
396 UChar_t* x = (UChar_t*) & fLastQuad->fValue;
397 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
400 /**************************************************************************/
401 /**************************************************************************/
403 void QuadSet::ComputeBBox()
405 static const Exc_t eH("QuadSet::ComputeBBox ");
407 // !!!! Missing handling of FrameBox !!!!
408 // It shoud even simpify things ...
410 if(fPlex.Size() == 0) {
416 if (fQuadType == QT_AxisAlignedFixedZ ||
417 fQuadType == QT_AxisAlignedFixedDimZ)
419 fBBox[4] = fDefCoord;
420 fBBox[5] = fDefCoord;
422 else if (fQuadType == QT_AxisAlignedFixedY ||
423 fQuadType == QT_AxisAlignedFixedDimY)
425 fBBox[2] = fDefCoord;
426 fBBox[3] = fDefCoord;
429 for (Int_t c=0; c<fPlex.VecSize(); ++c)
431 QuadBase* qbp = (QuadBase*) fPlex.Chunk(c);
432 Int_t n = fPlex.NAtoms(c);
439 FreeQuad* qp = (FreeQuad*) qbp;
441 Float_t* p = qp->fVertices;
442 BBoxCheckPoint(p); p += 3;
443 BBoxCheckPoint(p); p += 3;
444 BBoxCheckPoint(p); p += 3;
453 AAQuad* qp = (AAQuad*) qbp;
456 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
457 if(q.fX + q.fW > fBBox[1]) fBBox[1] = q.fX + q.fW;
458 if(q.fY < fBBox[2]) fBBox[2] = q.fY;
459 if(q.fY + q.fH > fBBox[3]) fBBox[3] = q.fY + q.fH;
460 if(q.fZ < fBBox[4]) fBBox[4] = q.fZ;
461 if(q.fZ > fBBox[5]) fBBox[5] = q.fZ;
467 case QT_AxisAlignedFixedDim:
469 AAFixDimQuad* qp = (AAFixDimQuad*) qbp;
470 const Float_t& w = fDefWidth;
471 const Float_t& h = fDefHeight;
473 AAFixDimQuad& q = * qp;
474 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
475 if(q.fX + w > fBBox[1]) fBBox[1] = q.fX + w;
476 if(q.fY < fBBox[2]) fBBox[2] = q.fY;
477 if(q.fY + h > fBBox[3]) fBBox[3] = q.fY + h;
478 if(q.fZ < fBBox[4]) fBBox[4] = q.fZ;
479 if(q.fZ > fBBox[5]) fBBox[5] = q.fZ;
485 case QT_AxisAlignedFixedZ:
487 AAFixZQuad* qp = (AAFixZQuad*) qbp;
489 AAFixZQuad& q = * qp;
490 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
491 if(q.fX + q.fW > fBBox[1]) fBBox[1] = q.fX + q.fW;
492 if(q.fY < fBBox[2]) fBBox[2] = q.fY;
493 if(q.fY + q.fH > fBBox[3]) fBBox[3] = q.fY + q.fH;
499 case QT_AxisAlignedFixedY:
501 AAFixZQuad* qp = (AAFixZQuad*) qbp;
503 AAFixZQuad& q = * qp;
504 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
505 if(q.fX + q.fW > fBBox[1]) fBBox[1] = q.fX + q.fW;
506 if(q.fY < fBBox[4]) fBBox[4] = q.fY;
507 if(q.fY + q.fH > fBBox[5]) fBBox[5] = q.fY + q.fH;
513 case QT_AxisAlignedFixedDimZ:
515 AAFixDimZQuad* qp = (AAFixDimZQuad*) qbp;
516 const Float_t& w = fDefWidth;
517 const Float_t& h = fDefHeight;
519 AAFixDimZQuad& q = * qp;
520 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
521 if(q.fX + w > fBBox[1]) fBBox[1] = q.fX + w;
522 if(q.fY < fBBox[2]) fBBox[2] = q.fY;
523 if(q.fY + h > fBBox[3]) fBBox[3] = q.fY + h;
529 case QT_AxisAlignedFixedDimY:
531 AAFixDimZQuad* qp = (AAFixDimZQuad*) qbp;
532 const Float_t& w = fDefWidth;
533 const Float_t& h = fDefHeight;
535 AAFixDimZQuad& q = * qp;
536 if(q.fX < fBBox[0]) fBBox[0] = q.fX;
537 if(q.fX + w > fBBox[1]) fBBox[1] = q.fX + w;
538 if(q.fY < fBBox[4]) fBBox[4] = q.fY;
539 if(q.fY + h > fBBox[5]) fBBox[5] = q.fY + h;
547 LineFixedZ* qp = (LineFixedZ*) qbp;
549 LineFixedZ& q = * qp;
550 BBoxCheckPoint(q.fX, q.fY, fDefCoord);
551 BBoxCheckPoint(q.fX + q.fDx, q.fY + q.fDy, fDefCoord);
559 LineFixedZ* qp = (LineFixedZ*) qbp;
561 LineFixedZ& q = * qp;
562 BBoxCheckPoint(q.fX, fDefCoord, q.fY);
563 BBoxCheckPoint(q.fX + q.fDx, fDefCoord, q.fY + q.fDy);
570 throw(eH + "unsupported quad-type.");
573 } // end switch quad-type
579 /**************************************************************************/
581 void QuadSet::Paint(Option_t* /*option*/)
583 static const Exc_t eH("QuadSet::Paint ");
585 TBuffer3D buff(TBuffer3DTypes::kGeneric);
590 buff.fTransparency = 0;
591 fHMTrans.SetBuffer3D(buff);
592 buff.SetSectionsValid(TBuffer3D::kCore);
594 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
595 if (reqSections != TBuffer3D::kNone)
596 Error(eH, "only direct GL rendering supported.");
599 /**************************************************************************/