diff --git a/modules/gfx/src/impl/backbone_trace.cc b/modules/gfx/src/impl/backbone_trace.cc index 53b66b59ddada4d7f18c542a1275d030424cd6d0..2a0315380b75dfe55ef774155d60416c59f07fe9 100644 --- a/modules/gfx/src/impl/backbone_trace.cc +++ b/modules/gfx/src/impl/backbone_trace.cc @@ -38,8 +38,6 @@ 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; } @@ -178,7 +176,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; @@ -187,18 +185,13 @@ void BackboneTrace::PrepList(NodeEntryList& nelist) geom::Vec3 p12 = p2-p1; if(p10==-p12 || p10==p12) p12+=geom::Vec3(0.001,0.001,0.001); e1->v1=e1->normal; - e1->normal=geom::Normalize(geom::Cross(p10,p12)); - // twist avoidance - if(geom::Dot(geom::Normalize(geom::Cross(nref,p10)), - geom::Normalize(geom::Cross(p10,e1->normal)))>0.0) { + if(geom::Dot(e0->v1,e1->v1)<0.0) { e1->v1=-e1->v1; - e1->normal=-e1->normal; } - nref = e1->normal; - + e1->normal=geom::Normalize(geom::Cross(p10,p12)); float omega=0.5*acos(geom::Dot(geom::Normalize(p10),geom::Normalize(p12))); - geom::Vec3 orth=geom::Normalize(geom::AxisRotation(e1->normal, -omega)*p12); + geom::Vec3 orth=geom::AxisRotation(e1->normal, -omega)*p12; e1->direction=geom::Normalize(geom::Cross(e1->normal,orth)); // align normals to avoid twisting diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc index e3a2cff52367934889c591635911e6292ef1ab07..b52d496f0c32a1b3008098b0c14a599cab98e502 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); } @@ -108,7 +108,7 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset, #if !defined(NDEBUG) unsigned int tmp_count=0; #endif - for(SplineEntryListList::iterator sit=tmp_sll.begin();sit!=tmp_sll.end();++sit) { + for(SplineEntryListList::const_iterator sit=tmp_sll.begin();sit!=tmp_sll.end();++sit) { if(sit->size()==2 and sit->at(0).type==6) { // don't intpol cylinders spline_list_list.push_back(*sit); @@ -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,0.0,0.0}; + float accum[]={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=-3;k<=3;++k) { + for(int k=-2;k<=2;++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+3]+=spread(v1,v2,v3,v4); + accum[k+2]+=spread(v1,v2,v3,v4); } } float best_spread=accum[0]; - int best_off=-3; - for(int k=-2;k<=3;++k) { - if(accum[k+3]<best_spread) { + int best_off=-2; + for(int k=-1;k<=2;++k) { + if(accum[k+2]<best_spread) { best_spread=accum[k+2]; best_off=k; } diff --git a/modules/gfx/src/impl/entity_detail.cc b/modules/gfx/src/impl/entity_detail.cc index d449fb0f66b5a0ddb96cd548109d28df5eaf2f5d..40ba7351876fbf25ea823b383fdaca532fef41d6 100644 --- a/modules/gfx/src/impl/entity_detail.cc +++ b/modules/gfx/src/impl/entity_detail.cc @@ -27,7 +27,6 @@ namespace ost { using namespace mol; -using namespace geom; // this is used _so_ often, its worth pulling it in namespace gfx { namespace impl { @@ -38,7 +37,7 @@ static const float default_radius=0.28; struct BlurQuadEntry { float zdist; - Vec3 p1,p2,p3,p4; + geom::Vec3 p1,p2,p3,p4; gfx::Color c1,c2,c3,c4; }; @@ -64,17 +63,17 @@ void DoRenderBlur(BondEntryList& bl, float bf1, float bf2) if(!it->atom1 || !it->atom2) continue; - const Vec3 p0=tf.Apply(it->atom1->atom.GetPos()); - const Vec3 p2=tf.Apply(it->atom2->atom.GetPos()); - Vec3 p1=(p0+p2)*0.5; + const geom::Vec3 p0=tf.Apply(it->atom1->atom.GetPos()); + const geom::Vec3 p2=tf.Apply(it->atom2->atom.GetPos()); + geom::Vec3 p1=(p0+p2)*0.5; - const Vec3 q0=tf.Apply(it->pp1); - const Vec3 q2=tf.Apply(it->pp2); - Vec3 q1=(q0+q2)*0.5; + const geom::Vec3 q0=tf.Apply(it->pp1); + const geom::Vec3 q2=tf.Apply(it->pp2); + geom::Vec3 q1=(q0+q2)*0.5; - float ll0 = Length2(p0-q0); - float ll1 = Length2(p1-q1); - float ll2 = Length2(p2-q2); + float ll0 = geom::Length2(p0-q0); + float ll1 = geom::Length2(p1-q1); + float ll2 = geom::Length2(p2-q2); if(ll0<1e-2 && ll1<1e-2 && ll2<1e-2) continue; @@ -241,7 +240,7 @@ static int bsplineGet(float *xa, float *ya, float *y2a, int n, float x, float *y sublist.at((size-1)*nsub). COMPONENT = v; \ } -SplineEntryList Spline::Generate(SplineEntryList& entry_list, int nsub, uint color_blend_mode) +SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub, uint color_blend_mode) { if(nsub<=0) { return entry_list; @@ -305,139 +304,44 @@ SplineEntryList Spline::Generate(SplineEntryList& entry_list, int nsub, uint col SPLINE_ENTRY_INTERPOLATE(rad); LOG_DEBUG("SplineGenerate: assigning direction and normal components"); - -#if 1 - std::vector<Quat> quats(size+3); - - Vec3 prevn; - for(int c=0;c<size;++c) { - Vec3 d1,d2; - if(c==0) { - d1=Normalize(entry_list.at(c).position-entry_list.at(c+1).position); - d2=Normalize(entry_list.at(c+1).position-entry_list.at(c+2).position); - } else if(c==size-1) { - d1=Normalize(entry_list.at(c-2).position-entry_list.at(c-1).position); - d2=Normalize(entry_list.at(c-1).position-entry_list.at(c).position); - } else { - d1=Normalize(entry_list.at(c-1).position-entry_list.at(c).position); - d2=Normalize(entry_list.at(c).position-entry_list.at(c+1).position); - } - Vec3 d=d2; - Vec3 n=Normalize(Cross(d1,d2)); - //Vec3 n=entry_list.at(c).v1; - Vec3 o = Normalize(Cross(d,n)); - - if(c>0) { - if(Dot(Normalize(Cross(d,prevn)),Normalize(Cross(d,n)))<0.0) { - n=-n; - o=-o; - } - } - prevn=n; - - //n = Normalize(Cross(o,d)); - Quat q(Mat3(d[0],n[0],o[0], - d[1],n[1],o[1], - d[2],n[2],o[2])); - quats[c+1]=q; - } - quats.at(0)=quats.at(1); - quats.at(size)=quats.at(size-1); - quats.at(size+1)=quats.at(size-1); - - std::vector<Quat> squats(size*nsub); - // now for the quaternion interpolation, using squad - for(int c=0;c<size;++c) { - Quat q0=quats.at(c+0); - Quat q1=quats.at(c+1); - Quat q2=quats.at(c+2); - Quat q3=quats.at(c+3); - - Quat s1=q1*Exp(-0.25*Log(Inv(q1)*q2)+Log(Inv(q1)*q0)); - Quat s2=q2*Exp(-0.25*Log(Inv(q2)*q3)+Log(Inv(q2)*q1)); - - for(int d=0;d<nsub;++d) { - float u=static_cast<float>(d)*i_nsub; - squats.at(c*nsub+d) = Slerp(Slerp(q1,q2,u),Slerp(s1,s2,u),2.0*u*(1.0-u)); - } - } - - assert(sublist.size()<=squats.size()); - - for(unsigned int i=0;i<sublist.size();++i) { - Mat3 m=squats[i].ToRotationMatrix(); - sublist.at(i).direction=Normalize(Vec3(m(0,0),m(1,0),m(2,0))); - sublist.at(i).normal=Normalize(Vec3(m(0,1),m(1,1),m(2,1))); - sublist.at(i).v2=Normalize(Vec3(m(0,2),m(1,2),m(2,2))); - } - - std::vector<Vec3> nlist(sublist.size()); - for(uint i=0;i<sublist.size();++i) { - Vec3 p0,p1; - if(i<sublist.size()-1) { - p0 = sublist.at(i).position; - p1 = sublist.at(i+1).position; - } else { - p0 = sublist.at(i-1).position; - p1 = sublist.at(i).position; - } - sublist.at(i).direction=Normalize(p1-p0); - Vec3 orth = Normalize(Cross(sublist.at(i).direction,sublist.at(i).normal)); - nlist[i] = Normalize(Cross(orth,sublist.at(i).direction)); - sublist.at(i).v2=orth; - if(i>0) { - if(Dot(Normalize(Cross(sublist.at(i).direction,nlist[i-1])),orth)<0.0) { - nlist[i]=-nlist[i]; - sublist.at(i).v2=-sublist.at(i).v2; - } - } - } - - sublist.at(0).normal=nlist[0]; - sublist.back().normal=nlist.back(); - for(uint i=1;i<sublist.size()-1;++i) { - sublist.at(i).normal=(nlist[i-1]+nlist[i]+nlist[i+1])/3.0; - } -#else - // assign direction and normal // entity trace has the same algorithm - Vec3 p0 = sublist.at(0).position; - Vec3 p1 = sublist.at(1).position; - Vec3 p2 = ipsize>2 ? sublist.at(2).position : p1+(p1-p0); + geom::Vec3 p0 = sublist.at(0).position; + geom::Vec3 p1 = sublist.at(1).position; + geom::Vec3 p2 = ipsize>2 ? sublist.at(2).position : p1+(p1-p0); // normal of 0 is set at the end - sublist.at(0).direction=Normalize(p1-p0); - sublist.at(0).v1=Normalize(sublist.at(0).v1); - Vec3 orth = Cross(sublist.at(0).direction,sublist.at(0).v1); - sublist.at(0).v0 = Normalize(Cross(orth,sublist.at(0).direction)); + sublist.at(0).direction=geom::Normalize(p1-p0); + sublist.at(0).v1=geom::Normalize(sublist.at(0).v1); + geom::Vec3 orth = geom::Cross(sublist.at(0).direction,sublist.at(0).v1); + sublist.at(0).v0 = geom::Normalize(geom::Cross(orth,sublist.at(0).direction)); // reference normal to avoid twisting - //Vec3 nref=Normalize(Cross(p0-p1,p2-p1)); + //geom::Vec3 nref=geom::Normalize(geom::Cross(p0-p1,p2-p1)); unsigned int i=1; for(;i<sublist.size()-1;++i) { - Vec3 p10 = p0-p1; - Vec3 p12 = p2-p1; + geom::Vec3 p10 = p0-p1; + geom::Vec3 p12 = p2-p1; // correction for perfectly aligned consecutive directions - if(p10==-p12 || p10==p12) p12+=Vec3(0.001,0.001,0.001); - sublist.at(i).normal=Normalize(Cross(p10,p12)); + if(p10==-p12 || p10==p12) p12+=geom::Vec3(0.001,0.001,0.001); + sublist.at(i).normal=geom::Normalize(geom::Cross(p10,p12)); // paranoid error checking due to occasional roundoff troubles - float cosw = Dot(Normalize(p10),Normalize(p12)); + float cosw = geom::Dot(geom::Normalize(p10),geom::Normalize(p12)); cosw = std::min(float(1.0),std::max(float(-1.0),cosw)); float omega=0.5*acos(cosw); - orth=AxisRotation(sublist.at(i).normal, -omega)*p12; - sublist.at(i).direction=Normalize(Cross(sublist.at(i).normal,orth)); + orth=geom::AxisRotation(sublist.at(i).normal, -omega)*p12; + sublist.at(i).direction=geom::Normalize(geom::Cross(sublist.at(i).normal,orth)); // twist avoidance - sublist.at(i).v1=Normalize(sublist.at(i).v1); - orth = Cross(sublist.at(i).direction,sublist.at(i).v1); - sublist.at(i).v0 = Normalize(Cross(orth,sublist.at(i).direction)); - if(Dot(sublist.at(i-1).v0,sublist.at(i).v0)<0.0) { + sublist.at(i).v1=geom::Normalize(sublist.at(i).v1); + orth = geom::Cross(sublist.at(i).direction,sublist.at(i).v1); + sublist.at(i).v0 = geom::Normalize(geom::Cross(orth,sublist.at(i).direction)); + if(geom::Dot(sublist.at(i-1).v0,sublist.at(i).v0)<0.0) { sublist.at(i).v0=-sublist.at(i).v0; //sublist.at(i).nflip = !sublist.at(i).nflip; } // avoid twisting - //if(Dot(sublist.at(i).normal,nref)<0.0) sublist.at(i).normal=-sublist.at(i).normal; + //if(geom::Dot(sublist.at(i).normal,nref)<0.0) sublist.at(i).normal=-sublist.at(i).normal; //nref=sublist.at(i).normal; // skip over shift for the last iteration if(i==sublist.size()-2) break; @@ -448,12 +352,12 @@ SplineEntryList Spline::Generate(SplineEntryList& entry_list, int nsub, uint col } // assign remaining ones sublist.at(0).normal=sublist.at(1).normal; - sublist.at(i+1).direction=Normalize(p2-p1); + sublist.at(i+1).direction=geom::Normalize(p2-p1); sublist.at(i+1).normal=sublist.at(i).normal; - sublist.at(i+1).v1=Normalize(sublist.at(i+1).v1); - orth = Cross(sublist.at(i+1).direction,sublist.at(i+1).v1); - sublist.at(i+1).v0 = Normalize(Cross(orth,sublist.at(i+1).direction)); - if(Dot(sublist.at(i).v0,sublist.at(i+1).v0)<0.0) { + sublist.at(i+1).v1=geom::Normalize(sublist.at(i+1).v1); + orth = geom::Cross(sublist.at(i+1).direction,sublist.at(i+1).v1); + sublist.at(i+1).v0 = geom::Normalize(geom::Cross(orth,sublist.at(i+1).direction)); + if(geom::Dot(sublist.at(i).v0,sublist.at(i+1).v0)<0.0) { sublist.at(i+1).v0=-sublist.at(i+1).v0; } @@ -463,8 +367,6 @@ SplineEntryList Spline::Generate(SplineEntryList& entry_list, int nsub, uint col sublist.at(i).normal = sublist.at(i).v0; } -#endif - LOG_DEBUG("SplineGenerate: assigning non-interpolated entry components"); // finally the non-interpolated type // with some tweaks for proper strand rendering @@ -512,18 +414,18 @@ SplineEntryList Spline::Generate(SplineEntryList& entry_list, int nsub, uint col while(c<sublist.size()-1) { int cstart=c; if(sublist.at(c).type==1 && sublist.at(c+1).type==1) { - Vec3 n = Normalize(Cross(sublist.at(c).normal, + geom::Vec3 n = geom::Normalize(geom::Cross(sublist.at(c).normal, sublist.at(c).direction)); - Vec3 p0 = sublist.at(c).position+n; - Vec3 q0 = sublist.at(c).position-n; + geom::Vec3 p0 = sublist.at(c).position+n; + geom::Vec3 q0 = sublist.at(c).position-n; float psum=0.0; float qsum=0.0; ++c; while(c<sublist.size() && sublist.at(c).type==1) { - n = Normalize(Cross(sublist.at(c).normal, + n = geom::Normalize(geom::Cross(sublist.at(c).normal, sublist.at(c).direction)); - Vec3 p1 = sublist.at(c).position+n; - Vec3 q1 = sublist.at(c).position-n; + geom::Vec3 p1 = sublist.at(c).position+n; + geom::Vec3 q1 = sublist.at(c).position-n; psum+=Length(p1-p0); qsum+=Length(q1-q0); p0=p1; diff --git a/modules/gfx/src/impl/entity_detail.hh b/modules/gfx/src/impl/entity_detail.hh index c41a4a98cbe1592c7e78041df0f533c8cecfbba1..2ae0a848f14c3e7c711f67dc31e436969a4a22d0 100644 --- a/modules/gfx/src/impl/entity_detail.hh +++ b/modules/gfx/src/impl/entity_detail.hh @@ -158,7 +158,7 @@ typedef std::vector<SplineEntryList> SplineEntryListList; class DLLEXPORT_OST_GFX Spline { public: - static SplineEntryList Generate(SplineEntryList& entry_list,int nsub,uint color_blend_mode=0); + static SplineEntryList Generate(const SplineEntryList& entry_list,int nsub,uint color_blend_mode=0); }; }}} // ns