Revision: 34068 http://brlcad.svn.sourceforge.net/brlcad/?rev=34068&view=rev Author: bob1961 Date: 2009-03-24 16:28:04 +0000 (Tue, 24 Mar 2009)
Log Message: ----------- Added rt_bot_flip, rot_bot_sync, ged_bot_flip and ged_bot_sync functions. Also added bot_flip and bot_sync commands to MGED. Modified Paths: -------------- brlcad/trunk/include/ged.h brlcad/trunk/include/raytrace.h brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj brlcad/trunk/src/libdm/dm-ogl.c brlcad/trunk/src/libdm/dm-wgl.c brlcad/trunk/src/libged/Makefile.am brlcad/trunk/src/librt/primitives/bot/bot.c brlcad/trunk/src/mged/setup.c Added Paths: ----------- brlcad/trunk/src/libged/bot_flip.c brlcad/trunk/src/libged/bot_sync.c Modified: brlcad/trunk/include/ged.h =================================================================== --- brlcad/trunk/include/ged.h 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/include/ged.h 2009-03-24 16:28:04 UTC (rev 34068) @@ -1266,6 +1266,14 @@ GED_EXPORT BU_EXTERN(int ged_bot_face_sort, (struct ged *gedp, int argc, const char *argv[])); /** + * Flip/reverse the specified bot's orientation. + * + * Usage: + * bot_flip bot_obj + */ +GED_EXPORT BU_EXTERN(int ged_bot_flip, (struct ged *gedp, int argc, const char *argv[])); + +/** * Create bot_dest by merging the bot sources. * * Usage: @@ -1277,7 +1285,7 @@ * Calculate vertex normals for the BOT primitive * * Usage: - * bot_smoooth [-t ntol] new_bot old_bot + * bot_smooth [-t ntol] new_bot old_bot */ GED_EXPORT BU_EXTERN(int ged_bot_smooth, (struct ged *gedp, int argc, const char *argv[])); @@ -1290,6 +1298,14 @@ GED_EXPORT BU_EXTERN(int ged_bot_split, (struct ged *gedp, int argc, const char *argv[])); /** + * Sync the specified bot's orientation (i.e. make sure all neighboring triangles have same orientation). + * + * Usage: + * bot_sync bot_obj + */ +GED_EXPORT BU_EXTERN(int ged_bot_sync, (struct ged *gedp, int argc, const char *argv[])); + +/** * Fuse bot vertices * * Usage: Modified: brlcad/trunk/include/raytrace.h =================================================================== --- brlcad/trunk/include/raytrace.h 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/include/raytrace.h 2009-03-24 16:28:04 UTC (rev 34068) @@ -4667,6 +4667,10 @@ char *bot_name, struct db_i *dbip, fastf_t normal_tolerance_angle)); +RT_EXPORT BU_EXTERN(int rt_bot_flip, + (struct rt_bot_internal *bot)); +RT_EXPORT BU_EXTERN(int rt_bot_sync, + (struct rt_bot_internal *bot)); #endif RT_EXPORT BU_EXTERN(int rt_bot_same_orientation, Modified: brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj =================================================================== --- brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj 2009-03-24 16:28:04 UTC (rev 34068) @@ -306,6 +306,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\bot_flip.c" + > + </File> + <File RelativePath="..\..\..\src\libged\bot_merge.c" > </File> @@ -318,6 +322,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\bot_sync.c" + > + </File> + <File RelativePath="..\..\..\src\libged\bot_vertex_fuse.c" > </File> Modified: brlcad/trunk/src/libdm/dm-ogl.c =================================================================== --- brlcad/trunk/src/libdm/dm-ogl.c 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/src/libdm/dm-ogl.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -179,6 +179,7 @@ HIDDEN float ambientColor[4]; HIDDEN float specularColor[4]; HIDDEN float diffuseColor[4]; +HIDDEN float backColor[] = {1.0, 1.0, 0.0, 1.0}; /* yellow */ void ogl_fogHint(struct dm *dmp, int fastfog) @@ -1015,8 +1016,13 @@ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor); + if (1 < dmp->dm_light) { + glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); + glMaterialfv(GL_BACK, GL_DIFFUSE, backColor); + } else + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor); + if (dmp->dm_transparency) glEnable(GL_BLEND); } Modified: brlcad/trunk/src/libdm/dm-wgl.c =================================================================== --- brlcad/trunk/src/libdm/dm-wgl.c 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/src/libdm/dm-wgl.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -161,11 +161,7 @@ HIDDEN float ambientColor[4]; HIDDEN float specularColor[4]; HIDDEN float diffuseColor[4]; -#if 1 HIDDEN float backColor[] = {1.0, 1.0, 0.0, 1.0}; /* yellow */ -#else -HIDDEN float backColor[] = {0.1, 0.1, 0.1, 1.0}; /* dark gray */ -#endif void wgl_fogHint(dmp, fastfog) @@ -984,16 +980,12 @@ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor); -#if 0 - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor); -#else - if (1 < dmp->dm_light) - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor); - else { + + if (1 < dmp->dm_light) { glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); glMaterialfv(GL_BACK, GL_DIFFUSE, backColor); - } -#endif + } else + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor); if (dmp->dm_transparency) glEnable(GL_BLEND); Modified: brlcad/trunk/src/libged/Makefile.am =================================================================== --- brlcad/trunk/src/libged/Makefile.am 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/src/libged/Makefile.am 2009-03-24 16:28:04 UTC (rev 34068) @@ -23,9 +23,11 @@ bot_dump.c \ bot_face_fuse.c \ bot_face_sort.c \ + bot_flip.c \ bot_merge.c \ bot_smooth.c \ bot_split.c \ + bot_sync.c \ bot_vertex_fuse.c \ cat.c \ center.c \ Added: brlcad/trunk/src/libged/bot_flip.c =================================================================== --- brlcad/trunk/src/libged/bot_flip.c (rev 0) +++ brlcad/trunk/src/libged/bot_flip.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -0,0 +1,99 @@ +/* B O T _ F L I P . C + * BRL-CAD + * + * Copyright (c) 2008-2009 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 bot_flip.c + * + * The bot_flip command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include "bio.h" + +#include "rtgeom.h" + +#include "./ged_private.h" + + +int +ged_bot_flip(struct ged *gedp, int argc, const char *argv[]) +{ + register int i; + struct directory *dp; + struct rt_db_internal intern; + struct rt_bot_internal *bot; + static const char *usage = "bot [bot2 bot3 ...]"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_READ_ONLY(gedp, BRLCAD_ERROR); + GED_CHECK_ARGC_GT_0(gedp, argc, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + + /* must be wanting help */ + if (argc == 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_HELP; + } + + for (i=1; i < argc; ++i) { + if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_QUIET)) == DIR_NULL) { + bu_vls_printf(&gedp->ged_result_str, "%s: db_lookup(%s) error\n", argv[0], argv[i]); + continue; + } + + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, bn_mat_identity, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "%s: rt_db_get_internal(%s) error\n", argv[0], argv[i]); + return BRLCAD_ERROR; + } + + if (intern.idb_type != ID_BOT) { + bu_vls_printf(&gedp->ged_result_str, "%s: %s is not a BOT solid!!!\n", argv[0], argv[i]); + continue; + } + + bot = (struct rt_bot_internal *)intern.idb_ptr; + rt_bot_flip(bot); + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, gedp->ged_wdbp->wdb_resp)) { + bu_vls_printf(&gedp->ged_result_str, + "Failed to write BOT (%s) to database!!!", + dp->d_namep); + rt_db_free_internal(&intern, gedp->ged_wdbp->wdb_resp); + return BRLCAD_ERROR; + } + } + + return BRLCAD_OK; +} + +/* + * 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/bot_flip.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/bot_sync.c =================================================================== --- brlcad/trunk/src/libged/bot_sync.c (rev 0) +++ brlcad/trunk/src/libged/bot_sync.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -0,0 +1,99 @@ +/* B O T _ S Y N C . C + * BRL-CAD + * + * Copyright (c) 2008-2009 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 bot_sync.c + * + * The bot_sync command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include "bio.h" + +#include "rtgeom.h" + +#include "./ged_private.h" + + +int +ged_bot_sync(struct ged *gedp, int argc, const char *argv[]) +{ + register int i; + struct directory *dp; + struct rt_db_internal intern; + struct rt_bot_internal *bot; + static const char *usage = "bot [bot2 bot3 ...]"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_READ_ONLY(gedp, BRLCAD_ERROR); + GED_CHECK_ARGC_GT_0(gedp, argc, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + + /* must be wanting help */ + if (argc == 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_HELP; + } + + for (i=1; i < argc; ++i) { + if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_QUIET)) == DIR_NULL) { + bu_vls_printf(&gedp->ged_result_str, "%s: db_lookup(%s) error\n", argv[0], argv[i]); + continue; + } + + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, bn_mat_identity, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "%s: rt_db_get_internal(%s) error\n", argv[0], argv[i]); + return BRLCAD_ERROR; + } + + if (intern.idb_type != ID_BOT) { + bu_vls_printf(&gedp->ged_result_str, "%s: %s is not a BOT solid!!!\n", argv[0], argv[i]); + continue; + } + + bot = (struct rt_bot_internal *)intern.idb_ptr; + rt_bot_sync(bot); + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, gedp->ged_wdbp->wdb_resp)) { + bu_vls_printf(&gedp->ged_result_str, + "Failed to write BOT (%s) to database!!!", + dp->d_namep); + rt_db_free_internal(&intern, gedp->ged_wdbp->wdb_resp); + return BRLCAD_ERROR; + } + } + + return BRLCAD_OK; +} + +/* + * 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/bot_sync.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/librt/primitives/bot/bot.c =================================================================== --- brlcad/trunk/src/librt/primitives/bot/bot.c 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/src/librt/primitives/bot/bot.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -3938,6 +3938,177 @@ return( 0 ); } +int +rt_bot_flip(struct rt_bot_internal *bot) +{ + register int i; + register int tmp_index; + + RT_BOT_CK_MAGIC(bot); + + for (i = 0; i < bot->num_faces; ++i) { + /* Swap any two vertex references. Here we're swapping 1 and 2. */ + tmp_index = bot->faces[i*3+1]; + bot->faces[i*3+1] = bot->faces[i*3+2]; + bot->faces[i*3+2] = tmp_index; + } + + switch (bot->orientation) { + case RT_BOT_CCW: + bot->orientation = RT_BOT_CW; + break; + case RT_BOT_CW: + bot->orientation = RT_BOT_CCW; + break; + case RT_BOT_UNORIENTED: + default: + break; + } + + return 0; +} + +struct tri_edges { + struct bu_list l; + int edge_1[2]; + int edge_2[2]; + int edge_3[2]; + int tri; +}; + +void +rt_bot_sync_func(struct rt_bot_internal *bot, + struct tri_edges *tep, + struct tri_edges *headTep, + struct tri_edges *usedTep) +{ + struct tri_edges *neighbor_tep; + + for (BU_LIST_FOR(neighbor_tep, tri_edges, &headTep->l)) { + if ((tep->edge_1[0] == neighbor_tep->edge_1[0] && + tep->edge_1[1] == neighbor_tep->edge_1[1]) || + (tep->edge_1[0] == neighbor_tep->edge_2[0] && + tep->edge_1[1] == neighbor_tep->edge_2[1]) || + (tep->edge_1[0] == neighbor_tep->edge_3[0] && + tep->edge_1[1] == neighbor_tep->edge_3[1]) || + (tep->edge_2[0] == neighbor_tep->edge_1[0] && + tep->edge_2[1] == neighbor_tep->edge_1[1]) || + (tep->edge_2[0] == neighbor_tep->edge_2[0] && + tep->edge_2[1] == neighbor_tep->edge_2[1]) || + (tep->edge_2[0] == neighbor_tep->edge_3[0] && + tep->edge_2[1] == neighbor_tep->edge_3[1]) || + (tep->edge_3[0] == neighbor_tep->edge_1[0] && + tep->edge_3[1] == neighbor_tep->edge_1[1]) || + (tep->edge_3[0] == neighbor_tep->edge_2[0] && + tep->edge_3[1] == neighbor_tep->edge_2[1]) || + (tep->edge_3[0] == neighbor_tep->edge_3[0] && + tep->edge_3[1] == neighbor_tep->edge_3[1])) { + /* Found a shared edge of a neighboring triangle whose orientation needs to be reversed. */ + int tmp_index; + + BU_LIST_DEQUEUE(&neighbor_tep->l); + BU_LIST_APPEND(&usedTep->l, &neighbor_tep->l); + + /* Swap any two vertex references. Here we're swapping 1 and 2. */ + tmp_index = bot->faces[neighbor_tep->tri*3+1]; + bot->faces[neighbor_tep->tri*3+1] = bot->faces[neighbor_tep->tri*3+2]; + bot->faces[neighbor_tep->tri*3+2] = tmp_index; + + /* Also need to reverse the edges in neighbor_tep */ + tmp_index = neighbor_tep->edge_1[0]; + neighbor_tep->edge_1[0] = neighbor_tep->edge_1[1]; + neighbor_tep->edge_1[1] = tmp_index; + tmp_index = neighbor_tep->edge_2[0]; + neighbor_tep->edge_2[0] = neighbor_tep->edge_2[1]; + neighbor_tep->edge_2[1] = tmp_index; + tmp_index = neighbor_tep->edge_3[0]; + neighbor_tep->edge_3[0] = neighbor_tep->edge_3[1]; + neighbor_tep->edge_3[1] = tmp_index; + + rt_bot_sync_func(bot, neighbor_tep, headTep, usedTep); + neighbor_tep = headTep; + } else if ((tep->edge_1[0] == neighbor_tep->edge_1[1] && + tep->edge_1[1] == neighbor_tep->edge_1[0]) || + (tep->edge_1[0] == neighbor_tep->edge_2[1] && + tep->edge_1[1] == neighbor_tep->edge_2[0]) || + (tep->edge_1[0] == neighbor_tep->edge_3[1] && + tep->edge_1[1] == neighbor_tep->edge_3[0]) || + (tep->edge_2[0] == neighbor_tep->edge_1[1] && + tep->edge_2[1] == neighbor_tep->edge_1[0]) || + (tep->edge_2[0] == neighbor_tep->edge_2[1] && + tep->edge_2[1] == neighbor_tep->edge_2[0]) || + (tep->edge_2[0] == neighbor_tep->edge_3[1] && + tep->edge_2[1] == neighbor_tep->edge_3[0]) || + (tep->edge_3[0] == neighbor_tep->edge_1[1] && + tep->edge_3[1] == neighbor_tep->edge_1[0]) || + (tep->edge_3[0] == neighbor_tep->edge_2[1] && + tep->edge_3[1] == neighbor_tep->edge_2[0]) || + (tep->edge_3[0] == neighbor_tep->edge_3[1] && + tep->edge_3[1] == neighbor_tep->edge_3[0])) { + /* Found a shared edge of a neighboring triangle whose orientation is fine. */ + + BU_LIST_DEQUEUE(&neighbor_tep->l); + BU_LIST_APPEND(&usedTep->l, &neighbor_tep->l); + + rt_bot_sync_func(bot, neighbor_tep, headTep, usedTep); + neighbor_tep = headTep; + } + } +} + +int +rt_bot_sync(struct rt_bot_internal *bot) +{ + register int i; + struct tri_edges headTep; + struct tri_edges usedTep; + struct tri_edges *tep; + int pt_A, pt_B, pt_C; + + RT_BOT_CK_MAGIC(bot); + + /* Nothing to do */ + if (bot->num_faces < 2) + return 0; + + BU_LIST_INIT(&headTep.l); + BU_LIST_INIT(&usedTep.l); + + /* Initialize tep list */ + for (i = 0; i < bot->num_faces; ++i) { + tep = (struct tri_edges *)bu_calloc(1, sizeof(struct tri_edges), "rt_bot_sync_orient: tep"); + BU_LIST_APPEND(&headTep.l, &tep->l); + + pt_A = bot->faces[i*3]; + pt_B = bot->faces[i*3+1]; + pt_C = bot->faces[i*3+2]; + + tep->tri = i; + tep->edge_1[0] = pt_A; + tep->edge_1[1] = pt_B; + tep->edge_2[0] = pt_B; + tep->edge_2[1] = pt_C; + tep->edge_3[0] = pt_C; + tep->edge_3[1] = pt_A; + } + + while (BU_LIST_WHILE(tep, tri_edges, &headTep.l)) { + BU_LIST_DEQUEUE(&tep->l); + BU_LIST_APPEND(&usedTep.l, &tep->l); + + rt_bot_sync_func(bot, tep, &headTep, &usedTep); + } + + while (BU_LIST_WHILE(tep, tri_edges, &usedTep.l)) { + BU_LIST_DEQUEUE(&tep->l); + bu_free(tep, "rt_bot_sync_orient: tep"); + } + + return 0; +} + + + /** @} */ /* * Local Variables: Modified: brlcad/trunk/src/mged/setup.c =================================================================== --- brlcad/trunk/src/mged/setup.c 2009-03-24 14:41:09 UTC (rev 34067) +++ brlcad/trunk/src/mged/setup.c 2009-03-24 16:28:04 UTC (rev 34068) @@ -78,9 +78,11 @@ {"bot_decimate", cmd_ged_plain_wrapper, ged_bot_decimate}, {"bot_face_fuse", cmd_ged_plain_wrapper, ged_bot_face_fuse}, {"bot_face_sort", cmd_ged_plain_wrapper, ged_bot_face_sort}, + {"bot_flip", cmd_ged_plain_wrapper, ged_bot_flip}, {"bot_merge", cmd_ged_plain_wrapper, ged_bot_merge}, {"bot_smooth", cmd_ged_plain_wrapper, ged_bot_smooth}, {"bot_split", cmd_ged_plain_wrapper, ged_bot_split}, + {"bot_sync", cmd_ged_plain_wrapper, ged_bot_sync}, {"bot_vertex_fuse", cmd_ged_plain_wrapper, ged_bot_vertex_fuse}, {"bottom", bv_bottom, GED_FUNC_PTR_NULL}, {"c", cmd_ged_plain_wrapper, ged_comb_std}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits