Skip to content

Commit

Permalink
Implementation of REveText, addition of GL overlay support (prototype).
Browse files Browse the repository at this point in the history
Contains contributions from Waad, Alja and Matevz. Squashed to avoid adding of extra files in the repo (some committed by mistake) and to avoid 32 commits.

* Waad: initial implementation & tuning.
* Alja: integration with REve.
* Matevz: final cleanup, loading of fonts & font metrics.

Full set of commits available in https://github.com/alja/root/tree/waa-master-2024

Related PR in RenderCore: UL-FRI-LGM/RenderCore#20

Demo: tutorials/eve7/texts.C
  • Loading branch information
waadfalshehri authored and osschar committed Jun 10, 2024
1 parent 9cf390b commit aeb8e7d
Show file tree
Hide file tree
Showing 48 changed files with 792 additions and 328 deletions.
2 changes: 2 additions & 0 deletions graf3d/eve7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTEve
ROOT/REveSystem.hxx
ROOT/REveTableInfo.hxx
ROOT/REveTableProxyBuilder.hxx
ROOT/REveText.hxx
ROOT/REveTrack.hxx
ROOT/REveTrackProjected.hxx
ROOT/REveTrackPropagator.hxx
Expand Down Expand Up @@ -113,6 +114,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTEve
src/REveStraightLineSet.cxx
src/REveTableInfo.cxx
src/REveTableProxyBuilder.cxx
src/REveText.cxx
src/REveTrack.cxx
src/REveTrackProjected.cxx
src/REveTrackPropagator.cxx
Expand Down
3 changes: 3 additions & 0 deletions graf3d/eve7/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
#pragma link C++ class ROOT::Experimental::REveJetCone+;
#pragma link C++ class ROOT::Experimental::REveJetConeProjected+;

// REveText
#pragma link C++ class ROOT::Experimental::REveText+;

// Ellipse
#pragma link C++ class ROOT::Experimental::REveEllipsoid+;
#pragma link C++ class ROOT::Experimental::REveEllipsoidProjected+;
Expand Down
11 changes: 6 additions & 5 deletions graf3d/eve7/inc/ROOT/REveElement.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public:
kCBColorSelection = BIT(0), // Main color or select/hilite state changed.
kCBTransBBox = BIT(1), // Transformation matrix or bounding-box changed.
kCBObjProps = BIT(2), // Object changed, requires dropping its display-lists.
kCBVisibility = BIT(3), // Rendering of self/children changed.
kCBElementAdded = BIT(4) // Element was added to a new parent.
// kCBElementRemoved = BIT() // Element was removed from a parent.
kCBVisibility = BIT(3), // Rendering of self/children changed.
kCBElementAdded = BIT(4) // Element was added to a new parent.
// kCBElementRemoved = BIT() // Element was removed from a parent.

// Deletions are handled in a special way in REveManager::PreDeleteElement().
};
Expand All @@ -342,13 +342,14 @@ protected:
public:
void StampColorSelection() { AddStamp(kCBColorSelection); }
void StampTransBBox() { AddStamp(kCBTransBBox); }
void StampObjProps() { AddStamp(kCBObjProps); }
void StampObjPropsPreChk() { if ( ! (fChangeBits & kCBObjProps)) AddStamp(kCBObjProps); }
void StampObjProps() { if ( ! (fChangeBits & kCBObjProps)) AddStamp(kCBObjProps); }
void StampVisibility() { AddStamp(kCBVisibility); }
void StampElementAdded() { AddStamp(kCBElementAdded); }
// void StampElementRemoved() { AddStamp(kCBElementRemoved); }
virtual void AddStamp(UChar_t bits);
virtual void ClearStamps() { fChangeBits = 0; }
// Default stamp for object properties -- the most common case.
void Stamp() { StampObjProps(); }

UChar_t GetChangeBits() const { return fChangeBits; }

Expand Down
23 changes: 7 additions & 16 deletions graf3d/eve7/inc/ROOT/REveScene.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ protected:
Bool_t fHierarchical{kFALSE}; ///<!

Bool_t fAcceptingChanges{kFALSE}; ///<!
Bool_t fChanged{kFALSE}; ///<!
// Changed or/and added.
// XXXX can change to vector (element checks if already registered now).
List_t fChangedElements; ///<!
// For the following two have to re-think how the hierarchy will be handled.
Expand All @@ -81,6 +79,7 @@ protected:
std::vector<SceneCommand> fCommands; ///<!

bool fMandatory{true};
bool fIsOverlay{false};
// void RetransHierarchicallyRecurse(REveElement* el, const REveTrans& tp);

public:
Expand All @@ -93,8 +92,7 @@ public:
void SetHierarchical(Bool_t h) { fHierarchical = h; }
Bool_t GetHierarchical() const { return fHierarchical; }

void Changed() { fChanged = kTRUE; } // AMT ??? depricated
Bool_t IsChanged() const;
bool IsChanged() const;

