Demonstrates 3D viewer architecture TVirtualViewer3D and TBuffer3D in the local frame.
Here each shape is described in a TBuffer3D class, with a suitible translation matrix to place each instance NOTE: to be executed via .x viewer3DLocal.C+
NOTE: We don't implement raw tesselation of sphere - hence this will not appear in viewers which don't support directly (non-OpenGL) Shows that viewers can at least deal gracefully with these cases
Our abstract base shape class.
As we overload TObject::Paint which is called directly from compiled code, this script must also be compiled to work correctly.
#include <vector>
public:
~Shape() override{};
protected:
};
class Sphere : public Shape {
public:
~Sphere() override{};
TBuffer3D &GetBuffer3D(
UInt_t reqSections)
override;
private:
};
{
}
{
}
Double_t halfLength[3] = {fRadius, fRadius, fRadius};
}
}
}
}
return buffer;
}
class Box : public Shape {
public:
~Box() override{};
TBuffer3D &GetBuffer3D(
UInt_t reqSections)
override;
private:
};
{
}
{
}
Double_t halfLength[3] = {fDX, fDY, fDZ};
}
}
buffer.
fPnts[0] = fX - fDX;
buffer.
fPnts[1] = fY - fDY;
buffer.
fPnts[2] = fZ - fDZ;
buffer.
fPnts[3] = fX + fDX;
buffer.
fPnts[4] = fY - fDY;
buffer.
fPnts[5] = fZ - fDZ;
buffer.
fPnts[6] = fX + fDX;
buffer.
fPnts[7] = fY + fDY;
buffer.
fPnts[8] = fZ - fDZ;
buffer.
fPnts[9] = fX - fDX;
buffer.
fPnts[10] = fY + fDY;
buffer.
fPnts[11] = fZ - fDZ;
buffer.
fPnts[12] = fX - fDX;
buffer.
fPnts[13] = fY - fDY;
buffer.
fPnts[14] = fZ + fDZ;
buffer.
fPnts[15] = fX + fDX;
buffer.
fPnts[16] = fY - fDY;
buffer.
fPnts[17] = fZ + fDZ;
buffer.
fPnts[18] = fX + fDX;
buffer.
fPnts[19] = fY + fDY;
buffer.
fPnts[20] = fZ + fDZ;
buffer.
fPnts[21] = fX - fDX;
buffer.
fPnts[22] = fY + fDY;
buffer.
fPnts[23] = fZ + fDZ;
buffer.
fSegs[0] = fColor;
buffer.
fSegs[3] = fColor;
buffer.
fSegs[6] = fColor;
buffer.
fSegs[9] = fColor;
buffer.
fSegs[12] = fColor;
buffer.
fSegs[15] = fColor;
buffer.
fSegs[18] = fColor;
buffer.
fSegs[21] = fColor;
buffer.
fSegs[24] = fColor;
buffer.
fSegs[27] = fColor;
buffer.
fSegs[30] = fColor;
buffer.
fSegs[33] = fColor;
buffer.
fPols[0] = fColor;
buffer.
fPols[6] = fColor;
buffer.
fPols[12] = fColor;
buffer.
fPols[18] = fColor;
buffer.
fPols[24] = fColor;
buffer.
fPols[30] = fColor;
}
return buffer;
}
class SBPyramid : public Shape {
public:
~SBPyramid() override{};
TBuffer3D &GetBuffer3D(
UInt_t reqSections)
override;
private:
};
{
}
{
}
Double_t halfLength[3] = {fDX, fDY, fDZ / 2.0};
Double_t origin[3] = {fX, fY, fZ + halfLength[2]};
}
}
buffer.
fPnts[0] = fX - fDX;
buffer.
fPnts[1] = fY - fDY;
buffer.
fPnts[3] = fX + fDX;
buffer.
fPnts[4] = fY - fDY;
buffer.
fPnts[6] = fX + fDX;
buffer.
fPnts[7] = fY + fDY;
buffer.
fPnts[9] = fX - fDX;
buffer.
fPnts[10] = fY + fDY;
buffer.
fPnts[14] = fZ + fDZ;
buffer.
fSegs[0] = fColor;
buffer.
fSegs[3] = fColor;
buffer.
fSegs[6] = fColor;
buffer.
fSegs[9] = fColor;
buffer.
fSegs[12] = fColor;
buffer.
fSegs[15] = fColor;
buffer.
fSegs[18] = fColor;
buffer.
fSegs[21] = fColor;
buffer.
fPols[0] = fColor;
buffer.
fPols[6] = fColor;
buffer.
fPols[11] = fColor;
buffer.
fPols[16] = fColor;
buffer.
fPols[21] = fColor;
}
return buffer;
}
public:
MyGeom();
~MyGeom() override;
private:
std::vector<Shape *> fShapes;
};
MyGeom::MyGeom()
{
Shape *aShape;
aShape =
new Sphere(
kYellow, 80.0, 60.0, 120.0, 10.0);
fShapes.push_back(aShape);
aShape =
new Box(
kRed, 0.0, 0.0, 0.0, 20.0, 20.0, 20.0);
fShapes.push_back(aShape);
aShape =
new Box(
kBlue, 50.0, 100.0, 200.0, 5.0, 10.0, 15.0);
fShapes.push_back(aShape);
aShape =
new SBPyramid(
kGreen, 20.0, 25.0, 45.0, 30.0, 30.0, 90.0);
fShapes.push_back(aShape);
}
MyGeom::~MyGeom()
{
}
{
gPad->GetViewer3D(option);
}
{
std::vector<Shape *>::const_iterator ShapeIt = fShapes.begin();
Shape *shape;
while (ShapeIt != fShapes.end()) {
shape = *ShapeIt;
TBuffer3D &buffer = shape->GetBuffer3D(reqSections);
shape->GetBuffer3D(reqSections);
}
ShapeIt++;
}
}
void viewer3DLocal()
{
printf("\n\nviewer3DLocal: This frame demonstates local frame use of 3D viewer architecture.\n");
printf("Creates sphere, two boxes and a square based pyramid, described in local frame.\n");
printf("We do not implement raw tesselation of sphere - hence will not appear in viewers\n");
printf("which do not support in natively (non-GL viewer).\n\n");
gROOT->SetWebDisplay(
"off");
MyGeom *myGeom = new MyGeom;
myGeom->Draw("ogl");
}
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
#define ClassDefOverride(name, id)
Use this attribute class when an object should have 3D capabilities.
Sphere description class - see TBuffer3DTypes for producer classes Supports hollow and cut spheres.
Generic 3D primitive description class.
void SetLocalMasterIdentity()
Set kRaw tessellation section of buffer with supplied sizes.
Double_t fLocalMaster[16]
void ClearSectionsValid()
Clear any sections marked valid.
void SetSectionsValid(UInt_t mask)
void SetAABoundingBox(const Double_t origin[3], const Double_t halfLengths[3])
Set fBBVertex in kBoundingBox section to a axis aligned (local) BB using supplied origin and box half...
Bool_t SetRawSizes(UInt_t reqPnts, UInt_t reqPntsCapacity, UInt_t reqSegs, UInt_t reqSegsCapacity, UInt_t reqPols, UInt_t reqPolsCapacity)
Set kRaw tessellation section of buffer with supplied sizes.
Mother of all ROOT objects.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Abstract 3D shapes viewer.
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=nullptr)=0