Revision: 73120
          http://sourceforge.net/p/brlcad/code/73120
Author:   starseeker
Date:     2019-05-21 20:43:06 +0000 (Tue, 21 May 2019)
Log Message:
-----------
Try to be more selective about normal averaging

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/cdt.cpp
    brlcad/trunk/src/libbrep/cdt_edge.cpp
    brlcad/trunk/src/libbrep/cdt_surf.cpp

Modified: brlcad/trunk/src/libbrep/cdt.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt.cpp    2019-05-21 20:22:44 UTC (rev 73119)
+++ brlcad/trunk/src/libbrep/cdt.cpp    2019-05-21 20:43:06 UTC (rev 73120)
@@ -392,6 +392,7 @@
     if (!s_cdt->w3dnorms->size()) {
        for (int index = 0; index < brep->m_V.Count(); index++) {
            ON_BrepVertex& v = brep->m_V[index];
+           int have_calculated = 0;
            ON_3dVector vnrml(0.0, 0.0, 0.0);
 
            for (int eind = 0; eind != v.EdgeCount(); eind++) {
@@ -399,6 +400,10 @@
                ON_3dVector trim1_norm = ON_3dVector::UnsetVector;
                ON_3dVector trim2_norm = ON_3dVector::UnsetVector;
                ON_BrepEdge& edge = brep->m_E[v.m_ei[eind]];
+               if (edge.TrimCount() != 2) {
+                   // Don't know what to do with this yet... skip.
+                   continue;
+               }
                ON_BrepTrim *trim1 = edge.Trim(0);
                ON_BrepTrim *trim2 = edge.Trim(1);
                ON_Interval t1range = trim1->Domain();
@@ -413,15 +418,37 @@
                    if (trim1->Face()->m_bRev) {
                        trim1_norm = trim1_norm * -1;
                    }
-                   vnrml += trim1_norm;
                }
                if (surface_EvNormal(s2, t2_2d.x, t2_2d.y, tmp2, trim2_norm)) {
                    if (trim2->Face()->m_bRev) {
                        trim2_norm = trim2_norm * -1;
                    }
+               }
+
+               // Want the angle between the two faces to not be "sharp" - if
+               // it is, we don't want to use the average, since that will
+               // tend to introduce visual artifacts at the vertex.
+               //
+               // TODO - come up with a strategy to allow a fallback to this
+               // anyway if the surface is just giving nonsense answers at the
+               // edge...
+               if (trim1_norm == ON_3dVector::UnsetVector) {
+                   continue;
+               }
+               if (trim2_norm == ON_3dVector::UnsetVector) {
+                   continue;
+               }
+               if (ON_DotProduct(trim1_norm, trim2_norm) > 0.5) {
+                   vnrml += trim1_norm;
                    vnrml += trim2_norm;
+                   have_calculated = 1;
+               } else {
+                   continue;
                }
            }
+           if (!have_calculated) {
+               continue;
+           }
            vnrml.Unitize();
 
            // We store this as a point to keep C++ happy...  If we try to
@@ -997,10 +1024,6 @@
                s_cdt->face_degen_pnts[face_index]->insert(p2_B);
                s_cdt->face_degen_pnts[face_index]->insert(p2_C);
 
-               if (face_index == 521) {
-                   bu_log("Have zero area tri in face %d\n", face_index);
-               }
-
                /* If we have degeneracies along an edge, the impact is not
                 * local to this face but will also impact the other face.
                 * Find it and let it know.(probably need another map - 3d pnt
@@ -1116,9 +1139,6 @@
                }
            }
            if (involved_pnt_cnt > 1) {
-               if (face_index == 521) {
-                   bu_log("Have involved triangle in face %d\n", face_index);
-               }
 
                // TODO - construct the plane of this face, project 3D points
                // into that plane to get new 2D coordinates specific to this
@@ -1203,9 +1223,6 @@
                        double t1, t2;
                        eline3d.ClosestPointTo(*op1, &t1);
                        eline3d.ClosestPointTo(*op2, &t2);
-                       if (face_index == 521) {
-                        bu_log("involved tri edge(%f,%f): %f %f %f -> %f %f 
%f\n", t1, t2, op1->x, op1->y, op1->z, op2->x, op2->y, op2->z);
-                       }
                        std::set<p2t::Point *>::iterator fdp_it;
                        for (fdp_it = fdp->begin(); fdp_it != fdp->end(); 
fdp_it++) {
                            p2t::Point *p = *fdp_it;
@@ -1216,9 +1233,6 @@
                                        double tp;
                                        eline3d.ClosestPointTo(*p3d, &tp);
                                        if (tp > t1 && tp < t2) {
-                                           if (face_index == 521) {
-                                               bu_log("point on tri 
edge(%f,%f): %f %f %f (%f)\n", t1, t2, p3d->x, p3d->y, p3d->z, tp);
-                                           }
                                            edge_3d_pnts.insert(p3d);
                                            ordered_new_pnts[tp] = p3d;
                                            double u,v;
@@ -1236,10 +1250,6 @@
                                            old2d_to_new2d[p] = np;
                                            on3d_to_new2d[p3d] = np;
 
-                                       } else {
-                                           if (face_index == 521) {
-                                               bu_log("point on tri line but 
not on edge(%f,%f): %f %f %f (%f)\n", t1, t2, p3d->x, p3d->y, p3d->z, tp);
-                                           }
                                        }
                                    }
                                }
@@ -1326,19 +1336,7 @@
                        }
 
                    } else {
-                       if (face_index == 521) {
-                           bu_log("ec triangulate found %d faces\n", 
num_faces);
-                       }
                        for (int k = 0; k < num_faces; k++) {
-                           if (face_index == 521) {
-                               bu_log("tri[%d]: %d -> %d -> %d\n", k, 
ecfaces[3*k], ecfaces[3*k+1], ecfaces[3*k+2]);
-                               bu_log("tri[%d]: %f %f -> %f %f -> %f %f\n", k, 
ec_pnts[ecfaces[3*k]][X], ec_pnts[ecfaces[3*k]][Y], ec_pnts[ecfaces[3*k+1]][X], 
ec_pnts[ecfaces[3*k+1]][Y], ec_pnts[ecfaces[3*k+2]][X], 
ec_pnts[ecfaces[3*k+2]][Y]);
-                               ON_3dPoint *p1 = 
(*pointmap)[new2d_to_old2d[ec_to_p2t[ecfaces[3*k]]]];
-                               ON_3dPoint *p2 = 
(*pointmap)[new2d_to_old2d[ec_to_p2t[ecfaces[3*k+1]]]];
-                               ON_3dPoint *p3 = 
(*pointmap)[new2d_to_old2d[ec_to_p2t[ecfaces[3*k+2]]]];
-                               bu_log("tri[%d]: %f %f %f -> %f %f %f -> %f %f 
%f\n", k, p1->x, p1->y, p1->z, p2->x, p2->y, p2->z, p3->x, p3->y, p3->z);
-                           }
-
                            p2t::Point *p2_1 = 
new2d_to_old2d[ec_to_p2t[ecfaces[3*k]]];
                            p2t::Point *p2_2 = 
new2d_to_old2d[ec_to_p2t[ecfaces[3*k+1]]];
                            p2t::Point *p2_3 = 
new2d_to_old2d[ec_to_p2t[ecfaces[3*k+2]]];
@@ -1453,9 +1451,6 @@
                p2t::Point *p = t->GetPoint(j);
                ON_3dPoint *op = (*pointmap)[p];
                int ind = on_pnt_to_bot_pnt[op];
-               if (face_index == 521) {
-                   bu_log("tri[%d](%d)(%zu): %f %f %f -> %d\n", face_index, 
face_cnt, j, op->x, op->y, op->z, ind);
-               }
                (*faces)[face_cnt*3 + j] = ind;
                if (normals) {
                    int nind = on_pnt_to_bot_norm[op];

Modified: brlcad/trunk/src/libbrep/cdt_edge.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_edge.cpp       2019-05-21 20:22:44 UTC (rev 
73119)
+++ brlcad/trunk/src/libbrep/cdt_edge.cpp       2019-05-21 20:43:06 UTC (rev 
73120)
@@ -376,10 +376,11 @@
        if (trim.Face()->m_bRev) {
            trim1_start_normal = trim1_start_normal  * -1.0;
        }
-       if (ON_DotProduct(trim1_start_normal, *edge_start_3dnorm) < 0) {
+       if (edge_start_3dnorm && ON_DotProduct(trim1_start_normal, 
*edge_start_3dnorm) < -0.5) {
            t1_sn = edge_start_3dnorm;
        } else {
            t1_sn = new ON_3dPoint(trim1_start_normal);
+           *t1_sn = trim1_start_normal;
            s_cdt->w3dnorms->push_back(t1_sn);
        }
     }
@@ -389,10 +390,11 @@
        if (trim.Face()->m_bRev) {
            trim1_end_normal = trim1_end_normal  * -1.0;
        }
-       if (ON_DotProduct(trim1_end_normal, *edge_end_3dnorm) < 0) {
+       if (edge_end_3dnorm && ON_DotProduct(trim1_end_normal, 
*edge_end_3dnorm) < -0.5) {
            t1_en = edge_end_3dnorm;
        } else {
            t1_en = new ON_3dPoint(trim1_end_normal);
+           *t1_en = trim1_end_normal;
            s_cdt->w3dnorms->push_back(t1_en);
        }
     }
@@ -405,10 +407,11 @@
        if (trim2->Face()->m_bRev) {
            trim2_start_normal = trim2_start_normal  * -1.0;
        }
-       if (ON_DotProduct(trim2_start_normal, *edge_start_3dnorm) < 0) {
+       if (edge_start_3dnorm && ON_DotProduct(trim2_start_normal, 
*edge_start_3dnorm) < -0.5) {
            t2_sn = edge_start_3dnorm;
        } else {
            t2_sn = new ON_3dPoint(trim2_start_normal);
+           *t2_sn = trim2_start_normal;
            s_cdt->w3dnorms->push_back(t2_sn);
        }
     }
@@ -418,10 +421,11 @@
        if (trim2->Face()->m_bRev) {
            trim2_end_normal = trim2_end_normal  * -1.0;
        }
-       if (ON_DotProduct(trim2_end_normal, *edge_end_3dnorm) < 0) {
+       if (edge_end_3dnorm && ON_DotProduct(trim2_end_normal, 
*edge_end_3dnorm) < -0.5) {
            t2_en = edge_end_3dnorm;
        } else {
            t2_en = new ON_3dPoint(trim2_end_normal);
+           *t2_en = trim2_end_normal;
            s_cdt->w3dnorms->push_back(t2_en);
        }
     }

Modified: brlcad/trunk/src/libbrep/cdt_surf.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_surf.cpp       2019-05-21 20:22:44 UTC (rev 
73119)
+++ brlcad/trunk/src/libbrep/cdt_surf.cpp       2019-05-21 20:43:06 UTC (rev 
73120)
@@ -309,7 +309,8 @@
        V_MAX(dist, mid.DistanceTo(line2.ClosestPointTo(mid)));
        
        for (int i = 0; i < 4; i++) {
-           if (ON_DotProduct(norm[i], norm_mid) < 0) {
+           double nnm_dot = ON_DotProduct(norm[i], norm_mid);
+           if ((nnm_dot < ON_ZERO_TOLERANCE) && (fabs(nnm_dot) > 
ON_ZERO_TOLERANCE)) {
                fastf_t uc = (i == 0 || i == 3) ? u1 : u2;
                fastf_t vc = (i == 0 || i == 1) ? v1 : v2;
                bu_log("norm[%d](%f %f %f) backwards at %d point %f,%f\n", i, 
norm[i].x, norm[i].y, norm[i].z, i, uc, vc);

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



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to