Bool_t IsAcceptingChanges() const { return fAcceptingChanges; }
void BeginAcceptingChanges();
Expand All @@ -105,13 +103,6 @@ public:
void StreamElements();
void StreamJsonRecurse(REveElement *el, nlohmann::json &jobj);

// void Repaint(Bool_t dropLogicals=kFALSE);
// void RetransHierarchically();

// virtual void Paint(Option_t* option = "");

// void DestroyElementRenderers(REveElement* element);
// void DestroyElementRenderers(TObject* rnrObj);
void StreamRepresentationChanges();
void SendChangesToSubscribers();

Expand All @@ -122,6 +113,9 @@ public:
bool GetMandatory() { return fMandatory; }
void SetMandatory(bool x) { fMandatory = x; }

bool GetIsOverlay() { return fIsOverlay; }
void SetIsOverlay(bool x) { fIsOverlay = x; }

void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action);
};

Expand All @@ -143,11 +137,8 @@ public:

void DestroyScenes();

// void RepaintChangedScenes(Bool_t dropLogicals);
// void RepaintAllScenes(Bool_t dropLogicals);

// void DestroyElementRenderers(REveElement* element);
void AcceptChanges(bool);
void BeginAcceptingChanges();
void EndAcceptingChanges();
bool AnyChanges() const;
};

Expand Down
44 changes: 25 additions & 19 deletions graf3d/eve7/inc/ROOT/REveShape.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public:
typedef std::vector<REveVector2> vVector2_t;

protected:
Color_t fFillColor; // fill color of polygons
Color_t fLineColor; // outline color of polygons
Float_t fLineWidth; // outline width of polygons
Color_t fFillColor = 7; // fill color of polygons
Color_t fLineColor = 12; // outline color of polygons
UChar_t fFillAlpha = 255; // alpha of the fill
UChar_t fLineAlpha = 255; // alpha of outline
Float_t fLineWidth = 1; // outline width of polygons

Bool_t fDrawFrame; // draw frame
Bool_t fHighlightFrame; // highlight frame / all shape
Bool_t fMiniFrame; // draw minimal frame
Bool_t fDrawFrame = true; // draw frame
Bool_t fHighlightFrame = false; // highlight frame / all shape
Bool_t fMiniFrame = true; // draw minimal frame

public:
REveShape(const std::string &n = "REveShape", const std::string &t = "");
Expand All @@ -54,19 +56,23 @@ public:
// Rendering parameters.
void SetMainColor(Color_t color) override;

virtual Color_t GetFillColor() const { return fFillColor; }
virtual Color_t GetLineColor() const { return fLineColor; }
virtual Float_t GetLineWidth() const { return fLineWidth; }
virtual Bool_t GetDrawFrame() const { return fDrawFrame; }
virtual Bool_t GetHighlightFrame() const { return fHighlightFrame; }
virtual Bool_t GetMiniFrame() const { return fMiniFrame; }

virtual void SetFillColor(Color_t c) { fFillColor = c; }
virtual void SetLineColor(Color_t c) { fLineColor = c; }
virtual void SetLineWidth(Float_t lw) { fLineWidth = lw; }
virtual void SetDrawFrame(Bool_t f) { fDrawFrame = f; }
virtual void SetHighlightFrame(Bool_t f) { fHighlightFrame = f; }
virtual void SetMiniFrame(Bool_t r) { fMiniFrame = r; }
Color_t GetFillColor() const { return fFillColor; }
Color_t GetLineColor() const { return fLineColor; }
UChar_t GetFillAlpha() const { return fFillAlpha; }
UChar_t GetLineAlpha() const { return fLineAlpha; }
Float_t GetLineWidth() const { return fLineWidth; }
Bool_t GetDrawFrame() const { return fDrawFrame; }
Bool_t GetHighlightFrame() const { return fHighlightFrame; }
Bool_t GetMiniFrame() const { return fMiniFrame; }

void SetFillColor(Color_t c) { fFillColor = c; StampObjProps(); }
void SetLineColor(Color_t c) { fLineColor = c; StampObjProps(); }
void SetFillAlpha(UChar_t c) { fFillAlpha = c; StampObjProps(); }
void SetLineAlpha(UChar_t c) { fLineAlpha = c; StampObjProps(); }
void SetLineWidth(Float_t lw) { fLineWidth = lw; StampObjProps(); }
void SetDrawFrame(Bool_t f) { fDrawFrame = f; StampObjProps(); }
void SetHighlightFrame(Bool_t f) { fHighlightFrame = f; StampObjProps(); }
void SetMiniFrame(Bool_t r) { fMiniFrame = r; StampObjProps(); }

// ----------------------------------------------------------------

Expand Down
85 changes: 85 additions & 0 deletions graf3d/eve7/inc/ROOT/REveText.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// @(#)root/eve7:$Id$
// Author: Waad Alshehri, 2023

