diff options
Diffstat (limited to 'source/blender/freestyle/intern/view_map')
-rwxr-xr-x | source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp | 41 | ||||
-rwxr-xr-x | source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp | 10 |
2 files changed, 49 insertions, 2 deletions
diff --git a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp index ecb0a4979f0..bb9ef5d574b 100755 --- a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp +++ b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp @@ -155,6 +155,7 @@ real SilhouetteGeomEngine::ImageToWorldParameter(FEdge *fe, real t) // we need to compute for each parameter t the corresponding // parameter T which gives the intersection in 3D. +#if 0 //currentEdge = (*fe); Vec3r A = (fe)->vertexA()->point3D(); Vec3r B = (fe)->vertexB()->point3D(); @@ -175,6 +176,46 @@ real SilhouetteGeomEngine::ImageToWorldParameter(FEdge *fe, real t) real T; T = (Ic[2]*Ac[1] - Ic[1]*Ac[2])/(Ic[1]*(Bc[2]-Ac[2])-Ic[2]*(Bc[1]-Ac[1])); +#else + // suffix w for world, i for image + Vec3r Aw = (fe)->vertexA()->point3D(); + Vec3r Bw = (fe)->vertexB()->point3D(); + Vec3r Ai = (fe)->vertexA()->point2D(); + Vec3r Bi = (fe)->vertexB()->point2D(); + Vec3r Ii = Ai + t * (Bi - Ai); // the intersection point in 2D + Vec3r Pw, Pi; + real T_sta = 0.0; + real T_end = 1.0; + real T; + real delta_x, delta_y, dist, dist_threshold = 1e-6; + int i, max_iters = 100; + for (i = 0; i < max_iters; i++) { + T = T_sta + 0.5 * (T_end - T_sta); + Pw = Aw + T * (Bw - Aw); + GeomUtils::fromWorldToImage(Pw, Pi, _transform, _viewport); + delta_x = Ii[0] - Pi[0]; + delta_y = Ii[1] - Pi[1]; + dist = sqrt(delta_x * delta_x + delta_y * delta_y); + if (dist < dist_threshold) + break; + if (Ai[0] < Bi[0]) { + if (Pi[0] < Ii[0]) + T_sta = T; + else + T_end = T; + } else { + if (Pi[0] > Ii[0]) + T_sta = T; + else + T_end = T; + } + } +#if 0 + printf("SilhouetteGeomEngine::ImageToWorldParameter(): #iters = %d, dist = %e\n", i, dist); +#endif + if (i == max_iters) + printf("SilhouetteGeomEngine::ImageToWorldParameter(): reached to max_iters (dist = %e)\n", dist); +#endif return T; } diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp index 3a4d86ea16f..9c7a084c204 100755 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp @@ -946,14 +946,20 @@ void ViewMapBuilder::ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsi real tb = (*i)->tB; if((ta < -epsilon) || (ta > 1+epsilon)) - cerr << "Warning: intersection out of range for edge " << fA->vertexA()->getId() << " - " << fA->vertexB()->getId() << endl; + cerr << "Warning: 2D intersection out of range for edge " << fA->vertexA()->getId() << " - " << fA->vertexB()->getId() << endl; if((tb < -epsilon) || (tb > 1+epsilon)) - cerr << "Warning: intersection out of range for edge " << fB->vertexA()->getId() << " - " << fB->vertexB()->getId() << endl; + cerr << "Warning: 2D intersection out of range for edge " << fB->vertexA()->getId() << " - " << fB->vertexB()->getId() << endl; real Ta = SilhouetteGeomEngine::ImageToWorldParameter(fA, ta); real Tb = SilhouetteGeomEngine::ImageToWorldParameter(fB, tb); + if((Ta < -epsilon) || (Ta > 1+epsilon)) + cerr << "Warning: 3D intersection out of range for edge " << fA->vertexA()->getId() << " - " << fA->vertexB()->getId() << endl; + + if((Tb < -epsilon) || (Tb > 1+epsilon)) + cerr << "Warning: 3D intersection out of range for edge " << fB->vertexA()->getId() << " - " << fB->vertexB()->getId() << endl; + TVertex * tvertex = ioViewMap->CreateTVertex(Vec3r(A1 + Ta*(A2-A1)), Vec3r(a1 + ta*(a2-a1)), fA, Vec3r(B1 + Tb*(B2-B1)), Vec3r(b1 + tb*(b2-b1)), fB, id); |