22#include "TGLIncludes.h"
105 ClearDrawElementVec(fVisibleElements,
maxSize);
117 ClearDrawElementPtrVec(fOpaqueElements,
maxSize);
118 ClearDrawElementPtrVec(fTranspElements,
maxSize);
119 ClearDrawElementPtrVec(fSelOpaqueElements,
maxSize);
120 ClearDrawElementPtrVec(fSelTranspElements,
maxSize);
130 for (
DrawElementVec_i i = fVisibleElements.begin(); i != fVisibleElements.end(); ++i)
131 i->fPhysical->QuantizeShapeLOD(i->fPixelLOD, ctx.
CombiLOD(), i->fFinalLOD);
142 fOpaqueElements.clear();
143 fTranspElements.clear();
144 fSelOpaqueElements.clear();
145 fSelTranspElements.clear();
147 for (
DrawElementVec_i i = fVisibleElements.begin(); i != fVisibleElements.end(); ++i)
149 if (i->fPhysical->IsSelected())
151 if (i->fPhysical->IsTransparent())
152 fSelTranspElements.push_back(&*i);
154 fSelOpaqueElements.push_back(&*i);
156 if (i->fPhysical->IsTransparent())
157 fTranspElements.push_back(&*i);
159 fOpaqueElements.push_back(&*i);
205 std::map<TClass*, UInt_t>::iterator it = fByShapeCnt.find(
logIsA);
206 if (it == fByShapeCnt.end()) {
208 it = fByShapeCnt.insert(std::make_pair(
logIsA, 0
u)).first;
224 out +=
Form(
"Drew scene (%s / %i LOD) - %i (Op %i Trans %i) %i pixel\n",
226 fOpaqueCnt + fTranspCnt, fOpaqueCnt, fTranspCnt, fAsPixelCnt);
227 out +=
Form(
"\tInner phys nums: physicals=%d, of_interest=%lu, visible=%lu, op=%lu, trans=%lu",
229 (
ULong_t)fShapesOfInterest.size(), (
ULong_t)fVisibleElements.size(),
230 (
ULong_t)fOpaqueElements.size(), (
ULong_t)fTranspElements.size());
235 out +=
"\n\tStatistics by shape:\n";
236 std::map<TClass*, UInt_t>::const_iterator it = fByShapeCnt.begin();
237 while (it != fByShapeCnt.end()) {
238 out +=
Form(
"\t%-20s %u\n", it->first->GetName(), it->second);
242 Info(
"TGLScene::DumpDrawStats()",
"%s",out.Data());
320 lit->second->DLCachePurge();
329 lit->second->DLCacheDrop();
359 return (
shape1->BoundingBox().Volume() >
shape2->BoundingBox().Volume());
369 return (
shape1->BoundingBox().Diagonal() >
shape2->BoundingBox().Diagonal());
385 if (
sinfo ==
nullptr ||
sinfo->GetScene() !=
this) {
386 Error(
"TGLScene::RebuildSceneInfo",
"Scene mismatch.");
397 sinfo->fShapesOfInterest.clear();
405 if (
rnrCtx.GetCamera()->OfInterest(
pshp->BoundingBox(),
406 lshp->IgnoreSizeForOfInterest()))
408 sinfo->fShapesOfInterest.push_back(
pshp);
416 sinfo->ClearAfterRebuild();
429 if (
sinfo ==
nullptr ||
sinfo->GetScene() !=
this) {
430 Error(
"TGLScene::UpdateSceneInfo",
"Scene mismatch.");
438 if (!
sinfo->IsVisible())
441 sinfo->fVisibleElements.clear();
447 sinfo->ResetUpdateTimeouted();
468 std::vector<TGLPlane>::iterator pi =
sinfo->ClipPlanes().
begin();
469 while (pi !=
sinfo->ClipPlanes().
end())
482 std::vector<TGLPlane>::iterator pi =
sinfo->ClipPlanes().
begin();
484 while (pi !=
sinfo->ClipPlanes().
end())
493 if (cnt ==
sinfo->ClipPlanes().size())
501 std::vector<TGLPlane>::iterator pi =
sinfo->FrustumPlanes().
begin();
502 while (pi !=
sinfo->FrustumPlanes().
end())
518 sinfo->fVisibleElements.push_back(
de);
525 sinfo->UpdateTimeouted();
527 Warning(
"TGLScene::UpdateSceneInfo",
528 "Timeout reached, not all elements processed.");
533 sinfo->ClearAfterUpdate();
547 if (
sinfo ==
nullptr ||
sinfo->GetScene() !=
this) {
548 Error(
"TGLScene::LodifySceneInfo",
"Scene mismatch.");
571 if (
sinfo ==
nullptr ||
sinfo->GetScene() !=
this) {
573 Error(
"TGLScene::PreDraw",
"%s",
Form(
"SceneInfo mismatch (0x%zx, '%s').",
574 (
size_t)
si,
si ?
si->IsA()->GetName() :
"<>"));
596 lit->second->DLCacheClear();
607 sinfo->ResetDrawStats();
616 if (!
sinfo->fOpaqueElements.empty())
626 if (!
sinfo->fTranspElements.empty())
636 if ( !
sinfo->fSelOpaqueElements.empty())
646 if (!
sinfo->fSelTranspElements.empty())
656 if ( !
sinfo->fSelOpaqueElements.empty())
666 if (!
sinfo->fSelTranspElements.empty())
712 sinfo->DumpDrawStats();
746 if (
sinfo->ShouldClip())
816 if ( !
sinfo->ShouldClip())
827 Info(
"TGLScene::RenderAllPasses()",
916 rnrCtx.SetShapeLOD((*i)->fFinalLOD);
917 rnrCtx.SetShapePixSize((*i)->fPixelSize);
928 rnrCtx.HasStopwatchTimedOut())
931 Warning(
"TGLScene::RenderElements",
932 "Timeout reached, not all elements rendered.");
958 rec.SetTransparent(
pshp->IsTransparent());
959 rec.SetPhysShape(
pshp);
961 rec.SetObject(
pshp->GetLogical()->GetExternal());
962 rec.SetSpecific(
nullptr);
1021 Error(
"TGLScene::AdoptLogical",
"expected ModifyLock");
1039 Error(
"TGLScene::DestroyLogical",
"expected ModifyLock");
1047 Error(
"TGLScene::DestroyLogical",
"logical not found in map.");
1053 while ((
phid =
logical->UnrefFirstPhysical()) != 0)
1059 Warning(
"TGLScene::DestroyLogical",
"an attached physical not found in map.");
1076 Error(
"TGLScene::DestroyLogicals",
"expected ModifyLock");
1132 Error(
"TGLScene::AdoptPhysical",
"expected ModifyLock");
1162 Error(
"TGLScene::DestroyPhysical",
"expected ModifyLock.");
1169 Error(
"TGLScene::DestroyPhysical::UpdatePhysical",
"physical not found.");
1186 Error(
"TGLScene::DestroyPhysicals",
"expected ModifyLock");
1200 count +=
lshp->Ref();
1201 lshp->DestroyPhysicals();
1286 Error(
"TGLScene::UpdateLogical",
"expected ModifyLock");
1292 if (log ==
nullptr) {
1293 Error(
"TGLScene::UpdateLogical",
"logical not found");
1297 log->DLCacheClear();
1298 log->UpdateBoundingBox();
1307 Error(
"TGLScene::UpdatePhysical",
"expected ModifyLock");
1313 if (
phys ==
nullptr) {
1314 Error(
"TGLScene::UpdatePhysical",
"physical not found");
1318 if (trans)
phys->SetTransform(trans);
1319 if (col)
phys->SetDiffuseColor(col);
1328 Error(
"TGLScene::UpdatePhysical",
"expected ModifyLock");
1334 if (
phys ==
nullptr) {
1335 Error(
"TGLScene::UpdatePhysical",
"physical not found");
1340 phys->SetTransform(trans);
1355 Error(
"TGLScene::UpdatePhysioLogical",
"expected ModifyLock");
1361 if (log ==
nullptr) {
1362 Error(
"TGLScene::UpdatePhysioLogical",
"logical not found");
1366 if (log->Ref() != 1) {
1367 Warning(
"TGLScene::UpdatePhysioLogical",
"expecting a single physical (%d).", log->Ref());
1371 if (trans)
phys->SetTransform(trans);
1372 if (col)
phys->SetDiffuseColor(col);
1382 Error(
"TGLScene::UpdatePhysioLogical",
"expected ModifyLock");
1388 if (log ==
nullptr) {
1389 Error(
"TGLScene::UpdatePhysioLogical",
"logical not found");
1393 if (log->Ref() != 1) {
1394 Warning(
"TGLScene::UpdatePhysioLogical",
"expecting a single physical (%d).", log->Ref());
1399 phys->SetTransform(trans);
1423 if (i->second->KeepDuringSmartRefresh() ==
kFALSE) {
1464 Warning(
"TGLScene::FindLogicalSmartRefresh",
"Wrong renderer-type found in cache.");
1501 size +=
sizeof(*logicalShape);
1505 printf(
"Size: Scene + Logical Shapes %u\n",
size);
1511 size +=
sizeof(*physicalShape);
1515 printf(
"Size: Scene + Logical Shapes + Physical Shapes %u\n",
size);
1525 printf(
"Scene: %u Logicals / %u Physicals\n",
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
std::vector< TGLPlane > TGLPlaneSet_t
std::vector< TGLPlane >::const_iterator TGLPlaneSet_ci
winID h TVirtualViewer3D TVirtualGLPainter p
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
const_iterator begin() const
const_iterator end() const
TClass instances represent classes, structs and namespaces in the ROOT type system.
The color creation and management class.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
Identifier of a shared GL-context.
Bool_t TakeLock(ELock lock) const
Lock the object in mode 'lock'.
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the 'lock' argument.
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
static void SetEnvDefaults()
TGLScene * fScene
Shape's bounding box.
static TClass * GetGLRenderer(TClass *isa)
Return direct-rendering GL class for class isa.
Concrete physical shape - a GL drawable.
const TGLLogicalShape * GetLogical() const
Bool_t IsTransparent() const
3D plane class - of format Ax + By + Cz + D = 0
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
static const char * StyleName(Short_t style)
Return string describing the style.
Scene base-class – provides basic interface expected by the TGLViewer or its sub-classes:
virtual void PostDraw(TGLRnrCtx &rnrCtx)
Finalize drawing.
TGLBoundingBox fBoundingBox
virtual void LodifySceneInfo(TGLRnrCtx &ctx)
Setup LOD-dependant values in scene-info.
UInt_t GetMinorStamp() const
void InvalidateBoundingBox()
virtual void PreDraw(TGLRnrCtx &rnrCtx)
Perform basic pre-render initialization:
virtual void RebuildSceneInfo(TGLRnrCtx &ctx)
Fill scene-info with very basic information that is practically view independent.
virtual void UpdateSceneInfo(TGLRnrCtx &ctx)
Fill scene-info with information needed for rendering, take into account the render-context (viewer s...
void TagViewersChanged()
Tag all viewers as changed.
Base class for extended scene context.
void PostDraw()
Clean-up after drawing, nothing to be done here.
void ClearAfterRebuild()
Clear DrawElementVector fVisibleElement and optionally resize it so that it doesn't take more space t...
void ResetDrawStats()
Reset draw statistics.
void DumpDrawStats()
Output draw stats to Info stream.
~TSceneInfo() override
Destructor.
TSceneInfo(TGLViewerBase *view=nullptr, TGLScene *scene=nullptr)
Constructor.
void PreDraw()
Prepare for drawing - fill DrawElementPtrVectors from the contents of fVisibleElements if there was s...
void ClearDrawElementVec(DrawElementVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it.
void UpdateDrawStats(const TGLPhysicalShape &shape, Short_t lod)
Update draw stats, for newly drawn 'shape'.
void ClearAfterUpdate()
Clear DrawElementPtrVectors and optionally resize them so that they don't take more space then requir...
void Lodify(TGLRnrCtx &ctx)
Quantize LODs for given render-context.
void ClearDrawElementPtrVec(DrawElementPtrVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it.
TGLScene provides management and rendering of ROOT's default 3D /object representation as logical and...
Float_t fLastLineWidthScale
void UpdateSceneInfo(TGLRnrCtx &rnrCtx) override
Fill scene-info with information needed for rendering, take into account the render-context (viewer s...
std::vector< DrawElement_t > DrawElementVec_t
virtual TGLPhysicalShape * FindPhysical(UInt_t phid) const
Find and return physical shape identified by unique 'ID'.
PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t
void RenderOpaque(TGLRnrCtx &rnrCtx) override
Render opaque elements.
void CalcBoundingBox() const override
Encapsulates all physical shapes bounding box with axes aligned box.
virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit)
Virtual function to destroy a physical.
void PostDraw(TGLRnrCtx &rnrCtx) override
Called after the rendering is finished.
virtual Bool_t BeginUpdate()
Put scene in update mode, return true if lock acquired.
virtual void AdoptPhysical(TGLPhysicalShape &shape)
Adopt dynamically created physical 'shape' - add to internal map and take responsibility for deleting...
void ReleaseGLCtxIdentity()
Release all GL resources for current context identity.
LogicalShapeMap_t::const_iterator LogicalShapeMapCIt_t
void RebuildSceneInfo(TGLRnrCtx &rnrCtx) override
Major change in scene, need to rebuild all-element draw-vector and sort it.
virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE)
Exit scene update mode.
Float_t fLastPointSizeScale
static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'.
LogicalShapeMap_t fLogicalShapes
virtual Int_t DestroyPhysicals()
Destroy physical shapes.
virtual void RenderAllPasses(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout)
Do full rendering of scene.
virtual void AdoptLogical(TGLLogicalShape &shape)
Adopt dynamically created logical 'shape' - add to internal map and take responsibility for deleting.
void LodifySceneInfo(TGLRnrCtx &rnrCtx) override
Setup LOD-dependant values in scene-info.
virtual void RenderElements(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout, const TGLPlaneSet_t *clipPlanes=nullptr)
Render DrawElements in elementVec with given timeout.
Bool_t ResolveSelectRecord(TGLSelectRecord &rec, Int_t curIdx) override
Process selection record rec.
static Bool_t IsOutside(const TGLBoundingBox &box, const TGLPlaneSet_t &planes)
Check if box is outside of all planes.
void RenderSelTranspForHighlight(TGLRnrCtx &rnrCtx) override
Render selected transparent elements for highlight.
void EndSmartRefresh()
Wipes logicals in refresh-cache.
virtual Bool_t DestroyLogical(TObject *logid, Bool_t mustFind=kTRUE)
Destroy logical shape defined by unique 'ID'.
std::vector< const TGLPhysicalShape * > ShapeVec_t
UInt_t SizeOfScene() const
Return memory cost of scene.
PhysicalShapeMap_t::iterator PhysicalShapeMapIt_t
LogicalShapeMap_t fSmartRefreshCache
virtual void RenderHighlight(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec)
PhysicalShapeMap_t fPhysicalShapes
std::vector< DrawElement_t >::iterator DrawElementVec_i
TSceneInfo * CreateSceneInfo(TGLViewerBase *view) override
Create a scene-info instance appropriate for this scene class.
LogicalShapeMap_t::iterator LogicalShapeMapIt_t
PhysicalShapeMap_t::value_type PhysicalShapeMapValueType_t
LogicalShapeMap_t::value_type LogicalShapeMapValueType_t
std::vector< DrawElement_t * > DrawElementPtrVec_t
std::map< TObject *, TGLLogicalShape * > LogicalShapeMap_t
ShapeVec_t::iterator ShapeVec_i
void RenderSelOpaqueForHighlight(TGLRnrCtx &rnrCtx) override
Render selected opaque elements for highlight.
virtual void UpdatePhysioLogical(TObject *logid, Double_t *trans, UChar_t *col)
Reposition/recolor physical for given logical (assume TGLObject and a single physical).
virtual Bool_t DestroyPhysical(UInt_t phid)
Destroy physical shape defined by unique 'ID'.
static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0)
Fill rgba color from ROOT color-index ci and transparency (0->100).
void RenderTransp(TGLRnrCtx &rnrCtx) override
Render transparent elements.
virtual Int_t DestroyLogicals()
Destroy all logical shapes in scene.
TGLLogicalShape * FindLogicalSmartRefresh(TObject *ID) const
Find and return logical shape identified by unique 'ID' in refresh-cache.
~TGLScene() override
Destroy scene objects.
std::vector< DrawElement_t * >::iterator DrawElementPtrVec_i
void RenderSelTransp(TGLRnrCtx &rnrCtx) override
Render selected transparent elements.
virtual void UpdateLogical(TObject *logid)
Drop display-lists for the logical (assume TGLObject/direct rendering).
TGLContextIdentity * fGLCtxIdentity
void PreDraw(TGLRnrCtx &rnrCtx) override
Initialize rendering.
void DumpMapSizes() const
Print sizes of logical and physical-shape maps.
virtual void UpdatePhysical(UInt_t phid, Double_t *trans, UChar_t *col)
Reposition/recolor physical shape.
virtual UInt_t GetMaxPhysicalID()
Returns the maximum used physical id.
TGLLogicalShape * FindLogical(TObject *logid) const override
Find and return logical shape identified by unique logid.
UInt_t BeginSmartRefresh()
Moves logicals that support smart-refresh to intermediate cache.
static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'.
void RenderSelOpaque(TGLRnrCtx &rnrCtx) override
Render selected opaque elements.
Standard selection record including information about containing scene and details ob out selected ob...
static Float_t GetPointSizeScale()
Get global point-size scale.
static Float_t GetLineWidthScale()
Returns global line-width scale.
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
3 component (x/y/z) vertex class.
Base class for GL viewers.
Mother of all ROOT objects.
virtual TClass * IsA() const
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)