diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc index 1e3da5faf4997ce05e7bb164902c3c901b16d1f9..a737d4db5c716de6459afb4352ef9d1700090ef2 100644 --- a/modules/gfx/src/impl/cartoon_renderer.cc +++ b/modules/gfx/src/impl/cartoon_renderer.cc @@ -122,10 +122,12 @@ void CartoonRenderer::PrepareRendering() { TraceRendererBase::PrepareRendering(); if(state_>0) { + va_.Clear(); this->PrepareRendering(trace_subset_, va_, spline_list_list_, false); RebuildSplineObj(va_, spline_list_list_, false); } if (this->HasSelection() && (state_>0 || sel_state_>0)) { + sel_va_.Clear(); // extract spline segments from list_list that match // (via id) the selection subset // first put all ids into a set for fast lookup diff --git a/modules/gfx/src/impl/entity_detail.cc b/modules/gfx/src/impl/entity_detail.cc index 5c22c6587535a657f41afba2a0f0b2faacfcc430..59f1042337de0328a45bbc98a35fc3a75bb02445 100644 --- a/modules/gfx/src/impl/entity_detail.cc +++ b/modules/gfx/src/impl/entity_detail.cc @@ -379,7 +379,6 @@ SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub, ui 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; @@ -389,6 +388,18 @@ SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub, ui sublist.back().type2=type2; sublist.back().frac=0.0; + // the id for selections, shifted by one half + for(int c=0;c<size-1;++c) { + int d=0; + for(;d<nsub/2;++d) { + sublist.at(c*nsub+d).id=entry_list[c].id; + } + for(;d<nsub;++d) { + sublist.at(c*nsub+d).id=entry_list[c+1].id; + } + } + sublist.back().id=entry_list.back().id; + // the nflip flags for helices for correct inside/outside assignment // this probably belongs into cartoon renderer LOGN_DEBUG("SplineGenerate: setting nflip flags for helices"); diff --git a/modules/gfx/src/impl/line_trace_renderer.cc b/modules/gfx/src/impl/line_trace_renderer.cc index e8fd9a224c094f144e8cda0ad4b64a6b01e5b98e..f183c6b5b0439696f8fa357baaeb24951c65dc49 100644 --- a/modules/gfx/src/impl/line_trace_renderer.cc +++ b/modules/gfx/src/impl/line_trace_renderer.cc @@ -66,7 +66,8 @@ void LineTraceRenderer::PrepareRendering() sel_va_.Clear(); sel_va_.SetOutlineWidth(options_->GetLineWidth()+3.0); if (this->HasSelection()) { - this->PrepareRendering(sel_subset_, sel_va_, true); + //this->PrepareRendering(sel_subset_, sel_va_, true); + this->PrepareRendering(trace_subset_, sel_va_, true); sel_va_.SetLineWidth(options_->GetLineWidth()+4.0); } } @@ -85,26 +86,46 @@ void LineTraceRenderer::PrepareRendering(const BackboneTrace& trace_subset, va.SetLineWidth(options_->GetLineWidth()); va.SetPointSize(options_->GetLineWidth()); va.SetAALines(options_->GetAALines()); - for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { - const NodeEntryList& nl=trace_subset.GetList(node_list); - - if (nl.size()<2) { - continue; + if(is_sel) { + for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { + const NodeEntryList& nl=trace_subset.GetList(node_list); + if(nl.size()<1) continue; + for(unsigned int i=0;i<nl.size();++i) { + const NodeEntry& entry=nl[i]; + if(sel_.FindAtom(entry.atom).IsValid()) { + geom::Vec3 apos = entry.atom.GetPos(); + VertexID p0=va.Add(apos, geom::Vec3(),sel_clr); + if(i>0) { + VertexID p1 =va.Add(apos+0.5*(nl[i-1].atom.GetPos()-apos), geom::Vec3(), sel_clr); + va.AddLine(p0, p1); + } + if(i<nl.size()-1) { + VertexID p1 =va.Add(apos+0.5*(nl[i+1].atom.GetPos()-apos), geom::Vec3(), sel_clr); + va.AddLine(p0, p1); + } + } + } } - - VertexID p0=va.Add(nl[0].atom.GetPos(), geom::Vec3(), - is_sel ? sel_clr : nl[0].color1); - for (unsigned int i=1; i<nl.size()-1;++i) { - const NodeEntry& entry=nl[i]; - VertexID p1 =va.Add(entry.atom.GetPos(), geom::Vec3(), - is_sel ? sel_clr : entry.color1); - va.AddLine(p0, p1); - p0=p1; + } else { + for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { + const NodeEntryList& nl=trace_subset.GetList(node_list); + + if (nl.size()<2) continue; + + VertexID p0=va.Add(nl[0].atom.GetPos(), geom::Vec3(), + nl[0].color1); + for (unsigned int i=1; i<nl.size()-1;++i) { + const NodeEntry& entry=nl[i]; + VertexID p1 =va.Add(entry.atom.GetPos(), geom::Vec3(), + entry.color1); + va.AddLine(p0, p1); + p0=p1; + } + const NodeEntry& entry=nl.back(); + VertexID p1 =va.Add(entry.atom.GetPos(), geom::Vec3(), + entry.color1); + va.AddLine(p0, p1); } - const NodeEntry& entry=nl.back(); - VertexID p1 =va.Add(entry.atom.GetPos(), geom::Vec3(), - is_sel ? sel_clr : entry.color1); - va.AddLine(p0, p1); } } sel_state_=0; diff --git a/modules/gfx/src/impl/trace_renderer.cc b/modules/gfx/src/impl/trace_renderer.cc index eacf3f0a99a6fb38e6e87326c5630ee1fefd17e5..23156bfc47ee5da37e347de65092b9dea7d28353 100644 --- a/modules/gfx/src/impl/trace_renderer.cc +++ b/modules/gfx/src/impl/trace_renderer.cc @@ -42,15 +42,15 @@ void TraceRenderer::PrepareRendering() this->PrepareRendering(trace_subset_, va_, false); sel_va_.Clear(); if (this->HasSelection()) { - this->PrepareRendering(sel_subset_, sel_va_, true); - sel_va_.SetLighting(false); + //this->PrepareRendering(sel_subset_, sel_va_, true); + this->PrepareRendering(trace_subset_, sel_va_, true); + sel_va_.SetLighting(false); } } void TraceRenderer::PrepareRendering(BackboneTrace& trace_subset, IndexedVertexArray& va, bool is_sel) { - float plus=is_sel ? 0.05: 0.0; const Color& sel_clr=this->GetSelectionColor(); if(options_!=NULL){ va.Clear(); @@ -58,27 +58,57 @@ void TraceRenderer::PrepareRendering(BackboneTrace& trace_subset, va.SetCullFace(true); va.SetColorMaterial(true); va.SetTwoSided(false); - for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { - const NodeEntryList& nl=trace_subset.GetList(node_list); - mol::AtomHandle a1=nl[0].atom; - va.AddSphere(SpherePrim(a1.GetPos(), - options_->GetTubeRadius()+plus, - is_sel ? sel_clr : nl[0].color1), - options_->GetArcDetail()); - for(unsigned int i=1;i<nl.size();++i) { - mol::AtomHandle a2=nl[i].atom; - va.AddSphere(SpherePrim(a2.GetPos(), - options_->GetTubeRadius()+plus, - is_sel ? sel_clr : nl[i].color1), - options_->GetArcDetail()); - const geom::Vec3& p0=a1.GetPos(); - const geom::Vec3& p2=a2.GetPos(); - geom::Vec3 p1=(p0+p2)*0.5; - va.AddCylinder(CylinderPrim(p0,p1,options_->GetTubeRadius()+plus,nl[i-1].color1), - options_->GetArcDetail()); - va.AddCylinder(CylinderPrim(p1,p2,options_->GetTubeRadius()+plus,nl[i].color1), - options_->GetArcDetail()); - a1=a2; + if(is_sel) { + for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { + const NodeEntryList& nl=trace_subset.GetList(node_list); + for(unsigned int i=0;i<nl.size();++i) { + mol::AtomHandle ah=nl[i].atom; + if(sel_.FindAtom(ah).IsValid()) { + geom::Vec3 apos = ah.GetPos(); + va.AddSphere(SpherePrim(apos, + options_->GetTubeRadius()+0.05, + sel_clr), + options_->GetArcDetail()); + if(i>0) { + va.AddCylinder(CylinderPrim(apos+0.5*(nl[i-1].atom.GetPos()-apos), + apos, + options_->GetTubeRadius()+0.05, + sel_clr), + options_->GetArcDetail()); + } + if(i<nl.size()-1) { + va.AddCylinder(CylinderPrim(apos, + apos+0.5*(nl[i+1].atom.GetPos()-apos), + options_->GetTubeRadius()+0.05, + sel_clr), + options_->GetArcDetail()); + } + } + } + } + } else { + for (int node_list=0; node_list<trace_subset.GetListCount(); ++node_list) { + const NodeEntryList& nl=trace_subset.GetList(node_list); + mol::AtomHandle a1=nl[0].atom; + va.AddSphere(SpherePrim(a1.GetPos(), + options_->GetTubeRadius(), + nl[0].color1), + options_->GetArcDetail()); + for(unsigned int i=1;i<nl.size();++i) { + mol::AtomHandle a2=nl[i].atom; + va.AddSphere(SpherePrim(a2.GetPos(), + options_->GetTubeRadius(), + nl[i].color1), + options_->GetArcDetail()); + const geom::Vec3& p0=a1.GetPos(); + const geom::Vec3& p2=a2.GetPos(); + geom::Vec3 p1=(p0+p2)*0.5; + va.AddCylinder(CylinderPrim(p0,p1,options_->GetTubeRadius(),nl[i-1].color1), + options_->GetArcDetail()); + va.AddCylinder(CylinderPrim(p1,p2,options_->GetTubeRadius(),nl[i].color1), + options_->GetArcDetail()); + a1=a2; + } } } }