Revision: 51786
          http://brlcad.svn.sourceforge.net/brlcad/?rev=51786&view=rev
Author:   r_weiss
Date:     2012-08-07 19:56:37 +0000 (Tue, 07 Aug 2012)
Log Message:
-----------
Added a new mged command "bot_fuse". Add a new file "src/libged/bot_fuse.c" and 
updated files "include/ged.h", "include/raytrace.h", "src/libged/Makefile.am", 
"src/libged/CMakeLists.txt", "src/mged/setup.c", "src/libtclcad/tclcad_obj.c" 
and "src/librt/primitives/bot/bot_brep.cpp". This new command is a work in 
progress. This command attempts to repair BOTs using NMG fuse functions. 

Modified Paths:
--------------
    brlcad/trunk/include/ged.h
    brlcad/trunk/include/raytrace.h
    brlcad/trunk/src/libged/CMakeLists.txt
    brlcad/trunk/src/libged/Makefile.am
    brlcad/trunk/src/librt/primitives/bot/bot_brep.cpp
    brlcad/trunk/src/libtclcad/tclcad_obj.c
    brlcad/trunk/src/mged/setup.c

Added Paths:
-----------
    brlcad/trunk/src/libged/bot_fuse.c

Modified: brlcad/trunk/include/ged.h
===================================================================
--- brlcad/trunk/include/ged.h  2012-08-07 19:50:53 UTC (rev 51785)
+++ brlcad/trunk/include/ged.h  2012-08-07 19:56:37 UTC (rev 51786)
@@ -816,6 +816,11 @@
 GED_EXPORT extern int ged_bot_flip(struct ged *gedp, int argc, const char 
*argv[]);
 
 /**
+ * Fuse bot
+ */
+GED_EXPORT extern int ged_bot_fuse(struct ged *gedp, int argc, const char 
*argv[]);
+
+/**
  * Create bot_dest by merging the bot sources.
  */
 GED_EXPORT extern int ged_bot_merge(struct ged *gedp, int argc, const char 
*argv[]);

Modified: brlcad/trunk/include/raytrace.h
===================================================================
--- brlcad/trunk/include/raytrace.h     2012-08-07 19:50:53 UTC (rev 51785)
+++ brlcad/trunk/include/raytrace.h     2012-08-07 19:56:37 UTC (rev 51786)
@@ -4389,6 +4389,12 @@
 RT_EXPORT extern int rt_bot_same_orientation(const int *a,
                                             const int *b);
 
+RT_EXPORT extern int rt_bot_tess(struct nmgregion **r,
+                                struct model *m,
+                                struct rt_db_internal *ip,
+                                const struct rt_tess_tol *ttol,
+                                const struct bn_tol *tol);
+
 /* From nmg_tri.c */
 RT_EXPORT extern void nmg_triangulate_shell(struct shell *s,
                                            const struct bn_tol  *tol);

Modified: brlcad/trunk/src/libged/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libged/CMakeLists.txt      2012-08-07 19:50:53 UTC (rev 
51785)
+++ brlcad/trunk/src/libged/CMakeLists.txt      2012-08-07 19:56:37 UTC (rev 
51786)
@@ -65,6 +65,7 @@
   bot_dump.c
   bot_face_fuse.c
   bot_face_sort.c
+  bot_fuse.c
   bot_flip.c
   bot_merge.c
   bot_smooth.c

Modified: brlcad/trunk/src/libged/Makefile.am
===================================================================
--- brlcad/trunk/src/libged/Makefile.am 2012-08-07 19:50:53 UTC (rev 51785)
+++ brlcad/trunk/src/libged/Makefile.am 2012-08-07 19:56:37 UTC (rev 51786)
@@ -27,6 +27,7 @@
        bot_dump.c \
        bot_face_fuse.c \
        bot_face_sort.c \
+       bot_fuse.c \
        bot_flip.c \
        bot_merge.c \
        bot_smooth.c \

