Revision: 64350
          http://sourceforge.net/p/brlcad/code/64350
Author:   starseeker
Date:     2015-03-09 18:01:00 +0000 (Mon, 09 Mar 2015)
Log Message:
-----------
refactor corner finding logic out of cyl into util, and have cone do the check. 
 Still need to handle partials when found.

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

Modified: brlcad/trunk/src/libbrep/shape_recognition.h
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.h        2015-03-09 17:09:38 UTC 
(rev 64349)
+++ brlcad/trunk/src/libbrep/shape_recognition.h        2015-03-09 18:01:00 UTC 
(rev 64350)
@@ -158,6 +158,10 @@
 void map_to_array(int **array, int *array_cnt, std::map<int,int> *map);
 void array_to_map(std::map<int,int> *map, int *array, int array_cnt);
 
+int
+subbrep_find_corners(struct subbrep_object_data *data, int 
**corner_verts_array, ON_Plane *pcyl);
+
+
 #endif /* SHAPE_RECOGNITION_H */
 
 // Local Variables:

Modified: brlcad/trunk/src/libbrep/shape_recognition_cone.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-09 17:09:38 UTC 
(rev 64349)
+++ brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-09 18:01:00 UTC 
(rev 64350)
@@ -302,6 +302,18 @@
 
     } else {
 
+       int *corner_verts_array = NULL;
+       ON_Plane pcyl;
+       std::set<int> corner_verts; /* verts with one nonlinear edge */
+       int corner_verts_cnt = subbrep_find_corners(data, &corner_verts_array, 
&pcyl);
+
+       if (corner_verts_cnt == -1) return 0;
+       if (corner_verts_cnt > 0) {
+           array_to_set(&corner_verts, corner_verts_array, corner_verts_cnt);
+           bu_free(corner_verts_array, "free tmp array");
+           bu_log("Found partial TGC!\n");
+       }
+
        ON_3dPoint base = set1_c.Center();
        ON_3dVector hvect = set2_c.Center() - set1_c.Center();
        struct csg_object_params * obj;

Modified: brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-09 
17:09:38 UTC (rev 64349)
+++ brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-09 
18:01:00 UTC (rev 64350)
@@ -394,100 +394,18 @@
     // vertex points, which are not removed by the subtraction.
     //
     // Until such cases can be resolved, any curve complications of
-    // this sort are a conversion blocker.  To make sure the supplied
-    // inputs are cases that can be handled, we collect all of the
-    // vertices in the data that are connected to one and only one
-    // non-linear edge in the set.  Failure cases are:
-    //
-    // * More than four vertices that are mated with exactly one
-    //   non-linear edge in the data set
-    // * Four vertices meeting previous criteria that are non-planar
-    // * Any vertex on a linear edge that is not coplanar with the
-    //   plane described by the vertices meeting the above criteria
-    std::set<int> candidate_verts;
+    // this sort are a conversion blocker.
+    int *corner_verts_array = NULL;
+    ON_Plane pcyl;
     std::set<int> corner_verts; /* verts with one nonlinear edge */
-    std::set<int> linear_verts; /* verts with only linear edges */
-    std::set<int>::iterator v_it, e_it;
-    std::set<int> edges;
-    array_to_set(&edges, data->edges, data->edges_cnt);
-    // collect all candidate vertices
-    for (int i = 0; i < data->edges_cnt; i++) {
-       int ei = data->edges[i];
-       const ON_BrepEdge *edge = &(data->brep->m_E[ei]);
-       candidate_verts.insert(edge->Vertex(0)->m_vertex_index);
-       candidate_verts.insert(edge->Vertex(1)->m_vertex_index);
-    }
-    for (v_it = candidate_verts.begin(); v_it != candidate_verts.end(); 
v_it++) {
-       const ON_BrepVertex *vert = &(data->brep->m_V[*v_it]);
-       int curve_cnt = 0;
-       int line_cnt = 0;
-       for (int i = 0; i < vert->m_ei.Count(); i++) {
-           int ei = vert->m_ei[i];
-           const ON_BrepEdge *edge = &(data->brep->m_E[ei]);
-           if (edges.find(edge->m_edge_index) != edges.end()) {
-               ON_Curve *ecv = edge->EdgeCurveOf()->Duplicate();
-               if (ecv->IsLinear()) {
-                   line_cnt++;
-               } else {
-                   curve_cnt++;
-               }
-               delete ecv;
-           }
-       }
-       if (curve_cnt == 1) {
-           corner_verts.insert(*v_it);
-           //std::cout << "found corner vert: " << *v_it << "\n";
-       }
-       if (line_cnt > 1 && curve_cnt == 0) {
-           linear_verts.insert(*v_it);
-           std::cout << "found linear vert: " << *v_it << "\n";
-       }
-    }
+    int corner_verts_cnt = subbrep_find_corners(data, &corner_verts_array, 
&pcyl);
 
-    // First, check corner count
-    if (corner_verts.size() > 4) {
-       std::cout << "more than 4 corners - complex\n";
-       return 0;
+    if (corner_verts_cnt == -1) return 0;
+    if (corner_verts_cnt > 0) {
+       array_to_set(&corner_verts, corner_verts_array, corner_verts_cnt);
+       bu_free(corner_verts_array, "free tmp array");
     }
 
-    // Second, create the candidate face plane.  Verify coplanar status of 
points if we've got 4.
-    ON_Plane pcyl;
-    if (corner_verts.size() == 4) {
-       std::set<int>::iterator s_it = corner_verts.begin();
-       ON_3dPoint p1 = data->brep->m_V[*s_it].Point();
-       s_it++;
-       ON_3dPoint p2 = data->brep->m_V[*s_it].Point();
-       s_it++;
-       ON_3dPoint p3 = data->brep->m_V[*s_it].Point();
-       s_it++;
-       ON_3dPoint p4 = data->brep->m_V[*s_it].Point();
-       ON_Plane tmp_plane(p1, p2, p3);
-       if (tmp_plane.DistanceTo(p4) > BREP_PLANAR_TOL) {
-           std::cout << "planar tol fail\n";
-           return 0;
-       } else {
-           pcyl = tmp_plane;
-       }
-    } else {
-       // TODO - If we have less than four corner points and no additional 
curve planes, we
-       // must have a face subtraction that tapers to a point at the edge of 
the
-       // cylinder.  Pull the linear edges from the two corner points to find 
the third point -
-       // this is a situation where a simpler arb (arb6?) is adequate to make 
the subtraction.
-    }
-
-    // Third, if we had vertices with only linear edges, check to make sure 
they are in fact
-    // on the candidate plane for the face (if not, we've got something more 
complex going on).
-    if (linear_verts.size() > 0) {
-       std::set<int>::iterator s_it;
-       for (s_it = linear_verts.begin(); s_it != linear_verts.end(); s_it++) {
-           ON_3dPoint pnt = data->brep->m_V[*s_it].Point();
-           if (pcyl.DistanceTo(pnt) > BREP_PLANAR_TOL) {
-               std::cout << "stray verts fail\n";
-               return 0;
-           }
-       }
-    }
-
     // Check if the two circles are parallel to each other.  If they are, and 
we have
     // no corner points, then we have a complete cylinder
     if (cyl_planes.Count() == 2 && 
cyl_planes[0].Normal().IsParallelTo(cyl_planes[1].Normal(), 0.1/*cyl_tol*/) != 
0 && cyl_planes[0].Normal().IsParallelTo(cylinder.Axis(), 0.1/*cyl_tol*/) != 0) 
{

Modified: brlcad/trunk/src/libbrep/shape_recognition_util.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-09 17:09:38 UTC 
(rev 64349)
+++ brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-09 18:01:00 UTC 
(rev 64350)
@@ -465,6 +465,116 @@
    if (neg_cnt) return -1;
 }
 
+/* Find corners that can be used to construct a planar face
+ *
+ * Collect all of the vertices in the data that are connected
+ * to one and only one non-linear edge in the set.
+ *
+ * Failure cases are:
+ *
+ * More than four vertices that are mated with exactly one
+ * non-linear edge in the data set
+ * Four vertices meeting previous criteria that are non-planar
+ * Any vertex on a linear edge that is not coplanar with the
+ * plane described by the vertices meeting the above criteria
+ *
+ * return -1 if failed, number of corner verts if successful
+ */
+int
+subbrep_find_corners(struct subbrep_object_data *data, int 
**corner_verts_array, ON_Plane *pcyl)
+{
+    std::set<int> candidate_verts;
+    std::set<int> corner_verts;
+    std::set<int> linear_verts;
+    std::set<int>::iterator v_it, e_it;
+    std::set<int> edges;
+    if (!data || !corner_verts_array || !pcyl) return -1;
+    array_to_set(&edges, data->edges, data->edges_cnt);
+    // collect all candidate vertices
+    for (int i = 0; i < data->edges_cnt; i++) {
+       int ei = data->edges[i];
+       const ON_BrepEdge *edge = &(data->brep->m_E[ei]);
+       candidate_verts.insert(edge->Vertex(0)->m_vertex_index);
+       candidate_verts.insert(edge->Vertex(1)->m_vertex_index);
+    }
+    for (v_it = candidate_verts.begin(); v_it != candidate_verts.end(); 
v_it++) {
+        const ON_BrepVertex *vert = &(data->brep->m_V[*v_it]);
+        int curve_cnt = 0;
+        int line_cnt = 0;
+        for (int i = 0; i < vert->m_ei.Count(); i++) {
+            int ei = vert->m_ei[i];
+            const ON_BrepEdge *edge = &(data->brep->m_E[ei]);
+            if (edges.find(edge->m_edge_index) != edges.end()) {
+                ON_Curve *ecv = edge->EdgeCurveOf()->Duplicate();
+                if (ecv->IsLinear()) {
+                    line_cnt++;
+                } else {
+                    curve_cnt++;
+                }
+                delete ecv;
+            }
+        }
+        if (curve_cnt == 1) {
+            corner_verts.insert(*v_it);
+            //std::cout << "found corner vert: " << *v_it << "\n";
+        }
+        if (line_cnt > 1 && curve_cnt == 0) {
+            linear_verts.insert(*v_it);
+            std::cout << "found linear vert: " << *v_it << "\n";
+        }
+    }
+
+    // First, check corner count
+    if (corner_verts.size() > 4) {
+        std::cout << "more than 4 corners - complex\n";
+        return -1;
+    }
+    if (corner_verts.size() == 0) return 0;
+    // Second, create the candidate face plane.  Verify coplanar status of 
points if we've got 4.
+    std::set<int>::iterator s_it = corner_verts.begin();
+    ON_3dPoint p1 = data->brep->m_V[*s_it].Point();
+    s_it++;
+    ON_3dPoint p2 = data->brep->m_V[*s_it].Point();
+    s_it++;
+    ON_3dPoint p3 = data->brep->m_V[*s_it].Point();
+    ON_Plane tmp_plane(p1, p2, p3);
+    if (corner_verts.size() == 4) {
+        s_it++;
+        ON_3dPoint p4 = data->brep->m_V[*s_it].Point();
+        if (tmp_plane.DistanceTo(p4) > BREP_PLANAR_TOL) {
+            std::cout << "planar tol fail\n";
+            return -1;
+        } else {
+            (*pcyl) = tmp_plane;
+        }
+    } else {
+        // TODO - If we have less than four corner points and no additional 
curve planes, we
+        // must have a face subtraction that tapers to a point at the edge of 
the
+        // cylinder.  Pull the linear edges from the two corner points to find 
the third point -
+        // this is a situation where a simpler arb (arb6?) is adequate to make 
the subtraction.
+       (*pcyl) = tmp_plane;
+    }
+
+    // Third, if we had vertices with only linear edges, check to make sure 
they are in fact
+    // on the candidate plane for the face (if not, we've got something more 
complex going on).
+    if (linear_verts.size() > 0) {
+        std::set<int>::iterator ls_it;
+        for (ls_it = linear_verts.begin(); ls_it != linear_verts.end(); 
ls_it++) {
+            ON_3dPoint pnt = data->brep->m_V[*ls_it].Point();
+            if ((*pcyl).DistanceTo(pnt) > BREP_PLANAR_TOL) {
+                std::cout << "stray verts fail\n";
+                return -1;
+            }
+        }
+    }
+
+    // If we've made it here, package up the verts and return
+    int verts_cnt = 0;
+    if (corner_verts.size() > 0)
+       set_to_array(corner_verts_array, &verts_cnt, &corner_verts);
+    return verts_cnt;
+}
+
 // Local Variables:
 // tab-width: 8
 // mode: C++

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