Revision: 64386
          http://sourceforge.net/p/brlcad/code/64386
Author:   starseeker
Date:     2015-03-13 01:15:41 +0000 (Fri, 13 Mar 2015)
Log Message:
-----------
make a line/plane intersect function in openNURBS data types.  Easier to read 
and use, fixes some issues with NIST 2.  Needs much more careful/rigorous 
testing, but as of this commit all 5 raytraces, CSG only and CSG/NURBS 
combinations, from a casual visual inspection don't appear to contain any major 
errors.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/shape_recognition.cpp
    brlcad/trunk/src/libbrep/shape_recognition.h
    brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
    brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp
    brlcad/trunk/src/libbrep/shape_recognition_util.cpp

Modified: brlcad/trunk/src/libbrep/shape_recognition.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.cpp      2015-03-12 22:36:53 UTC 
(rev 64385)
+++ brlcad/trunk/src/libbrep/shape_recognition.cpp      2015-03-13 01:15:41 UTC 
(rev 64386)
@@ -304,7 +304,7 @@
                                if (cdata && cdata->params) {
                                    cdata->params->bool_op = 
(cdata->params->bool_op == '-') ? 'u' : '-';
                                } else {
-                                   std::cout << "Child without params??: " << 
bu_vls_addr(cdata->key) << ", parent: " << bu_vls_addr(cobj->key) << "\n";
+                                   //std::cout << "Child without params??: " 
<< bu_vls_addr(cdata->key) << ", parent: " << bu_vls_addr(cobj->key) << "\n";
                                }
                            }
 
@@ -360,7 +360,7 @@
            bool bbi = isect.Intersection(*pobj->bbox, *sobj->bbox);
            bool bbc = pobj->bbox->Includes(*sobj->bbox);
            if (bbi || bbc) {
-               std::cout << " Found intersecting subbrep " << 
bu_vls_addr(sobj->key) << " under " << bu_vls_addr(pobj->key) << "\n";
+               //std::cout << " Found intersecting subbrep " << 
bu_vls_addr(sobj->key) << " under " << bu_vls_addr(pobj->key) << "\n";
                bu_ptbl_ins(subbreps_tree, *sb_it2);
            }
        }

Modified: brlcad/trunk/src/libbrep/shape_recognition.h
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.h        2015-03-12 22:36:53 UTC 
(rev 64385)
+++ brlcad/trunk/src/libbrep/shape_recognition.h        2015-03-13 01:15:41 UTC 
(rev 64386)
@@ -175,6 +175,8 @@
 int subbrep_find_corners(struct subbrep_object_data *data, int 
**corner_verts_array, ON_Plane *pcyl);
 int subbrep_top_bottom_pnts(struct subbrep_object_data *data, std::set<int> 
*corner_verts, ON_Plane *top_plane, ON_Plane *bottom_plane, 
ON_SimpleArray<const ON_BrepVertex *> *top_pnts, ON_SimpleArray<const 
ON_BrepVertex *> *bottom_pnts);
 
+ON_3dPoint ON_LinePlaneIntersect(ON_Line &line, ON_Plane &plane);
+
 #endif /* SHAPE_RECOGNITION_H */
 
 // Local Variables:

Modified: brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-12 
22:36:53 UTC (rev 64385)
+++ brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-13 
01:15:41 UTC (rev 64386)
@@ -6,8 +6,6 @@
 #include "bu/log.h"
 #include "bu/str.h"
 #include "bu/malloc.h"
