Revision: 74888 http://sourceforge.net/p/brlcad/code/74888 Author: brlcad Date: 2020-02-11 08:32:23 +0000 (Tue, 11 Feb 2020) Log Message: ----------- implement a basic adjustment for platemode to clamp the thickness to within a platemode thickness distance from the surface. this is not final form, but is working surprisingly as intended. using an overly simple and inefficient stepping method to walk the los thickness back; needs newton's method or more aggressive stepping.
Modified Paths: -------------- brlcad/trunk/src/librt/primitives/brep/brep.cpp Modified: brlcad/trunk/src/librt/primitives/brep/brep.cpp =================================================================== --- brlcad/trunk/src/librt/primitives/brep/brep.cpp 2020-02-11 08:15:26 UTC (rev 74887) +++ brlcad/trunk/src/librt/primitives/brep/brep.cpp 2020-02-11 08:32:23 UTC (rev 74888) @@ -980,12 +980,45 @@ brep_platemode_thickness(const struct xray& ray, const brep_hit& hit, const struct brep_specific& bs) { double los = bs.plate_mode_thickness; + if (bs.plate_mode_nocos) { + return los; + } - if (!bs.plate_mode_nocos) { + double dot = fabs(VDOT(hit.normal, ray.r_dir)); + los = los / dot; - double dot = fabs(VDOT(hit.normal, ray.r_dir)); - los = los / dot; + point_t hp; + VJOIN1(hp, ray.r_pt, hit.dist + los, ray.r_dir); + ON_3dPoint los_pnt(V3ARGS(hp)); + /* try to make sure we don't extend more than plate-mode thickness + * beyond the surface by calculating the proposed exit point's + * distance to the surface. + */ + const ON_Surface* surf = hit.face.SurfaceOf(); + const ON_BrepFace& face = hit.face; + SurfaceTree* tree = NULL; + ON_2dPoint uvpt; + get_closest_point(uvpt, face, los_pnt, tree); + ON_3dPoint p = surf->PointAt(uvpt[0], uvpt[1]); + double dist_to_surf = p.DistanceTo(los_pnt); + + const int MAX_ITERATIONS = 10; + const double stepsize = bs.plate_mode_thickness * 0.1; + int iterations = 0; + while (!NEAR_EQUAL(dist_to_surf, bs.plate_mode_thickness, stepsize) && iterations++ < MAX_ITERATIONS) { + + if (dist_to_surf > bs.plate_mode_thickness) + los -= stepsize; /* nudge back a full step */ + else if (dist_to_surf < bs.plate_mode_thickness) + los += (stepsize * 0.9); /* nudge forward 90% step */ + + /* calculate a new exit point distance to surface */ + VJOIN1(hp, ray.r_pt, hit.dist + los, ray.r_dir); + los_pnt = ON_3dPoint(V3ARGS(hp)); + get_closest_point(uvpt, face, los_pnt, tree); + p = surf->PointAt(uvpt[0], uvpt[1]); + dist_to_surf = p.DistanceTo(los_pnt); } return los; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits