Revision: 70127
          http://sourceforge.net/p/brlcad/code/70127
Author:   starseeker
Date:     2017-08-24 22:11:50 +0000 (Thu, 24 Aug 2017)
Log Message:
-----------
Stub in a dsp command for down-and-dirty work with dsp objects.

Modified Paths:
--------------
    brlcad/trunk/include/ged/objects.h
    brlcad/trunk/src/libged/CMakeLists.txt
    brlcad/trunk/src/mged/setup.c
    brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl
    brlcad/trunk/src/tclscripts/lib/Ged.tcl
    brlcad/trunk/src/tclscripts/mged/help.tcl

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

Modified: brlcad/trunk/include/ged/objects.h
===================================================================
--- brlcad/trunk/include/ged/objects.h  2017-08-24 21:13:53 UTC (rev 70126)
+++ brlcad/trunk/include/ged/objects.h  2017-08-24 22:11:50 UTC (rev 70127)
@@ -481,6 +481,11 @@
 GED_EXPORT extern int ged_delete_pipept(struct ged *gedp, int argc, const char 
*argv[]);
 
 /**
+ * DSP utility command
+ */
+GED_EXPORT extern int ged_dsp(struct ged *gedp, int argc, const char *argv[]);
+
+/**
  * Arb specific edits.
  */
 GED_EXPORT extern int ged_edarb(struct ged *gedp, int argc, const char 
*argv[]);

Modified: brlcad/trunk/src/libged/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libged/CMakeLists.txt      2017-08-24 21:13:53 UTC (rev 
70126)
+++ brlcad/trunk/src/libged/CMakeLists.txt      2017-08-24 22:11:50 UTC (rev 
70127)
@@ -79,6 +79,7 @@
   display_list.c
   draw.c
   draw_calc.cpp
+  dsp.c
   dump.c
   dup.c
   eac.c

