diff --git a/modules/gfx/src/impl/backbone_trace.cc b/modules/gfx/src/impl/backbone_trace.cc index c99508826de934526fcb3ee659a3f41bf9cae09f..53b66b59ddada4d7f18c542a1275d030424cd6d0 100644 --- a/modules/gfx/src/impl/backbone_trace.cc +++ b/modules/gfx/src/impl/backbone_trace.cc @@ -38,6 +38,8 @@ bool in_sequence(const mol::ResidueHandle& r1, const mol::ResidueHandle& r2) if(n2.GetInsCode()!='\0') { if(n1.NextInsertionCode()==n2) return true; } + if(mol::InSequence(r1,r2)) return true; + // fallback, perhaps the wrong thing to do if(n1.GetNum()+1==n2.GetNum()) return true; return false; } @@ -176,7 +178,7 @@ void BackboneTrace::PrepList(NodeEntryList& nelist) e0->v1 = e0->normal; //reference normal to avoid twisting - geom::Vec3 nref=geom::Normalize(geom::Cross(p0-p1,p2-p1)); + //geom::Vec3 nref=geom::Normalize(geom::Cross(p0-p1,p2-p1)); // start loop with the second unsigned int i=1; diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc index 0f9b5bb5a87327e61e05ca75e38e8f009c3b199b..e3a2cff52367934889c591635911e6292ef1ab07 100644 --- a/modules/gfx/src/impl/cartoon_renderer.cc +++ b/modules/gfx/src/impl/cartoon_renderer.cc @@ -79,19 +79,19 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset, int type=0; const NodeEntry& entry=nl[i]; if(!force_tube_) { - mol::ResidueHandle resh = entry.atom.GetResidue(); - mol::SecStructure sst=resh.GetSecStructure(); - if(sst.IsHelical()) { - type=1; - } else if(sst.IsExtended()) { - type=2; - } + mol::ResidueHandle resh = entry.atom.GetResidue(); + mol::SecStructure sst=resh.GetSecStructure(); + if(sst.IsHelical()) { + type=1; + } else if(sst.IsExtended()) { + type=2; + } } SplineEntry ee(entry.atom.GetPos(),entry.direction, - entry.normal, entry.rad, - entry.color1, - entry.color2, - type, entry.id); + entry.normal, entry.rad, + entry.color1, + entry.color2, + type, entry.id); ee.v1 = entry.v1; spl.push_back(ee); } @@ -147,28 +147,28 @@ void CartoonRenderer::PrepareRendering() 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++]); - // override with the selection color - nlist.back().color1=sel_color; - nlist.back().color2=sel_color; - } - } 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; - } + 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++]); + // override with the selection color + nlist.back().color1=sel_color; + nlist.back().color2=sel_color; + } + } 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(); + sel_spline_list_list_.push_back(nlist); + nlist.clear(); } } RebuildSplineObj(sel_va_, sel_spline_list_list_, true); @@ -287,17 +287,17 @@ void CartoonRenderer::FudgeSplineObj(SplineEntryListList& olistlist) nlistlist.push_back(nlist); 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(); - + + // 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]); @@ -329,42 +329,42 @@ void CartoonRenderer::FudgeSplineObj(SplineEntryListList& olistlist) for(;lc<olist.size() && olist.at(lc).type==2;++lc,++kend) { nlist.push_back(olist.at(lc)); } - if(kend-kstart<2) { - // dont bother with too short strands - for(unsigned int i=kstart;i<kend;++i) { - nlist.at(i).type=0; - } - } else { - kend-=1; - // these magic numbers are used in RebuildSplineObj for proper arrow rendering - nlist.at(kend-1).type=3; - nlist.at(kend).type=5; - - if(options_->GetStrandMode()==1) { - // smooth the strands for mode 1 - nlist.at(kstart).direction = geom::Normalize(nlist.at(kend).position-nlist.at(kstart).position); - nlist.at(kend).direction=nlist.at(kstart).direction; - float invf=1.0/static_cast<float>(kend-kstart); - for(unsigned int k=kstart;k<=kend;++k) { - float f = static_cast<float>(k-kstart)*invf; - nlist.at(k).position=nlist.at(kstart).position+f*(nlist.at(kend).position-nlist.at(kstart).position); - nlist.at(k).direction=nlist.at(kstart).direction; - geom::Vec3 tmpn=geom::Normalize(nlist.at(kstart).normal+f*(nlist.at(kend).normal-nlist.at(kstart).normal)); - geom::Vec3 tmpx=geom::Normalize(geom::Cross(nlist.at(kstart).direction,tmpn)); - nlist.at(k).normal=geom::Normalize(geom::Cross(tmpx,nlist.at(kstart).direction)); - } - } - - // break nodelist, re-start at arrow tip for both modes - if(lc+1<olist.size()) { - nlistlist.push_back(nlist); - nlist.clear(); - nlist.push_back(nlistlist.back().back()); - nlist.back().type=0; - nlist.back().color1=olist[lc+1].color1; - nlist.back().color2=olist[lc+1].color2; - } - } + if(kend-kstart<2) { + // dont bother with too short strands + for(unsigned int i=kstart;i<kend;++i) { + nlist.at(i).type=0; + } + } else { + kend-=1; + // these magic numbers are used in RebuildSplineObj for proper arrow rendering + nlist.at(kend-1).type=3; + nlist.at(kend).type=5; + + if(options_->GetStrandMode()==1) { + // smooth the strands for mode 1 + nlist.at(kstart).direction = geom::Normalize(nlist.at(kend).position-nlist.at(kstart).position); + nlist.at(kend).direction=nlist.at(kstart).direction; + float invf=1.0/static_cast<float>(kend-kstart); + for(unsigned int k=kstart;k<=kend;++k) { + float f = static_cast<float>(k-kstart)*invf; + nlist.at(k).position=nlist.at(kstart).position+f*(nlist.at(kend).position-nlist.at(kstart).position); + nlist.at(k).direction=nlist.at(kstart).direction; + geom::Vec3 tmpn=geom::Normalize(nlist.at(kstart).normal+f*(nlist.at(kend).normal-nlist.at(kstart).normal)); + geom::Vec3 tmpx=geom::Normalize(geom::Cross(nlist.at(kstart).direction,tmpn)); + nlist.at(k).normal=geom::Normalize(geom::Cross(tmpx,nlist.at(kstart).direction)); + } + } + + // break nodelist, re-start at arrow tip for both modes + if(lc+1<olist.size()) { + nlistlist.push_back(nlist); + nlist.clear(); + nlist.push_back(nlistlist.back().back()); + nlist.back().type=0; + nlist.back().color1=olist[lc+1].color1; + nlist.back().color2=olist[lc+1].color2; + } + } } if(lc<olist.size()) { nlist.push_back(olist.at(lc)); @@ -385,40 +385,40 @@ void CartoonRenderer::RebuildSplineObj(IndexedVertexArray& va, LOG_DEBUG("CartoonRenderer: starting profile assembly"); unsigned int detail = std::min(MAX_ARC_DETAIL, std::max(options_->GetArcDetail(), - (unsigned int)1)); + (unsigned int)1)); std::vector<TraceProfile> profiles; float factor=is_sel ? 0.2 : 0.0; profiles.push_back(GetCircProfile(detail, - options_->GetTubeRadius()*options_->GetTubeRatio()+factor, - options_->GetTubeRadius()+factor, - options_->GetTubeProfileType(), - 1.0)); // profile 0 = tube + options_->GetTubeRadius()*options_->GetTubeRatio()+factor, + options_->GetTubeRadius()+factor, + options_->GetTubeProfileType(), + 1.0)); // profile 0 = tube if (!force_tube_) { profiles.push_back(GetCircProfile(detail, - options_->GetHelixWidth()+factor, - options_->GetHelixThickness()+factor, - options_->GetHelixProfileType(), - options_->GetHelixEcc())); // profile 1 = helix + options_->GetHelixWidth()+factor, + options_->GetHelixThickness()+factor, + options_->GetHelixProfileType(), + options_->GetHelixEcc())); // profile 1 = helix profiles.push_back(GetCircProfile(detail, - options_->GetStrandWidth()+factor, - options_->GetStrandThickness()+factor, - options_->GetStrandProfileType(), - options_->GetStrandEcc())); // profile 2 = strand + options_->GetStrandWidth()+factor, + options_->GetStrandThickness()+factor, + options_->GetStrandProfileType(), + options_->GetStrandEcc())); // profile 2 = strand profiles.push_back(profiles.back()); // profile 3==2, strand - + profiles.push_back(GetCircProfile(detail, - 1.7*options_->GetStrandWidth()+factor, - 1.1*options_->GetStrandThickness()+factor, - options_->GetStrandProfileType(), - options_->GetStrandEcc())); // profile 4 = arrow start + 1.7*options_->GetStrandWidth()+factor, + 1.1*options_->GetStrandThickness()+factor, + options_->GetStrandProfileType(), + options_->GetStrandEcc())); // profile 4 = arrow start profiles.push_back(GetCircProfile(detail, - 0.01*options_->GetStrandWidth()+factor, - 1.1*options_->GetStrandThickness()+factor, - options_->GetStrandProfileType(), - options_->GetStrandEcc())); // profile 5 = arrow end - + 0.01*options_->GetStrandWidth()+factor, + 1.1*options_->GetStrandThickness()+factor, + options_->GetStrandProfileType(), + options_->GetStrandEcc())); // profile 5 = arrow end + } - + // iterate over all spline segments #if !defined(NDEBUG) @@ -434,13 +434,13 @@ void CartoonRenderer::RebuildSplineObj(IndexedVertexArray& va, SplineEntryList slist=*it; if(slist.empty()) continue; LOG_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); + options_->GetHelixWidth(), + slist[0].color1,slist[1].color1), + options_->GetArcDetail(),true); continue; } @@ -564,25 +564,25 @@ void CartoonRenderer::AssembleProfile(const TraceProfile& prof1, size_t size=prof1.size()-1; // first get the best correction offset - float accum[]={0.0,0.0,0.0,0.0,0.0}; + float accum[]={0.0,0.0,0.0,0.0,0.0,0.0,0.0}; for(size_t i=0;i<size;++i) { int i1=(i+0)%(size); int i2=(i+1)%(size); geom::Vec3 v1=va.GetVert(prof1[i1].id); geom::Vec3 v2=va.GetVert(prof1[i2].id); - for(int k=-2;k<=2;++k) { + for(int k=-3;k<=3;++k) { int i3=(i+k+0+size)%(size); int i4=(i+k+1+size)%(size); geom::Vec3 v3=va.GetVert(prof2[i3].id); geom::Vec3 v4=va.GetVert(prof2[i4].id); - accum[k+2]+=spread(v1,v2,v3,v4); + accum[k+3]+=spread(v1,v2,v3,v4); } } float best_spread=accum[0]; - int best_off=-2; - for(int k=-1;k<=2;++k) { - if(accum[k+2]<best_spread) { + int best_off=-3; + for(int k=-2;k<=3;++k) { + if(accum[k+3]<best_spread) { best_spread=accum[k+2]; best_off=k; } diff --git a/modules/gfx/src/impl/sline_renderer.cc b/modules/gfx/src/impl/sline_renderer.cc index 92cf81bd54184bb5a005c5d514a71b786f9b0ddd..2b54046dd634acc1da4413aa9d69b7f4960889a9 100644 --- a/modules/gfx/src/impl/sline_renderer.cc +++ b/modules/gfx/src/impl/sline_renderer.cc @@ -81,14 +81,16 @@ void SlineRenderer::PrepareRendering(const BackboneTrace& trace_subset, VertexID p0=va.Add(sit->position, geom::Vec3(),sit->color1); for (++sit; sit!=sel.end(); ++sit) { VertexID p1 = va.Add(sit->position, geom::Vec3(),sit->color1); - //va.AddLine(p0,p1); + va.AddLine(p0,p1); p0=p1; +#if 0 VertexID p2 = va.Add(sit->position+sit->direction,geom::Vec3(),Color(0,1,0)); VertexID p3 = va.Add(sit->position+sit->normal,geom::Vec3(),Color(1,0,0)); VertexID p4 = va.Add(sit->position+sit->v2,geom::Vec3(),Color(1,0,1)); va.AddLine(p0,p2); va.AddLine(p0,p3); va.AddLine(p0,p4); +#endif } } } diff --git a/modules/gfx/src/impl/trace_renderer.cc b/modules/gfx/src/impl/trace_renderer.cc index e0827989db551a74180065c70ae0244fca080278..a6b442ee63540e9dd9c20aa0615282a5d313e65d 100644 --- a/modules/gfx/src/impl/trace_renderer.cc +++ b/modules/gfx/src/impl/trace_renderer.cc @@ -61,55 +61,55 @@ void TraceRenderer::PrepareRendering(BackboneTrace& trace_subset, if(is_sel) { va.SetOpacity(GetSelectionColor().Alpha()); 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()); - } - } - } + 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; - } + 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; + } } } } diff --git a/modules/gfx/src/prim_list.cc b/modules/gfx/src/prim_list.cc index 72047addeb091fbec674ae9372f1c98125ee67ee..c48abf97955178245c2b79ff6b2acb0f50ea2824 100644 --- a/modules/gfx/src/prim_list.cc +++ b/modules/gfx/src/prim_list.cc @@ -23,6 +23,7 @@ #include "scene.hh" #include "prim_list.hh" +#include "povray.hh" namespace ost { namespace gfx { @@ -31,7 +32,6 @@ PrimList::PrimList(const String& name): points_(), lines_(), radius_(0.5), - diameter_(0.5), sphere_detail_(4), arc_detail_(4) {} @@ -136,7 +136,18 @@ void PrimList::CustomRenderGL(RenderPass pass) void PrimList::CustomRenderPov(PovState& pov) { - // TODO: add primlist pov export + if(points_.empty() && lines_.empty()) return; + pov.write_merge_or_union(GetName()); + + for(PointEntryList::const_iterator it=points_.begin();it!=points_.end();++it) { + pov.write_sphere(it->pos,radius_,it->color,GetName()); + } + for(LineEntryList::const_iterator it=lines_.begin();it!=lines_.end();++it) { + pov.write_sphere(it->pos1,radius_,it->color,GetName()); + pov.write_sphere(it->pos2,radius_,it->color,GetName()); + pov.write_cyl(it->pos1,it->pos2,radius_,it->color,GetName(),true); + } + pov.inc() << " }\n"; } void PrimList::AddPoint(geom::Vec3& p, const Color& col) @@ -155,7 +166,7 @@ void PrimList::AddLine(geom::Vec3& p1, geom::Vec3& p2, const Color& col) void PrimList::SetDiameter(float d) { - diameter_=d; + radius_=d*0.5; Scene::Instance().RequestRedraw(); FlagRebuild(); } @@ -229,11 +240,11 @@ void PrimList::render_custom() } for(LineEntryList::const_iterator it=lines_.begin();it!=lines_.end();++it) { - va_.AddSphere(SpherePrim(it->pos1, diameter_/2.0, it->color), + va_.AddSphere(SpherePrim(it->pos1, radius_, it->color), GetSphereDetail()); - va_.AddSphere(SpherePrim(it->pos2, diameter_/2.0, it->color), + va_.AddSphere(SpherePrim(it->pos2, radius_, it->color), GetSphereDetail()); - va_.AddCylinder(CylinderPrim(it->pos1,it->pos2,diameter_/2.0,it->color), + va_.AddCylinder(CylinderPrim(it->pos1,it->pos2,radius_,it->color), GetArcDetail()); } } diff --git a/modules/gfx/src/prim_list.hh b/modules/gfx/src/prim_list.hh index fbac2cffc2f633bdf5bfe4ef8fc20ce6658c72d4..b4aa65b98a3c601b913376b4c857c8d4aedda18d 100644 --- a/modules/gfx/src/prim_list.hh +++ b/modules/gfx/src/prim_list.hh @@ -74,6 +74,7 @@ class DLLEXPORT_OST_GFX PrimList: public GfxObj const mol::Transform& tf) const; /// \brief get center virtual geom::Vec3 GetCenter() const; + virtual void CustomRenderPov(PovState& pov); virtual void CustomRenderGL(RenderPass pass);