Revision: 45746
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45746&view=rev
Author:   r_weiss
Date:     2011-08-01 20:29:15 +0000 (Mon, 01 Aug 2011)

Log Message:
-----------
Updated functions 'nmg_class_pt_e', 'nmg_class_pt_l', 'class_vu_vs_s', 
'nmg_class_pt_s', 'class_eu_vs_s' and 'class_lu_vs_s' within file 
'nmg_class.c'. Most of the updates were changes to support the prototype 
version of function 'nmg_triangulate_fu'. The remainer of the changes were code 
cleanup. The logic changes are disabled by default and are a work in progress. 
These changes are related to classification of nmg objects during boolean 
operations.

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/nmg/nmg_class.c

Modified: brlcad/trunk/src/librt/primitives/nmg/nmg_class.c
===================================================================
--- brlcad/trunk/src/librt/primitives/nmg/nmg_class.c   2011-08-01 20:22:33 UTC 
(rev 45745)
+++ brlcad/trunk/src/librt/primitives/nmg/nmg_class.c   2011-08-01 20:29:15 UTC 
(rev 45746)
@@ -265,8 +265,14 @@
         * to decide things.
         */
        if (closest->p.eu && closest->p.eu->up.lu_p == eu->up.lu_p) {
+#ifdef TRI_PROTOTYPE
            if (closest->class == NMG_CLASS_AoutB ||
+               closest->class == NMG_CLASS_AonBshared ||
+               closest->class == NMG_CLASS_AonBanti) {
+#else
+           if (closest->class == NMG_CLASS_AoutB ||
                closest->class == NMG_CLASS_AonBshared) {
+#endif
                if (rt_g.NMG_debug & DEBUG_CLASSIFY)
                    bu_log("\t\tSkipping, earlier eu from same lu at same dist, 
is OUT or ON.\n");
                return;
@@ -286,8 +292,14 @@
             * and when loop A is visited the distances will be exactly
             * equal, not giving A a chance to claim its hit.
             */
+#ifdef TRI_PROTOTYPE
            if (closest->class == NMG_CLASS_AinB ||
+               closest->class == NMG_CLASS_AonBshared ||
+               closest->class == NMG_CLASS_AonBanti) {
+#else
+           if (closest->class == NMG_CLASS_AinB ||
                closest->class == NMG_CLASS_AonBshared) {
+#endif
                if (rt_g.NMG_debug & DEBUG_CLASSIFY)
                    bu_log("\t\tSkipping, earlier eu from other another lu at 
same dist, is IN or ON\n");
                return;
@@ -439,16 +451,32 @@
        HPRINT("\tplane eqn", peqn);
     }
 
+#ifdef TRI_PROTOTYPE
+    if (V3PT_OUT_RPP_TOL(pt, lg->min_pt, lg->max_pt, tol)) {
+#else
     if (!V3PT_IN_RPP_TOL(pt, lg->min_pt, lg->max_pt, tol)) {
-       if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+#endif
+       if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
            bu_log("\tPoint is outside loop RPP\n");
+       }
+#ifdef TRI_PROTOTYPE
+       closest->class = NMG_CLASS_AoutB;
+#endif
        return;
     }
     if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_EDGEUSE_MAGIC) {
        for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
            nmg_class_pt_e(closest, pt, eu, tol);
            /* If point lies ON edge, we are done */
+#ifdef TRI_PROTOTYPE
+           if (closest->class == NMG_CLASS_AonBanti) {
+                break;
+            } else if (closest->class == NMG_CLASS_AonBshared) {
+               bu_bomb("nmg_class_pt_l(): nmg_class_pt_e returned AonBshared 
but can only return AonBanti\n");
+            }
+#else
            if (closest->class == NMG_CLASS_AonBshared) break;
+#endif
        }
     } else if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC) {
        register struct vertexuse *vu;
@@ -459,7 +487,11 @@
            if (lu->orientation == OT_OPPOSITE) {
                closest->class = NMG_CLASS_AoutB;
            } else if (lu->orientation == OT_SAME) {
+#ifdef TRI_PROTOTYPE
+               closest->class = NMG_CLASS_AonBanti;
+#else
                closest->class = NMG_CLASS_AonBshared;
+#endif
            } else {
                nmg_pr_orient(lu->orientation, "\t");
                bu_bomb("nmg_class_pt_l: bad orientation for face loopuse\n");
@@ -634,28 +666,27 @@
     struct xray rp;
 #ifdef TRI_PROTOTYPE
     fastf_t model_bb_max_width;
-    struct nmgregion *r;
     point_t m_min_pt, m_max_pt; /* nmg model min and max points */
 #endif
 
+    m = s->r_p->m_p;
+    NMG_CK_MODEL(m);
     NMG_CK_SHELL(s);
     BN_CK_TOL(tol);
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-       bu_log("nmg_class_pt_s:\tpt=(%g, %g, %g), s=x%x\n",
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       bu_log("nmg_class_pt_s(): pt=(%g, %g, %g), s=x%x\n",
               V3ARGS(pt), s);
-
+    }
     if (V3PT_OUT_RPP_TOL(pt, s->sa_p->min_pt, s->sa_p->max_pt, tol)) {
-       if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-           bu_log("    OUT, point not in RPP\n");
+       if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+           bu_log("nmg_class_pt_s(): OUT, point not in RPP\n");
+       }
        return NMG_CLASS_AoutB;
     }
 
-    m = s->r_p->m_p;
-    NMG_CK_MODEL(m);
     if (!in_or_out_only) {
        faces_seen = (long *)bu_calloc(m->maxindex, sizeof(long), 
"nmg_class_pt_s faces_seen[]");
-
        /*
         * First pass:  Try hard to see if point is ON a face.
         */
@@ -663,10 +694,13 @@
            plane_t n;
 
            /* If this face processed before, skip on */
-           if (NMG_INDEX_TEST(faces_seen, fu->f_p)) continue;
-
+           if (NMG_INDEX_TEST(faces_seen, fu->f_p)) {
+               continue;
+           }
            /* Only consider the outward pointing faceuses */
-           if (fu->orientation != OT_SAME) continue;
+           if (fu->orientation != OT_SAME) {
+               continue;
+           }
 
            /* See if this point lies on this face */
            NMG_GET_FU_PLANE(n, fu);
@@ -675,22 +709,46 @@
                 * short circuit everything.
                 */
                class = nmg_class_pt_fu_except(pt, fu, (struct loopuse *)0,
-                                              (void (*)())NULL, (void 
(*)())NULL, (char *)NULL, 0,
-                                              0, tol);
+                       (void (*)())NULL, (void (*)())NULL, (char *)NULL, 0, 0, 
tol);
+#ifdef TRI_PROTOTYPE
                if (class == NMG_CLASS_AonBshared) {
+                   bu_bomb("nmg_class_pt_s(): function nmg_class_pt_fu_except 
returned AonBshared when it can only return AonBanti\n");
+               }
+#endif
+               if (class == NMG_CLASS_AonBshared) {
                    /* Point is ON face, therefore it must be
                     * ON the shell also.
                     */
                    class = NMG_CLASS_AonBshared;
                    goto out;
                }
+#ifdef TRI_PROTOTYPE
+               if (class == NMG_CLASS_AonBanti) {
+                   /* Point is ON face, therefore it must be
+                    * ON the shell also.
+                    */
+                   class = NMG_CLASS_AonBanti;
+                   goto out;
+               }
+#endif
+
+#ifdef TRI_PROTOTYPE
                if (class == NMG_CLASS_AinB) {
                    /* Point is IN face, therefor it must be
                     * ON the shell also.
                     */
+                   class = NMG_CLASS_AonBanti;
+                   goto out;
+               }
+#else
+               if (class == NMG_CLASS_AinB) {
+                   /* Point is IN face, therefor it must be
+                    * ON the shell also.
+                    */
                    class = NMG_CLASS_AonBshared;
                    goto out;
                }
+#endif
                /* Point is OUTside face, its undecided. */
            }
 
@@ -710,14 +768,7 @@
     region_diameter = MAGNITUDE(region_diagonal);
 
 #ifdef TRI_PROTOTYPE
-    /* find the nmg model bounding box */
-    VSETALL(m_min_pt, MAX_FASTF);
-    VSETALL(m_max_pt, -MAX_FASTF);
-    for (BU_LIST_FOR(r, nmgregion, &s->r_p->m_p->r_hd)) {
-        NMG_CK_REGION(r);
-        VMIN(m_min_pt, r->ra_p->min_pt);
-        VMAX(m_max_pt, r->ra_p->max_pt);
-    }
+    nmg_model_bb(m_min_pt, m_max_pt, m);
     model_bb_max_width = bn_dist_pt3_pt3(m_min_pt, m_max_pt);
 #endif
 
@@ -729,12 +780,16 @@
        VMOVE(projection_dir, *pp);
     }
 
-    if (++try > 10) goto out; /* only nmg_good_dirs to try (10) */
+    if (++try > 10) {
+       goto out; /* only nmg_good_dirs to try (10) */
+    }
+
     VUNITIZE(projection_dir);
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-       bu_log("\tPt=(%g, %g, %g) dir=(%g, %g, %g), reg_diam=%g\n",
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       bu_log("nmg_class_pt_s(): Pt=(%g, %g, %g) dir=(%g, %g, %g), 
reg_diam=%g\n",
               V3ARGS(pt), V3ARGS(projection_dir), region_diameter);
+    }
 
     VMOVE(rp.r_pt, pt);
 
@@ -749,15 +804,26 @@
 
     /* get NMG ray-tracer to tell us if start point is inside or outside */
     class = nmg_class_ray_vs_shell(&rp, s, in_or_out_only, tol);
-    if (class == NMG_CLASS_Unknown) goto retry;
 
+#ifdef TRI_PROTOTYPE
+    if (class == NMG_CLASS_AonBshared) {
+       bu_bomb("nmg_class_pt_s(): function nmg_class_ray_vs_shell returned 
AonBshared when it can only return AonBanti\n");
+    }
+#endif
+    if (class == NMG_CLASS_Unknown) {
+       goto retry;
+    }
+
 out:
-    if (!in_or_out_only)
+    if (!in_or_out_only) {
        bu_free((char *)faces_seen, "nmg_class_pt_s faces_seen[]");
+    }
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-       bu_log("nmg_class_pt_s: returning %s, s=x%x, try=%d\n",
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       bu_log("nmg_class_pt_s(): returning %s, s=x%x, try=%d\n",
               nmg_class_name(class), s, try);
+    }
+
     return class;
 }
 
@@ -775,6 +841,7 @@
     char *reason;
     int status = 0;
     int class;
+    struct vertex *sv;
 
     NMG_CK_VERTEXUSE(vu);
     NMG_CK_SHELL(sB);
@@ -810,33 +877,37 @@
     for (BU_LIST_FOR(vup, vertexuse, &vu->v_p->vu_hd)) {
 
        if (*vup->up.magic_p == NMG_LOOPUSE_MAGIC) {
-           if (nmg_find_s_of_lu(vup->up.lu_p) != sB) continue;
-           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared],
-                         vu->v_p);
+           if (nmg_find_s_of_lu(vup->up.lu_p) != sB) {
+               continue;
+           }
+           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], vu->v_p);
            reason = "a loopuse of vertex is on shell";
            status = ON_SURF;
            goto out;
        } else if (*vup->up.magic_p == NMG_EDGEUSE_MAGIC) {
-           if (nmg_find_s_of_eu(vup->up.eu_p) != sB) continue;
-           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared],
-                         vu->v_p);
+           if (nmg_find_s_of_eu(vup->up.eu_p) != sB) {
+               continue;
+           }
+           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], vu->v_p);
            reason = "an edgeuse of vertex is on shell";
            status = ON_SURF;
            goto out;
        } else if (*vup->up.magic_p == NMG_SHELL_MAGIC) {
-           if (vup->up.s_p != sB) continue;
-           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared],
-                         vu->v_p);
+           if (vup->up.s_p != sB) {
+               continue;
+           }
+           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], vu->v_p);
            reason = "vertex is shell's lone vertex";
            status = ON_SURF;
            goto out;
        } else {
-           bu_bomb("class_vu_vs_s() bad vertex UP pointer\n");
+           bu_bomb("class_vu_vs_s(): bad vertex UP pointer\n");
        }
     }
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-       bu_log("\tCan't classify vertex via topology\n");
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       bu_log("class_vu_vs_s(): Can't classify vertex via topology\n");
+    }
 
     /* The topology doesn't tell us about the vertex being "on" the shell
      * so now it's time to look at the geometry to determine the vertex
@@ -846,20 +917,28 @@
      * edges, since the intersection algorithm would have combined the
      * topology if that had been the case.
      */
-    /* XXX eventually, make this conditional on DEBUG_CLASSIFY */
-    {
-       /* Verify this assertion */
-       struct vertex *sv = nmg_find_pt_in_shell(sB, pt, tol);
-       if (sv) {
+
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       if ((sv = nmg_find_pt_in_shell(sB, pt, tol))) {
            bu_log("vu=x%x, v=x%x, sv=x%x, pt=(%g, %g, %g)\n",
-                  vu, vu->v_p, sv, V3ARGS(pt));
-           bu_bomb("nmg_class_pt_s() vertex topology not shared properly\n");
+                   vu, vu->v_p, sv, V3ARGS(pt));
+           bu_bomb("class_vu_vs_s(): logic error, vertex topology not shared 
properly\n");
        }
     }
 
     reason = "of nmg_class_pt_s()";
+#ifdef TRI_PROTOTYPE
+    /* 3rd parameter '0' allows return of AonBanti instead of
+     * only AinB or AoutB
+     */
+    class = nmg_class_pt_s(pt, sB, 0, tol);
+
+    if (class == NMG_CLASS_AonBshared) {
+       bu_bomb("class_vu_vs_s(): function nmg_class_pt_s returned AonBshared 
when it can only return AonBanti\n");
+    }
+#else
     class = nmg_class_pt_s(pt, sB, 1, tol);
-
+#endif
     if (class == NMG_CLASS_AoutB) {
        NMG_INDEX_SET(classlist[NMG_CLASS_AoutB], vu->v_p);
        status = OUTSIDE;
@@ -869,10 +948,15 @@
     }  else if (class == NMG_CLASS_AonBshared) {
        NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], vu->v_p);
        status = ON_SURF;
+#ifdef TRI_PROTOTYPE
+    }  else if (class == NMG_CLASS_AonBanti) {
+       NMG_INDEX_SET(classlist[NMG_CLASS_AonBanti], vu->v_p);
+       status = ON_SURF;
+#endif
     } else {
-       bu_log("class=%s\n", nmg_class_name(class));
+       bu_log("class_vu_vs_s(): class=%s\n", nmg_class_name(class));
        VPRINT("pt", pt);
-       bu_bomb("class_vu_vs_s: nmg_class_pt_s() failure\n");
+       bu_bomb("class_vu_vs_s(): nmg_class_pt_s() failure\n");
     }
 
 out:
@@ -957,8 +1041,9 @@
        FILE *fp;
 
        sprintf(buf, "class%d.pl", num++);
-       if ((fp = fopen(buf, "wb")) == NULL)
+       if ((fp = fopen(buf, "wb")) == NULL) {
            bu_bomb(buf);
+       }
        nmg_pl_s(fp, s);
        /* A yellow line for the angry edge */
        pl_color(fp, 255, 255, 0);
@@ -966,11 +1051,11 @@
                  eu->eumate_p->vu_p->v_p->vg_p->coord);
        fclose(fp);
 
-       nmg_pr_class_status("eu vu", euv_cl);
-       nmg_pr_class_status("eumate vu", matev_cl);
+       nmg_pr_class_status("class_eu_vs_s(): eu vu", euv_cl);
+       nmg_pr_class_status("class_eu_vs_s(): eumate vu", matev_cl);
        if (RT_G_DEBUG || rt_g.NMG_debug) {
            /* Do them over, so we can watch */
-           bu_log("Edge not cut, doing it over\n");
+           bu_log("class_eu_vs_s(): Edge not cut, doing it over\n");
            NMG_INDEX_CLEAR(classlist[NMG_CLASS_AinB], eu->vu_p);
            NMG_INDEX_CLEAR(classlist[NMG_CLASS_AoutB], eu->vu_p);
            NMG_INDEX_CLEAR(classlist[NMG_CLASS_AinB], eu->eumate_p->vu_p);
@@ -978,12 +1063,12 @@
            rt_g.NMG_debug |= DEBUG_CLASSIFY;
            (void)class_vu_vs_s(eu->vu_p, s, classlist, tol);
            (void)class_vu_vs_s(eu->eumate_p->vu_p, s, classlist, tol);
-           nmg_euprint("didn't this edge get cut?", eu);
-           nmg_pr_eu(eu, "  ");
+           nmg_euprint("class_eu_vs_s(): didn't this edge get cut?", eu);
+           nmg_pr_eu(eu, "class_eu_vs_s():");
        }
 
