Revision: 56228
          http://sourceforge.net/p/brlcad/code/56228
Author:   n_reed
Date:     2013-07-25 21:31:22 +0000 (Thu, 25 Jul 2013)
Log Message:
-----------
Add a 'translate' subcommand to the brep command. Currently minimal code to 
move a control vertex of a nurbs surface with no validty checks or implied 
edits.

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

Modified: brlcad/trunk/src/libged/brep.c
===================================================================
--- brlcad/trunk/src/libged/brep.c      2013-07-25 21:30:17 UTC (rev 56227)
+++ brlcad/trunk/src/libged/brep.c      2013-07-25 21:31:22 UTC (rev 56228)
@@ -64,9 +64,11 @@
     struct rt_brep_internal* bi;
     struct brep_specific* bs;
     struct soltab *stp;
-    int real_flag;
     char commtag[64];
     char namebuf[64];
+    int i, j, real_flag, valid_command;
+    const char *commands[] = {"info", "plot", "translate"};
+    int num_commands = (int)(sizeof(commands) / sizeof(const char *));
 
     GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
     GED_CHECK_DRAWABLE(gedp, GED_ERROR);
@@ -88,10 +90,11 @@
        bu_vls_printf(gedp->ged_result_str, "\tintersect obj2 i j 
[PP|PC|PS|CC|CS|SS] - BREP intersections\n");
        bu_vls_printf(gedp->ged_result_str, "\t[brepname] - convert the 
non-BREP object to BREP form\n");
        bu_vls_printf(gedp->ged_result_str, "\t[suffix] - convert non-BREP comb 
to unevaluated BREP form\n");
+       bu_vls_printf(gedp->ged_result_str, "\ttranslate SCV index i j dx dy dz 
- translate a surface control vertex\n");
        return GED_HELP;
     }
 
-    if (argc < 2 || argc > 7) {
+    if (argc < 2 || argc > 10) {
        bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
        return GED_ERROR;
     }
@@ -119,7 +122,6 @@
     if (BU_STR_EQUAL(argv[2], "intersect")) {
        /* handle surface-surface intersection */
        struct rt_db_internal intern2;
-       int i, j;
 
        /* we need exactly 6 or 7 arguments */
        if (argc != 6 && argc != 7) {
@@ -270,7 +272,15 @@
        return GED_HELP;
     }
 
-    if (!BU_STR_EQUAL(argv[2], "info") && !BU_STR_EQUAL(argv[2], "plot")) {
+    valid_command = 0;
+    for (i = 0; i < num_commands; ++i) {
+       if (BU_STR_EQUAL(argv[2], commands[i])) {
+           valid_command = 1;
+           break;
+       }
+    }
+
+    if (!valid_command) {
        bu_vls_printf(gedp->ged_result_str, "Usage: %s %s\n", argv[0], usage);
        bu_vls_printf(gedp->ged_result_str, "\t%s is in brep form, please input 
a command.", solid_name);
        return GED_HELP;
@@ -287,6 +297,11 @@
 
     brep_command(gedp->ged_result_str, solid_name, (const struct rt_tess_tol 
*)&gedp->ged_wdbp->wdb_ttol, &gedp->ged_wdbp->wdb_tol, bs, bi, vbp, argc, argv, 
commtag);
 
+    if (BU_STR_EQUAL(argv[2], "translate")) {
+       bi->brep = bs->brep;
+       GED_DB_PUT_INTERNAL(gedp, ndp, &intern, &rt_uniresource, GED_ERROR);
+    }
+
     snprintf(namebuf, 64, "%s%s_", commtag, solid_name);
     _ged_cvt_vlblock_to_solids(gedp, vbp, namebuf, 0);
     rt_vlblock_free(vbp);

Modified: brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2013-07-25 
21:30:17 UTC (rev 56227)
+++ brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2013-07-25 
21:31:22 UTC (rev 56228)
@@ -2489,7 +2489,59 @@
     return ret;
 }
 
+int
+translate_command(
+       struct bu_vls *result,
+       struct brep_specific *bs,
+       int argc,
+       const char *argv[])
+{
+    //  0         1          2      3    4   5 6 7  8  9
+    // brep <solid_name> translate SCV index i j dx dy dz
+    if (argc != 10) {
+       return -1;
+    }
+    ON_Brep *brep = bs->brep;
 
+    if (BU_STR_EQUAL(argv[3], "SCV")) {
+       int surface_index = atoi(argv[4]);
+       int i = atoi(argv[5]);
+       int j = atoi(argv[6]);
+
+       ON_NurbsSurface *nurbsSurface = NULL;
+       ON_Surface *surface = brep->m_S[surface_index];
+       if (surface) {
+           nurbsSurface = dynamic_cast<ON_NurbsSurface *>(surface);
+       } else {
+           bu_vls_printf(result, "No surface %d.\n", surface_index);
+           return -1;
+       }
+
+       double *cv = NULL;
+       if (nurbsSurface) {
+           cv = nurbsSurface->CV(i, j);
+       } else {
+           bu_vls_printf(result, "Surface %d is not a NURBS surface.\n", 
surface_index);
+           return -1;
+       }
+
+       if (cv) {
+           ON_3dPoint newPt;
+           newPt.x = cv[X] + atof(argv[7]);
+           newPt.y = cv[Y] + atof(argv[8]);
+           newPt.z = cv[Z] + atof(argv[9]);
+           nurbsSurface->SetCV(i, j, newPt);
+       } else {
+           bu_vls_printf(result, "No control vertex (%d, %d).\n", i, j);
+           return -1;
+       }
+    } else {
+       return -1;
+    }
+
+    return 0;
+}
+
 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)
 {
@@ -2767,6 +2819,8 @@
                }
            }
        }
+    } else if (BU_STR_EQUAL(command, "translate")) {
+       ret = translate_command(vls, bs, argc, argv);
     }
     return ret;
 }

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


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to