Revision: 56307
http://sourceforge.net/p/brlcad/code/56307
Author: d_rossberg
Date: 2013-07-29 15:26:34 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
apply Jonathan's patch from https://sourceforge.net/p/brlcad/patches/195/
adding a g-raw converter in response to the GCI task
http://www.google-melange.com/gci/task/view/google/gci2012/7945223
Modified Paths:
--------------
brlcad/trunk/doc/docbook/system/man1/en/CMakeLists.txt
brlcad/trunk/src/conv/raw/CMakeLists.txt
Added Paths:
-----------
brlcad/trunk/doc/docbook/system/man1/en/g-raw.xml
brlcad/trunk/src/conv/raw/g-raw.c
Modified: brlcad/trunk/doc/docbook/system/man1/en/CMakeLists.txt
===================================================================
--- brlcad/trunk/doc/docbook/system/man1/en/CMakeLists.txt 2013-07-29
14:24:29 UTC (rev 56306)
+++ brlcad/trunk/doc/docbook/system/man1/en/CMakeLists.txt 2013-07-29
15:26:34 UTC (rev 56307)
@@ -96,6 +96,7 @@
g-nff.xml
g-nmg.xml
g-obj.xml
+ g-raw.xml
g-shell-rect.xml
g-stl.xml
g-tankill.xml
Added: brlcad/trunk/doc/docbook/system/man1/en/g-raw.xml
===================================================================
--- brlcad/trunk/doc/docbook/system/man1/en/g-raw.xml
(rev 0)
+++ brlcad/trunk/doc/docbook/system/man1/en/g-raw.xml 2013-07-29 15:26:34 UTC
(rev 56307)
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- lifted from troff+man by doclifter -->
+<refentry xmlns='http://docbook.org/ns/docbook' version='5.0' xml:lang='en'
xml:id='graw1'>
+<refmeta>
+ <refentrytitle>G-RAW
+</refentrytitle>
+<manvolnum>1</manvolnum>
+<refmiscinfo class='source'>BRL-CAD</refmiscinfo>
+<refmiscinfo class='software'>BRL-CAD</refmiscinfo>
+<refmiscinfo class='manual'>User Commands</refmiscinfo>
+</refmeta>
+
+<refnamediv>
+<refname>g-raw</refname>
+<refpurpose> RAW Translator (BRL-CAD to RAW)</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+<refsynopsisdiv xml:id='synopsis'>
+<cmdsynopsis>
+ <command>g-raw</command>
+ <arg choice='opt'>-o <replaceable>output_file</replaceable></arg>
+ <arg choice='opt'>-m <replaceable>output_directory</replaceable></arg>
+ <arg choice='opt'>-P <replaceable>num_cpus</replaceable></arg>
+ <arg choice='opt'>-i</arg>
+ <arg choice='opt'>-8</arg>
+ <arg choice='opt'>-D <replaceable>calculation_tolerance</replaceable></arg>
+ <arg choice='opt'>-a <replaceable>absolute_tol</replaceable></arg>
+ <arg choice='opt'>-r <replaceable>relative_tol</replaceable></arg>
+ <arg choice='opt'>-n <replaceable>normal_tol</replaceable></arg>
+ <arg choice='opt'>-xX <replaceable>level</replaceable></arg>
+ <arg choice='opt'>-v</arg>
+
+ <arg choice='plain'><replaceable>database.g</replaceable></arg>
+ <arg choice='plain' rep='repeat'><replaceable>object(s)</replaceable></arg>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<refsect1 xml:id='description'><title>DESCRIPTION</title>
+<para><emphasis remap='I'>g-raw</emphasis>
+converts the specified
+<emphasis remap='I'>object(s)</emphasis>
+from a BRL-CAD
+<emphasis remap='I'>database.g</emphasis>
+file to the
+<emphasis remap='I'>stereolithography</emphasis>
+file format.</para>
+
+
+<para>The following options are recognized.</para>
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><option>-o PATH</option></term>
+ <listitem>
+<para>Specify output file name (default is stdout).</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-m DIR</option></term>
+ <listitem>
+<para>Specify a directory for output files.
+Each region converted is written to a separate file. File names are
constructed from the
+full path names of each region (the path from the specified object to the
region).
+Any "/" characters in the path name are replaced by "@" characters and "." and
white
+space are replaced by "_" characters. If the -m option is not specified, all
regions
+are written to the same file. The <option>-o</option> and <option>-m</option>
options
+are mutually exclusive.
+</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-P#</option></term>
+ <listitem>
+<para>Specify the number of CPUs to utilize.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-i</option></term>
+ <listitem>
+<para>Use inches as the output format (the default is mm).</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-8</option></term>
+ <listitem>
+<para>Facetize using the marching cubes algorithm.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-D#</option></term>
+ <listitem>
+<para>Specify a calculational distance tolerance (mm). Any two vertices that
are
+less than this distance apart will be treated as the same vertex.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-a#</option></term>
+ <listitem>
+<para>Specify the absolute tesselation tolerance.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-r#</option></term>
+ <listitem>
+<para>Specify the relative tesselation tolerance.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-n#</option></term>
+ <listitem>
+<para>Specify the surface-normal tesselation tolerance.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-x#</option></term>
+ <listitem>
+<para>Specify an RT debug flag.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-X#</option></term>
+ <listitem>
+<para>Specify an NMG debug flag.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-v</option></term>
+ <listitem>
+<para>Enable verbose output.</para>
+ </listitem>
+ </varlistentry>
+</variablelist>
+</refsect1>
+
+<refsect1 xml:id='example'><title>EXAMPLE</title>
+<synopsis>
+$ <emphasis remap='I'>g-raw -o sample.raw sample.g sample_object</emphasis>
+</synopsis>
+</refsect1>
+
+<refsect1 xml:id='diagnostics'><title>DIAGNOSTICS</title>
+<para>Error messages are intended to be self-explanatory.</para>
+
+</refsect1>
+
+<refsect1 xml:id='author'><title>AUTHOR</title>
+<para>BRL-CAD Team</para>
+
+</refsect1>
+
+<refsect1 xml:id='copyright'><title>COPYRIGHT</title>
+<para>This software is Copyright (c) 2013 by the United States
+Government as represented by U.S. Army Research Laboratory.</para>
+</refsect1>
+
+<refsect1 xml:id='bug_reports'><title>BUG REPORTS</title>
+<para>Reports of bugs or problems should be submitted via electronic
+mail to <[email protected]>.</para>
+</refsect1>
+</refentry>
Property changes on: brlcad/trunk/doc/docbook/system/man1/en/g-raw.xml
___________________________________________________________________
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/conv/raw/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/conv/raw/CMakeLists.txt 2013-07-29 14:24:29 UTC (rev
56306)
+++ brlcad/trunk/src/conv/raw/CMakeLists.txt 2013-07-29 15:26:34 UTC (rev
56307)
@@ -19,6 +19,8 @@
)
BRLCAD_ADDEXEC(raw-g "${rawg_SRCS}" "libwdb;librt;libbu" NOSTRICT)
+BRLCAD_ADDEXEC(g-raw g-raw.c "librt;libgcv;libbu;${WINSOCK_LIB}")
+
set(RAW_IGNORE_FILES
Bot.h
RegionList.h
Added: brlcad/trunk/src/conv/raw/g-raw.c
===================================================================
--- brlcad/trunk/src/conv/raw/g-raw.c (rev 0)
+++ brlcad/trunk/src/conv/raw/g-raw.c 2013-07-29 15:26:34 UTC (rev 56307)
@@ -0,0 +1,398 @@
+/* G - R A W . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This program 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 program 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 g-raw.c
+ *
+ * Program to convert a BRL-CAD model (in a .g file) to an RAW file by
+ * calling on the NMG booleans. Based on g-stl.c.
+ *
+ */
+
+#include "common.h"
+
+/* system headers */
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+#include <math.h>
+#include <string.h>
+#include "bio.h"
+#include "bin.h"
+
+/* interface headers */
+#include "vmath.h"
+#include "nmg.h"
+#include "rtgeom.h"
+#include "raytrace.h"
+#include "gcv.h"
+
+
+#define V3ARGSIN(a) (a)[X]/25.4, (a)[Y]/25.4, (a)[Z]/25.4
+#define VSETIN(a, b) {\
+ (a)[X] = (b)[X]/25.4; \
+ (a)[Y] = (b)[Y]/25.4; \
+ (a)[Z] = (b)[Z]/25.4; \
+}
+
+
+static char usage[] = "Usage: %s [-vi8] [-xX lvl] [-P num_cpus] [-a
abs_tess_tol] [-r rel_tess_tol] [-n norm_tess_tol] [-D dist_calc_tol] [-o
output_file_name.stl | -m directory_name] brlcad_db.g object(s)\n";
+
+
+static int verbose;
+static int NMG_debug; /* saved arg of -X, for longjmp
handling */
+static int ncpu = 1; /* Number of processors */
+static char *output_file = NULL; /* output filename */
+static char *output_directory = NULL; /* directory name to hold output files
*/
+static FILE *fp; /* Output file pointer */
+static struct db_i *dbip;
+static struct model *the_model;
+static struct bu_vls file_name = BU_VLS_INIT_ZERO; /* file name
built from region name */
+static struct rt_tess_tol ttol; /* tessellation tolerance in mm
*/
+static struct bn_tol tol; /* calculation tolerance */
+static struct db_tree_state tree_state; /* includes tol & model */
+
+static int regions_tried = 0;
+static int regions_converted = 0;
+static int regions_written = 0;
+static int inches = 0;
+static size_t tot_polygons = 0;
+
+
+/* Byte swaps a four byte value */
+void
+lswap(unsigned int *v)
+{
+ unsigned int r;
+
+ r =*v;
+ *v = ((r & 0xff) << 24) | ((r & 0xff00) << 8) | ((r & 0xff0000) >> 8)
+ | ((r & 0xff000000) >> 24);
+}
+
+
+static void
+nmg_to_raw(struct nmgregion *r, const struct db_full_path *pathp, int
UNUSED(region_id), int UNUSED(material_id), float UNUSED(color[3]))
+{
+ struct model *m;
+ struct shell *s;
+ struct vertex *v;
+ char *region_name;
+ int region_polys=0;
+
+ NMG_CK_REGION(r);
+ RT_CK_FULL_PATH(pathp);
+
+ region_name = db_path_to_string(pathp);
+
+ if (output_directory) {
+ char *c;
+
+ bu_vls_trunc(&file_name, 0);
+ bu_vls_strcpy(&file_name, output_directory);
+ bu_vls_putc(&file_name, '/');
+ c = region_name;
+ c++;
+ while (*c != '\0') {
+ if (*c == '/') {
+ bu_vls_putc(&file_name, '@');
+ } else if (*c == '.' || isspace((int)*c)) {
+ bu_vls_putc(&file_name, '_');
+ } else {
+ bu_vls_putc(&file_name, *c);
+ }
+ c++;
+ }
+ bu_vls_strcat(&file_name, ".raw");
+ /* Open ASCII output file */
+ if ((fp=fopen(bu_vls_addr(&file_name), "wb+")) == NULL)
+ {
+ perror("g-raw");
+ bu_exit(1, "Cannot open ASCII output file (%s) for writing\n",
bu_vls_addr(&file_name));
+ }
+ }
+
+ m = r->m_p;
+ NMG_CK_MODEL(m);
+
+ /* Write pertinent info for this region */
+ fprintf(fp, "%s\n", (region_name+1));
+
+ /* triangulate model */
+ nmg_triangulate_model(m, &tol);
+
+ /* Check triangles */
+ for (BU_LIST_FOR (s, shell, &r->s_hd))
+ {
+ struct faceuse *fu;
+
+ NMG_CK_SHELL(s);
+
+ for (BU_LIST_FOR (fu, faceuse, &s->fu_hd))
+ {
+ struct loopuse *lu;
+
+ NMG_CK_FACEUSE(fu);
+
+ if (fu->orientation != OT_SAME)
+ continue;
+
+ for (BU_LIST_FOR (lu, loopuse, &fu->lu_hd))
+ {
+ struct edgeuse *eu;
+ int vert_count=0;
+ unsigned char vert_buffer[50];
+
+ NMG_CK_LOOPUSE(lu);
+
+ if (BU_LIST_FIRST_MAGIC(&lu->down_hd) != NMG_EDGEUSE_MAGIC)
+ continue;
+
+ memset(vert_buffer, 0, sizeof(vert_buffer));
+
+ /* check vertex numbers for each triangle */
+ for (BU_LIST_FOR (eu, edgeuse, &lu->down_hd))
+ {
+ NMG_CK_EDGEUSE(eu);
+
+ vert_count++;
+
+ v = eu->vu_p->v_p;
+ NMG_CK_VERTEX(v);
+ if (inches)
+ fprintf(fp, vert_count != 3 ? "%f %f %f " : "%f %f
%f\n", V3ARGSIN(v->vg_p->coord));
+ else
+ fprintf(fp, vert_count != 3 ? "%f %f %f " : "%f %f
%f\n", V3ARGS(v->vg_p->coord));
+ }
+ if (vert_count > 3)
+ {
+ bu_free(region_name, "region name");
+ bu_log("lu %p has %d vertices!\n", (void *)lu, vert_count);
+ bu_exit(1, "ERROR: LU is not a triangle");
+ }
+ else if (vert_count < 3)
+ continue;
+
+ tot_polygons++;
+ region_polys++;
+ }
+ }
+ }
+
+ if (output_directory) {
+ fclose(fp);
+ }
+ bu_free(region_name, "region name");
+}
+
+
+/* FIXME: this be a dumb hack to avoid void* conversion */
+struct gcv_data {
+ void (*func)(struct nmgregion *, const struct db_full_path *, int, int,
float [3]);
+};
+static struct gcv_data gcvwriter = {nmg_to_raw};
+
+
+/*
+ * M A I N
+ */
+int
+main(int argc, char *argv[])
+{
+ int c;
+ double percent;
+ int i;
+ int use_mc = 0;
+ int mutex;
+ int missingg;
+
+ bu_setlinebuf(stderr);
+
+ tree_state = rt_initial_tree_state; /* struct copy */
+ tree_state.ts_tol = &tol;
+ tree_state.ts_ttol = &ttol;
+ tree_state.ts_m = &the_model;
+
+ /* Set up tessellation tolerance defaults */
+ ttol.magic = RT_TESS_TOL_MAGIC;
+ /* Defaults, updated by command line options. */
+ ttol.abs = 0.0;
+ ttol.rel = 0.01;
+ ttol.norm = 0.0;
+
+ /* Set up calculation tolerance defaults */
+ /* FIXME: These need to be improved */
+ tol.magic = BN_TOL_MAGIC;
+ tol.dist = 0.0005;
+ tol.dist_sq = tol.dist * tol.dist;
+ tol.perp = 1e-6;
+ tol.para = 1 - tol.perp;
+
+ /* init resources we might need */
+ rt_init_resource(&rt_uniresource, 0, NULL);
+
+ /* make empty NMG model */
+ the_model = nmg_mm();
+ BU_LIST_INIT(&rt_g.rtg_vlfree); /* for vlist macros */
+
+ /* Get command line arguments. */
+ while ((c = bu_getopt(argc, argv, "a:b8m:n:o:r:vx:D:P:X:i")) != -1) {
+ switch (c) {
+ case 'a': /* Absolute tolerance. */
+ ttol.abs = atof(bu_optarg);
+ ttol.rel = 0.0;
+ break;
+ case 'n': /* Surface normal tolerance. */
+ ttol.norm = atof(bu_optarg);
+ ttol.rel = 0.0;
+ break;
+ case '8':
+ use_mc = 1;
+ break;
+ case 'o': /* Output file name. */
+ output_file = bu_optarg;
+ break;
+ case 'm':
+ output_directory = bu_optarg;
+ break;
+ case 'r': /* Relative tolerance. */
+ ttol.rel = atof(bu_optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'P':
+ ncpu = atoi(bu_optarg);
+ rt_g.debug = 1;
+ break;
+ case 'x':
+ sscanf(bu_optarg, "%x", (unsigned int *)&rt_g.debug);
+ break;
+ case 'D':
+ tol.dist = atof(bu_optarg);
+ tol.dist_sq = tol.dist * tol.dist;
+ rt_pr_tol(&tol);
+ break;
+ case 'X':
+ sscanf(bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug);
+ NMG_debug = rt_g.NMG_debug;
+ break;
+ case 'i':
+ inches = 1;
+ break;
+ default:
+ bu_exit(1, usage, argv[0]);
+ break;
+ }
+ }
+
+ mutex = (output_file && output_directory);
+ missingg = (bu_optind+1 >= argc);
+ if (mutex)
+ bu_log("%s: options \"-o\" and \"-m\" are mutually
exclusive\n",argv[0]);
+ if (missingg)
+ bu_log("%s: missing .g file and object(s)\n",argv[0]);
+ if (mutex || missingg)
+ bu_exit(1, usage, argv[0]);
+
+ if (!output_file && !output_directory) {
+ fp = stdout;
+ } else if (output_file) {
+ /* Open ASCII output file */
+ if ((fp=fopen(output_file, "wb+")) == NULL)
+ {
+ perror(argv[0]);
+ bu_exit(1, "%s: Cannot open ASCII output file (%s) for
writing\n",argv[0],output_file);
+ }
+ }
+
+ /* Open brl-cad database */
+ argc -= bu_optind;
+ argv += bu_optind;
+ if ((dbip = db_open(argv[0], DB_OPEN_READONLY)) == DBI_NULL) {
+ perror(argv[0]);
+ bu_exit(1, "Unable to open geometry database file (%s)\n", argv[0]);
+ }
+ if (db_dirbuild(dbip)) {
+ bu_exit(1, "ERROR: db_dirbuild failed\n");
+ }
+
+ BN_CK_TOL(tree_state.ts_tol);
+ RT_CK_TESS_TOL(tree_state.ts_ttol);
+
+ if (verbose) {
+ bu_log("Model: %s\n", argv[0]);
+ bu_log("Objects:");
+ for (i=1; i<argc; i++)
+ bu_log(" %s", argv[i]);
+ bu_log("\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm =
%g\n",
+ tree_state.ts_ttol->abs, tree_state.ts_ttol->rel,
tree_state.ts_ttol->norm);
+ bu_log("Calculational tolerances:\n\tdist = %g mm perp = %g\n",
+ tree_state.ts_tol->dist, tree_state.ts_tol->perp);
+ }
+
+
+ /* Walk indicated tree(s). Each region will be output separately */
+ (void) db_walk_tree(dbip, argc-1, (const char **)(argv+1),
+ 1, /* ncpu */
+ &tree_state,
+ 0, /* take all regions */
+ use_mc?gcv_region_end_mc:gcv_region_end,
+ use_mc?NULL:nmg_booltree_leaf_tess,
+ (genptr_t)&gcvwriter);
+
+ percent = 0;
+ if (regions_tried>0) {
+ percent = ((double)regions_converted * 100) / regions_tried;
+ if (verbose)
+ bu_log("Tried %d regions, %d converted to NMG's successfully.
%g%%\n",
+ regions_tried, regions_converted, percent);
+ }
+ percent = 0;
+
+ if (regions_tried > 0) {
+ percent = ((double)regions_written * 100) / regions_tried;
+ if (verbose)
+ bu_log(" %d triangulated successfully. %g%%\n",
+ regions_written, percent);
+ }
+
+ if (output_file) {
+ fclose(fp);
+ }
+
+ /* Release dynamic storage */
+ nmg_km(the_model);
+ rt_vlist_cleanup();
+ db_close(dbip);
+
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/conv/raw/g-raw.c
___________________________________________________________________
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
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