From 642d551faa52547e4bdb18a35de50ef4ea2f4790 Mon Sep 17 00:00:00 2001 From: ansgar <ansgar@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Thu, 29 Apr 2010 02:39:14 +0000 Subject: [PATCH] prelim work to get selection rendering working again git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/branches/new_gfx@2134 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gfx/src/impl/backbone_trace.cc | 10 ++- modules/gfx/src/impl/cartoon_renderer.cc | 93 +++++++++++++++++++----- modules/gfx/src/impl/cartoon_renderer.hh | 2 +- modules/gfx/src/impl/debug_renderer.cc | 2 +- modules/gfx/src/impl/entity_detail.cc | 1 + modules/gfx/src/impl/entity_detail.hh | 9 ++- modules/gfx/src/impl/entity_renderer.hh | 6 +- modules/gfx/src/impl/sline_renderer.cc | 3 +- 8 files changed, 95 insertions(+), 31 deletions(-) diff --git a/modules/gfx/src/impl/backbone_trace.cc b/modules/gfx/src/impl/backbone_trace.cc index fb4b714cc..85403263a 100644 --- a/modules/gfx/src/impl/backbone_trace.cc +++ b/modules/gfx/src/impl/backbone_trace.cc @@ -32,7 +32,8 @@ public: TraceBuilder(BackboneTrace* bb_trace): backbone_trace_(bb_trace), last_residue_(), - list_() + list_(), + id_counter_(0) {} virtual bool VisitChain(const mol::ChainHandle& chain) @@ -60,11 +61,11 @@ public: if (ca) { NodeEntry entry={ca, GfxObj::Ele2Color(ca.GetAtomProps().element), GfxObj::Ele2Color(ca.GetAtomProps().element), - geom::Vec3(0.0,0.0,0.0), // this will be set by the gfx trace obj + geom::Vec3(), // this will be set by the gfx trace obj res.GetCentralNormal(), 1.0, - geom::Vec3(),geom::Vec3(),geom::Vec3(), - false}; + geom::Vec3(),geom::Vec3(),geom::Vec3(), // for later use in NA rendering + false,id_counter_++}; list_.push_back(entry); } @@ -85,6 +86,7 @@ private: mol::ResidueHandle last_residue_; mol::ChainHandle last_chain_; NodeEntryList list_; + int id_counter_; }; BackboneTrace::BackboneTrace() diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc index a16e52c8c..942bff0ab 100644 --- a/modules/gfx/src/impl/cartoon_renderer.cc +++ b/modules/gfx/src/impl/cartoon_renderer.cc @@ -91,7 +91,8 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset, SplineEntry ee(entry.atom.GetPos(),entry.direction, entry.normal, entry.rad, is_sel ? sel_clr : entry.color1, - is_sel ? sel_clr : entry.color2, type); + is_sel ? sel_clr : entry.color2, + type, entry.id); ee.v1 = entry.v1; spl.push_back(ee); } @@ -102,25 +103,68 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset, } if(!force_tube_) { LOGN_DEBUG("CartoonRenderer: adjusting spline-entry-list lists for various modes"); - FudgeSplineObj(va,tmp_sll); + FudgeSplineObj(tmp_sll); } spline_list_list.clear(); unsigned int tmp_count=0; for(SplineEntryListList::const_iterator sit=tmp_sll.begin();sit!=tmp_sll.end();++sit) { - LOGN_DEBUG("CartoonRenderer: generating full spline for spline-entry-list " << tmp_count++); - spline_list_list.push_back(Spline::Generate(*sit,spline_detail)); + if(sit->size()==2 and sit->at(0).type==6) { + // don't intpol cylinders + spline_list_list.push_back(*sit); + } else { + LOGN_DEBUG("CartoonRenderer: generating full spline for spline-entry-list " << tmp_count++); + spline_list_list.push_back(Spline::Generate(*sit,spline_detail)); + } } - RebuildSplineObj(va, spline_list_list, is_sel); - //va.SmoothNormals(options_->GetNormalSmoothFactor()); } void CartoonRenderer::PrepareRendering() { TraceRendererBase::PrepareRendering(); - va_.Clear(); - this->PrepareRendering(trace_subset_, va_, spline_list_list_, false); - if (this->HasSelection()) { - this->PrepareRendering(sel_subset_, sel_va_, sel_spline_list_list_, true); + if(state_>0) { + this->PrepareRendering(trace_subset_, va_, spline_list_list_, false); + RebuildSplineObj(va_, spline_list_list_, false); + } + if (this->HasSelection() && (state_>0 || sel_state_>0)) { + // extract spline segments from list_list that match + // (via id) the selection subset + // first put all ids into a set for fast lookup + std::set<int> id_set; + for(int nlc=0;nlc<sel_subset_.GetListCount();++nlc) { + const NodeEntryList& nelist=sel_subset_.GetList(nlc); + for(NodeEntryList::const_iterator nit=nelist.begin();nit!=nelist.end();++nit) { + id_set.insert(nit->id); + } + } + // now find all matching spline segments + sel_spline_list_list_.clear(); + for(SplineEntryListList::const_iterator sit=spline_list_list_.begin();sit!=spline_list_list_.end();++sit) { + const SplineEntryList& slist=*sit; + SplineEntryList nlist; + unsigned int sc=0; + while(sc<slist.size()) { + int curr_id=slist.at(sc).id; + if(id_set.count(curr_id)>0) { + // if a match is found, add all until a new id is found + while(sc<slist.size() && slist.at(sc).id==curr_id) { + nlist.push_back(slist[sc++]); + } + } else { + // introduce break + if(!nlist.empty()) { + sel_spline_list_list_.push_back(nlist); + nlist.clear(); + } + // and advance to the next id + while(sc<slist.size() && slist.at(sc).id==curr_id) ++sc; + } + } + if(!nlist.empty()) { + sel_spline_list_list_.push_back(nlist); + nlist.clear(); + } + } + RebuildSplineObj(sel_va_, sel_spline_list_list_, true); sel_va_.SetColorMaterial(false); sel_va_.SetLighting(false); } @@ -183,7 +227,7 @@ namespace { } // ns -void CartoonRenderer::FudgeSplineObj(IndexedVertexArray& va, SplineEntryListList& olistlist) +void CartoonRenderer::FudgeSplineObj(SplineEntryListList& olistlist) { SplineEntryListList nlistlist; SplineEntryList nlist; @@ -234,6 +278,16 @@ void CartoonRenderer::FudgeSplineObj(IndexedVertexArray& va, SplineEntryListList nlist.clear(); } + // make a two entry list with the cyl type + nlist.push_back(SplineEntry(cyl.first,geom::Vec3(),geom::Vec3(),0.0, + olist[lstart].color1,olist[lstart].color1, + 6,olist[lstart].id)); + nlist.push_back(SplineEntry(cyl.second,geom::Vec3(),geom::Vec3(),0.0, + olist[lend].color1,olist[lend].color1, + 6,olist[lend].id)); + nlistlist.push_back(nlist); + nlist.clear(); + if(lend+1<olist.size()) { // and get going with an entry at the end of the cylinder SplineEntry tmp_start(olist[lend]); @@ -248,13 +302,6 @@ void CartoonRenderer::FudgeSplineObj(IndexedVertexArray& va, SplineEntryListList } nlist.push_back(tmp_start); } - - // and finally make the cylinder - va.AddCylinder(CylinderPrim(cyl.first,cyl.second, - options_->GetHelixWidth(), - olist[lstart].color1, - olist[lend].color1), - options_->GetArcDetail(),true); } } else { // helix mode 0 // just copy them over @@ -366,6 +413,16 @@ void CartoonRenderer::RebuildSplineObj(IndexedVertexArray& va, SplineEntryList slist=*it; if(slist.empty()) continue; LOGN_DEBUG("CartoonRenderer: assembling fragment " << tmp_count << " with " << slist.size() << " spline segments"); + + if(slist.size()==2 && slist[0].type==6) { + // make a cylinder + va.AddCylinder(CylinderPrim(slist[0].position,slist[1].position, + options_->GetHelixWidth(), + slist[0].color1,slist[1].color1), + options_->GetArcDetail(),true); + continue; + } + TraceProfile tprof1=TransformAndAddProfile(profiles,slist[0],va); CapProfile(tprof1,slist[0],true,va); TraceProfile tprof2; diff --git a/modules/gfx/src/impl/cartoon_renderer.hh b/modules/gfx/src/impl/cartoon_renderer.hh index d8a98f761..95a7b3844 100644 --- a/modules/gfx/src/impl/cartoon_renderer.hh +++ b/modules/gfx/src/impl/cartoon_renderer.hh @@ -54,7 +54,7 @@ private: void PrepareRendering(const BackboneTrace& subset, IndexedVertexArray& va, SplineEntryListList& spline_list_list, bool is_sel); - void FudgeSplineObj(IndexedVertexArray&, SplineEntryListList&); + void FudgeSplineObj(SplineEntryListList&); void RebuildSplineObj(IndexedVertexArray& va, const SplineEntryListList& spline_list_list, diff --git a/modules/gfx/src/impl/debug_renderer.cc b/modules/gfx/src/impl/debug_renderer.cc index c77dca568..574dad2d3 100644 --- a/modules/gfx/src/impl/debug_renderer.cc +++ b/modules/gfx/src/impl/debug_renderer.cc @@ -63,7 +63,7 @@ void DebugRenderer::PrepareRendering() } SplineEntry ee(it->atom.GetPos(),it->direction,it->normal, - it->rad,it->color1,it->color2,type); + it->rad,it->color1,it->color2,type,it->id); ee.v1 = it->v1; spl.push_back(ee); } diff --git a/modules/gfx/src/impl/entity_detail.cc b/modules/gfx/src/impl/entity_detail.cc index ec863e848..399c342c2 100644 --- a/modules/gfx/src/impl/entity_detail.cc +++ b/modules/gfx/src/impl/entity_detail.cc @@ -230,6 +230,7 @@ SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub) sublist.at(c*nsub+d).type1=type1; sublist.at(c*nsub+d).type2=type2; sublist.at(c*nsub+d).frac=float(d)/float(nsub); + sublist.at(c*nsub+d).id=entry_list[c].id; } } int type1=entry_list.back().type; diff --git a/modules/gfx/src/impl/entity_detail.hh b/modules/gfx/src/impl/entity_detail.hh index a077d2d54..0b539993d 100644 --- a/modules/gfx/src/impl/entity_detail.hh +++ b/modules/gfx/src/impl/entity_detail.hh @@ -90,6 +90,7 @@ struct DLLEXPORT_OST_GFX NodeEntry { float rad; geom::Vec3 v0,v1,v2; // helper vectors bool nflip; + int id; }; typedef std::vector<NodeEntry> NodeEntryList; @@ -122,7 +123,8 @@ struct DLLEXPORT_OST_GFX SplineEntry { v0(1.0,0.0,0.0), v1(0.0,1.0,0.0), v2(0.0,0.0,1.0), - nflip(false) + nflip(false), + id(-1) { } SplineEntry(const geom::Vec3& p, @@ -130,9 +132,9 @@ struct DLLEXPORT_OST_GFX SplineEntry { const geom::Vec3& n, float r, const Color& c1, const Color& c2, - unsigned int t): + unsigned int t, int i): position(p),direction(d),normal(n),color1(c1),color2(c2),rad(r),type(t), - type1(t),type2(t),frac(0.0),v0(),v1(),v2(),nflip(false) + type1(t),type2(t),frac(0.0),v0(),v1(),v2(),nflip(false),id(i) { } @@ -144,6 +146,7 @@ struct DLLEXPORT_OST_GFX SplineEntry { float frac; geom::Vec3 v0,v1,v2; // helper vectors bool nflip; + int id; }; typedef std::vector<SplineEntry> SplineEntryList; diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh index 4d90f97e0..b80bd9ecd 100644 --- a/modules/gfx/src/impl/entity_renderer.hh +++ b/modules/gfx/src/impl/entity_renderer.hh @@ -56,11 +56,11 @@ namespace ost { namespace gfx { namespace impl { typedef enum { - DIRTY_VIEW =1, - DIRTY_VA =2, + DIRTY_VIEW = 0x1, + DIRTY_VA = 0x2 } DirtyFlag; -typedef char DirtyFlags; +typedef unsigned int DirtyFlags; /// \internal class DLLEXPORT_OST_GFX EntityRenderer { diff --git a/modules/gfx/src/impl/sline_renderer.cc b/modules/gfx/src/impl/sline_renderer.cc index 7ae7f937a..62ef7ba45 100644 --- a/modules/gfx/src/impl/sline_renderer.cc +++ b/modules/gfx/src/impl/sline_renderer.cc @@ -71,7 +71,8 @@ void SlineRenderer::PrepareRendering(const BackboneTrace& trace_subset, SplineEntry ee(entry.atom.GetPos(), entry.direction, entry.normal, entry.rad, is_sel ? sel_clr : entry.color1, - is_sel ? sel_clr : entry.color2, 0); + is_sel ? sel_clr : entry.color2, + 0, entry.id); ee.v1 = entry.v1; spl.push_back(ee); } -- GitLab