int brep_edge_check(int reason, const SubsurfaceBBNode* sbv, const ON_BrepFace* face, const ON_Surface* surf, const ON_Ray& r, HitList& hits) { // if the intersection was not found for any reason, we need to // check and see if we are close to any topological edges; we may // have hit a crack... // the proper way to do this is to only look at edges // interesecting with the subsurface bounding box... but for // now, we'll look at the edges associated with the face for the bounding box... // XXX - optimize this set<ON_BrepEdge*> edges; ON_3dPoint pt; for (int i = 0; i < face->LoopCount(); i++) { ON_BrepLoop* loop = face->Loop(i); for (int j = 0; j < loop->TrimCount(); j++) { ON_BrepTrim* trim = loop->Trim(j); ON_BrepEdge* edge = trim->Edge(); pair<set<ON_BrepEdge*>::iterator, bool> res = edges.insert(edge); // if (res.second) { // only check if its the first time we've seen this // edge const ON_Curve* curve = edge->EdgeCurveOf(); Sample s; if (curve->CloseTo(ON_3dPoint(hits.back().point), BREP_EDGE_MISS_TOLERANCE, s)) { TRACE1("CLOSE TO EDGE"); hits.back().closeToEdge = true; return BREP_INTERSECT_FOUND; } } } return BREP_INTERSECT_TRIMMED; }
int brep_intersect(const SubsurfaceBBNode* sbv, const ON_BrepFace* face, const ON_Surface* surf, pt2d_t uv, ON_Ray& ray, HitList& hits) { int found = BREP_INTERSECT_ROOT_ITERATION_LIMIT; fastf_t Dlast = MAX_FASTF; int diverge_iter = 0; pt2d_t Rcurr; pt2d_t new_uv; ON_3dPoint pt; ON_3dVector su; ON_3dVector sv; plane_ray pr; brep_get_plane_ray(ray, pr); for (int i = 0; i < BREP_MAX_ITERATIONS; i++) { brep_r(surf,pr,uv,pt,su,sv,Rcurr); //fastf_t d = v2mag(Rcurr); fastf_t d = DIST_PT_PT(pt,ray.m_origin); //if (d < BREP_INTERSECTION_ROOT_EPSILON) { if (NEAR_ZERO(d-Dlast,BREP_INTERSECTION_ROOT_EPSILON)) { TRACE1("R:"<<ON_PRINT2(Rcurr)); found = BREP_INTERSECT_FOUND; break; } else if (d > Dlast) { found = BREP_INTERSECT_ROOT_DIVERGED; //break; diverge_iter++; if (diverge_iter > 10) break; //return brep_edge_check(found, sbv, face, surf, ray, hits); } brep_newton_iterate(surf, pr, Rcurr, su, sv, uv, new_uv); move(uv, new_uv); Dlast = d; } if (found > 0) { fastf_t l,h; ON_3dPoint _pt; ON_3dVector _norm; surf->EvNormal(uv[0],uv[1],_pt,_norm); if (face->m_bRev) _norm.Reverse(); hits.push_back(brep_hit(*face,(const fastf_t*)ray.m_origin,(const fastf_t*)_pt,(const fastf_t*)_norm, uv)); hits.back().sbv = sbv; if (!sbv->m_u.Includes(uv[0]) || !sbv->m_v.Includes(uv[1])) { // if (!sbv->m_u.Includes(uv[0]-BREP_SAME_POINT_TOLERANCE) || // !sbv->m_v.Includes(uv[1]-BREP_SAME_POINT_TOLERANCE)) { hits.back().oob = true; return BREP_INTERSECT_OOB; } if (sbv->doTrimming() && brep_pt_trimmed(uv, *face)) { hits.back().trimmed = true; TRACE1("Should be TRIMMED!"); // if the point was trimmed, see if it is close to the edge before removing it return brep_edge_check(BREP_INTERSECT_TRIMMED, sbv, face, surf, ray, hits); //return BREP_INTERSECT_TRIMMED; } } return found; }