-#include "bn/plane_calc.h"
-#include "bn/tol.h"
 #include "shape_recognition.h"
 
 /* Return -1 if the cylinder face is pointing in toward the cylinder axis,
@@ -752,53 +750,11 @@
                    data->type = COMB;
                    // First order of business - find the intersection between 
the axis and the capping
                    // plane
-                   point_t intersect_pt;
-                   fastf_t dist;
-                   point_t axis_pt;
-                   vect_t axis_dir;
-                   plane_t plane_eqn;
-                   struct bn_tol intersect_tol = {BN_TOL_MAGIC, BN_TOL_DIST, 
BN_TOL_DIST * BN_TOL_DIST, 1e-6, 1.0 - 1e-6 };
-                   VMOVE(axis_pt, cylinder.circle.Center());
-                   VMOVE(axis_dir, cylinder.Axis());
-                   VUNITIZE(axis_dir);
-                   plane_eqn[0] = cyl_planes[0].plane_equation.x;
-                   plane_eqn[1] = cyl_planes[0].plane_equation.y;
-                   plane_eqn[2] = cyl_planes[0].plane_equation.z;
-                   plane_eqn[3] = cyl_planes[0].plane_equation.d;
 
-                   if (bn_isect_line3_plane(&dist, axis_pt, axis_dir, 
plane_eqn, &intersect_tol) < 0) {
-                       plane_eqn[0] = -1 * cyl_planes[0].plane_equation.x;
-                       plane_eqn[1] = -1 * cyl_planes[0].plane_equation.y;
-                       plane_eqn[2] = -1 * cyl_planes[0].plane_equation.z;
-                       (void)bn_isect_line3_plane(&dist, axis_pt, axis_dir, 
plane_eqn, &intersect_tol);
-                   }
+                   ON_Line line(cylinder.circle.Center(), 
cylinder.circle.Center() + cylinder.Axis());
+                   ON_3dPoint ip1 = ON_LinePlaneIntersect(line, cyl_planes[0]);
+                   ON_3dPoint ip2 = ON_LinePlaneIntersect(line, cyl_planes[1]);
 
-                   VSCALE(axis_dir, axis_dir, dist);
-                   VADD2(intersect_pt, axis_pt, axis_dir);
-
-                   //std::cout << "Intersect point 1: " << intersect_pt[0] << 
"," << intersect_pt[1] << "," << intersect_pt[2] << "\n";
-                   ON_3dPoint ip1(intersect_pt[0], intersect_pt[1], 
intersect_pt[2]);
-
-                   VMOVE(axis_dir, cylinder.Axis());
-                   VUNITIZE(axis_dir);
-                   plane_eqn[0] = cyl_planes[1].plane_equation.x;
-                   plane_eqn[1] = cyl_planes[1].plane_equation.y;
-                   plane_eqn[2] = cyl_planes[1].plane_equation.z;
-                   plane_eqn[3] = cyl_planes[1].plane_equation.d;
-
-                   if (bn_isect_line3_plane(&dist, axis_pt, axis_dir, 
plane_eqn, &intersect_tol) < 0) {
-                       plane_eqn[0] = -1 * cyl_planes[1].plane_equation.x;
-                       plane_eqn[1] = -1 * cyl_planes[1].plane_equation.y;
-                       plane_eqn[2] = -1 * cyl_planes[1].plane_equation.z;
-                       (void)bn_isect_line3_plane(&dist, axis_pt, axis_dir, 
plane_eqn, &intersect_tol);
-                   }
-
-                   VSCALE(axis_dir, axis_dir, dist);
-                   VADD2(intersect_pt, axis_pt, axis_dir);
-
-                   //std::cout << "Intersect point 2: " << intersect_pt[0] << 
"," << intersect_pt[1] << "," << intersect_pt[2] << "\n";
-                   ON_3dPoint ip2(intersect_pt[0], intersect_pt[1], 
intersect_pt[2]);
-
                    // Define the cylinder.
                    struct subbrep_object_data *cyl_obj;
                    BU_GET(cyl_obj, struct subbrep_object_data);

Modified: brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp       2015-03-12 
22:36:53 UTC (rev 64385)
+++ brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp       2015-03-13 
01:15:41 UTC (rev 64386)
@@ -80,8 +80,8 @@
     double dotp = ON_DotProduct(vect, normal);
 
     if (NEAR_ZERO(dotp, 0.000001)) return 0;
-    if (dotp < 0) return 1;
-    return -1;
+    if (dotp < 0) return -1;
+    return 1;
 }
 
 
@@ -253,8 +253,8 @@
            ON_3dVector y = back_plane.Yaxis();
            x.Unitize();
            y.Unitize();
-           x = x * 1.05 * sph.Radius();
-           y = y * 1.05 * sph.Radius();
+           x = x * 1.5 * sph.Radius();
+           y = y * 1.5 * sph.Radius();
            arb1_points[0] = bpc - x - y;
            arb1_points[1] = bpc + x - y;
            arb1_points[2] = bpc + x + y;
@@ -290,8 +290,8 @@
            ON_3dPoint ecenter = edge_centers[i];
            ex.Unitize();
            ey.Unitize();
-           ex = ex * 1.05 * sph.Radius();
-           ey = ey * 1.05 * sph.Radius();
+           ex = ex * 1.5 * sph.Radius();
+           ey = ey * 1.5 * sph.Radius();
            arb_points[0] = ecenter - ex - ey;
            arb_points[1] = ecenter + ex - ey;
            arb_points[2] = ecenter + ex + ey;

Modified: brlcad/trunk/src/libbrep/shape_recognition_util.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-12 22:36:53 UTC 
(rev 64385)
+++ brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-13 01:15:41 UTC 
(rev 64386)
@@ -9,6 +9,35 @@
 #include "brep.h"
 #include "shape_recognition.h"
 
+ON_3dPoint
+ON_LinePlaneIntersect(ON_Line &line, ON_Plane &plane)
+{
+    ON_3dPoint result;
+    result.x = ON_DBL_MAX;
+    result.y = ON_DBL_MAX;
+    result.z = ON_DBL_MAX;
+    ON_3dVector n = plane.Normal();
+    ON_3dVector l = line.Direction();
+    ON_3dPoint l0 = line.PointAt(0.5);
+    ON_3dPoint p0 = plane.Origin();
+
+    ON_3dVector p0l0 = p0 - l0;
+    double p0l0n = ON_DotProduct(p0l0, n);
+    double ln = ON_DotProduct(l, n);
+    if (NEAR_ZERO(ln, 0.000001) && NEAR_ZERO(p0l0n, 0.000001)) {
+       result.x = -ON_DBL_MAX;
+       result.y = -ON_DBL_MAX;
+       result.z = -ON_DBL_MAX;
+       return result;
+    }
+    if (NEAR_ZERO(ln, 0.000001)) return result;
+
+    double d = p0l0n/ln;
+
+    result = d*l + l0;
+    return result;
+}
+
 curve_t
 GetCurveType(ON_Curve *curve)
 {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to