-       bu_log("wrote %s\n", buf);
-       bu_bomb("class_eu_vs_s:  edge didn't get cut\n");
+       bu_log("class_eu_vs_s(): wrote %s\n", buf);
+       bu_bomb("class_eu_vs_s():  edge didn't get cut\n");
     }
 
     if (euv_cl == ON_SURF && matev_cl == ON_SURF) {
@@ -995,8 +1080,7 @@
        do {
            NMG_CK_EDGEUSE(eup);
            if (nmg_find_s_of_eu(eup) == s) {
-               NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared],
-                             eu->e_p);
+               NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], eu->e_p);
                reason = "a radial edgeuse is on shell";
                status = ON_SURF;
                goto out;
@@ -1006,8 +1090,7 @@
 
        /* look for another eu between these two vertices */
        if (nmg_find_matching_eu_in_s(eu, s)) {
-           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared],
-                         eu->e_p);
+           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], eu->e_p);
            reason = "another eu between same vertices is on shell";
            status = ON_SURF;
            goto out;
@@ -1063,24 +1146,34 @@
                    reason = "point near EU end classification (both verts ON)";
                    break;
            }
+#ifdef TRI_PROTOTYPE
+            /* 3rd parameter of '0' allows a return of AonBanti
+             * instead of only AinB or AoutB.
+             */
+           class = nmg_class_pt_s(pt, s, 0, tol);
+#else
            class = nmg_class_pt_s(pt, s, 1, tol);
+#endif
            try++;
        }
 
+#ifdef TRI_PROTOTYPE
+       if (class == NMG_CLASS_AonBshared) {
+           bu_bomb("class_eu_vs_s(): function nmg_class_pt_s returned 
AonBshared when it can only return AonBanti\n"); 
+       }
+#endif
        if (class == NMG_CLASS_AoutB) {
            NMG_INDEX_SET(classlist[NMG_CLASS_AoutB], eu->e_p);
            status = OUTSIDE;
        }  else if (class == NMG_CLASS_AinB) {
            NMG_INDEX_SET(classlist[NMG_CLASS_AinB], eu->e_p);
            status = INSIDE;
-       } else if (class == NMG_CLASS_AonBshared) {
 #ifdef TRI_PROTOTYPE
-           NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], eu->e_p);
-           status = ON_SURF;
        } else if (class == NMG_CLASS_AonBanti) {
            NMG_INDEX_SET(classlist[NMG_CLASS_AonBanti], eu->e_p);
            status = ON_SURF;
 #else
+       } else if (class == NMG_CLASS_AonBshared) {
            FILE *fp;
            nmg_pr_fu_around_eu(eu, tol);
            VPRINT("class_eu_vs_s: midpoint of edge", pt);
@@ -1096,12 +1189,12 @@
                fclose(fp);
                bu_log("wrote shell2.pl\n");
            }
-           bu_bomb("class_eu_vs_s:  classifier found edge midpoint ON, edge 
topology should have been shared\n");
+           bu_bomb("class_eu_vs_s(): classifier found edge midpoint ON, edge 
topology should have been shared\n");
 #endif
        } else {
-           bu_log("class=%s\n", nmg_class_name(class));
-           nmg_euprint("Why wasn't this edge in or out?", eu);
-           bu_bomb("class_eu_vs_s: nmg_class_pt_s() midpoint failure\n");
+           bu_log("class_eu_vs_s(): class=%s\n", nmg_class_name(class));
+           nmg_euprint("class_eu_vs_s(): Why wasn't this edge in or out?", eu);
+           bu_bomb("class_eu_vs_s(): nmg_class_pt_s() midpoint failure\n");
        }
        goto out;
     }
@@ -1125,9 +1218,10 @@
        status = INSIDE;
        goto out;
     }
