From bc3f186d24df9861d435bf63bea18c34298e8044 Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Thu, 8 Jul 2010 07:55:42 +0000 Subject: [PATCH] tell ColorBy to not throw in case of undefined properties git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2543 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- examples/demos/conservation.py | 2 -- modules/gfx/doc/entity.rst | 3 +++ modules/gfx/src/impl/entity_renderer.hh | 6 +++--- modules/gfx/src/impl/trace_renderer_base.cc | 4 +++- modules/gfx/src/surface.cc | 3 ++- modules/mol/base/src/entity_view.cc | 11 ++++++++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/examples/demos/conservation.py b/examples/demos/conservation.py index b2e206c12..e4a254448 100644 --- a/examples/demos/conservation.py +++ b/examples/demos/conservation.py @@ -13,8 +13,6 @@ aln.SetSequenceOffset(0, 1) # First we set all properties to zero, then let alg.Conservation assign the # conservation scores to the residues #------------------------------------------------------------------------------- -for r in m.residues: - r.SetFloatProp('cons', 0) alg.Conservation(aln) #------------------------------------------------------------------------------- diff --git a/modules/gfx/doc/entity.rst b/modules/gfx/doc/entity.rst index 4ebe5f7d8..42fa5e38b 100644 --- a/modules/gfx/doc/entity.rst +++ b/modules/gfx/doc/entity.rst @@ -196,6 +196,9 @@ Entity API Reference the built-in properties is identical to the properties available in :doc:`query language <../mol/base/query>`. + In case a generic property is undefined for a certain element, the property + the value of min is used for that element. + :param prop: The name of the numeric property :type prop: str :param color1: Color corresponding to min value diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh index 28a932abf..b3e47c012 100644 --- a/modules/gfx/src/impl/entity_renderer.hh +++ b/modules/gfx/src/impl/entity_renderer.hh @@ -57,7 +57,7 @@ namespace ost { namespace gfx { namespace impl { typedef enum { DIRTY_VIEW =1, - DIRTY_VA =2, + DIRTY_VA =2 } DirtyFlag; typedef char DirtyFlags; @@ -204,14 +204,14 @@ struct UniformGetCol { }; struct GradientLevelGetCol { - GradientLevelGetCol(const GradientLevelColorOp& op):property_(op.GetProperty()), + GradientLevelGetCol(const GradientLevelColorOp& op): property_(op.GetProperty()), epm_(property_, op.GetLevel()), gradient_(op.GetGradient()), minv_(op.GetMinV()), maxv_(op.GetMaxV()){} Color ColorOfAtom(mol::AtomHandle& atom) const{ try{ - float n=Normalize(epm_.Get(atom), minv_, maxv_); + float n=Normalize(epm_.Get(atom, minv_), minv_, maxv_); return gradient_.GetColorAt(n); }catch(std::exception&){ LOGN_DEBUG("property " << property_ << " not found"); diff --git a/modules/gfx/src/impl/trace_renderer_base.cc b/modules/gfx/src/impl/trace_renderer_base.cc index 46084a880..6a49d7c16 100644 --- a/modules/gfx/src/impl/trace_renderer_base.cc +++ b/modules/gfx/src/impl/trace_renderer_base.cc @@ -34,7 +34,9 @@ void set_node_entry_color(NodeEntry& e, ColorMask mask, } template <typename T1> -inline void apply_color_op(TraceRendererBase* rend, TraceSubset& trace_subset, T1 get_col, const ColorOp& op) +inline void apply_color_op(TraceRendererBase* rend, + TraceSubset& trace_subset, T1 get_col, + const ColorOp& op) { rend->UpdateViews(); ColorMask mask = op.GetMask(); diff --git a/modules/gfx/src/surface.cc b/modules/gfx/src/surface.cc index dbf740077..00ee954a9 100644 --- a/modules/gfx/src/surface.cc +++ b/modules/gfx/src/surface.cc @@ -311,7 +311,8 @@ void Surface::Apply(const gfx::GradientLevelColorOp& op, bool store){ for(VMap::const_iterator it=vmap_.begin();it!=vmap_.end();++it) { mol::AtomHandle ah = sh_.GetVertex(it->first).atom; if(ah.IsValid()) { - va_.SetColor(it->second,gradient.GetColorAt(normalize(epm.Get(ah),minv,maxv))); + va_.SetColor(it->second,gradient.GetColorAt(normalize(epm.Get(ah, minv), + minv,maxv))); } } FlagRefresh(); diff --git a/modules/mol/base/src/entity_view.cc b/modules/mol/base/src/entity_view.cc index 6be3145f3..d81d02d98 100644 --- a/modules/mol/base/src/entity_view.cc +++ b/modules/mol/base/src/entity_view.cc @@ -688,9 +688,14 @@ std::pair<Real,Real> EntityView::GetMinMax(const String& prop, Real min_v=std::numeric_limits<Real>::max(); Real max_v=-std::numeric_limits<Real>::max(); for(AtomViewIter it=AtomsBegin(); it!=this->AtomsEnd(); ++it) { - Real v=epm.Get(*it); - max_v=std::max(v, max_v); - min_v=std::min(v, min_v); + try { + Real v=epm.Get(*it); + max_v=std::max(v, max_v); + min_v=std::min(v, min_v); + } catch(...) { + // do nothing in case of missing property + continue; + } } return std::make_pair(min_v,max_v); } -- GitLab