Added: brlcad/trunk/src/libged/dsp.c
===================================================================
--- brlcad/trunk/src/libged/dsp.c                               (rev 0)
+++ brlcad/trunk/src/libged/dsp.c       2017-08-24 22:11:50 UTC (rev 70127)
@@ -0,0 +1,162 @@
+/*                         D S P . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2017 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/dsp.c
+ *
+ * DSP command for displacement map operations.
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "bu/opt.h"
+#include "rt/geom.h"
+#include "wdb.h"
+#include "./ged_private.h"
+
+/* FIXME - we want the DSP macro for convenience here - should this be in 
include/rt/dsp.h ? */
+#include "../librt/primitives/dsp/dsp.h"
+
+int
+ged_dsp(struct ged *gedp, int argc, const char *argv[])
+{
+    struct directory *dsp_dp;
+    struct rt_db_internal intern;
+    struct rt_dsp_internal *dsp;
+    const char *cmd = argv[0];
+    size_t len;
+    const char *sub = NULL;
+    const char *primitive = NULL;
+    static const char *usage = "<obj> [command]\n";
+
+    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 < 3) {
+       bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", cmd, usage);
+       bu_vls_printf(gedp->ged_result_str, "commands:\n");
+       bu_vls_printf(gedp->ged_result_str, "\txy x y                  - report 
the height value at (x,y)\n");
+       bu_vls_printf(gedp->ged_result_str, "\tdiff obj [min_diff_val] - report 
height differences at x,y coordinates between two dsp objects\n");
+       return GED_ERROR;
+    }
+
+    /* get dsp */
+    primitive = argv[1];
+    GED_DB_LOOKUP(gedp, dsp_dp, primitive, LOOKUP_NOISY, GED_ERROR & 
GED_QUIET);
+    GED_DB_GET_INTERNAL(gedp, &intern, dsp_dp, bn_mat_identity, 
&rt_uniresource, GED_ERROR);
+
+    if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type 
!= DB5_MINORTYPE_BRLCAD_DSP) {
+       bu_vls_printf(gedp->ged_result_str, "%s: %s is not a DSP solid!", cmd, 
primitive);
+       rt_db_free_internal(&intern);
+       return GED_ERROR;
+    }
+
+    dsp = (struct rt_dsp_internal *)intern.idb_ptr;
+    RT_DSP_CK_MAGIC(dsp);
+
+    /* execute subcommand */
+    sub = argv[2];
+    len = strlen(sub);
+    if (BU_STR_EQUAL(sub, "xy")) {
+       unsigned short elev;
+       unsigned int gx = 0;
+       unsigned int gy = 0;
+       (void)bu_opt_int(NULL, 1, &argv[3], &gx);
+       (void)bu_opt_int(NULL, 1, &argv[4], &gy);
+       if (gx > dsp->dsp_xcnt || gy > dsp->dsp_ycnt) {
+           bu_vls_printf(gedp->ged_result_str, "Error - xy coordinate (%d,%d) 
is outside max data bounds of dsp: (%d,%d)", gx, gy, dsp->dsp_xcnt, 
dsp->dsp_ycnt);
+           rt_db_free_internal(&intern);
+           return GED_ERROR;
+       } else {
+           elev = DSP(dsp, gx, gy);
+           bu_vls_printf(gedp->ged_result_str, "%d", elev);
+       }
+       rt_db_free_internal(&intern);
+       return GED_OK;
+    }
+    if (BU_STR_EQUAL(sub, "diff")) {
+       struct directory *dsp_dp2;
+       struct rt_db_internal intern2;
+       struct rt_dsp_internal *dsp2;
+       if (argc < 4) {
+           bu_vls_printf(gedp->ged_result_str, "Error - diff subcommand 
specified, but not the object to diff against.");
+           rt_db_free_internal(&intern);
+           return GED_ERROR;
+       }
+       GED_DB_LOOKUP(gedp, dsp_dp2, argv[3], LOOKUP_NOISY, GED_ERROR & 
GED_QUIET);
+       GED_DB_GET_INTERNAL(gedp, &intern2, dsp_dp2, bn_mat_identity, 
&rt_uniresource, GED_ERROR);
+
+       if (intern2.idb_major_type != DB5_MAJORTYPE_BRLCAD || 
intern2.idb_minor_type != DB5_MINORTYPE_BRLCAD_DSP) {
+           bu_vls_printf(gedp->ged_result_str, "%s: %s is not a DSP solid!", 
cmd, argv[3]);
+           rt_db_free_internal(&intern);
+           rt_db_free_internal(&intern2);
+           return GED_ERROR;
+       }
+
+       dsp2 = (struct rt_dsp_internal *)intern.idb_ptr;
+       RT_DSP_CK_MAGIC(dsp2);
+
+       if (dsp->dsp_xcnt != dsp2->dsp_xcnt || dsp->dsp_ycnt != dsp2->dsp_ycnt) 
{
+           bu_vls_printf(gedp->ged_result_str, "%s xy grid size (%d,%d) 
differs from that of %s: (%d,%d)", dsp_dp2->d_namep, dsp2->dsp_xcnt, 
dsp2->dsp_ycnt, dsp_dp->d_namep, dsp->dsp_xcnt, dsp->dsp_ycnt);
+           rt_db_free_internal(&intern);
+           rt_db_free_internal(&intern2);
+           return GED_OK;
+       } else {
+           uint32_t i, j;
+           for (i = 0; i < dsp->dsp_xcnt; i++) {
+               for (j = 0; j < dsp->dsp_ycnt; j++) {
+                   unsigned short e1 = DSP(dsp, i, j);
+                   unsigned short e2 = DSP(dsp2, i, j);
+                   if (e1 != e2) {
+                       unsigned short delta = (e1 > e2) ? e1 - e2 : e2 - e1;
+                       bu_vls_printf(gedp->ged_result_str, "(%d,%d): %d\n", i, 
j, delta);
+                   }
+               }
+           }
+       }
+
+       rt_db_free_internal(&intern);
+       rt_db_free_internal(&intern2);
+       return GED_OK;
+    }
+
+    bu_vls_printf(gedp->ged_result_str, "Error - unknown dsp subcommand: %s", 
sub);
+    rt_db_free_internal(&intern);
+    return GED_ERROR;
+}
+
+
+/*
+ * 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/dsp.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/trunk/src/mged/setup.c
===================================================================
--- brlcad/trunk/src/mged/setup.c       2017-08-24 21:13:53 UTC (rev 70126)
+++ brlcad/trunk/src/mged/setup.c       2017-08-24 22:11:50 UTC (rev 70127)
@@ -127,6 +127,7 @@
     {"dump", cmd_ged_plain_wrapper, ged_dump},
     {"dm", f_dm, GED_FUNC_PTR_NULL},
     {"draw", cmd_draw, GED_FUNC_PTR_NULL},
+    {"dsp", cmd_ged_plain_wrapper, ged_dsp},
     {"dup", cmd_ged_plain_wrapper, ged_dup},
     {"E", cmd_E, GED_FUNC_PTR_NULL},
     {"e", cmd_draw, GED_FUNC_PTR_NULL},

Modified: brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl   2017-08-24 21:13:53 UTC 
(rev 70126)
+++ brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl   2017-08-24 22:11:50 UTC 
(rev 70127)
@@ -226,6 +226,7 @@
        method edcomb              {args}
        method edmater             {args}
        method d                   {args}
+       method dsp                 {args}
        method erase               {args}
        method ev                  {args}
        method exists              {args}
@@ -583,7 +584,7 @@
            bot_merge bot_smooth bot_split bot_sync bot_vertex_fuse \
            brep c cd clear clone closedb color comb comb_color combmem \
            copy copyeval copymat cp cpi dbconcat dbExpand decompose \
-           delete draw e E edarb edcodes edcolor edcomb edit edmater d erase 
ev exists \
+           delete draw dsp e E edarb edcodes edcolor edcomb edit edmater d 
erase ev exists \
            exit facetize fracture freezeGUI g get graph group hide human i 
igraph \
            importFg4Section in inside item kill killall killrefs \
            killtree l lc ls make make_name make_pnts man mater mirror move \
@@ -6364,6 +6365,10 @@
     return $ret
 }
 
+::itcl::body ArcherCore::dsp {args} {
+    eval gedWrapper dsp 0 0 1 1 $args
+}
+
 ::itcl::body ArcherCore::E {args} {
     eval gedWrapper E 1 0 0 1 $args
 }

Modified: brlcad/trunk/src/tclscripts/lib/Ged.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/lib/Ged.tcl     2017-08-24 21:13:53 UTC (rev 
70126)
+++ brlcad/trunk/src/tclscripts/lib/Ged.tcl     2017-08-24 22:11:50 UTC (rev 
70127)
@@ -213,6 +213,7 @@
        method dlist_on {args}
        method draw {args}
        method draw_ray {_start _partitions}
+       method dsp {args}
        method dump {args}
        method dup {args}
        method E {args}
@@ -1706,6 +1707,10 @@
     }
 }
 
+::itcl::body cadwidgets::Ged::dsp {args} {
+    eval $mGed dsp $args
+}
+
 ::itcl::body cadwidgets::Ged::dump {args} {
     eval $mGed dump $args
 }
@@ -6243,6 +6248,7 @@
     $help add delay            {{sec usec} {delay processing for the specified 
amount of time}}
     $help add dir2ae           {{az el} {returns a direction vector given the 
azimuth and elevation}}
     $help add draw             {{"-C#/#/# <objects>"} {draw objects}}
+    $help add dsp              {{obj [command]} {work with DSP primitives}}
     $help add dump             {{file} {write current state of database object 
to file}}
     $help add dup              {{file [prefix]} {check for dup names in 
'file'}}
     $help add E                        {{[-s] <objects>} {evaluated edit of 
objects. Option 's' provides a slower, but better fidelity evaluation}}

Modified: brlcad/trunk/src/tclscripts/mged/help.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/mged/help.tcl   2017-08-24 21:13:53 UTC (rev 
70126)
+++ brlcad/trunk/src/tclscripts/mged/help.tcl   2017-08-24 22:11:50 UTC (rev 
70127)
@@ -144,6 +144,7 @@
 set mged_help_data(dm)         {{set var [val]}        {do display-manager 
specific command}}
 set mged_help_data(dmtype)     {{{set dmtype}} {Without argument, display 
current display manager type.  With 'set dmtype' changes display manager 
instances to new type.}}
 set mged_help_data(draw)       $helplib_data(dgo_draw)
+set mged_help_data(dsp)         {{obj [command]} {work with DSP primitives}}
 set mged_help_data(dump)       $helplib_data(wdb_dump)
 set mged_help_data(dup)                $helplib_data(wdb_dup)
 set mged_help_data(E)          $helplib_data(dgo_E)

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to