-    bu_log("eu's vert is %s, mate's vert is %s\n",
+    bu_log("class_eu_vs_s(): eu's vert is %s, mate's vert is %s\n",
           nmg_class_status(euv_cl), nmg_class_status(matev_cl));
-    bu_bomb("class_eu_vs_s() inconsistent edgeuse\n");
+    bu_bomb("class_eu_vs_s(): inconsistent edgeuse\n");
+
 out:
     if (rt_g.NMG_debug & DEBUG_GRAPHCL)
        nmg_show_broken_classifier_stuff((unsigned long *)eu, classlist, 
nmg_class_nothing_broken, 0, (char *)NULL);
@@ -1576,33 +1670,35 @@
                NMG_INDEX_SET(classlist[NMG_CLASS_AonBshared], lu->l_p);
                break;
            default:
-               bu_bomb("class_lu_vs_s: bad vertexloop classification\n");
+               bu_bomb("class_lu_vs_s(): bad vertexloop classification\n");
        }
        status = class;
        goto out;
     } else if (magic1 != NMG_EDGEUSE_MAGIC) {
-       bu_bomb("class_lu_vs_s: bad child of loopuse\n");
+       bu_bomb("class_lu_vs_s(): bad child of loopuse\n");
     }
 
     /* loop is collection of edgeuses */
+    seen_error = 0;
 retry:
     in = outside = on = 0;
     for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
        /* Classify each edgeuse */
        class = class_eu_vs_s(eu, s, classlist, tol);
        switch (class) {
-           case INSIDE : ++in;
+           case INSIDE         : ++in;
                break;
            case OUTSIDE        : ++outside;
                break;
            case ON_SURF        : ++on;
                break;
-           default             : bu_bomb("class_lu_vs_s: bad class for 
edgeuse\n");
+           default             : bu_bomb("class_lu_vs_s(): bad class for 
edgeuse\n");
        }
     }
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
        bu_log("class_lu_vs_s: Loopuse edges in:%d on:%d out:%d\n", in, on, 
outside);
+    }
 
     if (in > 0 && outside > 0) {
        FILE *fp;
@@ -1615,7 +1711,6 @@
 
            m = nmg_find_model(lu->up.magic_p);
            b = (long *)bu_calloc(m->maxindex, sizeof(long), "nmg_pl_lu 
flag[]");
-
            for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
                if (NMG_INDEX_TEST(classlist[NMG_CLASS_AinB], eu->e_p))
                    nmg_euprint("In:  edgeuse", eu);
@@ -1628,7 +1723,6 @@
                else
                    nmg_euprint("BAD: edgeuse", eu);
            }
-
            sprintf(buf, "badloop%d.pl", num++);
            if ((fp=fopen(buf, "wb")) != NULL) {
                nmg_pl_lu(fp, lu, b, 255, 255, 255);
@@ -1640,11 +1734,14 @@
            nmg_stash_model_to_file("class.g", nmg_find_model((unsigned long 
*)lu), "class_ls_vs_s: loop transits plane of shell/face?");
            bu_free((char *)b, "nmg_pl_lu flag[]");
        }
-       if (seen_error)
-           bu_bomb("class_lu_vs_s: loop transits plane of shell/face?\n");
-       seen_error = 1;
+
+       if (seen_error > 3) {
+           bu_bomb("class_lu_vs_s(): loop transits plane of shell/face?\n");
+       }
+       seen_error++;
        goto retry;
     }
+
     if (outside > 0) {
        NMG_INDEX_SET(classlist[NMG_CLASS_AoutB], lu->l_p);
        reason = "edgeuses were OUT and ON";
@@ -1657,13 +1754,14 @@
        class = NMG_CLASS_AinB;
        status = INSIDE;
        goto out;
-    } else if (on == 0)
-       bu_bomb("class_lu_vs_s: alright, who's the wiseguy that stole my 
edgeuses?\n");
+    } else if (on == 0) {
+       bu_bomb("class_lu_vs_s(): missing edgeuses\n");
+    }
 
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
+       bu_log("class_lu_vs_s(): All edgeuses of loop are ON\n");
+    }
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
-       bu_log("\tAll edgeuses of loop are ON\n");
-
     /* since all of the edgeuses of this loop are "on" the other shell,
      * we need to see if this loop is "on" the other shell
      *
@@ -1706,35 +1804,52 @@
        /* if the radial edge is a part of a loop which is part of
         * a face, then it's one that we might be "on"
         */
