Revision: 65511
http://sourceforge.net/p/brlcad/code/65511
Author: ejno
Date: 2015-07-01 18:43:25 +0000 (Wed, 01 Jul 2015)
Log Message:
-----------
add rt_bot_decimate_gct(); add a feature_size parameter to ged_bot_reduce
specifying use of the GCT decimator
Modified Paths:
--------------
brlcad/trunk/doc/docbook/system/mann/en/bot_decimate.xml
brlcad/trunk/include/rt/primitives/bot.h
brlcad/trunk/src/libged/bot_decimate.c
brlcad/trunk/src/librt/primitives/bot/bot.c
brlcad/trunk/src/tclscripts/helplib.tcl
Modified: brlcad/trunk/doc/docbook/system/mann/en/bot_decimate.xml
===================================================================
--- brlcad/trunk/doc/docbook/system/mann/en/bot_decimate.xml 2015-07-01
15:17:45 UTC (rev 65510)
+++ brlcad/trunk/doc/docbook/system/mann/en/bot_decimate.xml 2015-07-01
18:43:25 UTC (rev 65511)
@@ -18,7 +18,8 @@
<!-- body begins here -->
<refsynopsisdiv xml:id="synopsis">
<cmdsynopsis sepchar=" ">
- <command>bot_decimate</command>
+ <command>bot_decimate</command>
+ <arg choice="opt" rep="norepeat">-f
<replaceable>feature_size</replaceable></arg>
<arg choice="opt" rep="norepeat">-c
<replaceable>maximum_chord_error</replaceable></arg>
<arg choice="opt" rep="norepeat">-n
<replaceable>maximum_normal_error</replaceable></arg>
<arg choice="opt" rep="norepeat">-e
<replaceable>minimum_edge_length</replaceable></arg>
@@ -32,7 +33,9 @@
<para> Reduces the number of triangles in the
<emphasis>old_bot_primitive</emphasis>
and saves the results to the <emphasis>new_bot_primitive</emphasis>.
The reduction is accomplished through an edge decimation algorithm. Only
changes that do not
- violate the specified constraints are performed. The
<emphasis>maximum_chord_error</emphasis>
+ violate the specified constraints are performed. Specifying the
<emphasis>feature_size</emphasis>
+ parameter will result in use of the new GCT decimator (this parameter is
mutually exclusive with
+ the other tolerances). The <emphasis>maximum_chord_error</emphasis>
parameter specifies the maximum distance allowed between the original
surface and
the surface of the new BOT primitive in the current editing units. The
<emphasis>maximum_normal_error</emphasis> specifies the maximum change in
surface normal (degrees)
Modified: brlcad/trunk/include/rt/primitives/bot.h
===================================================================
--- brlcad/trunk/include/rt/primitives/bot.h 2015-07-01 15:17:45 UTC (rev
65510)
+++ brlcad/trunk/include/rt/primitives/bot.h 2015-07-01 18:43:25 UTC (rev
65511)
@@ -122,7 +122,9 @@
fastf_t max_chord_error,
fastf_t max_normal_error,
fastf_t min_edge_length);
+RT_EXPORT extern size_t rt_bot_decimate_gct(struct rt_bot_internal *bot,
fastf_t feature_size);
+
/** @} */
__END_DECLS
Modified: brlcad/trunk/src/libged/bot_decimate.c
===================================================================
--- brlcad/trunk/src/libged/bot_decimate.c 2015-07-01 15:17:45 UTC (rev
65510)
+++ brlcad/trunk/src/libged/bot_decimate.c 2015-07-01 18:43:25 UTC (rev
65511)
@@ -41,10 +41,12 @@
struct rt_db_internal intern;
struct rt_bot_internal *bot;
struct directory *dp;
- fastf_t max_chord_error=-1.0;
- fastf_t max_normal_error=-1.0;
- fastf_t min_edge_length=-1.0;
- static const char *usage = "-c maximum_chord_error -n maximum_normal_error
-e minimum_edge_length new_bot_name current_bot_name";
+ fastf_t max_chord_error = -1.0;
+ fastf_t max_normal_error = -1.0;
+ fastf_t min_edge_length = -1.0;
+ fastf_t feature_size = -1.0;
+ static const char *usage = "-f feature_size (to use the newer GCT
decimator)"
+ "\nOR: -c maximum_chord_error -n
maximum_normal_error -e minimum_edge_length new_bot_name current_bot_name";
GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
GED_CHECK_READ_ONLY(gedp, GED_ERROR);
@@ -67,32 +69,53 @@
/* process args */
bu_optind = 1;
bu_opterr = 0;
- while ((c=bu_getopt(argc, (char * const *)argv, "c:n:e:")) != -1) {
+
+ while ((c = bu_getopt(argc, (char * const *)argv, "c:n:e:f:")) != -1) {
switch (c) {
case 'c':
max_chord_error = atof(bu_optarg);
+
if (max_chord_error < 0.0) {
bu_vls_printf(gedp->ged_result_str,
"Maximum chord error cannot be less than
zero");
return GED_ERROR;
}
+
break;
+
case 'n':
max_normal_error = atof(bu_optarg);
+
if (max_normal_error < 0.0) {
bu_vls_printf(gedp->ged_result_str,
"Maximum normal error cannot be less than
zero");
return GED_ERROR;
}
+
break;
+
case 'e':
min_edge_length = atof(bu_optarg);
+
if (min_edge_length < 0.0) {
bu_vls_printf(gedp->ged_result_str,
"minimum edge length cannot be less than
zero");
return GED_ERROR;
}
+
break;
+
+ case 'f':
+ feature_size = atof(bu_optarg);
+
+ if (feature_size < 0.0) {
+ bu_vls_printf(gedp->ged_result_str,
+ "minimum feature size cannot be less than
zero");
+ return GED_ERROR;
+ }
+
+ break;
+
default: {
bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0],
usage);
return GED_ERROR;
@@ -100,6 +123,11 @@
}
}
+ if (feature_size > 0.0 && (max_chord_error > 0.0 || max_normal_error > 0.0
|| min_edge_length > 0.0)) {
+ bu_vls_printf(gedp->ged_result_str, "-f may not be used with -c, -n, or
-e");
+ return GED_ERROR;
+ }
+
argc -= bu_optind;
argv += bu_optind;
@@ -124,19 +152,31 @@
RT_BOT_CK_MAGIC(bot);
- /* convert maximum error and edge length to mm */
+ /* convert maximum error, edge length, and feature size to mm */
if (max_chord_error > 0.0) {
max_chord_error = max_chord_error *
gedp->ged_wdbp->dbip->dbi_local2base;
}
+
if (min_edge_length > 0.0) {
min_edge_length = min_edge_length *
gedp->ged_wdbp->dbip->dbi_local2base;
}
- /* do the decimation */
- if (rt_bot_decimate(bot, max_chord_error, max_normal_error,
min_edge_length) < 0) {
- bu_vls_printf(gedp->ged_result_str, "Decimation Error\n");
- rt_db_free_internal(&intern);
- return GED_ERROR;
+ if (feature_size > 0.0) {
+ /* use the new GCT decimator */
+ const size_t orig_num_faces = bot->num_faces;
+ size_t edges_removed;
+ feature_size *= gedp->ged_wdbp->dbip->dbi_local2base;
+ edges_removed = rt_bot_decimate_gct(bot, feature_size);
+ bu_log("original face count = %zu\n", orig_num_faces);
+ bu_log("\tedges removed = %zu\n", edges_removed);
+ bu_log("\tnew face count = %zu\n", bot->num_faces);
+ } else {
+ /* use the old decimator */
+ if (rt_bot_decimate(bot, max_chord_error, max_normal_error,
min_edge_length) < 0) {
+ bu_vls_printf(gedp->ged_result_str, "Decimation Error\n");
+ rt_db_free_internal(&intern);
+ return GED_ERROR;
+ }
}
/* save the result to the database */
Modified: brlcad/trunk/src/librt/primitives/bot/bot.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/bot.c 2015-07-01 15:17:45 UTC (rev
65510)
+++ brlcad/trunk/src/librt/primitives/bot/bot.c 2015-07-01 18:43:25 UTC (rev
65511)
@@ -52,6 +52,11 @@
#include "rt/tie.h"
#include "btg.h" /* for the bottie_ functions */
+
+#include "gct_decimation/meshdecimation.h"
+#include "gct_decimation/meshoptimization.h"
+
+
#define MAXHITS 128
#define BOT_MIN_DN 1.0e-9
@@ -4249,6 +4254,45 @@
/**
+ * decimate a BOT using the new GCT decimator.
+ * `feature_size` is the smallest feature size to keep undecimated.
+ * returns the number of edges removed.
+ */
+size_t
+rt_bot_decimate_gct(struct rt_bot_internal *bot, fastf_t feature_size)
+{
+ const int opt_level = 3; /* maximum */
+ mdOperation mdop;
+
+ RT_BOT_CK_MAGIC(bot);
+
+ if (feature_size < 0.0 && !NEAR_ZERO(feature_size, RT_LEN_TOL))
+ bu_bomb("invalid feature_size");
+ else
+ feature_size = FMAX(0.0, feature_size);
+
+ mdOperationInit(&mdop);
+ mdOperationData(&mdop, bot->num_vertices, bot->vertices,
+ sizeof(bot->vertices[0]), 3 * sizeof(bot->vertices[0]),
bot->num_faces,
+ bot->faces, sizeof(bot->faces[0]), 3 *
sizeof(bot->faces[0]));
+ mdOperationStrength(&mdop, feature_size);
+ mdOperationAddAttrib(&mdop, bot->face_normals,
sizeof(bot->face_normals[0]), 3,
+ 3 * sizeof(bot->face_normals[0]),
MD_ATTRIB_FLAGS_COMPUTE_NORMALS);
+
+ mdMeshDecimation(&mdop, bu_avail_cpus(),
+ MD_FLAGS_NORMAL_VERTEX_SPLITTING |
MD_FLAGS_TRIANGLE_WINDING_CCW);
+
+ bot->num_vertices = mdop.vertexcount;
+ bot->num_faces = mdop.tricount;
+
+ mesh_optimization(bot->num_vertices, bot->num_faces, bot->faces,
+ sizeof(bot->faces[0]), bu_avail_cpus(), opt_level);
+
+ return mdop.decimationcount;
+}
+
+
+/**
* routine to reduce the number of triangles in a BOT by edges
* decimation.
*
Modified: brlcad/trunk/src/tclscripts/helplib.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/helplib.tcl 2015-07-01 15:17:45 UTC (rev
65510)
+++ brlcad/trunk/src/tclscripts/helplib.tcl 2015-07-01 18:43:25 UTC (rev
65511)
@@ -69,7 +69,7 @@
The "rm" subcommand deletes the specified attributes.
The "show" subcommand does a "get" and displays the results in a user
readable format.} }
set helplib_data(wdb_bot_face_sort) {{triangles_per_piece bot_solid1
[bot_solid2 bot_solid3 ...]} {sort the facelist of BOT solids to optimize ray
trace performance for a particular number of triangles per raytrace piece }}
-set helplib_data(wdb_bot_decimate) {{ -c maximum_chord_error -n
maximum_normal_error -e minimum_edge_length new_bot_name current_bot_name}
{Uses edge decimation to reduce the number of triangles in the specified BOT
while keeping within the specified constraints}}
+set helplib_data(wdb_bot_decimate) {{-f feature_size -c
maximum_chord_error -n maximum_normal_error -e minimum_edge_length new_bot_name
current_bot_name} {Uses edge decimation to reduce the number of triangles in
the specified BOT while keeping within the specified constraints}}
set helplib_data(wdb_cat) {{<objects>} {list attributes (brief)}}
set helplib_data(wdb_color) {{[-e] [low high r g b]} {text edit
color table or make new color entry}}
set helplib_data(wdb_comb) {{comb_name [-c|-r] [-w|-f|-l] [-S]
<operation solid>} {create or extend combination w/booleans}}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits