Revision: 64355
http://sourceforge.net/p/brlcad/code/64355
Author: starseeker
Date: 2015-03-10 15:12:17 +0000 (Tue, 10 Mar 2015)
Log Message:
-----------
Starting setting up to 'fall back' to brep creation if we can't successfully
handle a CSG representation. Doesn't generate completely correct results yet -
getting flipped normals and multithreaded raytracing hangs with the nist4
example for some reason.
Modified Paths:
--------------
brlcad/trunk/src/libbrep/shape_recognition.cpp
brlcad/trunk/src/libbrep/shape_recognition_cone.cpp
brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
brlcad/trunk/src/libbrep/shape_recognition_planar.cpp
brlcad/trunk/src/libbrep/shape_recognition_torus.cpp
brlcad/trunk/src/libbrep/shape_recognition_util.cpp
Modified: brlcad/trunk/src/libbrep/shape_recognition.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition.cpp 2015-03-10 00:39:56 UTC
(rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition.cpp 2015-03-10 15:12:17 UTC
(rev 64355)
@@ -31,7 +31,6 @@
// positive and negative volume. Probably convex/concave testing is what
// will be needed to resolve this.
-
struct bu_ptbl *
find_subbreps(const ON_Brep *brep)
{
@@ -156,7 +155,59 @@
}
}
- return subbreps;
+ // Now that we have the subbreps (or their substructures) and their
boolean status we need to
+ // construct the top level tree. Each object will be one of two things - a
top level
+ // object unioned into the global comb, or a top level object subtracted
from one of the other
+ // top level objects. We need to build a map of subtractions - for each
subtracted object,
+ // find via its shared edges/faces the parent subbrep it is subtracted
from.
+ //
+ struct bu_ptbl *subbreps_tree;
+ std::multimap<const char *, long *> ps;
+ for (unsigned int i = 0; i < BU_PTBL_LEN(subbreps); i++) {
+ struct subbrep_object_data *obj = (struct subbrep_object_data
*)BU_PTBL_GET(subbreps, i);
+ std::cout << "Checking " << bu_vls_addr(obj->key) << "\n";
+ std::cout << " op is: " << obj->params->bool_op << "\n";
+ if (obj->params->bool_op == '-') {
+ int found_parent = 0;
+ for (unsigned int j = 0; j < BU_PTBL_LEN(subbreps); j++) {
+ struct subbrep_object_data *pobj = (struct subbrep_object_data
*)BU_PTBL_GET(subbreps, j);
+ for (int k = 0; k < obj->fil_cnt; k++) {
+ for (int l = 0; l < pobj->fol_cnt; l++) {
+ if (pobj->fol[l] == obj->fil[k]) {
+ found_parent = 1;
+ ps.insert(std::make_pair(bu_vls_addr(pobj->key),
(long *)obj));
+ bu_log("%s is the parent of %s\n",
bu_vls_addr(pobj->key), bu_vls_addr(obj->key));
+ break;
+ }
+ if (found_parent) break;
+ }
+ if (found_parent) break;
+ }
+ if (found_parent) break;
+ }
+ if (!found_parent) {
+ std::cout << "Error - subtracted object " <<
bu_vls_addr(obj->key) << "\n";
+ }
+ }
+ }
+ BU_GET(subbreps_tree, struct bu_ptbl);
+ bu_ptbl_init(subbreps_tree, 8, "subbrep tree table");
+ for (unsigned int i = 0; i < BU_PTBL_LEN(subbreps); i++) {
+ struct subbrep_object_data *obj = (struct subbrep_object_data
*)BU_PTBL_GET(subbreps, i);
+ if (obj->params->bool_op == 'u') {
+ std::pair <std::multimap<const char *, long *>::iterator,
std::multimap<const char *, long *>::iterator > ret;
+ ret = ps.equal_range(bu_vls_addr(obj->key));
+ bu_ptbl_ins(subbreps_tree, (long *)obj);
+ std::cout << "unioning " << bu_vls_addr(obj->key) << "\n";
+ for (std::multimap<const char *, long *>::iterator it = ret.first;
it != ret.second; it++) {
+ struct subbrep_object_data *sub_obj = (struct
subbrep_object_data *)it->second;
+ std::cout << "subtracting " << bu_vls_addr(sub_obj->key) << "
from " << bu_vls_addr(obj->key) << "\n";
+ bu_ptbl_ins(subbreps_tree, (long *)sub_obj);
+ }
+ }
+ }
+ bu_ptbl_free(subbreps);
+ return subbreps_tree;
}
@@ -282,7 +333,7 @@
//if (BU_STR_EQUAL(bu_vls_addr(data->key), "325_326_441_527_528")) {
// std::cout << "looking at 325_326_441_527_528\n";
//}
-
+ int csg_fail = 0;
std::set<int> processed_faces;
std::set<std::string> subbrep_keys;
/* For each face, identify the candidate solid type. If that
@@ -371,21 +422,37 @@
new_obj->type = filters->type;
switch (new_obj->type) {
case CYLINDER:
- (void)cylinder_csg(new_obj, BREP_CYLINDRICAL_TOL);
+ if (!cylinder_csg(new_obj, BREP_CYLINDRICAL_TOL)) {
+ bu_log("cylinder csg failure: %s\n", key.c_str());
+ csg_fail++;
+ }
break;
case CONE:
- (void)cone_csg(new_obj, BREP_CONIC_TOL);
+ if (!cone_csg(new_obj, BREP_CONIC_TOL)) {
+ bu_log("cone csg failure: %s\n", key.c_str());
+ csg_fail++;
+ }
break;
case SPHERE:
- (void)sphere_csg(new_obj, BREP_SPHERICAL_TOL);
+ if (!sphere_csg(new_obj, BREP_SPHERICAL_TOL)) {
+ bu_log("sphere csg failure: %s\n", key.c_str());
+ csg_fail++;
+ }
break;
case ELLIPSOID:
- bu_log("process partial ellipsoid\n");
+ bu_log("TODO: process partial ellipsoid\n");
+ /* TODO - Until we properly handle these shapes, this is a
failure case */
+ csg_fail++;
break;
case TORUS:
- (void)torus_csg(new_obj, BREP_TOROIDAL_TOL);
+ if (!torus_csg(new_obj, BREP_TOROIDAL_TOL)) {
+ bu_log("torus csg failure: %s\n", key.c_str());
+ csg_fail++;
+ }
break;
default:
+ /* Unknown object type - can't convert to csg */
+ csg_fail++;
break;
}
@@ -394,12 +461,20 @@
filter_obj_free(filters);
BU_PUT(filters, struct filter_obj);
}
- if (subbrep_keys.size() == 0) {
- data->type = BREP;
- return 0;
+ if (subbrep_keys.size() == 0 || csg_fail > 0) {
+ goto csg_abort;
}
data->type = COMB;
return 1;
+csg_abort:
+ /* Clear children - we found something we can't handle, so there will be no
+ * CSG conversion of this subbrep */
+ data->type = BREP;
+ 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);
+ subbrep_object_free(cdata);
+ }
+ return 0;
}
int
Modified: brlcad/trunk/src/libbrep/shape_recognition_cone.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-10 00:39:56 UTC
(rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition_cone.cpp 2015-03-10 15:12:17 UTC
(rev 64355)
@@ -143,8 +143,6 @@
ON_3dVector hvect(cone.ApexPoint() - cone.BasePoint());
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;
@@ -297,7 +295,7 @@
data->params->r2 = 0.000001;
data->params->height = set1_c.Plane().DistanceTo(cone.ApexPoint());
if (data->params->height < 0) data->params->height =
data->params->height * -1;
-
+ return 1;
} else {
ON_3dPoint base = set1_c.Center();
ON_3dVector hvect = set2_c.Center() - set1_c.Center();
@@ -321,8 +319,6 @@
data->type = CONE;
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;
@@ -348,6 +344,8 @@
data->params->r2 = set2_c.Radius();
data->params->height = set1_c.Center().DistanceTo(set2_c.Center());
if (data->params->height < 0) data->params->height =
data->params->height * -1;
+
+ return 1;
} else {
// Have corners, need arb
data->type = COMB;
Modified: brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp 2015-03-10
00:39:56 UTC (rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition_cylinder.cpp 2015-03-10
15:12:17 UTC (rev 64355)
@@ -200,7 +200,7 @@
// is determined later.
int negative = negative_cylinder(data, *cylindrical_surfaces.begin(),
cyl_tol);
- bu_log("full cylinder negative test: %d\n", negative);
+ //bu_log("full cylinder negative test: %d\n", negative);
// TODO - the surface negative test may not be enough on its own - needs
// more thought
if (negative == -1) {
@@ -473,8 +473,6 @@
//std::cout << "Full cylinder\n";
data->type = CYLINDER;
- bu_log("parent boolean: %c\n", data->parent->params->bool_op);
-
if (data->parent->params->bool_op == '-') negative = -1 * negative;
switch (negative) {
@@ -517,10 +515,6 @@
bu_vls_sprintf(cyl_obj->key, "%s", key.c_str());
cyl_obj->type = CYLINDER;
- 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) {
@@ -841,8 +835,6 @@
// 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) {
Modified: brlcad/trunk/src/libbrep/shape_recognition_planar.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_planar.cpp 2015-03-10
00:39:56 UTC (rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition_planar.cpp 2015-03-10
15:12:17 UTC (rev 64355)
@@ -572,7 +572,7 @@
}
- int
+int
subbrep_make_planar(struct subbrep_object_data *data)
{
// First step is to count vertices, using the edges
Modified: brlcad/trunk/src/libbrep/shape_recognition_torus.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_torus.cpp 2015-03-10
00:39:56 UTC (rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition_torus.cpp 2015-03-10
15:12:17 UTC (rev 64355)
@@ -93,17 +93,17 @@
std::set<int> planar_surfaces;
std::set<int> toridal_surfaces;
std::set<int>::iterator f_it;
- std::cout << "processing toridal surface: \n";
+ //std::cout << "processing toridal surface: \n";
for (int i = 0; i < data->faces_cnt; i++) {
int f_ind = data->faces[i];
int surface_type =
(int)GetSurfaceType(data->brep->m_F[f_ind].SurfaceOf(), NULL);
switch (surface_type) {
case SURFACE_PLANE:
- std::cout << "planar face " << f_ind << "\n";
+ //std::cout << "planar face " << f_ind << "\n";
planar_surfaces.insert(f_ind);
break;
case SURFACE_TORUS:
- std::cout << "torus face " << f_ind << "\n";
+ //std::cout << "torus face " << f_ind << "\n";
toridal_surfaces.insert(f_ind);
break;
default:
@@ -149,25 +149,25 @@
ON_3dVector ep_normal = torus.plane.Normal();
// TODO - define a sensible constant for this...
if (ep_normal.IsParallelTo(torus_normal, 0.01)) {
- std::cout << "major edge: " << ei << "\n";
+ //std::cout << "major edge: " << ei << "\n";
major_circle_edges.insert(ei);
categorized = 1;
}
// TODO - define a sensible constant for this...
if (ep_normal.IsPerpendicularTo(torus_normal, 0.01)) {
- std::cout << "minor edge: " << ei << "\n";
+ //std::cout << "minor edge: " << ei << "\n";
minor_circle_edges.insert(ei);
categorized = 1;
}
if (!categorized) {
- std::cout << "Edge " << ei << " is neither parallel nor
perpendicular to torus - can't handle yet\n";
+ //std::cout << "Edge " << ei << " is neither parallel nor
perpendicular to torus - can't handle yet\n";
return 0;
}
} else {
// We've got non-arc edges in a toridal situation - not ready
// to handle this case yet.
- std::cout << "Edge " << ei << " is not an arc - can't handle yet\n";
+ //std::cout << "Edge " << ei << " is not an arc - can't handle
yet\n";
delete ecv;
return 0;
}
Modified: brlcad/trunk/src/libbrep/shape_recognition_util.cpp
===================================================================
--- brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-10 00:39:56 UTC
(rev 64354)
+++ brlcad/trunk/src/libbrep/shape_recognition_util.cpp 2015-03-10 15:12:17 UTC
(rev 64355)
@@ -418,6 +418,8 @@
int pos_cnt = 0;
int neg_cnt = 0;
+ if (data->fil_cnt == 0) return 1;
+
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]]);
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