Revision: 64329
          http://sourceforge.net/p/brlcad/code/64329
Author:   starseeker
Date:     2015-03-02 21:51:29 +0000 (Mon, 02 Mar 2015)
Log Message:
-----------
More boolean logic - no where near done, but looks like it is heading in the 
right direction.

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

Modified: brlcad/trunk/src/libbrep/shape_recognition_cone.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-02 21:26:53 UTC 
(rev 64328)
+++ brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-02 21:51:29 UTC 
(rev 64329)
@@ -8,7 +8,34 @@
 #include "bu/malloc.h"
 #include "shape_recognition.h"
 
+/* Return -1 if the cone face is pointing in toward the axis,
+ * 1 if it is pointing out, and 0 if there is some other problem */
+int
+negative_cone(struct subbrep_object_data *data, int face_index, double 
cone_tol) {
+    int ret = 0;
+    const ON_Surface *surf = data->brep->m_F[face_index].SurfaceOf();
+    ON_Cone cone;
+    ON_Surface *cs = surf->Duplicate();
+    cs->IsCone(&cone, cone_tol);
+    delete cs;
 
+    ON_3dPoint pnt;
+    ON_3dVector normal;
+    double u = surf->Domain(0).Mid();
+    double v = surf->Domain(1).Mid();
+    if (!surf->EvNormal(u, v, pnt, normal)) return 0;
+    ON_3dPoint base_pnt = cone.BasePoint();
+
+    ON_3dVector base_vect = pnt - base_pnt;
+    double dotp = ON_DotProduct(base_vect, normal);
+
+    if (NEAR_ZERO(dotp, 0.000001)) return 0;
+    ret = (dotp < 0) ? -1 : 1;
+    if (data->brep->m_F[face_index].m_bRev) ret = -1 * ret;
+    return ret;
+}
+
+
 int
 subbrep_is_cone(struct subbrep_object_data *data, fastf_t cone_tol)
 {
@@ -115,7 +142,25 @@
 
     ON_3dVector hvect(cone.ApexPoint() - cone.BasePoint());
 
-    data->params->bool_op = 'u';  //TODO - not always a union - need to 
determine positive/negative
+    int negative = negative_cone(data, *conic_surfaces.begin(), cone_tol);
+    bu_log("conic negative: %d\n", negative);
+    bu_log("parent boolean: %c\n", data->parent->params->bool_op);
+
+    if (data->parent->params->bool_op == '-') negative = -1 * negative;
+
+    switch (negative) {
+       case -1:
+           data->params->bool_op = '-';
+           break;
+       case 1:
+           data->params->bool_op = 'u';
+           break;
+       default:
+           std::cout << "Could not determine cone status???????\n";
+           data->params->bool_op = 'u';
+           break;
+    }
+
     data->params->origin[0] = cone.BasePoint().x;
     data->params->origin[1] = cone.BasePoint().y;
     data->params->origin[2] = cone.BasePoint().z;
@@ -224,7 +269,26 @@
        ON_3dPoint closest_to_base = 
set1_c.Plane().ClosestPointTo(cone.BasePoint());
        struct csg_object_params * obj;
         BU_GET(obj, struct csg_object_params);
-       data->params->bool_op = 'u';  //TODO - not always a union - need to 
determine positive/negative
+
+       int negative = negative_cone(data, *conic_surfaces.begin(), cone_tol);
+       bu_log("conic negative: %d\n", negative);
+       bu_log("parent boolean: %c\n", data->parent->params->bool_op);
+
+       if (data->parent->params->bool_op == '-') negative = -1 * negative;
+
+       switch (negative) {
+           case -1:
+               data->params->bool_op = '-';
+               break;
+           case 1:
+               data->params->bool_op = 'u';
+               break;
+           default:
+               std::cout << "Could not determine cone status???????\n";
+               data->params->bool_op = 'u';
+               break;
+       }
+
        data->params->origin[0] = closest_to_base.x;
        data->params->origin[1] = closest_to_base.y;
        data->params->origin[2] = closest_to_base.z;

Modified: brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-02 
21:26:53 UTC (rev 64328)
+++ brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp     2015-03-02 
21:51:29 UTC (rev 64329)
@@ -555,14 +555,23 @@
            //std::cout << "Full cylinder\n";
            data->type = CYLINDER;
 
-           // TODO - the surface negative test may not be enough on its own - 
needs
-           // more thought
-           if (negative == -1) {
-               data->params->bool_op = '-';
+           bu_log("parent boolean: %c\n", data->parent->params->bool_op);
+
+           if (data->parent->params->bool_op == '-') negative = -1 * negative;
+
+           switch (negative) {
+               case -1:
+                   data->params->bool_op = '-';
+                   break;
+               case 1:
+                   data->params->bool_op = 'u';
+                   break;
+               default:
+                   std::cout << "Could not determine cylinder status???????\n";
+                   data->params->bool_op = 'u';
+                   break;
            }
-           if (negative == 1) {
-               data->params->bool_op = 'u';
-           }
+
            data->params->origin[0] = set1_c.Center().x;
            data->params->origin[1] = set1_c.Center().y;
            data->params->origin[2] = set1_c.Center().z;

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