Added: brlcad/trunk/src/libged/bot_fuse.c
===================================================================
--- brlcad/trunk/src/libged/bot_fuse.c                          (rev 0)
+++ brlcad/trunk/src/libged/bot_fuse.c  2012-08-07 19:56:37 UTC (rev 51786)
@@ -0,0 +1,181 @@
+/*                         B O T _ F U S E . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2008-2012 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 libged/bot_fuse.c
+ *
+ * The bot_fuse command.
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include "bio.h"
+
+#include "rtgeom.h"
+
+#include "./ged_private.h"
+
+
+int
+ged_bot_fuse(struct ged *gedp, int argc, const char *argv[])
+{
+    struct directory *old_dp, *new_dp;
+    struct rt_db_internal intern, intern2;
+    struct rt_bot_internal *bot;
+    int count=0;
+    static const char *usage = "new_bot old_bot";
+
+    struct model *m;
+    struct nmgregion *r;
+    int ret;
+    struct bn_tol *tol = &gedp->ged_wdbp->wdb_tol;
+    int total = 0;
+
+    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
+    GED_CHECK_READ_ONLY(gedp, GED_ERROR);
+    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+
+    /* initialize result */
+    bu_vls_trunc(gedp->ged_result_str, 0);
+
+    /* must be wanting help */
+    if (argc == 1) {
+       bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+    if (argc != 3) {
+       bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_ERROR;
+    }
+
+    bu_log("%s: start\n", argv[0]);
+
+    GED_DB_LOOKUP(gedp, old_dp, argv[2], LOOKUP_NOISY, GED_ERROR & GED_QUIET);
+    GED_DB_GET_INTERNAL(gedp, &intern, old_dp, bn_mat_identity, 
&rt_uniresource, GED_ERROR);
+
+    if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type 
!= DB5_MINORTYPE_BRLCAD_BOT) {
+       bu_vls_printf(gedp->ged_result_str, "%s: %s is not a BOT solid!\n", 
argv[0], argv[2]);
+       return GED_ERROR;
+    }
+
+    /* create nmg model structure */
+    m = nmg_mm();
+
+    /* place bot in nmg structure */
+    bu_log("%s: running rt_bot_tess\n", argv[0]);
+    ret = rt_bot_tess(&r, m, &intern, &gedp->ged_wdbp->wdb_ttol, tol);
+
+    /* free internal representation of original bot */
+    rt_db_free_internal(&intern);
+
+    if (ret != 0) {
+       bu_vls_printf(gedp->ged_result_str, "%s: %s fuse failed (1).\n", 
argv[0], argv[2]);
+       nmg_km(m);
+       return GED_ERROR;
+    }
+
+    total = 0;
+
+    /* Step 1 -- the vertices. */
+    bu_log("%s: running nmg_vertex_fuse\n", argv[0]);
+    count = nmg_vertex_fuse(&m->magic, tol);
+    total += count;
+    bu_log("%s: %s, %d vertex fused\n", argv[0], argv[2], count);
+
+    /* Step 1.5 -- break edges on vertices, before fusing edges */
+    bu_log("%s: running nmg_model_break_e_on_v\n", argv[0]);
+    count = nmg_model_break_e_on_v(m, tol);
+    total += count;
+    bu_log("%s: %s, %d broke 'e' on 'v'\n", argv[0], argv[2], count);
+
+    if (total) {
+        struct nmgregion *r2;
+        struct shell *s;
+
+       bu_log("%s: running nmg_make_faces_within_tol\n", argv[0]);
+
+        /* vertices and/or edges have been moved,
+         * may have created out-of-tolerance faces
+         */
+
+        for (BU_LIST_FOR(r2, nmgregion, &m->r_hd)) {
+            for (BU_LIST_FOR(s, shell, &r2->s_hd))
+                nmg_make_faces_within_tol(s, tol);
+        }
+    }
+
+    /* Step 2 -- the face geometry */
+    bu_log("%s: running nmg_model_face_fuse\n", argv[0]);
+    count = nmg_model_face_fuse(m, tol);
+    total += count;
+    bu_log("%s: %s, %d faces fused\n", argv[0], argv[2], count);
+
+    /* Step 3 -- edges */
+    bu_log("%s: running nmg_model_edge_fuse\n", argv[0]);
+    count = nmg_model_edge_fuse(m, tol);
+    total += count;
+
+    bu_log("%s: %s, %d edges fused\n", argv[0], argv[2], count);
+
+    bu_log("%s: %s, %d total fused\n", argv[0], argv[2], total);
+
+    if (!BU_SETJUMP) {
+       /* try */
+
+       /* convert the nmg model back into a bot */
+       bot = nmg_bot(BU_LIST_FIRST(shell, &r->s_hd), tol);
+
+       /* free the nmg model structure */
+       nmg_km(m);
+    } else {
+       /* catch */
+            BU_UNSETJUMP;
+           bu_vls_printf(gedp->ged_result_str, "%s: %s fuse failed (2).\n", 
argv[0], argv[2]);
+           return GED_ERROR;
+    }
+
+    RT_DB_INTERNAL_INIT(&intern2);
+    intern2.idb_major_type = DB5_MAJORTYPE_BRLCAD;
+    intern2.idb_type = ID_BOT;
+    intern2.idb_meth = &rt_functab[ID_BOT];
+    intern2.idb_ptr = (genptr_t)bot;
+
+    GED_DB_DIRADD(gedp, new_dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, 
(genptr_t)&intern2.idb_type, GED_ERROR);
+    GED_DB_PUT_INTERNAL(gedp, new_dp, &intern2, &rt_uniresource, GED_ERROR);
+
+    bu_vls_printf(gedp->ged_result_str, "%s: %s fuse done.\n", argv[0], 
argv[2]);
+
+    return GED_OK;
+}
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
+


