Revision: 55798
          http://sourceforge.net/p/brlcad/code/55798
Author:   brlcad
Date:     2013-06-19 16:00:58 +0000 (Wed, 19 Jun 2013)
Log Message:
-----------
accept sf patch 189 (Optional arguments g-voxel.c) from Vlad Bogolin which 
provides the same optional arguments as libged's voxelize command.

Modified Paths:
--------------
    brlcad/trunk/src/conv/g-voxel.c

Modified: brlcad/trunk/src/conv/g-voxel.c
===================================================================
--- brlcad/trunk/src/conv/g-voxel.c     2013-06-19 14:17:47 UTC (rev 55797)
+++ brlcad/trunk/src/conv/g-voxel.c     2013-06-19 16:00:58 UTC (rev 55798)
@@ -40,58 +40,95 @@
 
 
 /*
- *                     M A I N
+ * M A I N
  */
 int
-main(int argc, char **argv) {
+main(int argc, char **argv)
+{
+    static struct rt_i *rtip;
+    static const char *usage = "[-s \"dx dy dz\"] [-d n] [-t f] model.g 
objects...\n";
+    fastf_t sizeVoxel[3], threshold;
+    int levelOfDetail;
+    genptr_t callBackData;
+    int c;
 
-static struct rt_i *rtip;
-fastf_t sizeVoxel[3], threshold;
-int levelOfDetail;
-genptr_t callBackData;
+    char title[1024] = {0};
 
-char title[1024] = {0};
-
     /* Check for command-line arguments.  Make sure we have at least a
      * geometry file and one geometry object on the command line.
      */
     if (argc < 3) {
-       bu_exit(1, "Usage: %s model.g objects...\n", argv[0]);
+       bu_exit(1, "Usage: %s %s", argv[0], usage);
     }
 
+    /* default user parameters */
+    sizeVoxel[0] = 1.0;
+    sizeVoxel[1] = 1.0;
+    sizeVoxel[2] = 1.0;
 
+    threshold = 0.5;
+    levelOfDetail = 4;
+
+    bu_optind = 1;
+    while ((c = bu_getopt(argc, (char * const *)argv, (const char *)"s:d:t:")) 
!= -1) {
+       double scan[3];
+
+       switch (c) {
+           case 's':
+               if (sscanf(bu_optarg, "%lf %lf %lf",
+                          &scan[0],
+                          &scan[1],
+                          &scan[2]) != 3) {
+                   bu_exit(1, "Usage: %s %s", argv[0], usage);
+               } else {
+                   /* convert from double to fastf_t */
+                   VMOVE(sizeVoxel, scan);
+               }
+               break;
+
+           case 'd':
+               if (sscanf(bu_optarg, "%d", &levelOfDetail) != 1) {
+                   bu_exit(1, "Usage: %s %s", argv[0], usage);
+               }
+               break;
+
+           case 't':
+               if(sscanf(bu_optarg, "%lf", &threshold) != 1) {
+                   bu_exit(1, "Usage: %s %s", argv[0], usage);
+               }
+               break;
+
+           default:
+               bu_exit(1, "Usage: %s %s", argv[0], usage);
+       }
+    }
+    argc -= bu_optind;
+    argv += bu_optind;
+
     /* Load the specified geometry database (i.e., a ".g" file).
      * rt_dirbuild() returns an "instance" pointer which describes the
      * database to be raytraced.  It also gives you back the title
      * string if you provide a buffer.  This builds a directory of the
      * geometry (i.e., a table of contents) in the file.
      */
-    rtip = rt_dirbuild(argv[1], title, sizeof(title));
+    rtip = rt_dirbuild(argv[0], title, sizeof(title));
     if (rtip == RTI_NULL) {
-       bu_exit(2, "Building the database directory for [%s] FAILED\n", 
argv[1]);
+       bu_exit(2, "Building the database directory for [%s] FAILED\n", 
argv[0]);
     }
+    argc--;
+    argv++;
 
-
     /* Walk the geometry trees.  Here you identify any objects in the
      * database that you want included in the ray trace by iterating
      * of the object names that were specified on the command-line.
      */
-    while (argc > 2) {
-       if (rt_gettree(rtip, argv[2]) < 0)
-           bu_log("Loading the geometry for [%s] FAILED\n", argv[2]);
+    while (argc > 0) {
+       if (rt_gettree(rtip, argv[0]) < 0)
+           bu_log("Loading the geometry for [%s] FAILED\n", argv[0]);
        argc--;
        argv++;
     }
 
-
-    /* user parameters are being given values directly here*/
-    sizeVoxel[0] = 1.0;
-    sizeVoxel[1] = 1.0;
-    sizeVoxel[2] = 1.0;
-
-    threshold = 0.5;
-    levelOfDetail = 4;
-
     callBackData = (void *)(& threshold);
 
     /* voxelize function is called here with rtip(ray trace instance), 
userParameters and printToFile/printToScreen options */

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


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to