Revision: 57309
          http://sourceforge.net/p/brlcad/code/57309
Author:   phoenixyjll
Date:     2013-08-30 06:54:15 +0000 (Fri, 30 Aug 2013)
Log Message:
-----------
Begin to implement comb -> brep conversion, as the NURBS evaluations are ready 
now.

Modified Paths:
--------------
    brlcad/trunk/src/libged/brep.c
    brlcad/trunk/src/librt/CMakeLists.txt
    brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp

Added Paths:
-----------
    brlcad/trunk/src/librt/comb/comb_brep.cpp

Modified: brlcad/trunk/src/libged/brep.c
===================================================================
--- brlcad/trunk/src/libged/brep.c      2013-08-30 05:39:56 UTC (rev 57308)
+++ brlcad/trunk/src/libged/brep.c      2013-08-30 06:54:15 UTC (rev 57309)
@@ -43,7 +43,7 @@
  * directly and export what we need from brep_debug.cpp which sucks.
  */
 RT_EXPORT extern int brep_command(struct bu_vls *vls, const char *solid_name, 
const struct rt_tess_tol *ttol, const struct bn_tol *tol, struct brep_specific* 
bs, struct rt_brep_internal* bi, struct bn_vlblock *vbp, int argc, const char 
*argv[], char *commtag);
-RT_EXPORT extern int brep_conversion(struct rt_db_internal *intern, ON_Brep 
**brep);
+RT_EXPORT extern int brep_conversion(struct rt_db_internal *intern, ON_Brep 
**brep, struct db_i *db);
 RT_EXPORT extern int brep_conversion_comb(struct rt_db_internal *old_internal, 
char *name, char *suffix, struct rt_wdb *wdbp, fastf_t local2mm);
 RT_EXPORT extern int brep_intersect_point_point(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
 RT_EXPORT extern int brep_intersect_point_curve(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
@@ -232,7 +232,7 @@
            bu_strlcat(bname, "_brep", strlen(bname)+6);
            suffix = "_brep";
        }
-       if (BU_STR_EQUAL(intern.idb_meth->ft_name, "ID_COMBINATION")) {
+       if (0) {
            char *bname_suffix;
            bname_suffix = 
(char*)bu_malloc(strlen(solid_name)+strlen(suffix)+1, "char");
            bu_strlcpy(bname_suffix, solid_name, strlen(solid_name)+1);
@@ -253,7 +253,7 @@
                if (argc > 2) bu_free(suffix, "char");
                return GED_OK;
            }
-           ret = brep_conversion(&intern, &brep);
+           ret = brep_conversion(&intern, &brep, gedp->ged_wdbp->dbip);
            if (ret == -1) {
                bu_vls_printf(gedp->ged_result_str, "%s doesn't have a 
brep-conversion function yet. Type: %s", solid_name, intern.idb_meth->ft_label);
            } else if (brep == NULL) {

Modified: brlcad/trunk/src/librt/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/librt/CMakeLists.txt       2013-08-30 05:39:56 UTC (rev 
57308)
+++ brlcad/trunk/src/librt/CMakeLists.txt       2013-08-30 06:54:15 UTC (rev 
57309)
@@ -30,6 +30,7 @@
   bundle.c
   cmd.c
   comb/comb.c
+  comb/comb_brep.cpp
   comb/comb_mirror.c
   comb/db_comb.c
   constraint.c

Added: brlcad/trunk/src/librt/comb/comb_brep.cpp
===================================================================
--- brlcad/trunk/src/librt/comb/comb_brep.cpp                           (rev 0)
+++ brlcad/trunk/src/librt/comb/comb_brep.cpp   2013-08-30 06:54:15 UTC (rev 
57309)
@@ -0,0 +1,177 @@
+/*                    C O M B _ B R E P . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file comb_brep.cpp
+ *
+ * Convert a combination to b-rep form (with NURBS boolean evaluations)
+ *
+ */
+
+#include "common.h"
+
+#include "raytrace.h"
+#include "rtgeom.h"
+#include "nmg.h"
+#include "brep.h"
+
+
+// Declaration
+extern "C" void rt_comb_brep(ON_Brep **b, const struct rt_db_internal *ip, 
const struct bn_tol *tol, struct db_i *db);
+
+
+int
+brep_conversion(struct rt_db_internal* intern, ON_Brep** brep, struct db_i* db)
+{
+    if (*brep)
+       delete *brep;
+
+    if (intern->idb_type == ID_BREP) {
+       // already a brep
+       RT_BREP_CK_MAGIC(intern->idb_ptr);
+       *brep = ((struct rt_brep_internal *)intern->idb_ptr)->brep->Duplicate();
+       if (*brep != NULL)
+           return 0;
+       return -2;
+    }
+
+    *brep = ON_Brep::New();
+    ON_Brep *old = *brep;
+    struct bn_tol tol;
+    tol.magic = BN_TOL_MAGIC;
+    tol.dist = BN_TOL_DIST;
+    tol.dist_sq = tol.dist * tol.dist;
+    tol.perp = SMALL_FASTF;
+    tol.para = 1.0 - tol.perp;
+    if (intern->idb_type == ID_COMBINATION) {
+       rt_comb_brep(brep, intern, &tol, db);
+    } else {
+       if (intern->idb_meth->ft_brep == NULL) {
+           delete old;
+           *brep = NULL;
+           return -1;
+       }
+       intern->idb_meth->ft_brep(brep, intern, &tol);
+    }
+    if (*brep == NULL) {
+       delete old;
+       return -2;
+    }
+    return 0;
+}
+
+
+int
+conv_tree(ON_Brep **b, union tree *t, struct db_i *db)
+{
+    ON_Brep *left = NULL, *right = NULL, *old = NULL;
+    int ret = 0;
+    switch (t->tr_op) {
+       case OP_UNION:
+       case OP_INTERSECT:
+       case OP_SUBTRACT:
+       case OP_XOR:
+           /* convert right */
+           old = right = ON_Brep::New();
+           ret = conv_tree(&right, t->tr_b.tb_right, db);
+           if (ret) {
+               if (right)
+                   delete old;
+               break;
+           }
+           /* fall through */
+       case OP_NOT:
+       case OP_GUARD:
+       case OP_XNOP:
+           /* convert left */
+           old = left = ON_Brep::New();
+           ret = conv_tree(&left, t->tr_b.tb_left, db);
+           if (!ret) {
+               // Perform NURBS evaluations
+               if (t->tr_op == OP_UNION)
+                   ret = ON_Boolean(*b, left, right, BOOLEAN_UNION);
+               else if (t->tr_op == OP_INTERSECT)
+                   ret = ON_Boolean(*b, left, right, BOOLEAN_INTERSECT);
+               else if (t->tr_op == OP_SUBTRACT)
+                   ret = ON_Boolean(*b, left, right, BOOLEAN_DIFF);
+               else if (t->tr_op == OP_XOR)
+                   ret = ON_Boolean(*b, left, right, BOOLEAN_XOR);
+               else {
+                   bu_log("operation %d isn't supported yet.\n", t->tr_op);
+                   ret = -1;
+               }
+           } else {
+               delete old;
+               delete right;
+           }
+           break;
+       case OP_DB_LEAF:
+           {
+               char *name = t->tr_l.tl_name;
+               directory *dir;
+               dir = db_lookup(db, name, LOOKUP_QUIET);
+               if (dir != RT_DIR_NULL) {
+                   rt_db_internal *intern;
+                   BU_ALLOC(intern, struct rt_db_internal);
+                   rt_db_get_internal(intern, dir, db, bn_mat_identity, 
&rt_uniresource);
+                   RT_CK_DB_INTERNAL(intern);
+                   ret = brep_conversion(intern, b, db);
+               } else {
+                   bu_log("Cannot find %s.\n", name);
+                   ret = -1;
+               }
+               break;
+           }
+       default:
+           bu_log("OPCODE NOT IMPLEMENTED: %d\n", t->tr_op);
+           ret = -1;
+    }
+
+    return ret;
+}
+
+
+/**
+ * R T _ C O M B _ B R E P
+ */
+extern "C" void
+rt_comb_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol 
*UNUSED(tol), struct db_i *db)
+{
+    RT_CK_DB_INTERNAL(ip);
+
+    struct rt_comb_internal *cip;
+    cip = (struct rt_comb_internal *)ip->idb_ptr;
+    RT_CK_COMB(cip);
+
+    if (cip->tree == NULL) {
+       *b = NULL;
+       return;
+    }
+
+    conv_tree(b, cip->tree, db);
+}
+
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8


Property changes on: brlcad/trunk/src/librt/comb/comb_brep.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2013-08-30 
05:39:56 UTC (rev 57308)
+++ brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2013-08-30 
06:54:15 UTC (rev 57309)
@@ -53,7 +53,7 @@
 extern "C" {
 #endif
     RT_EXPORT extern int brep_command(struct bu_vls *vls, const char 
*solid_name, const struct rt_tess_tol* ttol, const struct bn_tol* tol, struct 
brep_specific* bs, struct rt_brep_internal* bi, struct bn_vlblock *vbp, int 
argc, const char *argv[], char *commtag);
-    RT_EXPORT extern int brep_conversion(struct rt_db_internal* intern, 
ON_Brep** brep);
+    RT_EXPORT extern int brep_conversion(struct rt_db_internal* intern, 
ON_Brep** brep, struct db_i *ip);
     RT_EXPORT extern int brep_conversion_comb(struct rt_db_internal 
*old_internal, char *name, char *suffix, struct rt_wdb *wdbp, fastf_t local2mm);
     RT_EXPORT extern int brep_intersect_point_point(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
     RT_EXPORT extern int brep_intersect_point_curve(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
@@ -61,6 +61,7 @@
     RT_EXPORT extern int brep_intersect_curve_curve(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
     RT_EXPORT extern int brep_intersect_curve_surface(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
     RT_EXPORT extern int brep_intersect_surface_surface(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j, struct bn_vlblock *vbp);
+    extern void rt_comb_brep(ON_Brep **b, const struct rt_db_internal *ip, 
const struct bn_tol *UNUSED(tol), struct db_i *db);
 #ifdef __cplusplus
 }
 #endif
@@ -2286,22 +2287,27 @@
 
 
 int
-brep_conversion(struct rt_db_internal* intern, ON_Brep** brep)
+brep_conversion(struct rt_db_internal* intern, ON_Brep** brep, struct db_i* db)
 {
     *brep = ON_Brep::New();
     ON_Brep *old = *brep;
+
     struct bn_tol tol;
     tol.magic = BN_TOL_MAGIC;
     tol.dist = BN_TOL_DIST;
     tol.dist_sq = tol.dist * tol.dist;
     tol.perp = SMALL_FASTF;
     tol.para = 1.0 - tol.perp;
-    if (intern->idb_meth->ft_brep == NULL) {
-       delete old;
-       *brep = NULL;
-       return -1;
+    if (intern->idb_type == ID_COMBINATION) {
+       rt_comb_brep(brep, intern, &tol, db);
+    } else {
+       if (intern->idb_meth->ft_brep == NULL) {
+           delete old;
+           *brep = NULL;
+           return -1;
+       }
+       intern->idb_meth->ft_brep(brep, intern, &tol);
     }
-    intern->idb_meth->ft_brep(brep, intern, &tol);
     if (*brep == NULL) {
        delete old;
        return -2;
@@ -2380,7 +2386,7 @@
                    if (BU_STR_EQUAL(intern->idb_meth->ft_name, "ID_BREP")) {
                        *brep = ((struct rt_brep_internal 
*)intern->idb_ptr)->brep->Duplicate();
                    } else {
-                       ret = brep_conversion(intern, brep);
+                       ret = brep_conversion(intern, brep, db);
                        if (ret == -1) {
                            bu_log("The brep conversion of %s is 
unsuccessful.\n", oldname);
                            newtree = NULL;

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


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to