Property changes on: brlcad/trunk/src/libged/bot_fuse.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Modified: brlcad/trunk/src/librt/primitives/bot/bot_brep.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/bot_brep.cpp  2012-08-07 19:50:53 UTC 
(rev 51785)
+++ brlcad/trunk/src/librt/primitives/bot/bot_brep.cpp  2012-08-07 19:56:37 UTC 
(rev 51786)
@@ -31,7 +31,7 @@
 #include "brep.h"
 
 extern "C" {
-    extern void rt_bot_tess(struct nmgregion **r, struct model *m, struct 
rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol);
+    extern int rt_bot_tess(struct nmgregion **r, struct model *m, struct 
rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol);
     extern void rt_nmg_brep(ON_Brep **bi, struct rt_db_internal *ip, const 
struct bn_tol *tol);
 }
 
@@ -53,7 +53,7 @@
     struct model *botm = nmg_mm();
     struct nmgregion *botr;
     tmp_internal->idb_ptr = (genptr_t)ip->idb_ptr;
-    rt_bot_tess(&botr, botm, tmp_internal, ttol, tol);
+    (void)rt_bot_tess(&botr, botm, tmp_internal, ttol, tol);
     tmp_internal->idb_ptr = (genptr_t)botm;
     rt_nmg_brep(b, tmp_internal, tol);
     FREE_MODEL(botm);

Modified: brlcad/trunk/src/libtclcad/tclcad_obj.c
===================================================================
--- brlcad/trunk/src/libtclcad/tclcad_obj.c     2012-08-07 19:50:53 UTC (rev 
51785)
+++ brlcad/trunk/src/libtclcad/tclcad_obj.c     2012-08-07 19:56:37 UTC (rev 
51786)
@@ -842,6 +842,7 @@
     {"bot_face_fuse",  (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_face_fuse},
     {"bot_face_sort",  (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_face_sort},
     {"bot_flip",       (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_flip},
+    {"bot_fuse",       (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_fuse},
     {"bot_merge",      (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_merge},
     {"bot_smooth",     (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_smooth},
     {"bot_split",      (char *)0, TO_UNLIMITED, to_pass_through_func, 
ged_bot_split},

Modified: brlcad/trunk/src/mged/setup.c
===================================================================
--- brlcad/trunk/src/mged/setup.c       2012-08-07 19:50:53 UTC (rev 51785)
+++ brlcad/trunk/src/mged/setup.c       2012-08-07 19:56:37 UTC (rev 51786)
@@ -94,6 +94,7 @@
     {"bot_face_fuse", cmd_ged_plain_wrapper, ged_bot_face_fuse},
     {"bot_face_sort", cmd_ged_plain_wrapper, ged_bot_face_sort},
     {"bot_flip", cmd_ged_plain_wrapper, ged_bot_flip},
+    {"bot_fuse", cmd_ged_plain_wrapper, ged_bot_fuse},
     {"bot_merge", cmd_ged_plain_wrapper, ged_bot_merge},
     {"bot_smooth", cmd_ged_plain_wrapper, ged_bot_smooth},
     {"bot_split", cmd_ged_plain_wrapper, ged_bot_split},

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to