diff options
Diffstat (limited to 'source/blender/freestyle/intern/winged_edge')
-rwxr-xr-x | source/blender/freestyle/intern/winged_edge/Curvature.cpp | 32 | ||||
-rwxr-xr-x | source/blender/freestyle/intern/winged_edge/WEdge.cpp | 42 | ||||
-rwxr-xr-x | source/blender/freestyle/intern/winged_edge/WEdge.h | 35 |
3 files changed, 70 insertions, 39 deletions
diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.cpp b/source/blender/freestyle/intern/winged_edge/Curvature.cpp index 2997d9b6922..f8854b11d7b 100755 --- a/source/blender/freestyle/intern/winged_edge/Curvature.cpp +++ b/source/blender/freestyle/intern/winged_edge/Curvature.cpp @@ -20,6 +20,7 @@ #include <cstdlib> // for malloc and free #include "Curvature.h" #include <math.h> +#include <assert.h> #include "WEdge.h" #include "../system/FreestyleConfig.h" #include "../geometry/normal_cycle.h" @@ -43,7 +44,7 @@ static bool triangle_obtuse (WVertex*, WFace * f) bool b=false; for (int i=0; i<3; i++) b = b || - ((f->getEdgeList()[i]->getVec3r() * f->getEdgeList()[(i+1)%3]->getVec3r()) < 0); + ((f->getEdgeList()[i]->GetVec() * f->getEdgeList()[(i+1)%3]->GetVec()) < 0); return b; } @@ -378,7 +379,7 @@ void gts_vertex_principal_directions (WVertex * v, */ /* find the vector from v along edge e */ - vec_edge=Vec3r(-1*e->getVec3r()); + vec_edge=Vec3r(-1*e->GetVec()); ve2 = vec_edge.squareNorm(); vdotN = vec_edge * N; @@ -534,11 +535,11 @@ void gts_vertex_principal_directions (WVertex * v, } namespace OGF { - static real angle(WOEdge* h) { - Vec3r e(h->GetbVertex()->GetVertex()-h->GetaVertex()->GetVertex()) ; - Vec3r n1 = h->GetbFace()->GetNormal(); - Vec3r n2 = h->GetaFace()->GetNormal(); - real sine = (n1 ^ n2) * e / e.norm() ; + inline static real angle(WOEdge * h) { + const Vec3r& n1 = h->GetbFace()->GetNormal(); + const Vec3r& n2 = h->GetaFace()->GetNormal(); + const Vec3r v = h->getVec3r(); + real sine = (n1 ^ n2) * v / v.norm() ; if(sine >= 1.0) { return M_PI / 2.0 ; } @@ -606,13 +607,12 @@ namespace OGF { WVertex::incoming_edge_iterator woeitend = v->incoming_edges_end(); for(;woeit!=woeitend; ++woeit){ WOEdge *h = *woeit; - Vec3r V(h->GetaVertex()->GetVertex()-h->GetbVertex()->GetVertex()) ; - if((v == start) || V * (P - O) > 0.0) { + if((v == start) || h->GetVec() * (O - P) > 0.0) { + Vec3r V(-1 * h->GetVec()); bool isect = sphere_clip_vector(O, radius, P, V) ; - if(h->GetOwner()->GetNumberOfOEdges() == 2) { - real beta = angle(h) ; - nc.accumulate_dihedral_angle(V, beta) ; - } + assert (h->GetOwner()->GetNumberOfOEdges() == 2); // Because otherwise v->isBoundary() would be true + nc.accumulate_dihedral_angle(V, h->GetAngle()) ; + if(!isect) { WVertex* w = h->GetaVertex() ; if(vertices.find(w) == vertices.end()) { @@ -637,11 +637,9 @@ namespace OGF { WVertex::incoming_edge_iterator woeitend = start->incoming_edges_end(); for(;woeit!=woeitend; ++woeit){ WOEdge *h = (*woeit)->twin(); - Vec3r hvec(h->GetbVertex()->GetVertex()-h->GetaVertex()->GetVertex()); - nc.accumulate_dihedral_angle(hvec, angle(h)) ; + nc.accumulate_dihedral_angle(h->GetVec(), h->GetAngle()) ; WOEdge *hprev = h->getPrevOnFace(); - Vec3r hprevvec(hprev->GetbVertex()->GetVertex()-hprev->GetaVertex()->GetVertex()); - nc.accumulate_dihedral_angle(hprevvec, angle(hprev)) ; + nc.accumulate_dihedral_angle(hprev->GetVec(), hprev->GetAngle()) ; } } diff --git a/source/blender/freestyle/intern/winged_edge/WEdge.cpp b/source/blender/freestyle/intern/winged_edge/WEdge.cpp index 31082e3376f..a5918fd8400 100755 --- a/source/blender/freestyle/intern/winged_edge/WEdge.cpp +++ b/source/blender/freestyle/intern/winged_edge/WEdge.cpp @@ -178,6 +178,9 @@ WOEdge::WOEdge(WOEdge& iBrother) userdata = NULL; iBrother.userdata = new oedgedata; ((oedgedata*)(iBrother.userdata))->_copy = this; + + _vec = iBrother._vec; + _angle = iBrother._angle; } WOEdge * WOEdge::duplicate() @@ -680,8 +683,27 @@ WFace* WShape::MakeFace(vector<WVertex*>& iVertexList, unsigned iMaterial, WFace } } + + vector<WVertex*>::iterator it; + + // compute the face normal (v1v2 ^ v1v3) + WVertex *v1, *v2, *v3; + it = iVertexList.begin(); + v1 = *it; + it++; + v2 = *it; + it++; + v3 = *it; + + Vec3r vector1(v2->GetVertex()-v1->GetVertex()); + Vec3r vector2(v3->GetVertex()-v1->GetVertex()); + + Vec3r normal(vector1 ^ vector2); + normal.normalize(); + face->setNormal(normal); + // vertex pointers used to build each edge - vector<WVertex*>::iterator va, vb, it; + vector<WVertex*>::iterator va, vb; va = iVertexList.begin(); vb = va; @@ -710,25 +732,9 @@ WFace* WShape::MakeFace(vector<WVertex*>& iVertexList, unsigned iMaterial, WFace edge->setId(_EdgeList.size()); AddEdge(edge); // compute the mean edge value: - _meanEdgeSize += edge->GetaOEdge()->getVec3r().norm(); + _meanEdgeSize += edge->GetaOEdge()->GetVec().norm(); } } - - // compute the face normal (v1v2 ^ v1v3) - WVertex *v1, *v2, *v3; - it = iVertexList.begin(); - v1 = *it; - it++; - v2 = *it; - it++; - v3 = *it; - - Vec3r vector1(v2->GetVertex()-v1->GetVertex()); - Vec3r vector2(v3->GetVertex()-v1->GetVertex()); - - Vec3r normal(vector1 ^ vector2); - normal.normalize(); - face->setNormal(normal); // Add the face to the shape's faces list: face->setId(id); diff --git a/source/blender/freestyle/intern/winged_edge/WEdge.h b/source/blender/freestyle/intern/winged_edge/WEdge.h index ebf26cd6d23..abb6263ae69 100755 --- a/source/blender/freestyle/intern/winged_edge/WEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WEdge.h @@ -32,6 +32,7 @@ # include <vector> # include <iterator> +# include <math.h> # include "../system/FreestyleConfig.h" # include "../geometry/Geom.h" # include "../scene_graph/FrsMaterial.h" @@ -295,7 +296,11 @@ protected: WFace *_pbFace; // when following the edge, face on the left WEdge *_pOwner; // Edge + Vec3r _vec; + real _angle; + public: + void *userdata; inline WOEdge() { @@ -326,6 +331,9 @@ public: inline WFace *GetaFace() {return _paFace;} inline WFace *GetbFace() {return _pbFace;} inline WEdge *GetOwner() {return _pOwner;} + + inline const Vec3r& GetVec() { return _vec; } + inline const real GetAngle() { return _angle; } /*! modifiers */ @@ -333,10 +341,11 @@ public: // inline void SetbCWEdge(WOEdge *pe) {_pbCWEdge = pe;} // inline void SetaCCWEdge(WOEdge *pe) {_paCCWEdge = pe;} // inline void SetbCCCWEdge(WOEdge *pe) {_pbCCWEdge = pe;} - inline void setaVertex(WVertex *pv) {_paVertex = pv;} - inline void setbVertex(WVertex *pv) {_pbVertex = pv;} - inline void setaFace(WFace *pf) {_paFace = pf;} - inline void setbFace(WFace *pf) {_pbFace = pf;} + inline void setVecAndAngle(); + inline void setaVertex(WVertex *pv) {_paVertex = pv; setVecAndAngle(); } + inline void setbVertex(WVertex *pv) {_pbVertex = pv; setVecAndAngle(); } + inline void setaFace(WFace *pf) {_paFace = pf; setVecAndAngle(); } + inline void setbFace(WFace *pf) {_pbFace = pf; setVecAndAngle(); } inline void setOwner(WEdge *pe) {_pOwner = pe;} /*! Retrieves the list of edges in CW order */ @@ -955,4 +964,22 @@ void WOEdge::RetrieveCWOrderedEdges(vector<WEdge*>& oEdges) } while((currentOEdge != NULL) && (currentOEdge->GetOwner() != GetOwner())); } +inline void WOEdge::setVecAndAngle() { + if ( _paVertex != NULL && _pbVertex != NULL ) { + _vec = _pbVertex->GetVertex() - _paVertex->GetVertex(); + if ( _paFace != NULL && _pbFace != NULL ) { + real sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm() ; + if(sine >= 1.0) { + _angle = M_PI / 2.0 ; + return; + } + if(sine <= -1.0) { + _angle = -M_PI / 2.0 ; + return; + } + _angle = ::asin(sine); + } + } +} + #endif // WEDGE_H |