Skip to content

Commit

Permalink
Merge pull request #29 from alja/Prox4c1
Browse files Browse the repository at this point in the history
Introduce proxy builder view types
  • Loading branch information
alja authored Feb 13, 2019
2 parents e62e114 + 64b129e commit 5f85881
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 56 deletions.
2 changes: 1 addition & 1 deletion etc/eve7/EveElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@

var mainColor = JSROOT.Painter.root_colors[el.fMainColor];

mainColor = "lightgreen";
// mainColor = "lightgreen";

var buf = new Float32Array(el.fLinePlexSize * 6);
for (var i = 0; i < el.fLinePlexSize * 6; ++i)
Expand Down
4 changes: 3 additions & 1 deletion etc/eve7/EveScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@
EveScene.prototype.sceneElementChange = function(msg)
{
var el = this.mgr.GetElement(msg.fElementId);
this[msg.tag](el);
if (el.render_data) {
this[msg.tag](el);
}
}

EveScene.prototype.elementsRemoved = function(ids) {
Expand Down
2 changes: 2 additions & 0 deletions graf3d/eve7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTEve
inc/ROOT/REveProjectionManager.hxx
inc/ROOT/REveProjections.hxx
inc/ROOT/REveRenderData.hxx
inc/ROOT/REveScalableStraightLineSet.hxx
inc/ROOT/REveScene.hxx
inc/ROOT/REveSceneInfo.hxx
inc/ROOT/REveSecondarySelectable.hxx
Expand Down Expand Up @@ -75,6 +76,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTEve
src/REveProjectionManager.cxx
src/REveProjections.cxx
src/REveRenderData.cxx
src/REveScalableStraightLineSet.cxx
src/REveScene.cxx
src/REveSceneInfo.cxx
src/REveSecondarySelectable.cxx
Expand Down
9 changes: 7 additions & 2 deletions graf3d/eve7/inc/ROOT/REveDataProxyBuilderBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class REveDataProxyBuilderBase
public:
struct Product
{
std::string m_viewType;
const REveViewContext *m_viewContext;
REveCompound *m_elements;

Product(const REveViewContext* c);
Product(std::string viewType, const REveViewContext* c);
virtual ~Product();
};

Expand All @@ -41,7 +42,7 @@ public:
void Build();
// virtual void Build(REveElement* product);

REveElement* CreateProduct(const REveViewContext*);
REveElement* CreateProduct(std::string viewType, const REveViewContext*);
// void removePerViewProduct(const REveViewContext* vc);

void ModelChanges(const REveDataCollection::Ids_t&);
Expand All @@ -55,12 +56,16 @@ public:

std::string Type() const { return m_type; }

// const member functions
virtual bool HaveSingleProduct() const { return true; }

protected:
// Override this if visibility changes can cause (re)-creation of proxies.
// Returns true if new proxies were created.
virtual bool VisibilityModelChanges(int idx, REveElement*, const REveViewContext*);

virtual void Build(const REveDataCollection* iItem, REveElement* product, const REveViewContext*);
virtual void BuildViewType(const REveDataCollection* iItem, REveElement* product, std::string viewType, const REveViewContext*);

virtual void ModelChanges(const REveDataCollection::Ids_t&, Product*);

Expand Down
2 changes: 2 additions & 0 deletions graf3d/eve7/inc/ROOT/REveDataSimpleProxyBuilder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public:
protected:
using REveDataProxyBuilderBase::Build;
virtual void Build(const REveDataCollection* iCollection, REveElement* product, const REveViewContext*);
virtual void BuildViewType(const REveDataCollection* iCollection, REveElement* product, std::string viewType, const REveViewContext*);

//called once for each collection in collection, the void* points to the
// object properly offset in memory
virtual void Build(const void* data, REveElement* iCollectionHolder, const REveViewContext*) = 0;
virtual void BuildViewType(const void* data, REveElement* iCollectionHolder, std::string viewType, const REveViewContext*) = 0;

virtual void Clean();

Expand Down
15 changes: 14 additions & 1 deletion graf3d/eve7/inc/ROOT/REveDataSimpleProxyBuilderTemplate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ protected:
}
}

using REveDataSimpleProxyBuilder::BuildViewType;
virtual void BuildViewType(const void*iData, REveElement* itemHolder, std::string viewType, const REveViewContext* context)
{
if(0!=iData) {
BuildViewType(*reinterpret_cast<const T*> (iData), itemHolder, viewType, context);
}
}

virtual void Build(const T& iData, REveElement* itemHolder, const REveViewContext* context)
{
throw std::runtime_error("virtual build(const T&, unsigned int, TEveElement&, const FWViewContext*) not implemented by inherited class.");
throw std::runtime_error("virtual Build(const T&, unsigned int, TEveElement&, const FWViewContext*) not implemented by inherited class.");
}

virtual void BuildViewType(const T& iData, REveElement* itemHolder, std::string viewType, const REveViewContext* context)
{
throw std::runtime_error("virtual BuildViewType(const T&, unsigned int, TEveElement&, const FWViewContext*) not implemented by inherited class.");
}