/*************************************************************************
* Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT7_REveText
#define ROOT7_REveText

#include <ROOT/REveShape.hxx>
#include <ROOT/REveVector.hxx>

namespace ROOT {
namespace Experimental {

//------------------------------------------------------------------------------
// REveText
//------------------------------------------------------------------------------

class REveText : public REveShape
{
private:
REveText(const REveText &) = delete;
REveText &operator=(const REveText &) = delete;

protected:
std::string fText {"<no-text>"};
std::string fFont {"LiberationSans-Regular"};
REveVector fPosition {0, 0, 0};
Float_t fFontSize {80};
Float_t fFontHinting {1.0};
Float_t fExtraBorder {0.2}; // border around text in font-size units
Int_t fMode {1}; // default mode is in relative screen coordinates [0,1]
Color_t fTextColor {kMagenta};
// UChar_t fTextAlpha {255}; // Better than main transparency -- to be fixed.

public:
REveText(const Text_t *n = "REveText", const Text_t *t = "");
virtual ~REveText() {}

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
void BuildRenderData() override;

void ComputeBBox() override;

std::string GetText() const { return fText; }
void SetText(std::string_view text) { fText = text; StampObjProps(); }

std::string GetFont() const { return fFont; }
void SetFont(std::string_view font) { fFont = font; StampObjProps();}

Float_t GetFontSize() const { return fFontSize; }
void SetFontSize(float size) { fFontSize = size; StampObjProps();}

Int_t GetMode() const { return fMode; }
void SetMode(Int_t mode) { fMode = mode;}

Float_t GetFontHinting() const { return fFontHinting; }
void SetFontHinting(Float_t fontHinting) { fFontHinting = fontHinting; StampObjProps();}

Float_t GetExtraBorder() const { return fExtraBorder; }
void SetExtraBorder(float size) { fExtraBorder = size; StampObjProps();}

REveVector GetPosition() const { return fPosition; }
const REveVector& RefPosition() const { return fPosition; }
void SetPosition(const REveVector& position) { fPosition = position;}
void SetPosX(float x) { fPosition.fX = x; StampObjProps(); }
void SetPosY(float y) { fPosition.fY = y; StampObjProps(); }

Color_t GetTextColor() const { return fTextColor; }
void SetTextColor(Color_t color) { fTextColor = color; StampObjProps();}

// UChar_t GetTextAlpha() const { return fTextAlpha; }
// void SetTextAlpha(UChar_t c) { fTextAlpha = c; StampObjProps(); }
};

} // namespace Experimental
} // namespace ROOT

#endif
6 changes: 3 additions & 3 deletions graf3d/eve7/src/REveElement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,9 @@ Int_t REveElement::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
nlohmann::json rd = {};

rd["rnr_offset"] = rnr_offset;
rd["rnr_func"] = fRenderData->GetRnrFunc();
rd["vert_size"] = fRenderData->SizeV();
rd["norm_size"] = fRenderData->SizeN();
rd["rnr_func"] = fRenderData->GetRnrFunc();
rd["vert_size"] = fRenderData->SizeV();
rd["norm_size"] = fRenderData->SizeN();
rd["index_size"] = fRenderData->SizeI();
rd["trans_size"] = fRenderData->SizeT();

Expand Down
15 changes: 9 additions & 6 deletions graf3d/eve7/src/REveManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1050,14 +1050,17 @@ void REveManager::MIRExecThread()

lock.unlock();

// allow scenes to accept changes in the element
// Ideally, as in gled, MIR execution would be steered by scenes themselves.
// But this requires alpha/beta/gamma MIR elements and scene dependenices,
// so dependent scenes can be locked, too.
// On top of that, one could also implements authorization framework, as in gled.

gEve->GetWorld()->BeginAcceptingChanges();
gEve->GetScenes()->AcceptChanges(true);
gEve->GetScenes()->BeginAcceptingChanges();

ExecuteMIR(mir);

// disable scene's element changing
gEve->GetScenes()->AcceptChanges(false);
gEve->GetScenes()->EndAcceptingChanges();
gEve->GetWorld()->EndAcceptingChanges();

StreamSceneChangesToJson();
Expand Down Expand Up @@ -1170,14 +1173,14 @@ void REveManager::BeginChange()
fServerState.fVal = ServerState::UpdatingScenes;
}
GetWorld()->BeginAcceptingChanges();
GetScenes()->AcceptChanges(true);
GetScenes()->BeginAcceptingChanges();
}

//____________________________________________________________________
void REveManager::EndChange()
{
// tag scene to disable accepting chages, write the change json
GetScenes()->AcceptChanges(false);
GetScenes()->EndAcceptingChanges();
GetWorld()->EndAcceptingChanges();

StreamSceneChangesToJson();
Expand Down
Loading

0 comments on commit aeb8e7d

Please sign in to comment.