-       if (*eu->up.magic_p != NMG_LOOPUSE_MAGIC) continue;
+       if (*eu->up.magic_p != NMG_LOOPUSE_MAGIC) {
+           continue;
+       }
+
        q_lu = eu->up.lu_p;
-       if (*q_lu->up.magic_p != NMG_FACEUSE_MAGIC) continue;
+       if (*q_lu->up.magic_p != NMG_FACEUSE_MAGIC) {
+           continue;
+       }
+
        fu_qlu = q_lu->up.fu_p;
        NMG_CK_FACEUSE(fu_qlu);
 
-       if (q_lu == lu) continue;
+       if (q_lu == lu) {
+           continue;
+       }
 
        /* Only consider faces from shell 's' */
-       if (q_lu->up.fu_p->s_p != s) continue;
+       if (q_lu->up.fu_p->s_p != s) {
+           continue;
+       }
 
-       if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+       if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
            bu_log("\tfound radial lu (x%x), check for match\n", q_lu);
+       }
 
        /* now check if eu's match in both LU's */
        eu1 = BU_LIST_FIRST(edgeuse, &lu->down_hd);
-       if (eu1->vu_p->v_p == eu->vu_p->v_p)
+       if (eu1->vu_p->v_p == eu->vu_p->v_p) {
+            /* true when eu1-lu and eu-lu are opposite i.e. cw -vs- ccw */
            eu2 = eu;
-       else if (eu1->vu_p->v_p == eu->eumate_p->vu_p->v_p)
+       } else if (eu1->vu_p->v_p == eu->eumate_p->vu_p->v_p) {
+            /* true when eu1-lu and eu-lu are same i.e. cw or ccw */
            eu2 = BU_LIST_PNEXT_CIRC(edgeuse, &eu->l);
-       else
+       } else {
            eu2 = BU_LIST_PPREV_CIRC(edgeuse, &eu->l);
+        }
+
        found_match = 1;
        do {
-           if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+           if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                bu_log("\t\tcompare vertex x%x to vertex x%x\n", 
eu1->vu_p->v_p, eu2->vu_p->v_p);
+           }
            if (eu1->vu_p->v_p != eu2->vu_p->v_p) {
-               if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+               if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                    bu_log("\t\t\tnot a match\n");
+               }
                found_match = 0;
                break;
            }
@@ -1744,15 +1859,18 @@
 
        if (!found_match) {
            /* check opposite direction */
-           if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+           if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                bu_log("\tChecking for match in opposite direction\n");
+           }
            eu1 = BU_LIST_FIRST(edgeuse, &lu->down_hd);
-           if (eu1->vu_p->v_p == eu->vu_p->v_p)
+           if (eu1->vu_p->v_p == eu->vu_p->v_p) {
                eu2 = eu;
-           else if (eu1->vu_p->v_p == eu->eumate_p->vu_p->v_p)
+           } else if (eu1->vu_p->v_p == eu->eumate_p->vu_p->v_p) {
                eu2 = BU_LIST_PNEXT_CIRC(edgeuse, &eu->l);
-           else
+           } else {
                eu2 = BU_LIST_PPREV_CIRC(edgeuse, &eu->l);
+           }
+
            found_match = 1;
            do {
                if (rt_g.NMG_debug & DEBUG_CLASSIFY)
@@ -1771,43 +1889,48 @@
        if (found_match) {
            int test_class = NMG_CLASS_Unknown;
 
-           if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+           if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                bu_log("\tFound a matching LU's x%x and x%x\n", lu, q_lu);
+           }
 
-           if (fu_qlu->orientation == OT_SAME)
+           if (fu_qlu->orientation == OT_SAME) {
                test_class = class_shared_lu(lu, q_lu, tol);
-           else if (fu_qlu->orientation == OT_OPPOSITE)
+           } else if (fu_qlu->orientation == OT_OPPOSITE) {
                test_class = class_shared_lu(lu, q_lu->lumate_p, tol);
-           else {
+           } else {
                bu_log("class_lu_vs_s: FU x%x for lu x%x matching lu x%x has 
bad orientation (%s)\n",
                       fu_qlu, lu, q_lu, nmg_orientation(fu_qlu->orientation));
                bu_bomb("class_lu_vs_s: FU has bad orientation\n");
            }
 
-           if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+           if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                bu_log("\tclass_shared_lu says %s\n", 
nmg_class_name(test_class));
+           }
 
-           if (class == NMG_CLASS_Unknown)
+           if (class == NMG_CLASS_Unknown) {
                class = test_class;
-           else if (test_class == NMG_CLASS_AonBshared || test_class == 
NMG_CLASS_AonBanti)
+           } else if (test_class == NMG_CLASS_AonBshared || test_class == 
NMG_CLASS_AonBanti) {
                class = test_class;
+           }
 
-           if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+           if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                bu_log("\tclass set to %s\n",  nmg_class_name(class));
+           }
 