private:
Expand Down
30 changes: 30 additions & 0 deletions graf3d/eve7/inc/ROOT/REveScalableStraightLineSet.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef ROOT_REveScalableStraightLineSet
#define ROOT_REveScalableStraightLineSet

#include "ROOT/REveStraightLineSet.hxx"

namespace ROOT {
namespace Experimental {
class REveScalableStraightLineSet : public REveStraightLineSet
{
private:
REveScalableStraightLineSet(const REveScalableStraightLineSet&); // Not implemented
REveScalableStraightLineSet& operator=(const REveScalableStraightLineSet&); // Not implemented

protected:
Double_t fCurrentScale;
Float_t fScaleCenter[3];

public:
REveScalableStraightLineSet(const char* n="ScalableStraightLineSet", const char* t="");
virtual ~REveScalableStraightLineSet() {}

void SetScaleCenter(Float_t x, Float_t y, Float_t z);
void SetScale(Double_t scale);

Double_t GetScale() const;
};

} // namespace Experimental
} // namespace ROOT
#endif
9 changes: 4 additions & 5 deletions graf3d/eve7/src/REveDataClasses.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ REveDataCollection::REveDataCollection(const std::string& n, const std::string&
{
fChildClass = REveDataItem::Class();

fCanEditMainColor = kTRUE;
fCanEditMainTransparency = kTRUE;
SetMainColorPtr(new Color_t(REveDataCollection::fgDefaultColor));

SetupDefaultColorAndTransparency(fgDefaultColor, true, true);

_handler_func = 0;
_handler_func_ids = 0;
}
Expand All @@ -47,6 +45,7 @@ void REveDataCollection::AddItem(void *data_ptr, const std::string& n, const std
{
auto el = new REveDataItem(n, t);
AddElement(el);
el->SetMainColor(GetMainColor());
fItems.emplace_back(data_ptr, el);
}

Expand Down Expand Up @@ -186,7 +185,7 @@ void REveDataCollection::ItemChanged(REveDataItem* iItem)
REveDataItem::REveDataItem(const std::string& n, const std::string& t) :
REveElement(n, t)
{
SetMainColorPtr(new Color_t(REveDataCollection::fgDefaultColor));
SetupDefaultColorAndTransparency(kMagenta, true, true);
}

Int_t REveDataItem::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
Expand Down
42 changes: 31 additions & 11 deletions graf3d/eve7/src/REveDataProxyBuilderBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace ROOT::Experimental;
namespace REX = ROOT::Experimental;


REveDataProxyBuilderBase::Product::Product(const REveViewContext* c) : m_viewContext(c), m_elements(0)
REveDataProxyBuilderBase::Product::Product(std::string iViewType, const REveViewContext* c) : m_viewType(iViewType), m_viewContext(c), m_elements(0)
{
m_elements = new REveCompound("ProxyProduct", "", false);
m_elements->IncDenyDestroy();
Expand Down Expand Up @@ -79,7 +79,14 @@ void REveDataProxyBuilderBase::Build()
REveElement* elms = (*i)->m_elements;
size_t oldSize = elms->NumChildren();

Build(m_collection, elms, (*i)->m_viewContext);
if (HaveSingleProduct())
{
Build(m_collection, elms, (*i)->m_viewContext);
}
else
{
BuildViewType(m_collection, elms, (*i)->m_viewType, (*i)->m_viewContext);
}

// Project all children of current product.
// If product is not registered into any projection-manager,
Expand Down Expand Up @@ -153,23 +160,38 @@ void REveDataProxyBuilderBase::Build()
void
REveDataProxyBuilderBase::Build(const REveDataCollection*, REveElement*, const REveViewContext*)
{
assert("virtual build(const REveEventItem*, REveElement*, const REveViewContext*) not implemented by inherited class");
assert("virtual Build(const REveEventItem*, REveElement*, const REveViewContext*) not implemented by inherited class");
}


void
REveDataProxyBuilderBase::BuildViewType(const REveDataCollection*, REveElement*, std::string, const REveViewContext*)
{
assert("virtual BuildViewType(const FWEventItem*, TEveElementList*, FWViewType::EType, const FWViewContext*) not implemented by inherited class");
}

//______________________________________________________________________________


REveElement*
REveDataProxyBuilderBase::CreateProduct( const REveViewContext* viewContext)
REveDataProxyBuilderBase::CreateProduct( std::string viewType, const REveViewContext* viewContext)
{
if ( m_products.empty() == false)
{
if (HaveSingleProduct()) {
return m_products.back()->m_elements;
}
}
else {

for (Product_it i = m_products.begin(); i!= m_products.end(); ++i)
{
if (viewType == (*i)->m_viewType)
return (*i)->m_elements;
}
}
}

Product* product = new Product(viewContext);
Product* product = new Product(viewType, viewContext);
m_products.push_back(product);

if (m_collection)
Expand Down Expand Up @@ -215,12 +237,10 @@ REveDataProxyBuilderBase::ModelChanges(const REveDataCollection::Ids_t& iIds, Pr
REveElement::List_i itElement = elms->BeginChildren();
std::advance(itElement, itemIdx);
REveElement* comp = *itElement;
// AMT temporary workaround for use of compunds
if (comp->GetMainColor() != item->GetMainColor())
comp->SetMainColor(item->GetMainColor());
comp->SetMainColor(item->GetMainColor());
comp->SetRnrSelf(item->GetRnrSelf());
applyVisAttrToChildren(comp);

// AMT temporary workaround for use of compunds
// applyVisAttrToChildren(comp);

if (VisibilityModelChanges(*it, *itElement, p->m_viewContext))
{
Expand Down
34 changes: 32 additions & 2 deletions graf3d/eve7/src/REveDataSimpleProxyBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ REveDataSimpleProxyBuilder::Clean()

//______________________________________________________________________________

// AMT: looks like collection parameter is not necessary, maybe for callbacks
void
REveDataSimpleProxyBuilder::Build(const REveDataCollection* collection,
REveElement* product, const REveViewContext* vc)
Expand All @@ -53,7 +52,7 @@ REveDataSimpleProxyBuilder::Build(const REveDataCollection* collection,
else
{
itemHolder = CreateCompound(true, true);
itemHolder->SetMainColorPtr(collection->GetMainColorPtr());
itemHolder->SetMainColor(collection->GetMainColor());
SetupAddElement(itemHolder, product, true);
itemHolder->SetName(Form("compound %d", index));

Expand All @@ -66,6 +65,37 @@ REveDataSimpleProxyBuilder::Build(const REveDataCollection* collection,
}
}

void
REveDataSimpleProxyBuilder::BuildViewType(const REveDataCollection* collection,
REveElement* product, std::string viewType, const REveViewContext* vc)
{
size_t size = collection->GetNItems();
REveElement::List_i pIdx = product->BeginChildren();
for (int index = 0; index < static_cast<int>(size); ++index)
{
REveElement* itemHolder = 0;
if (index < product->NumChildren())
{
itemHolder = *pIdx;
itemHolder->SetRnrSelfChildren(true, true);
++pIdx;
}
else
{
itemHolder = CreateCompound(true, true);
itemHolder->SetMainColor(collection->GetMainColor());
SetupAddElement(itemHolder, product, true);
itemHolder->SetName(Form("compound %d", index));

}
auto di = Collection()->GetDataItem(index);
if (di->GetRnrSelf() && !di->GetFiltered())
{
BuildViewType(collection->GetDataPtr(index), itemHolder, viewType, vc);
}
}
}

//______________________________________________________________________________

bool
Expand Down
60 changes: 60 additions & 0 deletions graf3d/eve7/src/REveScalableStraightLineSet.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "ROOT/REveScalableStraightLineSet.hxx"
#include "ROOT/REveChunkManager.hxx"

/** \class REveScalableStraightLineSet
\ingroup REve
Straight-line-set with extra scaling, useful for projectables that need
to be scaled in accordance with an external object.
*/

using namespace ROOT::Experimental;
namespace REX = ROOT::Experimental;

////////////////////////////////////////////////////////////////////////////////
/// Constructor.

REveScalableStraightLineSet::REveScalableStraightLineSet(const char* n, const char* t):
REveStraightLineSet (n, t),
fCurrentScale(1.0)
{
fScaleCenter[0] = 0;
fScaleCenter[1] = 0;
fScaleCenter[2] = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Set scale center.

void REveScalableStraightLineSet::SetScaleCenter(Float_t x, Float_t y, Float_t z)
{
fScaleCenter[0] = x;
fScaleCenter[1] = y;
fScaleCenter[2] = z;
}

////////////////////////////////////////////////////////////////////////////////
/// Return current scale.

Double_t REveScalableStraightLineSet::GetScale() const
{
return fCurrentScale;
}

////////////////////////////////////////////////////////////////////////////////
/// Loop over line parameters and scale coordinates.

void REveScalableStraightLineSet::SetScale(Double_t scale)
{
REveChunkManager::iterator li(GetLinePlex());
while (li.next())
{
REveStraightLineSet::Line_t& l = * (REveStraightLineSet::Line_t*) li();
l.fV1[0] = fScaleCenter[0]+(l.fV1[0]-fScaleCenter[0])/fCurrentScale*scale;
l.fV1[1] = fScaleCenter[1]+(l.fV1[1]-fScaleCenter[1])/fCurrentScale*scale;
l.fV1[2] = fScaleCenter[2]+(l.fV1[2]-fScaleCenter[2])/fCurrentScale*scale;
l.fV2[0] = fScaleCenter[0]+(l.fV2[0]-fScaleCenter[0])/fCurrentScale*scale;
l.fV2[1] = fScaleCenter[1]+(l.fV2[1]-fScaleCenter[1])/fCurrentScale*scale;
l.fV2[2] = fScaleCenter[2]+(l.fV2[2]-fScaleCenter[2])/fCurrentScale*scale;
}
fCurrentScale = scale;
}
Loading

0 comments on commit 5f85881

Please sign in to comment.