Revision: 64328
http://sourceforge.net/p/brlcad/code/64328
Author: starseeker
Date: 2015-03-02 21:26:53 +0000 (Mon, 02 Mar 2015)
Log Message:
-----------
Getting close - cones aren't doing booleans right...
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
brlcad/trunk/src/librt/test_shape_recognition.cpp
Modified: brlcad/trunk/src/libbrep/shape_recognition.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.cpp 2015-03-02 17:14:38 UTC
(rev 64327)
+++ brlcad/trunk/src/libbrep/shape_recognition.cpp 2015-03-02 21:26:53 UTC
(rev 64328)
@@ -110,6 +110,25 @@
new_obj->is_island = 1;
new_obj->parent = NULL;
+ // Determine if this subset is being added to or taken from the
parent.
+ if (new_obj->fil_cnt > 0) {
+ int bool_op = subbrep_determine_boolean(new_obj);
+ if (bool_op == -1) {
+ std::cout << bu_vls_addr(new_obj->key) << " is
subtracted\n";
+ new_obj->params->bool_op = '-';
+ }
+ if (bool_op == 1) {
+ std::cout << bu_vls_addr(new_obj->key) << " is unioned\n";
+ new_obj->params->bool_op = 'u';
+ }
+ if (bool_op == 0) {
+ std::cout << "Error - ambiguous result for boolean test -
need to subdivide shape.\n";
+ }
+ } else {
+ std::cout << bu_vls_addr(new_obj->key) << " is unioned\n";
+ new_obj->params->bool_op = 'u';
+ }
+
surface_t hof = highest_order_face(new_obj);
if (hof >= SURFACE_GENERAL) {
new_obj->type = BREP;
Modified: brlcad/trunk/src/libbrep/shape_recognition.h
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.h 2015-03-02 17:14:38 UTC
(rev 64327)
+++ brlcad/trunk/src/libbrep/shape_recognition.h 2015-03-02 21:26:53 UTC
(rev 64328)
@@ -126,6 +126,9 @@
int subbrep_make_brep(struct subbrep_object_data *data);
int subbrep_make_planar(struct subbrep_object_data *data);
+int subbrep_determine_boolean(struct subbrep_object_data *data);
+
+
// Functions for defining a simplified planar subvolume
void subbrep_planar_init(struct subbrep_object_data *data);
void subbrep_planar_close_obj(struct subbrep_object_data *data);
Modified: brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp 2015-03-02
17:14:38 UTC (rev 64327)
+++ brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp 2015-03-02
21:26:53 UTC (rev 64328)
@@ -592,6 +592,10 @@
bu_log("partial cyl 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 = '-';
@@ -921,6 +925,10 @@
// is determined later.
int negative = negative_cylinder(data,
*cylindrical_surfaces.begin(), cyl_tol);
+ 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 = '-';
Modified: brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp 2015-03-02
17:14:38 UTC (rev 64327)
+++ brlcad/trunk/src/libbrep/shape_recognition_sphere.cpp 2015-03-02
21:26:53 UTC (rev 64328)
@@ -221,6 +221,11 @@
// is determined later.
int negative = negative_sphere(data, *spherical_surfaces.begin(),
sph_tol);
+ 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 = '-';
Modified: brlcad/trunk/src/libbrep/shape_recognition_util.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-02 17:14:38 UTC
(rev 64327)
+++ brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-02 21:26:53 UTC
(rev 64328)
@@ -6,6 +6,7 @@
#include "bu/log.h"
#include "bu/str.h"
#include "bu/malloc.h"
+#include "brep.h"
#include "shape_recognition.h"
curve_t
@@ -213,7 +214,7 @@
BU_GET(obj->children, struct bu_ptbl);
BU_GET(obj->params, struct csg_object_params);
obj->params->planes = NULL;
- obj->params->bool_op = 'u';
+ obj->params->bool_op = '\0';
obj->planar_obj = NULL;
bu_vls_init(obj->key);
bu_ptbl_init(obj->children, 8, "children table");
@@ -398,8 +399,74 @@
bu_vls_free(&log);
}
+/* This routine is used when there is uncertainty about whether a
+ * particular solid or combination is to be subtracted or unioned
+ * into a parent. For planar on planar cases, the check is whether every
+ * vertex of the candidate solid is either on or one of above/below
+ * the shared face plane. If some vertices are above and some
+ * are below, the candidate solid is self intersecting and must be
+ * further subdivided.
+ *
+ * For non-planar situations, we're probably looking at a surface
+ * surface intersection test. A possible test short of that might
+ * be vertices of bounding boxes, but that will result in situations
+ * reporting subdivision necessity when there isn't any unless we
+ * follow up with a more rigorous test. This needs more thought. */
+int
+subbrep_determine_boolean(struct subbrep_object_data *data)
+{
+ std::cout << "Faces to check: " << data->fil_cnt << "\n";
+ int pos_cnt = 0;
+ int neg_cnt = 0;
+ for (int i = 0; i < data->fil_cnt; i++) {
+ // Get face with inner loop
+ const ON_BrepFace *face = &(data->brep->m_F[data->fil[i]]);
+ const ON_Surface *surf = face->SurfaceOf();
+ surface_t stype = GetSurfaceType(surf, NULL);
+ ON_Plane face_plane;
+ if (stype == SURFACE_PLANE) {
+ ON_Surface *ts = surf->Duplicate();
+ (void)ts->IsPlanar(&face_plane, BREP_PLANAR_TOL);
+ delete ts;
+ }
+ std::set<int> verts;
+ for (int j = 0; j < data->edges_cnt; j++) {
+
verts.insert(data->brep->m_E[data->edges[j]].Vertex(0)->m_vertex_index);
+
verts.insert(data->brep->m_E[data->edges[j]].Vertex(1)->m_vertex_index);
+ }
+ for (std::set<int>::iterator s_it = verts.begin(); s_it != verts.end();
s_it++) {
+ // For each vertex in the subbrep, determine
+ // if it is above, below or on the face
+ if (stype == SURFACE_PLANE) {
+ ON_3dPoint p = data->brep->m_V[*s_it].Point();
+ double distance = face_plane.DistanceTo(p);
+ std::cout << "distance: " << distance << "\n";
+ if (distance > BREP_PLANAR_TOL) pos_cnt++;
+ if (distance < -1*BREP_PLANAR_TOL) neg_cnt++;
+ } else {
+ // TODO - this doesn't seem to work...
+ double current_distance = 0;
+ ON_3dPoint p = data->brep->m_V[*s_it].Point();
+ ON_3dPoint p3d;
+ ON_2dPoint p2d;
+ if
(surface_GetClosestPoint3dFirstOrder(surf,p,p2d,p3d,current_distance)) {
+ if (current_distance > 0.001) pos_cnt++;
+ } else {
+ neg_cnt++;
+ }
+ }
+ }
+ }
+ // Determine what we have. If we have both pos and neg counts > 0,
+ // the proposed brep needs to be broken down further. all pos
+ // counts is a union, all neg counts is a subtraction
+ if (pos_cnt && neg_cnt) return 0;
+ if (pos_cnt) return 1;
+ if (neg_cnt) return -1;
+}
+
// Local Variables:
// tab-width: 8
// mode: C++
Modified: brlcad/trunk/src/librt/test_shape_recognition.cpp
===================================================================
--- brlcad/trunk/src/librt/test_shape_recognition.cpp 2015-03-02 17:14:38 UTC
(rev 64327)
+++ brlcad/trunk/src/librt/test_shape_recognition.cpp 2015-03-02 21:26:53 UTC
(rev 64328)
@@ -312,7 +312,7 @@
struct bu_vls spacer = BU_VLS_INIT_ZERO;
for (int i = 0; i < depth; i++)
bu_vls_printf(&spacer, " ");
- std::cout << bu_vls_addr(&spacer) << "Making shape for " <<
bu_vls_addr(data->key) << "\n";
+ //std::cout << bu_vls_addr(&spacer) << "Making shape for " <<
bu_vls_addr(data->key) << "\n";
if (data->planar_obj && data->planar_obj->local_brep) {
struct bu_vls brep_name = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&brep_name, "planar_%s.s", bu_vls_addr(data->key));
@@ -338,17 +338,18 @@
bu_vls_sprintf(&comb_name, "comb_%s.c", bu_vls_addr(data->key));
BU_LIST_INIT(&wcomb.l);
if (data->planar_obj) {
- bu_log("%smake planar obj %s\n", bu_vls_addr(&spacer),
bu_vls_addr(data->key));
+ //bu_log("%smake planar obj %s\n", bu_vls_addr(&spacer),
bu_vls_addr(data->key));
process_params(data->planar_obj, wdbp, &wcomb);
}
- bu_log("make comb %s\n", bu_vls_addr(data->key));
+ //bu_log("make comb %s\n", bu_vls_addr(data->key));
for (unsigned int i = 0; i < BU_PTBL_LEN(data->children); i++){
struct subbrep_object_data *cdata = (struct subbrep_object_data
*)BU_PTBL_GET(data->children,i);
- std::cout << bu_vls_addr(&spacer) << "Making child shape " <<
bu_vls_addr(cdata->key) << " (" << cdata->type << "):\n";
+ //std::cout << bu_vls_addr(&spacer) << "Making child shape " <<
bu_vls_addr(cdata->key) << " (" << cdata->type << "):\n";
make_shapes(cdata, wdbp, &wcomb, depth+1);
subbrep_object_free(cdata);
}
mk_lcomb(wdbp, bu_vls_addr(&comb_name), &wcomb, 0, NULL, NULL,
NULL, 0);
+
// TODO - almost certainly need to do more work to get correct
booleans
if (pcomb) (void)mk_addmember(bu_vls_addr(&comb_name), &(pcomb->l),
NULL, db_str2op(&(data->params->bool_op)));
@@ -356,7 +357,7 @@
bu_vls_free(&comb_name);
} else {
//std::cout << "type: " << data->type << "\n";
- bu_log("%smake solid %s\n", bu_vls_addr(&spacer),
bu_vls_addr(data->key));
+ //bu_log("%smake solid %s\n", bu_vls_addr(&spacer),
bu_vls_addr(data->key));
process_params(data, wdbp, pcomb);
}
}
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