-           if (class == NMG_CLASS_AonBshared)
+           if (class == NMG_CLASS_AonBshared) {
                break;
+           }
        }
-
     }
 
     if (class != NMG_CLASS_Unknown) {
-       if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+       if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
            bu_log("Final class = %s\n", nmg_class_name(class));
+       }
        NMG_INDEX_SET(classlist[class], lu->l_p);
-       if (class == NMG_CLASS_AonBanti)
+       if (class == NMG_CLASS_AonBanti) {
            nmg_reclassify_lu_eu(lu, classlist, NMG_CLASS_AonBanti);
-
+       }
        reason = "edges identical with radial face";
        status = ON_SURF;
        goto out;
@@ -1828,7 +1951,6 @@
     }
 
     for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
-
        p = eu->radial_p;
        do {
            if (*p->up.magic_p == NMG_LOOPUSE_MAGIC &&
@@ -1836,48 +1958,51 @@
                p->up.lu_p->up.fu_p->s_p == s) {
 
                if (p->up.lu_p->up.fu_p->orientation == OT_OPPOSITE) {
-                   NMG_INDEX_SET(classlist[NMG_CLASS_AinB],
-                                 lu->l_p);
-                   if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+                   NMG_INDEX_SET(classlist[NMG_CLASS_AinB], lu->l_p);
+                   if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                        bu_log("Loop is INSIDE of fu x%x\n", 
p->up.lu_p->up.fu_p);
+                   }
                    reason = "radial faceuse is OT_OPPOSITE";
                    class = NMG_CLASS_AinB;
                    status = INSIDE;
                    goto out;
                } else if (p->up.lu_p->up.fu_p->orientation == OT_SAME) {
-                   NMG_INDEX_SET(classlist[NMG_CLASS_AoutB],
-                                 lu->l_p);
-                   if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+                   NMG_INDEX_SET(classlist[NMG_CLASS_AoutB], lu->l_p);
+                   if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
                        bu_log("Loop is OUTSIDEof fu x%x\n", 
p->up.lu_p->up.fu_p);
+                   }
                    reason = "radial faceuse is OT_SAME";
                    class = NMG_CLASS_AoutB;
                    status = OUTSIDE;
                    goto out;
                } else {
-                   bu_bomb("class_lu_vs_s() bad fu orientation\n");
+                   bu_bomb("class_lu_vs_s(): bad fu orientation\n");
                }
            }
            p = p->eumate_p->radial_p;
        } while (p != eu->eumate_p);
-
     }
 
-    if (rt_g.NMG_debug & DEBUG_CLASSIFY)
+    if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
        bu_log("Loop is OUTSIDE 'cause it isn't anything else\n");
+    }
 
     /* Since we didn't find any radial faces to classify ourselves against
      * and we already know that the edges are all "on" that must mean that
      * the loopuse is "on" a wireframe portion of the shell.
      */
+
     NMG_INDEX_SET(classlist[NMG_CLASS_AoutB], lu->l_p);
     reason = "loopuse is ON a wire loop in the shell";
     class = NMG_CLASS_AoutB;
     status = OUTSIDE;
+
 out:
     if (rt_g.NMG_debug & DEBUG_CLASSIFY) {
        bu_log("class_lu_vs_s(lu=x%x) return %s (%s) because %s\n",
               lu, nmg_class_status(status), nmg_class_name(class), reason);
     }
+
     return status;
 }
 


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

------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to