Thread: [brlcad-commits] SF.net SVN: brlcad:[66004] brlcad/trunk/src/libged (Page 10)
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2015-08-18 11:34:18
|
Revision: 66004 http://sourceforge.net/p/brlcad/code/66004 Author: starseeker Date: 2015-08-18 11:34:16 +0000 (Tue, 18 Aug 2015) Log Message: ----------- Commit patch #404 from Brad Hollister adding 'kill F' nmg subcommand Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/nmg.c Added Paths: ----------- brlcad/trunk/src/libged/nmg_kill_f.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2015-08-18 06:16:54 UTC (rev 66003) +++ brlcad/trunk/src/libged/CMakeLists.txt 2015-08-18 11:34:16 UTC (rev 66004) @@ -167,6 +167,7 @@ nmg_fix_normals.c nmg_simplify.c nmg_kill_v.c + nmg_kill_f.c ocenter.c open.c orient.c @@ -355,4 +356,3 @@ # indent-tabs-mode: t # End: # ex: shiftwidth=2 tabstop=8 - Modified: brlcad/trunk/src/libged/nmg.c =================================================================== --- brlcad/trunk/src/libged/nmg.c 2015-08-18 06:16:54 UTC (rev 66003) +++ brlcad/trunk/src/libged/nmg.c 2015-08-18 11:34:16 UTC (rev 66004) @@ -38,6 +38,7 @@ extern int ged_nmg_mm(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_cmface(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_kill_v(struct ged *gedp, int argc, const char *argv[]); +extern int ged_nmg_kill_f(struct ged *gedp, int argc, const char *argv[]); int ged_nmg(struct ged *gedp, int argc, const char *argv[]) @@ -63,6 +64,11 @@ "coordinates) and higher-order topology containing the vertex. " "When specifying vertex to be removed, user generally will display " "vertex coordinates in object via the MGED command labelvert.\n"); + bu_vls_printf(gedp->ged_result_str, "\tkill F - removes the " + "faceuse and face geometry of the selected face (via its " + "index). When specifying the face to be removed, user generally " + "will display face indices in object via the MGED command " + "labelface.\n"); return GED_HELP; } @@ -82,7 +88,12 @@ ged_nmg_cmface(gedp, argc, argv); } else if( BU_STR_EQUAL( "kill", subcmd ) ) { - ged_nmg_kill_v(gedp, argc, argv); + const char* opt = argv[2]; + if ( BU_STR_EQUAL( "V", opt ) ) { + ged_nmg_kill_v(gedp, argc, argv); + } else if ( BU_STR_EQUAL( "F", opt ) ) { + ged_nmg_kill_f(gedp, argc, argv); + } } else { bu_vls_printf(gedp->ged_result_str, "%s is not a subcommand.", subcmd ); Added: brlcad/trunk/src/libged/nmg_kill_f.c =================================================================== --- brlcad/trunk/src/libged/nmg_kill_f.c (rev 0) +++ brlcad/trunk/src/libged/nmg_kill_f.c 2015-08-18 11:34:16 UTC (rev 66004) @@ -0,0 +1,148 @@ +/* N M G _ K I L L _ F. C + * BRL-CAD + * + * Copyright (c) 2015 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/nmg_kill_f.c + * + * The kill F subcommand for nmg top-level command. + * + */ + +#include "common.h" + +#include <string.h> + +#include "bu/cmd.h" +#include "rt/geom.h" + +#include "./ged_private.h" + +void remove_face(const struct model* m, long int fid) +{ + struct nmgregion *r; + struct shell *s; + struct faceuse *fu; + struct face *f; + + NMG_CK_MODEL(m); + + for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) { + NMG_CK_REGION(r); + + if (r->ra_p) { + NMG_CK_REGION_A(r->ra_p); + } + + for (BU_LIST_FOR(s, shell, &r->s_hd)) { + NMG_CK_SHELL(s); + + if (s->sa_p) { + NMG_CK_SHELL_A(s->sa_p); + } + + /* Faces in shell */ + for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { + NMG_CK_FACEUSE(fu); + f = fu->f_p; + NMG_CK_FACE(f); + + if ( fid == f->index ) { + /* this kills both facesuses using the face, + * and the face itself. + */ + nmg_kfu(fu); + } + } + } + } +} + +int +ged_nmg_kill_f(struct ged* gedp, int argc, const char* argv[]) +{ + struct rt_db_internal internal; + struct directory *dp; + struct model* m; + const char* name; + long int fid; + + static const char *usage = "kill F id"; + + GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); + GED_CHECK_DRAWABLE(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 < 4) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_HELP; + } + + /* attempt to resolve and verify */ + name = argv[0]; + + if ( (dp=db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET)) + == RT_DIR_NULL ) { + bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", name); + return GED_ERROR; + } + + if (rt_db_get_internal(&internal, dp, gedp->ged_wdbp->dbip, + bn_mat_identity, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n"); + return GED_ERROR; + } + + if (internal.idb_type != ID_NMG) { + bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + /* get face index from command line */ + fid = (long int)atoi(argv[3]); + + m = (struct model *)internal.idb_ptr; + NMG_CK_MODEL(m); + + remove_face(m, fid); + + if ( wdb_put_internal(gedp->ged_wdbp, name, &internal, 1.0) < 0 ) { + bu_vls_printf(gedp->ged_result_str, "wdb_put_internal(%s)", argv[1]); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + rt_db_free_internal(&internal); + + return GED_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/nmg_kill_f.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. |
From: <sta...@us...> - 2015-08-18 11:38:27
|
Revision: 66005 http://sourceforge.net/p/brlcad/code/66005 Author: starseeker Date: 2015-08-18 11:38:24 +0000 (Tue, 18 Aug 2015) Log Message: ----------- Commit patch #405 from Brad Hollister adding 'move v' nmg subcommand Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/nmg.c Added Paths: ----------- brlcad/trunk/src/libged/nmg_move_v.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2015-08-18 11:34:16 UTC (rev 66004) +++ brlcad/trunk/src/libged/CMakeLists.txt 2015-08-18 11:38:24 UTC (rev 66005) @@ -168,6 +168,7 @@ nmg_simplify.c nmg_kill_v.c nmg_kill_f.c + nmg_move_v.c ocenter.c open.c orient.c Modified: brlcad/trunk/src/libged/nmg.c =================================================================== --- brlcad/trunk/src/libged/nmg.c 2015-08-18 11:34:16 UTC (rev 66004) +++ brlcad/trunk/src/libged/nmg.c 2015-08-18 11:38:24 UTC (rev 66005) @@ -39,6 +39,7 @@ extern int ged_nmg_cmface(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_kill_v(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_kill_f(struct ged *gedp, int argc, const char *argv[]); +extern int ged_nmg_move_v(struct ged *gedp, int argc, const char *argv[]); int ged_nmg(struct ged *gedp, int argc, const char *argv[]) @@ -69,6 +70,10 @@ "index). When specifying the face to be removed, user generally " "will display face indices in object via the MGED command " "labelface.\n"); + bu_vls_printf(gedp->ged_result_str, "\tmove V - moves an existing " + "vertex specified by the coordinates x_initial y_initial " + "z_initial to the position with coordinates x_final y_final " + "z_final.\n"); return GED_HELP; } @@ -95,6 +100,12 @@ ged_nmg_kill_f(gedp, argc, argv); } } + else if( BU_STR_EQUAL( "move", subcmd ) ) { + const char* opt = argv[2]; + if ( BU_STR_EQUAL( "V", opt ) ) { + ged_nmg_move_v(gedp, argc, argv); + } + } else { bu_vls_printf(gedp->ged_result_str, "%s is not a subcommand.", subcmd ); return GED_ERROR; Added: brlcad/trunk/src/libged/nmg_move_v.c =================================================================== --- brlcad/trunk/src/libged/nmg_move_v.c (rev 0) +++ brlcad/trunk/src/libged/nmg_move_v.c 2015-08-18 11:38:24 UTC (rev 66005) @@ -0,0 +1,339 @@ +/* N M G _ M O V E _ V. C + * BRL-CAD + * + * Copyright (c) 2015 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/nmg_move_v.c + * + * The move V subcommand for nmg top-level command. + * + */ + +#include "common.h" + +#include <string.h> + +#include "bu/cmd.h" +#include "rt/geom.h" + +#include "./ged_private.h" + +void move_vertex(const struct model* m, point_t v_old, point_t v_new) +{ + struct nmgregion *r; + struct shell *s; + struct faceuse *fu; + struct face *f; + struct loopuse *lu; + struct loop *l; + struct edgeuse *eu; + struct edge *e; + struct vertexuse *vu; + struct vertex *v; + + NMG_CK_MODEL(m); + + /* Traverse NMG model to find specified vertex and sets the new coords. + */ + + for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) { + NMG_CK_REGION(r); + + if (r->ra_p) { + NMG_CK_REGION_A(r->ra_p); + } + + for (BU_LIST_FOR(s, shell, &r->s_hd)) { + NMG_CK_SHELL(s); + + if (s->sa_p) { + NMG_CK_SHELL_A(s->sa_p); + } + + /* Faces in shell */ + for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { + NMG_CK_FACEUSE(fu); + f = fu->f_p; + NMG_CK_FACE(f); + + if (f->g.magic_p) switch (*f->g.magic_p) { + case NMG_FACE_G_PLANE_MAGIC: + break; + case NMG_FACE_G_SNURB_MAGIC: + break; + } + + /* Loops in face */ + for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) { + NMG_CK_LOOPUSE(lu); + l = lu->l_p; + NMG_CK_LOOP(l); + + if (l->lg_p) { + NMG_CK_LOOP_G(l->lg_p); + } + + if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC) { + /* Loop of Lone vertex */ + vu = BU_LIST_FIRST(vertexuse, &lu->down_hd); + + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + + if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + + continue; + } + + for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) { + NMG_CK_EDGEUSE(eu); + e = eu->e_p; + NMG_CK_EDGE(e); + + if (eu->g.magic_p) { + switch (*eu->g.magic_p) { + case NMG_EDGE_G_LSEG_MAGIC: + break; + case NMG_EDGE_G_CNURB_MAGIC: + break; + } + } + + vu = eu->vu_p; + + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + + if ( VNEAR_EQUAL(v->vg_p->coord, + v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + } + } + } + + /* Wire loops in shell */ + for (BU_LIST_FOR(lu, loopuse, &s->lu_hd)) { + NMG_CK_LOOPUSE(lu); + l = lu->l_p; + NMG_CK_LOOP(l); + + if (l->lg_p) { + NMG_CK_LOOP_G(l->lg_p); + } + + if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC) { + /* Wire loop of Lone vertex */ + vu = BU_LIST_FIRST(vertexuse, &lu->down_hd); + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + continue; + } + + for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) { + NMG_CK_EDGEUSE(eu); + e = eu->e_p; + NMG_CK_EDGE(e); + + if (eu->g.magic_p) switch (*eu->g.magic_p) { + case NMG_EDGE_G_LSEG_MAGIC: + break; + case NMG_EDGE_G_CNURB_MAGIC: + break; + } + vu = eu->vu_p; + + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + } + } + + /* Wire edges in shell */ + for (BU_LIST_FOR(eu, edgeuse, &s->eu_hd)) { + NMG_CK_EDGEUSE(eu); + e = eu->e_p; + NMG_CK_EDGE(e); + + if (eu->g.magic_p) { + switch (*eu->g.magic_p) { + case NMG_EDGE_G_LSEG_MAGIC: + break; + case NMG_EDGE_G_CNURB_MAGIC: + break; + } + } + + vu = eu->vu_p; + + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + + if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + } + + /* Lone vertex in shell */ + vu = s->vu_p; + + if (vu) { + /* check and remove vertexuse */ + NMG_CK_VERTEXUSE(vu); + v = vu->v_p; + NMG_CK_VERTEX(v); + + if (v->vg_p) { + NMG_CK_VERTEX_G(v->vg_p); + + if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) { + v->vg_p->coord[0] = v_new[0]; + v->vg_p->coord[1] = v_new[1]; + v->vg_p->coord[2] = v_new[2]; + } + } + } + } + } +} + +int +ged_nmg_move_v(struct ged* gedp, int argc, const char* argv[]) +{ + struct rt_db_internal internal; + struct directory *dp; + struct model* m; + const char* name; + point_t vtold; + point_t vtnew; + + static const char *usage = "move V x_old y_old z_old x_new y_new z_new"; + + GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); + GED_CHECK_DRAWABLE(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 != 9 ) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_HELP; + } + + /* attempt to resolve and verify */ + name = argv[0]; + + if ( (dp=db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET)) + == RT_DIR_NULL ) { + bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", name); + return GED_ERROR; + } + + if (rt_db_get_internal(&internal, dp, gedp->ged_wdbp->dbip, + bn_mat_identity, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n"); + return GED_ERROR; + } + + if (internal.idb_type != ID_NMG) { + bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + vtold[0] = atof(argv[3]); + vtold[1] = atof(argv[4]); + vtold[2] = atof(argv[5]); + + vtnew[0] = atof(argv[6]); + vtnew[1] = atof(argv[7]); + vtnew[2] = atof(argv[8]); + + m = (struct model *)internal.idb_ptr; + NMG_CK_MODEL(m); + + move_vertex(m, vtold, vtnew); + + if ( wdb_put_internal(gedp->ged_wdbp, name, &internal, 1.0) < 0 ) { + bu_vls_printf(gedp->ged_result_str, "wdb_put_internal(%s)", argv[1]); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + rt_db_free_internal(&internal); + + return GED_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/nmg_move_v.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. |
From: <sta...@us...> - 2015-08-21 01:03:13
|
Revision: 66071 http://sourceforge.net/p/brlcad/code/66071 Author: starseeker Date: 2015-08-21 01:03:10 +0000 (Fri, 21 Aug 2015) Log Message: ----------- Add patch 414 from Brad Hollister - nmg make V subcommand. Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/nmg.c Added Paths: ----------- brlcad/trunk/src/libged/nmg_make_v.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2015-08-21 00:55:57 UTC (rev 66070) +++ brlcad/trunk/src/libged/CMakeLists.txt 2015-08-21 01:03:10 UTC (rev 66071) @@ -161,6 +161,7 @@ mrot.c nirt.c nmg.c + nmg_make_v.c nmg_mm.c nmg_cmface.c nmg_collapse.c Modified: brlcad/trunk/src/libged/nmg.c =================================================================== --- brlcad/trunk/src/libged/nmg.c 2015-08-21 00:55:57 UTC (rev 66070) +++ brlcad/trunk/src/libged/nmg.c 2015-08-21 01:03:10 UTC (rev 66071) @@ -40,6 +40,7 @@ extern int ged_nmg_kill_v(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_kill_f(struct ged *gedp, int argc, const char *argv[]); extern int ged_nmg_move_v(struct ged *gedp, int argc, const char *argv[]); +extern int ged_nmg_make_v(struct ged *gedp, int argc, const char *argv[]); int ged_nmg(struct ged *gedp, int argc, const char *argv[]) @@ -74,6 +75,8 @@ "vertex specified by the coordinates x_initial y_initial " "z_initial to the position with coordinates x_final y_final " "z_final.\n"); + bu_vls_printf(gedp->ged_result_str, "\tmake V - creates a new " + "vertex in the nmg object.\n"); return GED_HELP; } @@ -106,6 +109,12 @@ ged_nmg_move_v(gedp, argc, argv); } } + else if( BU_STR_EQUAL( "make", subcmd ) ) { + const char* opt = argv[2]; + if ( BU_STR_EQUAL( "V", opt ) ) { + ged_nmg_make_v(gedp, argc, argv); + } + } else { bu_vls_printf(gedp->ged_result_str, "%s is not a subcommand.", subcmd ); return GED_ERROR; Added: brlcad/trunk/src/libged/nmg_make_v.c =================================================================== --- brlcad/trunk/src/libged/nmg_make_v.c (rev 0) +++ brlcad/trunk/src/libged/nmg_make_v.c 2015-08-21 01:03:10 UTC (rev 66071) @@ -0,0 +1,147 @@ +/* N M G _ M A K E _ V. C + * BRL-CAD + * + * Copyright (c) 2015 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/nmg_make_v.c + * + * The make V subcommand for nmg top-level command. + * + */ + +#include "common.h" +#include "nmg.h" + +#include <signal.h> +#include <string.h> + +#include "bu/cmd.h" +#include "rt/geom.h" + +#include "./ged_private.h" + +struct tmp_v { + point_t pt; + struct vertex *v; +}; + +int +ged_nmg_make_v(struct ged *gedp, int argc, const char *argv[]) +{ + struct rt_db_internal internal; + struct directory *dp; + struct model* m; + const char* name; + struct nmgregion* r; + struct shell* s; + struct tmp_v* verts; + struct bn_tol tol; + int idx; + int num_verts; + static const char *usage = "make V x0 y0 z0 ... xn yn zn"; + + GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); + GED_CHECK_READ_ONLY(gedp, GED_ERROR); + GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); + + num_verts = (argc - 3) / 3; + + /* check for less than three vertices or incomplete vertex coordinates */ + if (argc < ELEMENTS_PER_POINT + 3 || (argc - 3) % 3 != 0) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_HELP; + } + + /* attempt to resolve and verify */ + name = argv[0]; + + if ( (dp=db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET)) + == RT_DIR_NULL ) { + bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", name); + return GED_ERROR; + } + + if (rt_db_get_internal(&internal, dp, gedp->ged_wdbp->dbip, + bn_mat_identity, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n"); + return GED_ERROR; + } + + if (internal.idb_type != ID_NMG) { + bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + m = (struct model *)internal.idb_ptr; + NMG_CK_MODEL(m); + + if (BU_LIST_IS_EMPTY(&m->r_hd)) { + r = nmg_mrsv(m); + s = BU_LIST_FIRST(shell, &r->s_hd); + } else { + r = BU_LIST_FIRST(nmgregion, &m->r_hd); + s = BU_LIST_FIRST(shell, &r->s_hd); + } + + NMG_CK_REGION(r); + NMG_CK_SHELL(s); + + verts = (struct tmp_v *)NULL; + verts = (struct tmp_v *)bu_calloc(num_verts, + sizeof(struct tmp_v), "verts"); + + for (idx=0; idx < num_verts; idx++){ + struct shell* ns = nmg_msv(r); + NMG_CK_SHELL(ns); + + verts[idx].pt[0] = (fastf_t)atof(argv[idx*3+3]); + verts[idx].pt[1] = (fastf_t)atof(argv[idx*3+4]); + verts[idx].pt[2] = (fastf_t)atof(argv[idx*3+5]); + + nmg_vertex_gv( ns->vu_p->v_p, verts[idx].pt); + } + + 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; + + nmg_rebound(m, &tol); + + if ( wdb_put_internal(gedp->ged_wdbp, name, &internal, 1.0) < 0 ) { + bu_vls_printf(gedp->ged_result_str, "wdb_put_internal(%s)", argv[1]); + rt_db_free_internal(&internal); + return GED_ERROR; + } + + rt_db_free_internal(&internal); + bu_free(verts, "new verts"); + + return GED_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/nmg_make_v.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. |
From: <sta...@us...> - 2015-10-17 17:55:52
|
Revision: 66457 http://sourceforge.net/p/brlcad/code/66457 Author: starseeker Date: 2015-10-17 17:55:49 +0000 (Sat, 17 Oct 2015) Log Message: ----------- Add support for writing tikz output to a file, since the new approach results in fairly large outputs. Modified Paths: -------------- brlcad/trunk/src/libged/brep.c brlcad/trunk/src/libged/ged_private.h brlcad/trunk/src/libged/shape_recognition.cpp Modified: brlcad/trunk/src/libged/brep.c =================================================================== --- brlcad/trunk/src/libged/brep.c 2015-10-17 17:43:03 UTC (rev 66456) +++ brlcad/trunk/src/libged/brep.c 2015-10-17 17:55:49 UTC (rev 66457) @@ -218,7 +218,7 @@ bu_vls_printf(gedp->ged_result_str, "\tplot S [index] - plot specific BREP 'surface'\n"); bu_vls_printf(gedp->ged_result_str, "\tplot F [index] - plot specific BREP 'face'\n"); bu_vls_printf(gedp->ged_result_str, "\tcsg - convert BREP to implicit primitive CSG tree\n"); - bu_vls_printf(gedp->ged_result_str, "\ttikz - generate a Tikz LaTeX version of the B-Rep edges\n"); + bu_vls_printf(gedp->ged_result_str, "\ttikz [file] - generate a Tikz LaTeX version of the B-Rep edges\n"); bu_vls_printf(gedp->ged_result_str, "\ttranslate SCV index i j dx dy dz - translate a surface control vertex\n"); bu_vls_printf(gedp->ged_result_str, "\tintersect <obj2> <i> <j> [PP|PC|PS|CC|CS|SS] - BREP intersections\n"); bu_vls_printf(gedp->ged_result_str, "\tu|i|- <obj2> <output> - BREP boolean evaluations\n"); @@ -345,7 +345,11 @@ if (BU_STR_EQUAL(argv[2], "tikz")) { - return _ged_brep_tikz(gedp, argv[1]); + if (argc == 4) { + return _ged_brep_tikz(gedp, argv[1], argv[3]); + } else { + return _ged_brep_tikz(gedp, argv[1], NULL); + } } Modified: brlcad/trunk/src/libged/ged_private.h =================================================================== --- brlcad/trunk/src/libged/ged_private.h 2015-10-17 17:43:03 UTC (rev 66456) +++ brlcad/trunk/src/libged/ged_private.h 2015-10-17 17:55:49 UTC (rev 66457) @@ -525,7 +525,7 @@ extern int _ged_results_add(struct ged_results *results, const char *result_string); extern int _ged_brep_to_csg(struct ged *gedp, const char *obj_name, int verify); -extern int _ged_brep_tikz(struct ged *gedp, const char *obj_name); +extern int _ged_brep_tikz(struct ged *gedp, const char *obj_name, const char *outfile); __END_DECLS Modified: brlcad/trunk/src/libged/shape_recognition.cpp =================================================================== --- brlcad/trunk/src/libged/shape_recognition.cpp 2015-10-17 17:43:03 UTC (rev 66456) +++ brlcad/trunk/src/libged/shape_recognition.cpp 2015-10-17 17:55:49 UTC (rev 66457) @@ -738,7 +738,7 @@ } extern "C" int -_ged_brep_tikz(struct ged *gedp, const char *dp_name) +_ged_brep_tikz(struct ged *gedp, const char *dp_name, const char *outfile) { struct rt_db_internal intern; struct rt_brep_internal *brep_ip = NULL; @@ -762,19 +762,32 @@ ON_String s; struct bu_vls wrapper = BU_VLS_INIT_ZERO; + bu_vls_printf(&wrapper, "\\documentclass{article}\n"); + bu_vls_printf(&wrapper, "\\usepackage{tikz}\n"); + bu_vls_printf(&wrapper, "\\usepackage{tikz-3dplot}\n\n"); + bu_vls_printf(&wrapper, "\\begin{document}\n\n"); // Translate view az/el into tikz-3dplot variation - bu_vls_sprintf(&wrapper, "\\tdplotsetmaincoords{%f}{%f}\n", 90 + -1*gedp->ged_gvp->gv_aet[1], -1*(-90 + -1 * gedp->ged_gvp->gv_aet[0])); + bu_vls_printf(&wrapper, "\\tdplotsetmaincoords{%f}{%f}\n", 90 + -1*gedp->ged_gvp->gv_aet[1], -1*(-90 + -1 * gedp->ged_gvp->gv_aet[0])); bu_vls_printf(&wrapper, "\\begin{tikzpicture}[scale=1,tdplot_main_coords]\n"); s.Append(bu_vls_addr(&wrapper), bu_vls_strlen(&wrapper)); const ON_Brep *brep = brep_ip->brep; (void)ON_BrepTikz(s, brep, NULL, NULL); - bu_vls_sprintf(&wrapper, "\\end{tikzpicture}\n"); + bu_vls_sprintf(&wrapper, "\\end{tikzpicture}\n\n"); + bu_vls_printf(&wrapper, "\\end{document}\n"); s.Append(bu_vls_addr(&wrapper), bu_vls_strlen(&wrapper)); bu_vls_free(&wrapper); - bu_vls_sprintf(gedp->ged_result_str, "%s", s.Array()); + if (outfile) { + FILE *fp = fopen(outfile, "w"); + fprintf(fp, "%s", s.Array()); + fclose(fp); + bu_vls_sprintf(gedp->ged_result_str, "Output written to file %s", outfile); + } else { + + bu_vls_sprintf(gedp->ged_result_str, "%s", s.Array()); + } return GED_OK; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2015-10-26 21:38:22
|
Revision: 66514 http://sourceforge.net/p/brlcad/code/66514 Author: starseeker Date: 2015-10-26 21:38:20 +0000 (Mon, 26 Oct 2015) Log Message: ----------- make remove a C++ file Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libged/remove.cpp Removed Paths: ------------- brlcad/trunk/src/libged/remove.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2015-10-26 21:35:27 UTC (rev 66513) +++ brlcad/trunk/src/libged/CMakeLists.txt 2015-10-26 21:38:20 UTC (rev 66514) @@ -210,7 +210,7 @@ red.c regdef.c region.c - remove.c + remove.cpp report.c rfarb.c rmap.c Deleted: brlcad/trunk/src/libged/remove.c =================================================================== --- brlcad/trunk/src/libged/remove.c 2015-10-26 21:35:27 UTC (rev 66513) +++ brlcad/trunk/src/libged/remove.c 2015-10-26 21:38:20 UTC (rev 66514) @@ -1,536 +0,0 @@ -/* R E M O V E . C - * BRL-CAD - * - * Copyright (c) 2008-2014 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/remove.c - * - * The remove command. - * - */ - -#include "common.h" - -#include <string.h> -#include <limits.h> /* FOR INT_MAX */ - -#include "bu/cmd.h" -#include "bu/opt.h" -#include "bu/ptbl.h" -#include "bu/vls.h" - -#include "./ged_private.h" - -HIDDEN void -_remove_show_help(struct ged *gedp, const char *cmd, struct bu_opt_desc *d) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - const char *option_help = bu_opt_describe(d, NULL); - bu_vls_sprintf(&str, "Usage: %s [options] [comb] [comb/obj] object(s)\n\n", cmd); - bu_vls_printf(&str, "Any argument of the form comb/obj is interpreted as requesting removal of\n"); - bu_vls_printf(&str, "object \"obj\" from the first level tree of \"comb\" (instances of obj\n"); - bu_vls_printf(&str, "deeper in the tree of \"comb\" are not removed.) Note that these paths\n"); - bu_vls_printf(&str, "are processed first - any other rm operations will take place after these\n"); - bu_vls_printf(&str, "paths are handled.\n\n"); - bu_vls_printf(&str, "By default, if no options are supplied and the first object is a comb\n"); - bu_vls_printf(&str, "the object(s) are removed from \"comb\" - this is a convenient way to\n"); - bu_vls_printf(&str, "remove multiple objects from a single comb. Again, instances are.\n"); - bu_vls_printf(&str, "removed only from the immediate child object set of \"comb\".\n\n"); - bu_vls_printf(&str, "If one or more options are supplied or the first object specified is not a comb,\n"); - bu_vls_printf(&str, "the command form becomes:\n\n"); - bu_vls_printf(&str, " %s [options] object(s)\n\n", cmd); - bu_vls_printf(&str, "and the scope changes from a single comb's tree to the .g database.\n"); - if (option_help) { - bu_vls_printf(&str, "\nOptions:\n%s\n", option_help); - bu_free((char *)option_help, "help str"); - } - bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&str)); - bu_vls_free(&str); -} - -HIDDEN void -_rm_ref(struct ged *gedp, struct bu_ptbl *objs, struct bu_vls *rmlog, int dry_run) -{ - size_t i = 0; - struct directory *dp = RT_DIR_NULL; - struct rt_db_internal intern; - struct rt_comb_internal *comb; - - FOR_ALL_DIRECTORY_START(dp, gedp->ged_wdbp->dbip) { - if (!(dp->d_flags & RT_DIR_COMB)) - continue; - - if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { - if (rmlog) { - bu_vls_printf(rmlog, "rt_db_get_internal(%s) failure", dp->d_namep); - } - continue; - } - comb = (struct rt_comb_internal *)intern.idb_ptr; - RT_CK_COMB(comb); - - for (i = 0; i < BU_PTBL_LEN(objs); i++) { - int code; - - code = db_tree_del_dbleaf(&(comb->tree), (const char *)BU_PTBL_GET(objs, i), &rt_uniresource, dry_run); - if (code == -1) - continue; /* not found */ - if (code == -2) - continue; /* empty tree */ - if (code < 0) { - if (rmlog) { - bu_vls_printf(rmlog, "ERROR: Failure deleting %s/%s\n", dp->d_namep, (const char *)BU_PTBL_GET(objs, i)); - } - } else { - if (rmlog && dry_run) { - bu_vls_printf(rmlog, "Remove reference to object %s from %s", (const char *)BU_PTBL_GET(objs, i), dp->d_namep); - } - } - } - - if (!dry_run && rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { - if (rmlog) { - bu_vls_printf(rmlog, "ERROR: Unable to write new combination into database.\n"); - } - continue; - } - } FOR_ALL_DIRECTORY_END; -} - - -/* this finds references to 'obj' that are not within any of the the 'topobjs' - * combination hierarchies, elsewhere in the database. this is so we can make - * sure we don't kill objects that are referenced elsewhere in the - * database, in a hierarchy that is not being deleted. - */ -HIDDEN int -_rm_find_reference(struct db_i *dbip, struct bu_ptbl *topobjs, const char *obj, struct bu_vls *rmlog, int verbosity) -{ - int i; - int ret = 0; - struct bu_vls str = BU_VLS_INIT_ZERO; - - if (!dbip || !topobjs || !obj) - return 0; - - bu_vls_sprintf(&str, "-depth >0"); - for (i = 0; i < (int)BU_PTBL_LEN(topobjs); i++) { - bu_vls_printf(&str, " -not -below -name %s", ((struct directory *)BU_PTBL_GET(topobjs, i))->d_namep); - } - bu_vls_printf(&str, " -name %s", obj); - - ret = db_search(NULL, DB_SEARCH_TREE, bu_vls_cstr(&str), 0, NULL, dbip); - - if (ret && rmlog && verbosity > 0) { - bu_vls_printf(rmlog, "NOTE: %s is referenced by unremoved objects in the database - skipping.\n", obj); - } - - bu_vls_free(&str); - - return ret; -} - - -HIDDEN int -_rm_obj(struct ged *gedp, const char *objname, struct bu_ptbl *topobjs, struct bu_vls *rmlog, int verbosity, int force, int dry_run) -{ - struct directory *dp = RT_DIR_NULL; - if (!gedp || !objname) return -1; - - if (topobjs && !force) { - if (_rm_find_reference(gedp->ged_wdbp->dbip, topobjs, objname, rmlog, verbosity) > 0) return -1; - } - - dp = db_lookup(gedp->ged_wdbp->dbip, objname, LOOKUP_QUIET); - - if (dp != RT_DIR_NULL) { - if (!force && dp->d_major_type == DB5_MAJORTYPE_ATTRIBUTE_ONLY && dp->d_minor_type == 0) { - if (rmlog) { - bu_vls_printf(rmlog, "Warning: you attempted to delete the _GLOBAL object.\n"); - bu_vls_printf(rmlog, "\tIf you delete the \"_GLOBAL\" object you will be losing some important information\n"); - bu_vls_printf(rmlog, "\tsuch as your preferred units and the title of the database.\n"); - bu_vls_printf(rmlog, "\tUse the \"-f\" option, if you really want to do this.\n"); - } - return -1; - } - - /* don't worry about phony objects */ - if (dp->d_addr == RT_DIR_PHONY_ADDR) return 0; - - /* clear the object from the display */ - if (!dry_run) { - _dl_eraseAllNamesFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, objname, 0, gedp->freesolid); - - /* actually do the deletion */ - if (db_delete(gedp->ged_wdbp->dbip, dp) != 0 || db_dirdelete(gedp->ged_wdbp->dbip, dp) != 0) { - /* Abort kill processing on first error */ - if (rmlog) bu_vls_printf(rmlog, "Error: unable to delete %s", objname); - return -1; - } - } else { - bu_vls_printf(rmlog, "Delete object %s\n", objname); - } - } else { - if (rmlog && verbosity >= 2) { - bu_vls_printf(rmlog, "Attempted to delete object %s, but it was not found in the database\n", objname); - } - return -1; - } - return 0; -} - -HIDDEN int -_removal_queue(struct bu_ptbl *to_remove, struct ged *gedp, struct bu_ptbl *seeds, struct bu_vls *rmlog, int verbosity) -{ - size_t i = 0; - - if (!to_remove || !gedp || !seeds) return 0; - - for (i = 0; i < BU_PTBL_LEN(seeds); i++) { - const char *objname = ((struct directory *)BU_PTBL_GET(seeds, i))->d_namep; - if (_rm_find_reference(gedp->ged_wdbp->dbip, seeds, objname, rmlog, verbosity) > 0) continue; - } - - return 0; -} - - -HIDDEN int -_valid_rm_objs(struct directory ***dirp, struct bu_ptbl *validobjs, struct ged *gedp, struct bu_ptbl *objs, struct bu_vls *rmlog, int verbosity) -{ - int i = 0; - int dircnt = 0; - struct directory *rdp = RT_DIR_NULL; - for (i = 0; i < (int)BU_PTBL_LEN(objs); i++) { - rdp = db_lookup(gedp->ged_wdbp->dbip, (const char *)BU_PTBL_GET(objs, i), LOOKUP_QUIET); - if (rdp != RT_DIR_NULL) { - bu_ptbl_ins_unique(validobjs, (long *)rdp); - } else { - if (rmlog && verbosity >= 2) { - bu_vls_printf(rmlog, "Attempted to delete object %s, but it was not found in the database\n", (const char *)BU_PTBL_GET(objs, i)); - } - } - } - dircnt = BU_PTBL_LEN(validobjs); - /* Got valid objects, build search directory array */ - if (dircnt > 0) { - (*dirp) = (struct directory **)bu_calloc(BU_PTBL_LEN(validobjs), sizeof(struct directory *), "dp array"); - for (i = 0; i < (int)BU_PTBL_LEN(validobjs); i++) { - (*dirp)[i] = (struct directory *)BU_PTBL_GET(validobjs, i); - } - } - return dircnt; -} - -HIDDEN int -_ged_rm_path(struct ged *gedp, const char *in) -{ - int ret = GED_OK; - struct rt_db_internal intern; - struct rt_comb_internal *comb; - struct directory *dp; - struct bu_vls combstr = BU_VLS_INIT_ZERO; - struct bu_vls obj = BU_VLS_INIT_ZERO; - const char *slash = strrchr(in, '/'); - bu_vls_sprintf(&obj, "%s", slash+1); - bu_vls_strncpy(&combstr, in, strlen(in) - strlen(slash)); - bu_log("obj: %s\n", bu_vls_addr(&obj)); - bu_log("comb: %s\n", bu_vls_addr(&combstr)); - - if ((dp = db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&combstr), LOOKUP_NOISY)) == RT_DIR_NULL) { - bu_vls_printf(gedp->ged_result_str, "Error: first object %s in path %s does not exist", bu_vls_addr(&combstr), in); - ret = GED_ERROR; - goto cleanup; - } - - if ((dp->d_flags & RT_DIR_COMB) == 0) { - bu_vls_printf(gedp->ged_result_str, "Error: first object %s in path %s is not a comb", bu_vls_addr(&combstr), in); - ret = GED_ERROR; - goto cleanup; - } - - if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { - bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); - ret = GED_ERROR; - goto cleanup; - } - - comb = (struct rt_comb_internal *)intern.idb_ptr; - RT_CK_COMB(comb); - - if (db_tree_del_dbleaf(&(comb->tree), bu_vls_addr(&obj), &rt_uniresource, 0) < 0) { - bu_vls_printf(gedp->ged_result_str, "ERROR: Failure deleting %s/%s\n", dp->d_namep, bu_vls_addr(&obj)); - ret = GED_ERROR; - goto cleanup; - } else { - struct bu_vls path = BU_VLS_INIT_ZERO; - - bu_vls_printf(&path, "%s/%s", dp->d_namep, bu_vls_addr(&obj)); - _dl_eraseAllPathsFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, bu_vls_addr(&path), 0, gedp->freesolid); - bu_vls_free(&path); - bu_vls_printf(gedp->ged_result_str, "deleted %s/%s\n", dp->d_namep, bu_vls_addr(&obj)); - } - - if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { - bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); - ret = GED_ERROR; - } - -cleanup: - bu_vls_free(&combstr); - bu_vls_free(&obj); - return ret; -} - - -HIDDEN int -_rm_verbose(struct bu_vls *msg, int argc, const char **argv, void *set_v) -{ - int val = INT_MAX; - int *int_set = (int *)set_v; - int int_ret; - if (!argv || !argv[0] || strlen(argv[0]) == 0 || argc == 0) { - /* Have verbosity flag but no valid arg - go with just the flag */ - if (int_set) (*int_set) = 1; - return 0; - } - - int_ret = bu_opt_int(msg, argc, argv, (void *)&val); - if (int_ret == -1) return -1; - - if (val < 0) return -1; - if (val > 4) val = 4; - - if (int_set) (*int_set) = val; - - return 1; -} - -int -ged_remove(struct ged *gedp, int orig_argc, const char *orig_argv[]) -{ - int print_help = 0; - int remove_force = 0; - int remove_from_comb = 1; - int remove_recursive = 0; - int remove_refs = 0; - int verbose = 0; - int no_op = 0; - size_t argc = (size_t)orig_argc; - char **argv = bu_dup_argv(argc, orig_argv); - size_t free_argc = argc; - char **free_argv = argv; - int ret_ac; - - struct directory *dp; - int i; - struct rt_db_internal intern; - struct rt_comb_internal *comb; - int ret = GED_OK; - struct bu_opt_desc d[8]; - struct bu_vls str = BU_VLS_INIT_ZERO; - struct bu_vls rmlog = BU_VLS_INIT_ZERO; - struct bu_ptbl objs = BU_PTBL_INIT_ZERO; - - GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); - GED_CHECK_DRAWABLE(gedp, GED_ERROR); - GED_CHECK_READ_ONLY(gedp, GED_ERROR); - GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); - - BU_OPT(d[0], "h", "help", "", NULL, (void *)&print_help, "Print help and exit"); - BU_OPT(d[1], "?", "", "", NULL, (void *)&print_help, ""); - BU_OPT(d[2], "f", "force", "", NULL, (void *)&remove_force, "Treat combs like any other objects. If recursive flag is added, do not verify objects are unused in other trees before deleting."); - BU_OPT(d[3], "a", "references", "", NULL, (void *)&remove_refs, "Remove references to the removed object elsewhere in the database. When used without the force force flag, will *only* remove references to the specificed object or objects and not the objects themselves. When recursive mode is enabled will remove all references to all object identifed by the recursion, not just those explicitly listed by the user."); - BU_OPT(d[4], "r", "recursive", "", NULL, (void *)&remove_recursive, "Walks combs and deletes all of their sub-objects (or, when used with just -a, removes references to objects but not the actual objects.) Will not delete objects used elsewhere in the database unless the -f option is also supplied."); - BU_OPT(d[5], "v", "verbose", "[#]", &_rm_verbose, (void *)&verbose, "Enable verbose reporting. Optional integer parameter specifies verbosity level - 0 is no output (default when no verbsosity flag is added), 1 reports objects skipped due to use elsewhere in the database (the default if no integer is supplied to -v), 2 adds reports of attempts to delete objects not present in the database, 3 adds reporting of successful deletions, and 4 adds reports of all references successfully removed."); - BU_OPT(d[6], "n", "no-op", "", NULL, (void *)&no_op, "Perform a \"dry run\" - reports what actions would be taken but does not change the database."); - BU_OPT_NULL(d[7]); - - /* initialize result */ - bu_vls_trunc(gedp->ged_result_str, 0); - - /* Skip first arg */ - argv++; argc--; - - /* parse args */ - ret_ac = bu_opt_parse(&str, argc, (const char **)argv, d); - if (ret_ac < 0) { - bu_vls_printf(gedp->ged_result_str, "%s\n", bu_vls_addr(&str)); - _remove_show_help(gedp, orig_argv[0], d); - bu_vls_free(&str); - bu_free_argv(free_argc,free_argv); - return GED_ERROR; - } - - /* must be wanting help */ - if (print_help || ret_ac == 0) { - _remove_show_help(gedp, orig_argv[0], d); - bu_vls_free(&str); - bu_free_argv(free_argc,free_argv); - return GED_HELP; - } - - /* Collect paths without slashes - those are full object removals, not - * removal of an object from a comb. For paths *with* slashes, those - * are interpreted as removing the last object in the path from its parent - * comb - handle them immediately. */ - for (i = 0; i < ret_ac; i++) { - const char *slash = strrchr(argv[i], '/'); - if (slash == NULL) { - bu_ptbl_ins(&objs, (long *)argv[i]); - } else { - ret = _ged_rm_path(gedp, argv[i]); - /* If the first path arg was a full path, - * we're not removing the rest from a comb */ - if (i == 0) remove_from_comb = 0; - if (ret == GED_ERROR) goto rcleanup; - } - } - - if (remove_force || remove_refs || remove_recursive) remove_from_comb = 0; - - /* If we've got nothing else, we're done */ - if (!BU_PTBL_LEN(&objs) > 0) { - goto rcleanup; - } - - /* Behavior depends on the type of the first object (potentially, based on supplied flags) */ - if ((dp = db_lookup(gedp->ged_wdbp->dbip, (const char *)BU_PTBL_GET(&objs, 0), LOOKUP_NOISY)) == RT_DIR_NULL) { - ret = GED_ERROR; - goto rcleanup; - } - - /* If we've got a comb to start with and none of the flags are active, the - * interpretation is that the list of objs is removed from the comb child - * list of the first comb. */ - if (remove_from_comb && (dp->d_flags & RT_DIR_COMB) != 0) { - if (BU_PTBL_LEN(&objs) == 1) { - bu_vls_printf(gedp->ged_result_str, "Error: single comb supplied with no flags - not removing %s. To remove an individual comb from the database add the -f flag.", argv[1]); - ret = GED_ERROR; - goto rcleanup; - } - if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { - bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); - ret = GED_ERROR; - goto rcleanup; - } - - comb = (struct rt_comb_internal *)intern.idb_ptr; - RT_CK_COMB(comb); - - /* Process each argument */ - for (i = 1; i < (int)BU_PTBL_LEN(&objs); i++) { - const char *obj = (const char *)BU_PTBL_GET(&objs, i); - if (db_tree_del_dbleaf(&(comb->tree), obj, &rt_uniresource, 0) < 0) { - bu_vls_printf(gedp->ged_result_str, "ERROR: Failure deleting %s/%s\n", dp->d_namep, obj); - ret = GED_ERROR; - goto rcleanup; - } else { - struct bu_vls path = BU_VLS_INIT_ZERO; - - bu_vls_printf(&path, "%s/%s", dp->d_namep, obj); - _dl_eraseAllPathsFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, bu_vls_addr(&path), 0, gedp->freesolid); - bu_vls_free(&path); - bu_vls_printf(gedp->ged_result_str, "deleted %s/%s\n", dp->d_namep, obj); - } - } - - if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { - bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); - ret = GED_ERROR; - goto rcleanup; - } - goto rcleanup; - } - - /* Having handled the removal-from-comb cases, we move on to the more - * general database removals. The various combinations of options need - * different logic */ - if (!remove_refs && !remove_recursive) { - for (i = 0; i < (int)BU_PTBL_LEN(&objs); i++) { - (void)_rm_obj(gedp, (const char *)BU_PTBL_GET(&objs, i), NULL, &rmlog, verbose, remove_force, no_op); - } - goto rcleanup; - } - if ( remove_refs && !remove_force && !remove_recursive) { - _rm_ref(gedp, &objs, &rmlog, no_op); - if (remove_force) { - for (i = 0; i < (int)BU_PTBL_LEN(&objs); i++) { - (void)_rm_obj(gedp, (const char *)BU_PTBL_GET(&objs, i), NULL, &rmlog, verbose, remove_force, no_op); - } - } - goto rcleanup; - } - if (!remove_refs && remove_recursive) { - size_t ind = 0; - struct bu_ptbl resultobjs = BU_PTBL_INIT_ZERO; - struct bu_ptbl validobjs = BU_PTBL_INIT_ZERO; - struct directory **dirp = NULL; - int v_cnt = _valid_rm_objs(&dirp, &validobjs, gedp, &objs, &rmlog, verbose); - (void)db_search(&resultobjs, DB_SEARCH_RETURN_UNIQ_DP, "-name *", v_cnt, dirp, gedp->ged_wdbp->dbip); - for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { - (void)_rm_obj(gedp, ((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep, &validobjs, &rmlog, verbose, remove_force, no_op); - } - if (dirp) bu_free(dirp, "free dirp"); - bu_ptbl_free(&validobjs); - bu_ptbl_free(&resultobjs); - goto rcleanup; - } - - if ( remove_refs && !remove_force && remove_recursive) { - size_t ind = 0; - struct bu_ptbl resultobjs = BU_PTBL_INIT_ZERO; - struct bu_ptbl validobjs = BU_PTBL_INIT_ZERO; - struct bu_ptbl resultchars = BU_PTBL_INIT_ZERO; - struct directory **dirp = NULL; - int v_cnt = _valid_rm_objs(&dirp, &validobjs, gedp, &objs, &rmlog, verbose); - (void)db_search(&resultobjs, DB_SEARCH_RETURN_UNIQ_DP, "-name *", v_cnt, dirp, gedp->ged_wdbp->dbip); - for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { - bu_ptbl_ins(&resultchars, (long *)(((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep)); - } - _rm_ref(gedp, &resultchars, &rmlog, no_op); - for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { - if (remove_force) { - (void)_rm_obj(gedp, ((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep, NULL, &rmlog, verbose, remove_force, no_op); - } - } - if (dirp) bu_free(dirp, "free dirp"); - bu_ptbl_free(&resultchars); - bu_ptbl_free(&validobjs); - bu_ptbl_free(&resultobjs); - goto rcleanup; - } - -rcleanup: - bu_ptbl_free(&objs); - bu_vls_free(&str); - bu_free_argv(free_argc,free_argv); - bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&rmlog)); - bu_vls_free(&rmlog); - return ret; -} - - -/* - * Local Variables: - * tab-width: 8 - * mode: C - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Copied: brlcad/trunk/src/libged/remove.cpp (from rev 66513, brlcad/trunk/src/libged/remove.c) =================================================================== --- brlcad/trunk/src/libged/remove.cpp (rev 0) +++ brlcad/trunk/src/libged/remove.cpp 2015-10-26 21:38:20 UTC (rev 66514) @@ -0,0 +1,536 @@ +/* R E M O V E . C + * BRL-CAD + * + * Copyright (c) 2008-2014 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/remove.c + * + * The remove command. + * + */ + +#include "common.h" + +#include <string.h> +#include <limits.h> /* FOR INT_MAX */ + +#include "bu/cmd.h" +#include "bu/opt.h" +#include "bu/ptbl.h" +#include "bu/vls.h" + +#include "./ged_private.h" + +HIDDEN void +_remove_show_help(struct ged *gedp, const char *cmd, struct bu_opt_desc *d) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + const char *option_help = bu_opt_describe(d, NULL); + bu_vls_sprintf(&str, "Usage: %s [options] [comb] [comb/obj] object(s)\n\n", cmd); + bu_vls_printf(&str, "Any argument of the form comb/obj is interpreted as requesting removal of\n"); + bu_vls_printf(&str, "object \"obj\" from the first level tree of \"comb\" (instances of obj\n"); + bu_vls_printf(&str, "deeper in the tree of \"comb\" are not removed.) Note that these paths\n"); + bu_vls_printf(&str, "are processed first - any other rm operations will take place after these\n"); + bu_vls_printf(&str, "paths are handled.\n\n"); + bu_vls_printf(&str, "By default, if no options are supplied and the first object is a comb\n"); + bu_vls_printf(&str, "the object(s) are removed from \"comb\" - this is a convenient way to\n"); + bu_vls_printf(&str, "remove multiple objects from a single comb. Again, instances are.\n"); + bu_vls_printf(&str, "removed only from the immediate child object set of \"comb\".\n\n"); + bu_vls_printf(&str, "If one or more options are supplied or the first object specified is not a comb,\n"); + bu_vls_printf(&str, "the command form becomes:\n\n"); + bu_vls_printf(&str, " %s [options] object(s)\n\n", cmd); + bu_vls_printf(&str, "and the scope changes from a single comb's tree to the .g database.\n"); + if (option_help) { + bu_vls_printf(&str, "\nOptions:\n%s\n", option_help); + bu_free((char *)option_help, "help str"); + } + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&str)); + bu_vls_free(&str); +} + +HIDDEN void +_rm_ref(struct ged *gedp, struct bu_ptbl *objs, struct bu_vls *rmlog, int dry_run) +{ + size_t i = 0; + struct directory *dp = RT_DIR_NULL; + struct rt_db_internal intern; + struct rt_comb_internal *comb; + + FOR_ALL_DIRECTORY_START(dp, gedp->ged_wdbp->dbip) { + if (!(dp->d_flags & RT_DIR_COMB)) + continue; + + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { + if (rmlog) { + bu_vls_printf(rmlog, "rt_db_get_internal(%s) failure", dp->d_namep); + } + continue; + } + comb = (struct rt_comb_internal *)intern.idb_ptr; + RT_CK_COMB(comb); + + for (i = 0; i < BU_PTBL_LEN(objs); i++) { + int code; + + code = db_tree_del_dbleaf(&(comb->tree), (const char *)BU_PTBL_GET(objs, i), &rt_uniresource, dry_run); + if (code == -1) + continue; /* not found */ + if (code == -2) + continue; /* empty tree */ + if (code < 0) { + if (rmlog) { + bu_vls_printf(rmlog, "ERROR: Failure deleting %s/%s\n", dp->d_namep, (const char *)BU_PTBL_GET(objs, i)); + } + } else { + if (rmlog && dry_run) { + bu_vls_printf(rmlog, "Remove reference to object %s from %s", (const char *)BU_PTBL_GET(objs, i), dp->d_namep); + } + } + } + + if (!dry_run && rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + if (rmlog) { + bu_vls_printf(rmlog, "ERROR: Unable to write new combination into database.\n"); + } + continue; + } + } FOR_ALL_DIRECTORY_END; +} + + +/* this finds references to 'obj' that are not within any of the the 'topobjs' + * combination hierarchies, elsewhere in the database. this is so we can make + * sure we don't kill objects that are referenced elsewhere in the + * database, in a hierarchy that is not being deleted. + */ +HIDDEN int +_rm_find_reference(struct db_i *dbip, struct bu_ptbl *topobjs, const char *obj, struct bu_vls *rmlog, int verbosity) +{ + int i; + int ret = 0; + struct bu_vls str = BU_VLS_INIT_ZERO; + + if (!dbip || !topobjs || !obj) + return 0; + + bu_vls_sprintf(&str, "-depth >0"); + for (i = 0; i < (int)BU_PTBL_LEN(topobjs); i++) { + bu_vls_printf(&str, " -not -below -name %s", ((struct directory *)BU_PTBL_GET(topobjs, i))->d_namep); + } + bu_vls_printf(&str, " -name %s", obj); + + ret = db_search(NULL, DB_SEARCH_TREE, bu_vls_cstr(&str), 0, NULL, dbip); + + if (ret && rmlog && verbosity > 0) { + bu_vls_printf(rmlog, "NOTE: %s is referenced by unremoved objects in the database - skipping.\n", obj); + } + + bu_vls_free(&str); + + return ret; +} + + +HIDDEN int +_rm_obj(struct ged *gedp, const char *objname, struct bu_ptbl *topobjs, struct bu_vls *rmlog, int verbosity, int force, int dry_run) +{ + struct directory *dp = RT_DIR_NULL; + if (!gedp || !objname) return -1; + + if (topobjs && !force) { + if (_rm_find_reference(gedp->ged_wdbp->dbip, topobjs, objname, rmlog, verbosity) > 0) return -1; + } + + dp = db_lookup(gedp->ged_wdbp->dbip, objname, LOOKUP_QUIET); + + if (dp != RT_DIR_NULL) { + if (!force && dp->d_major_type == DB5_MAJORTYPE_ATTRIBUTE_ONLY && dp->d_minor_type == 0) { + if (rmlog) { + bu_vls_printf(rmlog, "Warning: you attempted to delete the _GLOBAL object.\n"); + bu_vls_printf(rmlog, "\tIf you delete the \"_GLOBAL\" object you will be losing some important information\n"); + bu_vls_printf(rmlog, "\tsuch as your preferred units and the title of the database.\n"); + bu_vls_printf(rmlog, "\tUse the \"-f\" option, if you really want to do this.\n"); + } + return -1; + } + + /* don't worry about phony objects */ + if (dp->d_addr == RT_DIR_PHONY_ADDR) return 0; + + /* clear the object from the display */ + if (!dry_run) { + _dl_eraseAllNamesFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, objname, 0, gedp->freesolid); + + /* actually do the deletion */ + if (db_delete(gedp->ged_wdbp->dbip, dp) != 0 || db_dirdelete(gedp->ged_wdbp->dbip, dp) != 0) { + /* Abort kill processing on first error */ + if (rmlog) bu_vls_printf(rmlog, "Error: unable to delete %s", objname); + return -1; + } + } else { + bu_vls_printf(rmlog, "Delete object %s\n", objname); + } + } else { + if (rmlog && verbosity >= 2) { + bu_vls_printf(rmlog, "Attempted to delete object %s, but it was not found in the database\n", objname); + } + return -1; + } + return 0; +} + +HIDDEN int +_removal_queue(struct bu_ptbl *to_remove, struct ged *gedp, struct bu_ptbl *seeds, struct bu_vls *rmlog, int verbosity) +{ + size_t i = 0; + + if (!to_remove || !gedp || !seeds) return 0; + + for (i = 0; i < BU_PTBL_LEN(seeds); i++) { + const char *objname = ((struct directory *)BU_PTBL_GET(seeds, i))->d_namep; + if (_rm_find_reference(gedp->ged_wdbp->dbip, seeds, objname, rmlog, verbosity) > 0) continue; + } + + return 0; +} + + +HIDDEN int +_valid_rm_objs(struct directory ***dirp, struct bu_ptbl *validobjs, struct ged *gedp, struct bu_ptbl *objs, struct bu_vls *rmlog, int verbosity) +{ + int i = 0; + int dircnt = 0; + struct directory *rdp = RT_DIR_NULL; + for (i = 0; i < (int)BU_PTBL_LEN(objs); i++) { + rdp = db_lookup(gedp->ged_wdbp->dbip, (const char *)BU_PTBL_GET(objs, i), LOOKUP_QUIET); + if (rdp != RT_DIR_NULL) { + bu_ptbl_ins_unique(validobjs, (long *)rdp); + } else { + if (rmlog && verbosity >= 2) { + bu_vls_printf(rmlog, "Attempted to delete object %s, but it was not found in the database\n", (const char *)BU_PTBL_GET(objs, i)); + } + } + } + dircnt = BU_PTBL_LEN(validobjs); + /* Got valid objects, build search directory array */ + if (dircnt > 0) { + (*dirp) = (struct directory **)bu_calloc(BU_PTBL_LEN(validobjs), sizeof(struct directory *), "dp array"); + for (i = 0; i < (int)BU_PTBL_LEN(validobjs); i++) { + (*dirp)[i] = (struct directory *)BU_PTBL_GET(validobjs, i); + } + } + return dircnt; +} + +HIDDEN int +_ged_rm_path(struct ged *gedp, const char *in) +{ + int ret = GED_OK; + struct rt_db_internal intern; + struct rt_comb_internal *comb; + struct directory *dp; + struct bu_vls combstr = BU_VLS_INIT_ZERO; + struct bu_vls obj = BU_VLS_INIT_ZERO; + const char *slash = strrchr(in, '/'); + bu_vls_sprintf(&obj, "%s", slash+1); + bu_vls_strncpy(&combstr, in, strlen(in) - strlen(slash)); + bu_log("obj: %s\n", bu_vls_addr(&obj)); + bu_log("comb: %s\n", bu_vls_addr(&combstr)); + + if ((dp = db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&combstr), LOOKUP_NOISY)) == RT_DIR_NULL) { + bu_vls_printf(gedp->ged_result_str, "Error: first object %s in path %s does not exist", bu_vls_addr(&combstr), in); + ret = GED_ERROR; + goto cleanup; + } + + if ((dp->d_flags & RT_DIR_COMB) == 0) { + bu_vls_printf(gedp->ged_result_str, "Error: first object %s in path %s is not a comb", bu_vls_addr(&combstr), in); + ret = GED_ERROR; + goto cleanup; + } + + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); + ret = GED_ERROR; + goto cleanup; + } + + comb = (struct rt_comb_internal *)intern.idb_ptr; + RT_CK_COMB(comb); + + if (db_tree_del_dbleaf(&(comb->tree), bu_vls_addr(&obj), &rt_uniresource, 0) < 0) { + bu_vls_printf(gedp->ged_result_str, "ERROR: Failure deleting %s/%s\n", dp->d_namep, bu_vls_addr(&obj)); + ret = GED_ERROR; + goto cleanup; + } else { + struct bu_vls path = BU_VLS_INIT_ZERO; + + bu_vls_printf(&path, "%s/%s", dp->d_namep, bu_vls_addr(&obj)); + _dl_eraseAllPathsFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, bu_vls_addr(&path), 0, gedp->freesolid); + bu_vls_free(&path); + bu_vls_printf(gedp->ged_result_str, "deleted %s/%s\n", dp->d_namep, bu_vls_addr(&obj)); + } + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); + ret = GED_ERROR; + } + +cleanup: + bu_vls_free(&combstr); + bu_vls_free(&obj); + return ret; +} + + +HIDDEN int +_rm_verbose(struct bu_vls *msg, int argc, const char **argv, void *set_v) +{ + int val = INT_MAX; + int *int_set = (int *)set_v; + int int_ret; + if (!argv || !argv[0] || strlen(argv[0]) == 0 || argc == 0) { + /* Have verbosity flag but no valid arg - go with just the flag */ + if (int_set) (*int_set) = 1; + return 0; + } + + int_ret = bu_opt_int(msg, argc, argv, (void *)&val); + if (int_ret == -1) return -1; + + if (val < 0) return -1; + if (val > 4) val = 4; + + if (int_set) (*int_set) = val; + + return 1; +} + +int +ged_remove(struct ged *gedp, int orig_argc, const char *orig_argv[]) +{ + int print_help = 0; + int remove_force = 0; + int remove_from_comb = 1; + int remove_recursive = 0; + int remove_refs = 0; + int verbose = 0; + int no_op = 0; + size_t argc = (size_t)orig_argc; + char **argv = bu_dup_argv(argc, orig_argv); + size_t free_argc = argc; + char **free_argv = argv; + int ret_ac; + + struct directory *dp; + int i; + struct rt_db_internal intern; + struct rt_comb_internal *comb; + int ret = GED_OK; + struct bu_opt_desc d[8]; + struct bu_vls str = BU_VLS_INIT_ZERO; + struct bu_vls rmlog = BU_VLS_INIT_ZERO; + struct bu_ptbl objs = BU_PTBL_INIT_ZERO; + + GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); + GED_CHECK_DRAWABLE(gedp, GED_ERROR); + GED_CHECK_READ_ONLY(gedp, GED_ERROR); + GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); + + BU_OPT(d[0], "h", "help", "", NULL, (void *)&print_help, "Print help and exit"); + BU_OPT(d[1], "?", "", "", NULL, (void *)&print_help, ""); + BU_OPT(d[2], "f", "force", "", NULL, (void *)&remove_force, "Treat combs like any other objects. If recursive flag is added, do not verify objects are unused in other trees before deleting."); + BU_OPT(d[3], "a", "references", "", NULL, (void *)&remove_refs, "Remove references to the removed object elsewhere in the database. When used without the force force flag, will *only* remove references to the specificed object or objects and not the objects themselves. When recursive mode is enabled will remove all references to all object identifed by the recursion, not just those explicitly listed by the user."); + BU_OPT(d[4], "r", "recursive", "", NULL, (void *)&remove_recursive, "Walks combs and deletes all of their sub-objects (or, when used with just -a, removes references to objects but not the actual objects.) Will not delete objects used elsewhere in the database unless the -f option is also supplied."); + BU_OPT(d[5], "v", "verbose", "[#]", &_rm_verbose, (void *)&verbose, "Enable verbose reporting. Optional integer parameter specifies verbosity level - 0 is no output (default when no verbsosity flag is added), 1 reports objects skipped due to use elsewhere in the database (the default if no integer is supplied to -v), 2 adds reports of attempts to delete objects not present in the database, 3 adds reporting of successful deletions, and 4 adds reports of all references successfully removed."); + BU_OPT(d[6], "n", "no-op", "", NULL, (void *)&no_op, "Perform a \"dry run\" - reports what actions would be taken but does not change the database."); + BU_OPT_NULL(d[7]); + + /* initialize result */ + bu_vls_trunc(gedp->ged_result_str, 0); + + /* Skip first arg */ + argv++; argc--; + + /* parse args */ + ret_ac = bu_opt_parse(&str, argc, (const char **)argv, d); + if (ret_ac < 0) { + bu_vls_printf(gedp->ged_result_str, "%s\n", bu_vls_addr(&str)); + _remove_show_help(gedp, orig_argv[0], d); + bu_vls_free(&str); + bu_free_argv(free_argc,free_argv); + return GED_ERROR; + } + + /* must be wanting help */ + if (print_help || ret_ac == 0) { + _remove_show_help(gedp, orig_argv[0], d); + bu_vls_free(&str); + bu_free_argv(free_argc,free_argv); + return GED_HELP; + } + + /* Collect paths without slashes - those are full object removals, not + * removal of an object from a comb. For paths *with* slashes, those + * are interpreted as removing the last object in the path from its parent + * comb - handle them immediately. */ + for (i = 0; i < ret_ac; i++) { + const char *slash = strrchr(argv[i], '/'); + if (slash == NULL) { + bu_ptbl_ins(&objs, (long *)argv[i]); + } else { + ret = _ged_rm_path(gedp, argv[i]); + /* If the first path arg was a full path, + * we're not removing the rest from a comb */ + if (i == 0) remove_from_comb = 0; + if (ret == GED_ERROR) goto rcleanup; + } + } + + if (remove_force || remove_refs || remove_recursive) remove_from_comb = 0; + + /* If we've got nothing else, we're done */ + if (!BU_PTBL_LEN(&objs) > 0) { + goto rcleanup; + } + + /* Behavior depends on the type of the first object (potentially, based on supplied flags) */ + if ((dp = db_lookup(gedp->ged_wdbp->dbip, (const char *)BU_PTBL_GET(&objs, 0), LOOKUP_NOISY)) == RT_DIR_NULL) { + ret = GED_ERROR; + goto rcleanup; + } + + /* If we've got a comb to start with and none of the flags are active, the + * interpretation is that the list of objs is removed from the comb child + * list of the first comb. */ + if (remove_from_comb && (dp->d_flags & RT_DIR_COMB) != 0) { + if (BU_PTBL_LEN(&objs) == 1) { + bu_vls_printf(gedp->ged_result_str, "Error: single comb supplied with no flags - not removing %s. To remove an individual comb from the database add the -f flag.", argv[1]); + ret = GED_ERROR; + goto rcleanup; + } + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); + ret = GED_ERROR; + goto rcleanup; + } + + comb = (struct rt_comb_internal *)intern.idb_ptr; + RT_CK_COMB(comb); + + /* Process each argument */ + for (i = 1; i < (int)BU_PTBL_LEN(&objs); i++) { + const char *obj = (const char *)BU_PTBL_GET(&objs, i); + if (db_tree_del_dbleaf(&(comb->tree), obj, &rt_uniresource, 0) < 0) { + bu_vls_printf(gedp->ged_result_str, "ERROR: Failure deleting %s/%s\n", dp->d_namep, obj); + ret = GED_ERROR; + goto rcleanup; + } else { + struct bu_vls path = BU_VLS_INIT_ZERO; + + bu_vls_printf(&path, "%s/%s", dp->d_namep, obj); + _dl_eraseAllPathsFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, bu_vls_addr(&path), 0, gedp->freesolid); + bu_vls_free(&path); + bu_vls_printf(gedp->ged_result_str, "deleted %s/%s\n", dp->d_namep, obj); + } + } + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); + ret = GED_ERROR; + goto rcleanup; + } + goto rcleanup; + } + + /* Having handled the removal-from-comb cases, we move on to the more + * general database removals. The various combinations of options need + * different logic */ + if (!remove_refs && !remove_recursive) { + for (i = 0; i < (int)BU_PTBL_LEN(&objs); i++) { + (void)_rm_obj(gedp, (const char *)BU_PTBL_GET(&objs, i), NULL, &rmlog, verbose, remove_force, no_op); + } + goto rcleanup; + } + if ( remove_refs && !remove_force && !remove_recursive) { + _rm_ref(gedp, &objs, &rmlog, no_op); + if (remove_force) { + for (i = 0; i < (int)BU_PTBL_LEN(&objs); i++) { + (void)_rm_obj(gedp, (const char *)BU_PTBL_GET(&objs, i), NULL, &rmlog, verbose, remove_force, no_op); + } + } + goto rcleanup; + } + if (!remove_refs && remove_recursive) { + size_t ind = 0; + struct bu_ptbl resultobjs = BU_PTBL_INIT_ZERO; + struct bu_ptbl validobjs = BU_PTBL_INIT_ZERO; + struct directory **dirp = NULL; + int v_cnt = _valid_rm_objs(&dirp, &validobjs, gedp, &objs, &rmlog, verbose); + (void)db_search(&resultobjs, DB_SEARCH_RETURN_UNIQ_DP, "-name *", v_cnt, dirp, gedp->ged_wdbp->dbip); + for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { + (void)_rm_obj(gedp, ((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep, &validobjs, &rmlog, verbose, remove_force, no_op); + } + if (dirp) bu_free(dirp, "free dirp"); + bu_ptbl_free(&validobjs); + bu_ptbl_free(&resultobjs); + goto rcleanup; + } + + if ( remove_refs && !remove_force && remove_recursive) { + size_t ind = 0; + struct bu_ptbl resultobjs = BU_PTBL_INIT_ZERO; + struct bu_ptbl validobjs = BU_PTBL_INIT_ZERO; + struct bu_ptbl resultchars = BU_PTBL_INIT_ZERO; + struct directory **dirp = NULL; + int v_cnt = _valid_rm_objs(&dirp, &validobjs, gedp, &objs, &rmlog, verbose); + (void)db_search(&resultobjs, DB_SEARCH_RETURN_UNIQ_DP, "-name *", v_cnt, dirp, gedp->ged_wdbp->dbip); + for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { + bu_ptbl_ins(&resultchars, (long *)(((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep)); + } + _rm_ref(gedp, &resultchars, &rmlog, no_op); + for (ind = 0; ind < BU_PTBL_LEN(&resultobjs); ind++) { + if (remove_force) { + (void)_rm_obj(gedp, ((struct directory *)BU_PTBL_GET(&resultobjs, ind))->d_namep, NULL, &rmlog, verbose, remove_force, no_op); + } + } + if (dirp) bu_free(dirp, "free dirp"); + bu_ptbl_free(&resultchars); + bu_ptbl_free(&validobjs); + bu_ptbl_free(&resultobjs); + goto rcleanup; + } + +rcleanup: + bu_ptbl_free(&objs); + bu_vls_free(&str); + bu_free_argv(free_argc,free_argv); + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&rmlog)); + bu_vls_free(&rmlog); + return ret; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-01-27 15:27:35
|
Revision: 66948 http://sourceforge.net/p/brlcad/code/66948 Author: starseeker Date: 2016-01-27 15:27:33 +0000 (Wed, 27 Jan 2016) Log Message: ----------- Remove a couple unnecessary/unused Tcl bits from libged. Modified Paths: -------------- brlcad/trunk/src/libged/joint.h brlcad/trunk/src/libged/nirt.c Modified: brlcad/trunk/src/libged/joint.h =================================================================== --- brlcad/trunk/src/libged/joint.h 2016-01-27 04:03:19 UTC (rev 66947) +++ brlcad/trunk/src/libged/joint.h 2016-01-27 15:27:33 UTC (rev 66948) @@ -65,21 +65,6 @@ # define TRUE 1 #endif -/* Check if database pointer is NULL */ -#define CHECK_DBI_NULL \ - if (dbip == DBI_NULL) { \ - Tcl_AppendResult(INTERP, "A database is not open!\n", (char *)NULL); \ - return TCL_ERROR; \ - } - -/* Check if the database is read only, and if so return TCL_ERROR */ -#define CHECK_READ_ONLY \ - if (dbip->dbi_read_only) { \ - Tcl_AppendResult(INTERP, "Sorry, this database is READ-ONLY\n", (char *)NULL); \ - return TCL_ERROR; \ - } - - /* NB: The quaternions should (MUST?) have zero twist! */ struct arc { struct bu_list l; Modified: brlcad/trunk/src/libged/nirt.c =================================================================== --- brlcad/trunk/src/libged/nirt.c 2016-01-27 04:03:19 UTC (rev 66947) +++ brlcad/trunk/src/libged/nirt.c 2016-01-27 15:27:33 UTC (rev 66948) @@ -40,17 +40,13 @@ #endif #include "bresource.h" -#include "tcl.h" - #include "bn.h" #include "bu/cmd.h" #include "vmath.h" - #include "./qray.h" #include "./ged_private.h" - /** * Invoke nirt with the current view & stuff */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-01-27 15:29:21
|
Revision: 66949 http://sourceforge.net/p/brlcad/code/66949 Author: starseeker Date: 2016-01-27 15:29:18 +0000 (Wed, 27 Jan 2016) Log Message: ----------- Couple more stray tcl.h includes Modified Paths: -------------- brlcad/trunk/src/libged/comb_std.c brlcad/trunk/src/libged/vdraw.c Modified: brlcad/trunk/src/libged/comb_std.c =================================================================== --- brlcad/trunk/src/libged/comb_std.c 2016-01-27 15:27:33 UTC (rev 66948) +++ brlcad/trunk/src/libged/comb_std.c 2016-01-27 15:29:18 UTC (rev 66949) @@ -28,8 +28,6 @@ #include <string.h> -#include "tcl.h" - #include "bu/getopt.h" #include "vmath.h" #include "rt/geom.h" Modified: brlcad/trunk/src/libged/vdraw.c =================================================================== --- brlcad/trunk/src/libged/vdraw.c 2016-01-27 15:27:33 UTC (rev 66948) +++ brlcad/trunk/src/libged/vdraw.c 2016-01-27 15:29:18 UTC (rev 66949) @@ -101,8 +101,6 @@ #include <math.h> #include <signal.h> -#include "tcl.h" - #include "bu/cmd.h" #include "bn.h" #include "vmath.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-02-24 23:23:47
|
Revision: 67131 http://sourceforge.net/p/brlcad/code/67131 Author: starseeker Date: 2016-02-24 23:23:44 +0000 (Wed, 24 Feb 2016) Log Message: ----------- tweaks Modified Paths: -------------- brlcad/trunk/src/libged/ged.c brlcad/trunk/src/libged/select.c Modified: brlcad/trunk/src/libged/ged.c =================================================================== --- brlcad/trunk/src/libged/ged.c 2016-02-24 20:47:53 UTC (rev 67130) +++ brlcad/trunk/src/libged/ged.c 2016-02-24 23:23:44 UTC (rev 67131) @@ -208,7 +208,7 @@ gedp->ged_gdp->gd_uplotOutputMode = PL_OUTPUT_MODE_BINARY; qray_init(gedp->ged_gdp); - gedp->ged_selections = bu_hash_tbl_create(0); + gedp->ged_selections = bu_hash_tbl_create(32); /* init the solid list */ BU_GET(freesolid, struct solid); Modified: brlcad/trunk/src/libged/select.c =================================================================== --- brlcad/trunk/src/libged/select.c 2016-02-24 20:47:53 UTC (rev 67130) +++ brlcad/trunk/src/libged/select.c 2016-02-24 23:23:44 UTC (rev 67131) @@ -280,13 +280,13 @@ int int_new; struct bu_hash_entry *entry; - entry = bu_hash_tbl_add(gedp->ged_selections, (unsigned char *)object_name, + entry = bu_hash_tbl_add(gedp->ged_selections, (uint8_t *)object_name, strlen(object_name), &int_new); if (int_new) { struct rt_object_selections *obj_selections; BU_ALLOC(obj_selections, struct rt_object_selections); - obj_selections->sets = bu_hash_tbl_create(0); + obj_selections->sets = bu_hash_tbl_create(32); bu_set_hash_value(entry, (unsigned char *)obj_selections); } @@ -302,13 +302,13 @@ obj_selections = ged_get_object_selections(gedp, object_name); entry = bu_hash_tbl_add(obj_selections->sets, - (const unsigned char *)selection_name, strlen(selection_name), &int_new); + (uint8_t *)selection_name, strlen(selection_name), &int_new); if (int_new) { struct rt_selection_set *set; BU_ALLOC(set, struct rt_selection_set); BU_PTBL_INIT(&set->selections); - bu_set_hash_value(entry, (unsigned char *)set); + bu_set_hash_value(entry, (void *)set); } return (struct rt_selection_set *)bu_get_hash_value(entry); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-02-26 16:22:37
|
Revision: 67151 http://sourceforge.net/p/brlcad/code/67151 Author: starseeker Date: 2016-02-26 16:22:34 +0000 (Fri, 26 Feb 2016) Log Message: ----------- move libged over to the new bu_hash api Modified Paths: -------------- brlcad/trunk/src/libged/ged.c brlcad/trunk/src/libged/select.c Modified: brlcad/trunk/src/libged/ged.c =================================================================== --- brlcad/trunk/src/libged/ged.c 2016-02-26 15:56:42 UTC (rev 67150) +++ brlcad/trunk/src/libged/ged.c 2016-02-26 16:22:34 UTC (rev 67151) @@ -83,47 +83,50 @@ ged_free(gedp); } -static int -free_selection_set_entry(struct bu_hash_entry *entry, void *UNUSED(arg)) +static void +free_selection_set(struct bu_hash_tbl *t) { int i; struct rt_selection_set *selection_set; struct bu_ptbl *selections; + struct bu_hash_entry *entry = bu_hash_next(t, NULL); void (*free_selection)(struct rt_selection *); - selection_set = (struct rt_selection_set *)bu_get_hash_value(entry); - selections = &selection_set->selections; - free_selection = selection_set->free_selection; + while (entry) { + selection_set = (struct rt_selection_set *)bu_hash_entry_val(entry, NULL); + selections = &selection_set->selections; + free_selection = selection_set->free_selection; - /* free all selection objects and containing items */ - for (i = BU_PTBL_LEN(selections) - 1; i >= 0; --i) { - long *s = BU_PTBL_GET(selections, i); - free_selection((struct rt_selection *)s); - bu_ptbl_rm(selections, s); + /* free all selection objects and containing items */ + for (i = BU_PTBL_LEN(selections) - 1; i >= 0; --i) { + long *s = BU_PTBL_GET(selections, i); + free_selection((struct rt_selection *)s); + bu_ptbl_rm(selections, s); + } + bu_ptbl_free(selections); + BU_FREE(selection_set, struct rt_selection_set); + /* Get next entry */ + entry = bu_hash_next(t, entry); } - bu_ptbl_free(selections); - BU_FREE(selection_set, struct rt_selection_set); - - return 0; } -static int -free_object_selections(struct bu_hash_entry *entry, void *UNUSED(arg)) +static void +free_object_selections(struct bu_hash_tbl *t) { struct rt_object_selections *obj_selections; + struct bu_hash_entry *entry = bu_hash_next(t, NULL); - obj_selections = (struct rt_object_selections *)bu_get_hash_value(entry); - - /* free entries - one set for each kind of selection */ - bu_hash_tbl_traverse(obj_selections->sets, free_selection_set_entry, NULL); - - /* free table itself */ - bu_hash_tbl_free(obj_selections->sets); - - /* free object */ - bu_free(obj_selections, "ged selections entry"); - - return 0; + while (entry) { + obj_selections = (struct rt_object_selections *)bu_hash_entry_val(entry, NULL); + /* free entries */ + free_selection_set(obj_selections->sets); + /* free table itself */ + bu_hash_tbl_destroy(obj_selections->sets); + /* free object */ + bu_free(obj_selections, "ged selections entry"); + /* Get next entry */ + entry = bu_hash_next(t, entry); + } } void @@ -172,8 +175,8 @@ } BU_PUT(gedp->freesolid, struct solid); - bu_hash_tbl_traverse(gedp->ged_selections, free_object_selections, NULL); - bu_hash_tbl_free(gedp->ged_selections); + free_object_selections(gedp->ged_selections); + bu_hash_tbl_destroy(gedp->ged_selections); } Modified: brlcad/trunk/src/libged/select.c =================================================================== --- brlcad/trunk/src/libged/select.c 2016-02-26 15:56:42 UTC (rev 67150) +++ brlcad/trunk/src/libged/select.c 2016-02-26 16:22:34 UTC (rev 67151) @@ -277,41 +277,34 @@ struct rt_object_selections * ged_get_object_selections(struct ged *gedp, const char *object_name) { - int int_new; - struct bu_hash_entry *entry; + struct rt_object_selections *obj_selections; - entry = bu_hash_tbl_add(gedp->ged_selections, (uint8_t *)object_name, - strlen(object_name), &int_new); + obj_selections = (struct rt_object_selections *)bu_hash_get(gedp->ged_selections, (uint8_t *)object_name, strlen(object_name)); - if (int_new) { - struct rt_object_selections *obj_selections; + if (!obj_selections) { BU_ALLOC(obj_selections, struct rt_object_selections); - obj_selections->sets = bu_hash_tbl_create(32); - bu_set_hash_value(entry, (unsigned char *)obj_selections); + obj_selections->sets = bu_hash_tbl_create(0); + (void)bu_hash_set(gedp->ged_selections, (uint8_t *)object_name, strlen(object_name), (void *)obj_selections); } - return (struct rt_object_selections *)bu_get_hash_value(entry); + return obj_selections; } struct rt_selection_set * ged_get_selection_set(struct ged *gedp, const char *object_name, const char *selection_name) { struct rt_object_selections *obj_selections; - struct bu_hash_entry *entry; - int int_new; + struct rt_selection_set *set; obj_selections = ged_get_object_selections(gedp, object_name); - entry = bu_hash_tbl_add(obj_selections->sets, - (uint8_t *)selection_name, strlen(selection_name), &int_new); - - if (int_new) { - struct rt_selection_set *set; + set = (struct rt_selection_set *)bu_hash_get(obj_selections->sets, (uint8_t *)selection_name, strlen(selection_name)); + if (set) { BU_ALLOC(set, struct rt_selection_set); BU_PTBL_INIT(&set->selections); - bu_set_hash_value(entry, (void *)set); + bu_hash_set(obj_selections->sets, (uint8_t *)selection_name, strlen(selection_name), (void *)set); } - return (struct rt_selection_set *)bu_get_hash_value(entry); + return set; } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-03-18 20:32:51
|
Revision: 67385 http://sourceforge.net/p/brlcad/code/67385 Author: starseeker Date: 2016-03-18 20:32:49 +0000 (Fri, 18 Mar 2016) Log Message: ----------- For insurance, do nref updates after kills. Modified Paths: -------------- brlcad/trunk/src/libged/kill.c brlcad/trunk/src/libged/killrefs.c brlcad/trunk/src/libged/killtree.c Modified: brlcad/trunk/src/libged/kill.c =================================================================== --- brlcad/trunk/src/libged/kill.c 2016-03-18 20:32:06 UTC (rev 67384) +++ brlcad/trunk/src/libged/kill.c 2016-03-18 20:32:49 UTC (rev 67385) @@ -117,6 +117,9 @@ } } + /* Update references. */ + db_update_nref(gedp->ged_wdbp->dbip, &rt_uniresource); + return GED_OK; } Modified: brlcad/trunk/src/libged/killrefs.c =================================================================== --- brlcad/trunk/src/libged/killrefs.c 2016-03-18 20:32:06 UTC (rev 67384) +++ brlcad/trunk/src/libged/killrefs.c 2016-03-18 20:32:49 UTC (rev 67385) @@ -112,6 +112,9 @@ } } FOR_ALL_DIRECTORY_END; + /* Update references. */ + db_update_nref(gedp->ged_wdbp->dbip, &rt_uniresource); + return ret; } Modified: brlcad/trunk/src/libged/killtree.c =================================================================== --- brlcad/trunk/src/libged/killtree.c 2016-03-18 20:32:06 UTC (rev 67384) +++ brlcad/trunk/src/libged/killtree.c 2016-03-18 20:32:49 UTC (rev 67385) @@ -246,6 +246,9 @@ bu_free(gktd.av, "free av"); gktd.av = NULL; + /* Update references. */ + db_update_nref(gedp->ged_wdbp->dbip, &rt_uniresource); + return GED_OK; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2016-08-18 02:00:22
|
Revision: 68710 http://sourceforge.net/p/brlcad/code/68710 Author: starseeker Date: 2016-08-18 02:00:19 +0000 (Thu, 18 Aug 2016) Log Message: ----------- rename report.c file in libged to match its actual command. Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libged/solid_report.c Removed Paths: ------------- brlcad/trunk/src/libged/report.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2016-08-17 20:48:29 UTC (rev 68709) +++ brlcad/trunk/src/libged/CMakeLists.txt 2016-08-18 02:00:19 UTC (rev 68710) @@ -209,7 +209,6 @@ regdef.c region.c remove.c - report.c rfarb.c rmap.c rmat.c @@ -262,6 +261,7 @@ simulate/world_object.cpp size.c slew.c + solid_report.c solids_on_ray.c sphgroup.c summary.c Deleted: brlcad/trunk/src/libged/report.c =================================================================== --- brlcad/trunk/src/libged/report.c 2016-08-17 20:48:29 UTC (rev 68709) +++ brlcad/trunk/src/libged/report.c 2016-08-18 02:00:19 UTC (rev 68710) @@ -1,82 +0,0 @@ -/* R E P O R T . C - * BRL-CAD - * - * Copyright (c) 2008-2016 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/report.c - * - * The report command. - * - */ - -#include "common.h" -#include <stdlib.h> - -#include "ged.h" -#include "./ged_private.h" - -/* - * Returns the solid table & vector list as a string - * - * Usage: - * report [lvl] - * - */ -int -ged_report(struct ged *gedp, int argc, const char *argv[]) -{ - int lvl = 0; - static const char *usage = "lvl"; - - GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); - GED_CHECK_DRAWABLE(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 == 1) { - bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); - return GED_HELP; - } - - if (argc != 2) { - bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); - return GED_ERROR; - } - - lvl = atoi(argv[1]); - - if (lvl <= 3) - dl_print_schain(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, lvl, 0, gedp->ged_result_str); - else - dl_print_schain(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, 0, 1, gedp->ged_result_str); - - return GED_OK; -} - - -/* - * Local Variables: - * tab-width: 8 - * mode: C - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Copied: brlcad/trunk/src/libged/solid_report.c (from rev 68709, brlcad/trunk/src/libged/report.c) =================================================================== --- brlcad/trunk/src/libged/solid_report.c (rev 0) +++ brlcad/trunk/src/libged/solid_report.c 2016-08-18 02:00:19 UTC (rev 68710) @@ -0,0 +1,82 @@ +/* R E P O R T . C + * BRL-CAD + * + * Copyright (c) 2008-2016 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/report.c + * + * The report command. + * + */ + +#include "common.h" +#include <stdlib.h> + +#include "ged.h" +#include "./ged_private.h" + +/* + * Returns the solid table & vector list as a string + * + * Usage: + * report [lvl] + * + */ +int +ged_report(struct ged *gedp, int argc, const char *argv[]) +{ + int lvl = 0; + static const char *usage = "lvl"; + + GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); + GED_CHECK_DRAWABLE(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 == 1) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_HELP; + } + + if (argc != 2) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_ERROR; + } + + lvl = atoi(argv[1]); + + if (lvl <= 3) + dl_print_schain(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, lvl, 0, gedp->ged_result_str); + else + dl_print_schain(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, 0, 1, gedp->ged_result_str); + + return GED_OK; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ej...@us...> - 2016-09-27 16:49:09
|
Revision: 68906 http://sourceforge.net/p/brlcad/code/68906 Author: ejno Date: 2016-09-27 16:49:06 +0000 (Tue, 27 Sep 2016) Log Message: ----------- remove duplicate code; add descriptions to file headers Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/simulate/collision.cpp brlcad/trunk/src/libged/simulate/collision.hpp brlcad/trunk/src/libged/simulate/interface.cpp brlcad/trunk/src/libged/simulate/physics_world.cpp brlcad/trunk/src/libged/simulate/physics_world.hpp brlcad/trunk/src/libged/simulate/rt_instance.cpp brlcad/trunk/src/libged/simulate/rt_instance.hpp brlcad/trunk/src/libged/simulate/simulation.cpp brlcad/trunk/src/libged/simulate/simulation.hpp brlcad/trunk/src/libged/simulate/world_object.cpp brlcad/trunk/src/libged/simulate/world_object.hpp Added Paths: ----------- brlcad/trunk/src/libged/simulate/utility.hpp Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/CMakeLists.txt 2016-09-27 16:49:06 UTC (rev 68906) @@ -346,6 +346,7 @@ simulate/physics_world.hpp simulate/rt_instance.hpp simulate/simulation.hpp + simulate/utility.hpp simulate/world_object.hpp osg.cpp ) Modified: brlcad/trunk/src/libged/simulate/collision.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/collision.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/collision.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file collision.cpp * - * Brief description + * Bullet collision algorithm. * */ Modified: brlcad/trunk/src/libged/simulate/collision.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/collision.hpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/collision.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file collision.hpp * - * Brief description + * Bullet collision algorithm. * */ @@ -27,13 +27,16 @@ #ifndef COLLISION_H #define COLLISION_H + +#include "common.h" + #include "rt_instance.hpp" +#include <btBulletDynamicsCommon.h> + #include <string> -#include <btBulletDynamicsCommon.h> - namespace simulate { Modified: brlcad/trunk/src/libged/simulate/interface.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/interface.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/interface.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,43 +19,23 @@ */ /** @file simulate.cpp * - * Brief description + * GED command. * */ + #include "common.h" -#include "ged.h" + #ifdef HAVE_BULLET + #include "simulation.hpp" -#include <sstream> -#include <stdexcept> +#include "utility.hpp" +#include "ged.h" -namespace -{ - -template<typename Target, typename Source> -Target lexical_cast(Source arg, - const std::string &description = "bad lexical_cast") -{ - std::stringstream interpreter; - Target result; - - if (!(interpreter << arg) || - !(interpreter >> result) || - !(interpreter >> std::ws).eof()) - throw std::invalid_argument(description); - - return result; -} - - -} - - int ged_simulate(ged *gedp, int argc, const char **argv) { @@ -73,8 +53,8 @@ if (!dir) return GED_ERROR; try { - btScalar seconds = lexical_cast<btScalar>(argv[2], - "invalid value for 'seconds'"); + btScalar seconds = simulate::lexical_cast<btScalar>(argv[2], + std::invalid_argument("invalid value for 'seconds'")); if (seconds < 0.0) throw std::runtime_error("invalid value for 'seconds'"); @@ -94,6 +74,10 @@ #else + +#include "ged.h" + + int ged_simulate(ged *gedp, int argc, const char **argv) { Modified: brlcad/trunk/src/libged/simulate/physics_world.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/physics_world.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/physics_world.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,13 +19,14 @@ */ /** @file physics_world.cpp * - * Brief description + * State for a simulated scene. * */ #ifdef HAVE_BULLET + #include "common.h" #include "physics_world.hpp" Modified: brlcad/trunk/src/libged/simulate/physics_world.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/physics_world.hpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/physics_world.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file physics_world.hpp * - * Brief description + * State for a simulated scene. * */ @@ -27,9 +27,12 @@ #ifndef PHYSICS_WORLD_H #define PHYSICS_WORLD_H + #include "common.h" + #include <btBulletDynamicsCommon.h> + namespace simulate { Modified: brlcad/trunk/src/libged/simulate/rt_instance.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/rt_instance.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/rt_instance.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file rt_instance.cpp * - * Brief description + * Rt instance for the ray tracing collision algorithm. * */ @@ -31,9 +31,7 @@ #include "rt_instance.hpp" -#include <stdexcept> - namespace { Modified: brlcad/trunk/src/libged/simulate/rt_instance.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/rt_instance.hpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/rt_instance.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file rt_instance.hpp * - * Brief description + * Rt instance for the ray tracing collision algorithm. * */ @@ -28,6 +28,8 @@ #define RT_INSTANCE_H +#include "common.h" + #include "raytrace.h" Modified: brlcad/trunk/src/libged/simulate/simulation.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/simulation.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/simulation.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file simulation.cpp * - * Brief description + * Programmatic interface for simulate. * */ Modified: brlcad/trunk/src/libged/simulate/simulation.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/simulation.hpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/simulation.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file simulation.hpp * - * Brief description + * Programmatic interface for simulate. * */ @@ -28,6 +28,8 @@ #define SIMULATION_H +#include "common.h" + #include "physics_world.hpp" #include "world_object.hpp" Added: brlcad/trunk/src/libged/simulate/utility.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/utility.hpp (rev 0) +++ brlcad/trunk/src/libged/simulate/utility.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -0,0 +1,100 @@ +/* U T I L I T Y . H P P + * BRL-CAD + * + * Copyright (c) 2016 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 utility.hpp + * + * Helpers used by simulate. + * + */ + + +#include "common.h" + +#include <sstream> +#include <stdexcept> + + +namespace simulate +{ + + +namespace detail +{ + + +template <typename T> void +autoptr_wrap_bu_free(T *ptr) +{ + bu_free(ptr, "AutoPtr"); +} + + +} + + +template<typename Target, typename Source> +Target lexical_cast(Source arg, + const std::exception &exception = std::invalid_argument("bad lexical_cast")) +{ + std::stringstream interpreter; + Target result; + + if (!(interpreter << arg) || + !(interpreter >> result) || + !(interpreter >> std::ws).eof()) + throw exception; + + return result; +} + + +template <typename T, void free_fn(T *) = detail::autoptr_wrap_bu_free> +struct AutoPtr { + explicit AutoPtr(T *vptr = NULL) : + ptr(vptr) + {} + + + ~AutoPtr() + { + if (ptr) + free_fn(ptr); + } + + + T *ptr; + + +private: + AutoPtr(const AutoPtr &source); + AutoPtr &operator=(const AutoPtr &source); +}; + + +} + + +// Local Variables: +// tab-width: 8 +// mode: C++ +// c-basic-offset: 4 +// indent-tabs-mode: t +// c-file-style: "stroustrup" +// End: +// ex: shiftwidth=4 tabstop=8 Property changes on: brlcad/trunk/src/libged/simulate/utility.hpp ___________________________________________________________________ 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/libged/simulate/world_object.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/world_object.cpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/world_object.cpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file world_object.cpp * - * Brief description + * Class for objects within a simulation. * */ @@ -30,11 +30,9 @@ #include "common.h" #include "world_object.hpp" +#include "utility.hpp" -#include <sstream> -#include <stdexcept> - namespace { @@ -42,42 +40,6 @@ static const std::string attribute_prefix = "simulate::"; -template <typename T, void (*Destructor)(T *)> -struct AutoDestroyer { - AutoDestroyer(T *vptr) : ptr(vptr) {} - - - ~AutoDestroyer() - { - Destructor(ptr); - } - - - T * const ptr; - - -private: - AutoDestroyer(const AutoDestroyer &source); - AutoDestroyer &operator=(const AutoDestroyer &source); -}; - - -template<typename Target, typename Source> -Target lexical_cast(Source arg, - const std::string &description = "bad lexical_cast") -{ - std::stringstream interpreter; - Target result; - - if (!(interpreter << arg) || - !(interpreter >> result) || - !(interpreter >> std::ws).eof()) - throw std::invalid_argument(description); - - return result; -} - - HIDDEN std::pair<btVector3, btVector3> get_bounding_box(db_i &db_instance, directory &dir) { @@ -107,7 +69,7 @@ &rt_uniresource) < 0) throw std::runtime_error("rt_db_get_internal() failed"); - AutoDestroyer<rt_db_internal, rt_db_free_internal> internal_autodestroy( + simulate::AutoPtr<rt_db_internal, rt_db_free_internal> internal_autoptr( &internal); if (internal.idb_meth->ft_volume) { @@ -135,7 +97,8 @@ for (int i = 0; i < 3; ++i) { std::string value; std::getline(stream, value, i != 2 ? ',' : '>'); - result[i] = lexical_cast<btScalar>(value, "invalid vector"); + result[i] = simulate::lexical_cast<btScalar>(value, + std::invalid_argument("invalid vector")); } if (stream.unget().get() != '>' || !(stream >> std::ws).eof()) @@ -236,7 +199,7 @@ if (db5_get_attributes(&db_instance, &obj_avs, &vdirectory) < 0) throw std::runtime_error("db5_get_attributes() failed"); - AutoDestroyer<bu_attribute_value_set, bu_avs_free> obj_avs_autodestroy( + simulate::AutoPtr<bu_attribute_value_set, bu_avs_free> obj_avs_autoptr( &obj_avs); for (std::size_t i = 0; i < obj_avs.count; ++i) @@ -246,7 +209,8 @@ const std::string value = obj_avs.avp[i].value; if (name == "mass") { - mass = lexical_cast<btScalar>(value, "invalid attribute 'mass'"); + mass = lexical_cast<btScalar>(value, + std::invalid_argument("invalid attribute 'mass'")); if (mass < 0.0) throw std::invalid_argument("invalid attribute 'mass'"); } else if (name == "linear_velocity") { Modified: brlcad/trunk/src/libged/simulate/world_object.hpp =================================================================== --- brlcad/trunk/src/libged/simulate/world_object.hpp 2016-09-26 14:51:43 UTC (rev 68905) +++ brlcad/trunk/src/libged/simulate/world_object.hpp 2016-09-27 16:49:06 UTC (rev 68906) @@ -19,7 +19,7 @@ */ /** @file world_object.hpp * - * Brief description + * Class for objects within a simulation. * */ @@ -28,6 +28,8 @@ #define WORLD_OBJECT_H +#include "common.h" + #include "collision.hpp" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2016-10-18 03:35:20
|
Revision: 69111 http://sourceforge.net/p/brlcad/code/69111 Author: brlcad Date: 2016-10-18 03:35:17 +0000 (Tue, 18 Oct 2016) Log Message: ----------- handle proper setting of the eye point by actually hooking on the end; command like we said we would, and just call the eye/perspective commands so we do the right thing. also no longer halt if the database seems different. just issue a warning and keep loading the view like we were asked. Modified Paths: -------------- brlcad/trunk/src/libged/ged_private.h brlcad/trunk/src/libged/loadview.c Modified: brlcad/trunk/src/libged/ged_private.h =================================================================== --- brlcad/trunk/src/libged/ged_private.h 2016-10-18 03:08:17 UTC (rev 69110) +++ brlcad/trunk/src/libged/ged_private.h 2016-10-18 03:35:17 UTC (rev 69111) @@ -310,6 +310,8 @@ const char **argv); extern int _ged_cm_set(const int argc, const char **argv); +extern int _ged_cm_end(const int argc, + const char **argv); extern int _ged_cm_null(const int argc, const char **argv); Modified: brlcad/trunk/src/libged/loadview.c =================================================================== --- brlcad/trunk/src/libged/loadview.c 2016-10-18 03:08:17 UTC (rev 69110) +++ brlcad/trunk/src/libged/loadview.c 2016-10-18 03:35:17 UTC (rev 69111) @@ -62,7 +62,7 @@ {"clean", "", "clean articulation from previous frame", _ged_cm_null, 1, 1}, {"end", "", "end of frame setup, begin raytrace", - _ged_cm_null, 1, 1}, + _ged_cm_end, 1, 1}, /* not output, by default in saveview */ @@ -93,6 +93,7 @@ ged_loadview(struct ged *gedp, int argc, const char *argv[]) { int ret; + int failed = 0; FILE *fp; char buffer[512] = {0}; @@ -143,18 +144,26 @@ while (!feof(fp)) { memset(buffer, 0, 512); ret = fscanf(fp, "%512s", buffer); - if (ret != 1) + if (ret != 1) { bu_log("Failed to read buffer\n"); + failed++; + } if (bu_strncmp(buffer, "-p", 2) == 0) { + char perspective_angle[128] = {0}; + const char *perspective_argv[2] = {"perspective", NULL}; + perspective_argv[1] = perspective_angle; + /* we found perspective */ buffer[0] = ' '; buffer[1] = ' '; sscanf(buffer, "%d", &perspective); /* bu_log("perspective=%d\n", perspective);*/ - gedp->ged_gvp->gv_perspective = perspective; + snprintf(perspective_angle, sizeof(perspective_angle), "%d", perspective); + ged_perspective(gedp, 2, (const char **)perspective_argv); + } else if (bu_strncmp(buffer, "$*", 2) == 0) { /* the next read is the file name, the objects come * after that @@ -162,8 +171,10 @@ memset(dbName, 0, MAX_DBNAME); ret = fscanf(fp, "%2048s", dbName); /* MAX_DBNAME */ - if (ret != 1) + if (ret != 1) { bu_log("Failed to read database name\n"); + failed++; + } /* if the last character is a line termination, * remove it (it should always be unless the user @@ -175,27 +186,26 @@ /* bu_log("dbName=%s\n", dbName); */ if (!bu_same_file(gedp->ged_wdbp->dbip->dbi_filename, dbName)) { - /* stop here if they are not the same file, - * otherwise, we may proceed as expected, and load - * the objects. + /* warn here if they are not the same file, otherwise, + * proceed as expected, and try to load the objects. */ - bu_vls_printf(gedp->ged_result_str, "View script references a different database\nCannot load the view without closing the current database\n(i.e. run \"opendb %s\")\n", dbName); - - /* restore state before leaving */ - gedp->ged_gvp->gv_perspective = prevPerspective; - fclose(fp); - return GED_ERROR; + bu_log("WARNING: view script seems to reference a different database\n([%s] != [%s])\n", dbName, gedp->ged_wdbp->dbip->dbi_filename); } /* get rid of anything that may be displayed, since we * will load objects that are listed in the script next. + * + * TODO: should only zap if the objects to be displayed + * all exist. */ (void)ged_zap(gedp, 1, NULL); /* now get the objects listed */ ret = fscanf(fp, "%10000s", objects); - if (ret != 1) + if (ret != 1) { bu_log("Failed to read object names\n"); + failed++; + } /* bu_log("OBJECTS=%s\n", objects);*/ while ((!feof(fp)) && (bu_strncmp(objects, "\\", 1) != 0)) { @@ -216,8 +226,10 @@ /* bu_log("objects=%s\n", objects);*/ ret = fscanf(fp, "%10000s", objects); - if (ret != 1) + if (ret != 1) { bu_log("Failed to read object names\n"); + failed++; + } } /* end iteration over reading in listed objects */ @@ -231,6 +243,7 @@ */ if (rt_do_cmd((struct rt_i *)0, cmdBuffer, ged_loadview_cmdtab) < 0) { bu_vls_printf(gedp->ged_result_str, "command failed: %s\n", cmdBuffer); + failed++; } bu_free((void *)cmdBuffer, "loadview cmdBuffer"); } @@ -243,14 +256,8 @@ /* end iteration over file until eof */ fclose(fp); - /* now we have to finish the eye point calculations that usually get - * postponed until the end command runs. Since we are at the "end" - * of a commands section, we may finish the computations. - */ - /* First step: put eye at view center (view 0, 0, 0) */ - MAT_COPY(gedp->ged_gvp->gv_rotation, _ged_viewrot); - MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, _ged_eye_model); - ged_view_update(gedp->ged_gvp); + if (failed) + return GED_ERROR; return GED_OK; } @@ -277,7 +284,8 @@ _ged_eye_model[X] = atof(argv[1]); _ged_eye_model[Y] = atof(argv[2]); _ged_eye_model[Z] = atof(argv[3]); - /* Processing is deferred until ged_cm_end() */ + + /* Processing is deferred until view 'end' */ return 0; } @@ -308,7 +316,7 @@ bn_mat_fromto(_ged_viewrot, dir, neg_Z_axis, &_ged_current_gedp->ged_wdbp->wdb_tol); } - /* Final processing is deferred until ged_cm_end(), but eye_pt + /* Final processing is deferred until view 'end', but eye_pt * must have been specified before here (for now) */ return 0; @@ -324,7 +332,7 @@ return -1; for (i = 0; i < 16; i++) _ged_viewrot[i] = atof(argv[i+1]); - /* Processing is deferred until ged_cm_end() */ + /* Processing is deferred until view 'end' */ return 0; } @@ -367,6 +375,34 @@ } +/** + * process the 'end' of a view. currently, requires an eye point be + * specified beforehand. + */ +int +_ged_cm_end(const int argc, const char **argv) +{ + struct bu_vls eye = BU_VLS_INIT_ZERO; + char *eye_argv[4] = {"eye", NULL, NULL, NULL}; + + if (argc < 0 || argv == NULL) + return 1; + + /* now we have to finish view calculations that are deferred until + * the end command runs. + */ + MAT_COPY(_ged_current_gedp->ged_gvp->gv_rotation, _ged_viewrot); + MAT_DELTAS_VEC_NEG(_ged_current_gedp->ged_gvp->gv_center, _ged_eye_model); + ged_view_update(_ged_current_gedp->ged_gvp); + + bu_vls_printf(&eye, "%lf %lf %lf", V3ARGS(_ged_eye_model)); + bu_argv_from_string(eye_argv+1, 4, bu_vls_addr(&eye)); + ged_eye(_ged_current_gedp, 4, (const char **)eye_argv); + bu_vls_free(&eye); + + return 0; +} + /* * Local Variables: * tab-width: 8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ej...@us...> - 2017-01-19 00:02:47
|
Revision: 69334 http://sourceforge.net/p/brlcad/code/69334 Author: ejno Date: 2017-01-19 00:02:44 +0000 (Thu, 19 Jan 2017) Log Message: ----------- initial implementation of a unit test for the simulate command Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libged/simulate/tests/ brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt brlcad/trunk/src/libged/simulate/tests/simulate_test.cpp Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2017-01-19 00:00:15 UTC (rev 69333) +++ brlcad/trunk/src/libged/CMakeLists.txt 2017-01-19 00:02:44 UTC (rev 69334) @@ -342,6 +342,8 @@ BRLCAD_ADDLIB(libged "${LIBGED_SOURCES}" "libwdb;librt;libnmg;libfb;libbg;libbn;libbu;libicv;libanalyze;${LIBGED_CMD_LIBS_LIST};${REGEX_LIBRARY};${WINSOCK_LIB};${CLIPPER_LIBRARY};${M_LIBRARY}") SET_TARGET_PROPERTIES(libged PROPERTIES VERSION 20.0.1 SOVERSION 20) +add_subdirectory(simulate/tests) + set(ged_ignore_files TODO ged_private.h Added: brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt (rev 0) +++ brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt 2017-01-19 00:02:44 UTC (rev 69334) @@ -0,0 +1,3 @@ +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") +BRLCAD_ADDEXEC(simulate_test "simulate_test.cpp" libged TEST) +add_test(NAME simulate_test COMMAND simulate_test) Property changes on: brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt ___________________________________________________________________ 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 Added: brlcad/trunk/src/libged/simulate/tests/simulate_test.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/tests/simulate_test.cpp (rev 0) +++ brlcad/trunk/src/libged/simulate/tests/simulate_test.cpp 2017-01-19 00:02:44 UTC (rev 69334) @@ -0,0 +1,141 @@ +#include "common.h" + +#include "simulation.hpp" +#include "utility.hpp" + +#include "wdb.h" + + +namespace +{ + + +HIDDEN bool +matrix_equal(const db_i &db, const std::string &path, + const fastf_t * const other_matrix) +{ + RT_CK_DBI(&db); + + if (!other_matrix) + bu_bomb("missing argument"); + + db_full_path full_path; + db_full_path_init(&full_path); + simulate::AutoPtr<db_full_path, db_free_full_path> autofree_full_path( + &full_path); + + if (db_string_to_path(&full_path, &db, path.c_str())) + bu_bomb("db_string_to_path() failed"); + + if (full_path.fp_len < 2) + bu_bomb("invalid path"); + + mat_t matrix = MAT_INIT_IDN; + + if (1 != db_path_to_mat(const_cast<db_i *>(&db), &full_path, matrix, + full_path.fp_len, &rt_uniresource)) + bu_bomb("db_path_to_mat() failed"); + + bn_tol tol = BN_TOL_INIT_ZERO; + rt_tol_default(&tol); + return bn_mat_is_equal(matrix, other_matrix, &tol); +} + + +HIDDEN bool +test_basic() +{ + simulate::AutoPtr<db_i, db_close> db(db_create_inmem()); + + if (!db.ptr) + bu_bomb("db_create_inmem() failed"); + + { + const point_t center = {10.0, -3.0, 7.0}; + + if (mk_sph(db.ptr->dbi_wdbp, "sphere.s", center, 1.0)) + bu_bomb("mk_sph() failed"); + } + + { + const point_t min = {-1.0, -4.0, -3.0}; + const point_t max = {6.0, 3.0, 5.0}; + + if (mk_rpp(db.ptr->dbi_wdbp, "base.s", min, max)) + bu_bomb("mk_rcc() failed"); + + if (db5_update_attribute("base.s", "simulate::mass", "0.0", db.ptr)) + bu_bomb("db5_update_attribute() failed"); + } + + mat_t base_matrix = { + -5.521101248230e-01, -3.139768433222e-01, 7.723942982217e-01, 2.187053795275e+01, + -2.610004893800e-01, 9.449108513725e-01, 1.975404452307e-01, 1.139654545789e+01, + -7.918668793499e-01, -9.253120995622e-02, -6.036429578589e-01, 1.538490559814e+01, + 0.0, 0.0, 0.0, 2.171448921007e+00 + }; + + { + mat_t sphere1_matrix = { + 8.107419012686e-01, -5.807087377357e-01, 7.399277968041e-02, -1.037746328886e+01, + -2.644176206353e-01, -2.504944693283e-01, 9.313086721026e-01, -3.751995030519e+00, + -5.222843013388e-01, -7.746159582357e-01, -3.566359850347e-01, 6.822434777292e+00, + 0.0, 0.0, 0.0, 2.187865118746e-01 + }; + + mat_t sphere2_matrix = { + 8.107419012686e-01, -5.807087377357e-01, 7.399277968041e-02, 1.315409627756e+00, + -2.644176206353e-01, -2.504944693283e-01, 9.313086721026e-01, -3.208803314406e-01, + -5.222843013388e-01, -7.746159582357e-01, -3.566359850347e-01, 1.381761676557e+01, + 0.0, 0.0, 0.0, 1.0 + }; + + wmember members; + BU_LIST_INIT(&members.l); + mk_addmember("sphere.s", &members.l, sphere1_matrix, WMOP_UNION); + mk_addmember("sphere.s", &members.l, sphere2_matrix, WMOP_UNION); + + if (mk_comb(db.ptr->dbi_wdbp, "falling.r", &members.l, true, NULL, NULL, NULL, + 0, 0, 0, 0, false, true, false)) + bu_bomb("mk_comb() failed"); + + BU_LIST_INIT(&members.l); + mk_addmember("base.s", &members.l, base_matrix, WMOP_UNION); + mk_addmember("falling.r", &members.l, NULL, WMOP_UNION); + + if (mk_comb(db.ptr->dbi_wdbp, "scene.c", &members.l, false, NULL, NULL, NULL, 0, + 0, 0, 0, false, true, false)) + bu_bomb("mk_comb() failed"); + } + + simulate::Simulation(*db.ptr, "scene.c").step(3.0); + + { + const mat_t expected_falling_matrix = { + -8.601763732025e-01, -3.622751595212e-02, -5.087041542726e-01, 1.267898491013e+01, + -2.648488540913e-02, 9.993015440712e-01, -2.638166412216e-02, 2.841764865291e-01, + 5.093044817210e-01, -9.219920561365e-03, -8.605341136100e-01, -1.939468699647e+01, + 0.0, 0.0, 0.0, 1.0 + }; + + return matrix_equal(*db.ptr, "/scene.c/base.s", base_matrix) + && matrix_equal(*db.ptr, "/scene.c/falling.r", expected_falling_matrix); + } +} + + +HIDDEN bool +simulate_test() +{ + return test_basic(); +} + + +} + + +int +main() +{ + return !simulate_test(); +} Property changes on: brlcad/trunk/src/libged/simulate/tests/simulate_test.cpp ___________________________________________________________________ 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. |
From: <ej...@us...> - 2017-01-19 15:23:45
|
Revision: 69339 http://sourceforge.net/p/brlcad/code/69339 Author: ejno Date: 2017-01-19 15:23:43 +0000 (Thu, 19 Jan 2017) Log Message: ----------- fix Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2017-01-19 15:15:18 UTC (rev 69338) +++ brlcad/trunk/src/libged/CMakeLists.txt 2017-01-19 15:23:43 UTC (rev 69339) @@ -6,7 +6,6 @@ set(LIBGED_CMD_LIBS_LIST ${LIBGED_CMD_LIBS_LIST} ${BULLET_LIBRARIES}) set(LIBGED_CMD_INCLUDE_DIRS ${LIBGED_CMD_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/simulate ${BULLET_INCLUDE_DIR}) add_definitions(-DHAVE_BULLET=1) - add_subdirectory(simulate/tests) endif(BULLET_LIBRARIES) if(ADAPTAGRAMS_FOUND) @@ -343,6 +342,8 @@ BRLCAD_ADDLIB(libged "${LIBGED_SOURCES}" "libwdb;librt;libnmg;libfb;libbg;libbn;libbu;libicv;libanalyze;${LIBGED_CMD_LIBS_LIST};${REGEX_LIBRARY};${WINSOCK_LIB};${CLIPPER_LIBRARY};${M_LIBRARY}") SET_TARGET_PROPERTIES(libged PROPERTIES VERSION 20.0.1 SOVERSION 20) +add_subdirectory(simulate/tests) + set(ged_ignore_files TODO ged_private.h Modified: brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt 2017-01-19 15:15:18 UTC (rev 69338) +++ brlcad/trunk/src/libged/simulate/tests/CMakeLists.txt 2017-01-19 15:23:43 UTC (rev 69339) @@ -1,3 +1,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") -BRLCAD_ADDEXEC(simulate_test "simulate_test.cpp" libged TEST) -add_test(NAME simulate_test COMMAND simulate_test) + + +if (BULLET_LIBRARIES) + BRLCAD_ADDEXEC(simulate_test "simulate_test.cpp" libged TEST) + add_test(NAME simulate_test COMMAND simulate_test) +endif(BULLET_LIBRARIES) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2017-09-02 21:45:27
|
Revision: 70183 http://sourceforge.net/p/brlcad/code/70183 Author: starseeker Date: 2017-09-02 21:45:23 +0000 (Sat, 02 Sep 2017) Log Message: ----------- We'll be wanting to list these sources for CMAKEFILES either way... Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2017-09-02 16:18:54 UTC (rev 70182) +++ brlcad/trunk/src/libged/CMakeLists.txt 2017-09-02 21:45:23 UTC (rev 70183) @@ -15,8 +15,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/simulate/BulletDynamics ${CMAKE_CURRENT_SOURCE_DIR}/simulate/BulletSoftBody ) - include(simulate/bullet/CMakeLists.txt) endif(BRLCAD_ENABLE_BULLET) +include(simulate/bullet/CMakeLists.txt) if(ADAPTAGRAMS_FOUND) set(LIBGED_CMD_LIBS_LIST ${LIBGED_CMD_LIBS_LIST} ${ADAPTAGRAMS_LIBRARIES}) Modified: brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt 2017-09-02 16:18:54 UTC (rev 70182) +++ brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt 2017-09-02 21:45:23 UTC (rev 70183) @@ -400,6 +400,7 @@ ${BulletSoftBody_SRCS} ) +if(BRLCAD_ENABLE_BULLET) set(LIBGED_SOURCES ${Bullet_SRCS} ${Bullet_HDRS}) include(CheckCXXCompilerFlag) @@ -410,6 +411,10 @@ set_property(SOURCE ${srcfile} APPEND PROPERTY COMPILE_FLAGS "-w -Wno-error") endforeach(srcfile ${Bullet_SRCS}) endif(NOERROR_FLAG_CXX AND NOWARN_FLAG_CXX) +else(BRLCAD_ENABLE_BULLET) + CMAKEFILES(${Bullet_SRCS}) + CMAKEFILES(${Bullet_HDRS}) +endif(BRLCAD_ENABLE_BULLET) CMAKEFILES(simulate/bullet/AUTHORS.txt simulate/bullet/LICENSE.txt) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2017-11-21 07:51:14
|
Revision: 70423 http://sourceforge.net/p/brlcad/code/70423 Author: brlcad Date: 2017-11-21 07:51:11 +0000 (Tue, 21 Nov 2017) Log Message: ----------- may need work on Windows, but this fixes the Mac build. architecturally, it should be a subbuild, not bundled into the lib as sources. this way also lets warnings be trivially disabled with the macro src/other uses. Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2017-11-21 07:31:32 UTC (rev 70422) +++ brlcad/trunk/src/libged/CMakeLists.txt 2017-11-21 07:51:11 UTC (rev 70423) @@ -347,7 +347,11 @@ BRLCAD_LIB_INCLUDE_DIRS(ged GED_INCLUDE_DIRS GED_LOCAL_INCLUDE_DIRS) -BRLCAD_ADDLIB(libged "${LIBGED_SOURCES}" "libwdb;librt;libnmg;libfb;libbg;libbn;libbu;libicv;libanalyze;${LIBGED_CMD_LIBS_LIST};${REGEX_LIBRARY};${WINSOCK_LIB};${CLIPPER_LIBRARY};${M_LIBRARY}") +if(BRLCAD_ENABLE_BULLET) + set(CADBULLET_LIBRARY cadbullet) +endif(BRLCAD_ENABLE_BULLET) + +BRLCAD_ADDLIB(libged "${LIBGED_SOURCES}" "libwdb;librt;libnmg;libfb;libbg;libbn;libbu;libicv;libanalyze;${LIBGED_CMD_LIBS_LIST};${CADBULLET_LIBRARY};${REGEX_LIBRARY};${WINSOCK_LIB};${CLIPPER_LIBRARY};${M_LIBRARY}") SET_TARGET_PROPERTIES(libged PROPERTIES VERSION 20.0.1 SOVERSION 20) if(CPP_DLL_DEFINES) Modified: brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt 2017-11-21 07:31:32 UTC (rev 70422) +++ brlcad/trunk/src/libged/simulate/bullet/CMakeLists.txt 2017-11-21 07:51:11 UTC (rev 70423) @@ -401,16 +401,8 @@ ) if(BRLCAD_ENABLE_BULLET) - set(LIBGED_SOURCES ${Bullet_SRCS} ${Bullet_HDRS}) - - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-Wno-error NOERROR_FLAG_CXX) - check_cxx_compiler_flag(-w NOWARN_FLAG_CXX) - if(NOERROR_FLAG_CXX AND NOWARN_FLAG_CXX) - foreach(srcfile ${Bullet_SRCS}) - set_property(SOURCE ${srcfile} APPEND PROPERTY COMPILE_FLAGS "-w -Wno-error") - endforeach(srcfile ${Bullet_SRCS}) - endif(NOERROR_FLAG_CXX AND NOWARN_FLAG_CXX) + add_library(cadbullet ${Bullet_SRCS} ${Bullet_HDRS}) + DISABLE_WARNINGS() else(BRLCAD_ENABLE_BULLET) CMAKEFILES(${Bullet_SRCS}) CMAKEFILES(${Bullet_HDRS}) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2018-01-11 20:44:19
|
Revision: 70590 http://sourceforge.net/p/brlcad/code/70590 Author: brlcad Date: 2018-01-11 20:44:16 +0000 (Thu, 11 Jan 2018) Log Message: ----------- might need to revert this, but icc is unhappy with const of pointer typedef (rightly so, need to kill them) Modified Paths: -------------- brlcad/trunk/src/libged/edit.c brlcad/trunk/src/libged/tables.c Modified: brlcad/trunk/src/libged/edit.c =================================================================== --- brlcad/trunk/src/libged/edit.c 2018-01-11 20:38:13 UTC (rev 70589) +++ brlcad/trunk/src/libged/edit.c 2018-01-11 20:44:16 UTC (rev 70590) @@ -1438,8 +1438,8 @@ const vect_t *from = (const vect_t *)cmd->translate.ref_vector.from->vector; const vect_t *to = (const vect_t *)cmd->translate.ref_vector.to->vector; return edit_translate(gedp, - (const vect_t * const)from, - (const vect_t * const)to, + (vect_t * const)from, + (vect_t * const)to, (const struct db_full_path *)cmd->translate.objects->object); } Modified: brlcad/trunk/src/libged/tables.c =================================================================== --- brlcad/trunk/src/libged/tables.c 2018-01-11 20:38:13 UTC (rev 70589) +++ brlcad/trunk/src/libged/tables.c 2018-01-11 20:44:16 UTC (rev 70590) @@ -224,11 +224,11 @@ bu_log("Could not import %s\n", tree_list[i].tl_tree->tr_l.tl_name); nsoltemp = 0; } - nsoltemp = tables_sol_number((const matp_t)temp_mat, tree_list[i].tl_tree->tr_l.tl_name, &old, numsol); + nsoltemp = tables_sol_number((matp_t)temp_mat, tree_list[i].tl_tree->tr_l.tl_name, &old, numsol); fprintf(tabptr, " %c [%d] ", op, nsoltemp); } } else { - const matp_t mat = (const matp_t)old_mat; + const matp_t mat = (matp_t)old_mat; nsoltemp = tables_sol_number(mat, tree_list[i].tl_tree->tr_l.tl_name, &old, numsol); fprintf(tabptr, " %c [%d] ", op, nsoltemp); continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2018-07-18 00:20:33
|
Revision: 71168 http://sourceforge.net/p/brlcad/code/71168 Author: brlcad Date: 2018-07-18 00:20:29 +0000 (Wed, 18 Jul 2018) Log Message: ----------- add a simple test harness for directly running ged_tops() Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libged/tests/ brlcad/trunk/src/libged/tests/test_tops.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2018-07-17 21:44:57 UTC (rev 71167) +++ brlcad/trunk/src/libged/CMakeLists.txt 2018-07-18 00:20:29 UTC (rev 71168) @@ -360,6 +360,7 @@ set_property(TARGET libged APPEND PROPERTY COMPILE_DEFINITIONS "CLIPPER_DLL_IMPORTS") endif(CPP_DLL_DEFINES) +add_subdirectory(tests) add_subdirectory(simulate/tests) set(ged_ignore_files Added: brlcad/trunk/src/libged/tests/test_tops.c =================================================================== --- brlcad/trunk/src/libged/tests/test_tops.c (rev 0) +++ brlcad/trunk/src/libged/tests/test_tops.c 2018-07-18 00:20:29 UTC (rev 71168) @@ -0,0 +1,63 @@ +/* T E S T _ T O P S . C + * BRL-CAD + * + * Copyright (c) 2018 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 test_tops.c + * + * Brief description + * + */ + +#include "common.h" + +#include <stdio.h> +#include <bu.h> +#include <ged.h> + +int +main(int ac, char *av[]) { + struct ged *dbp; + const char *tops[3] = {"tops", "-n", NULL}; + + if (ac != 2) { + printf("Usage: %s file.g\n", av[0]); + return 1; + } + if (!bu_file_exists(av[1], NULL)) { + printf("ERROR: [%s] does not exist, expecting .g file\n", av[1]); + return 2; + } + + dbp = ged_open("db", av[1], 1); + ged_tops(dbp, 2, tops); + printf("%s\n", bu_vls_addr(dbp->ged_result_str)); + ged_close(dbp); + BU_PUT(dbp, struct ged); + + return 0; +} + +/* + * 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/tests/test_tops.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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-07-28 13:20:27
|
Revision: 71287 http://sourceforge.net/p/brlcad/code/71287 Author: starseeker Date: 2018-07-28 13:20:19 +0000 (Sat, 28 Jul 2018) Log Message: ----------- Move some code used in multiple places to ged_util.c Modified Paths: -------------- brlcad/trunk/src/libged/cc.c brlcad/trunk/src/libged/columns.c brlcad/trunk/src/libged/ged_private.h brlcad/trunk/src/libged/ged_util.c brlcad/trunk/src/libged/ls.c Modified: brlcad/trunk/src/libged/cc.c =================================================================== --- brlcad/trunk/src/libged/cc.c 2018-07-28 03:12:24 UTC (rev 71286) +++ brlcad/trunk/src/libged/cc.c 2018-07-28 13:20:19 UTC (rev 71287) @@ -33,11 +33,6 @@ #include "./ged_private.h" - -#define RT_TERMINAL_WIDTH 80 -#define RT_COLUMNS ((RT_TERMINAL_WIDTH + V4_MAXNAME - 1) / V4_MAXNAME) - - /* * List constraint objects in this database */ Modified: brlcad/trunk/src/libged/columns.c =================================================================== --- brlcad/trunk/src/libged/columns.c 2018-07-28 03:12:24 UTC (rev 71286) +++ brlcad/trunk/src/libged/columns.c 2018-07-28 13:20:19 UTC (rev 71287) @@ -80,21 +80,6 @@ /* - * Given two pointers to pointers to directory entries, do a string compare - * on the respective names and return that value. - */ -int -cmpdirname(const void *a, const void *b) -{ - struct directory **dp1, **dp2; - - dp1 = (struct directory **)a; - dp2 = (struct directory **)b; - return bu_strcmp((*dp1)->d_namep, (*dp2)->d_namep); -} - - -/* * Local Variables: * mode: C * tab-width: 8 Modified: brlcad/trunk/src/libged/ged_private.h =================================================================== --- brlcad/trunk/src/libged/ged_private.h 2018-07-28 03:12:24 UTC (rev 71286) +++ brlcad/trunk/src/libged/ged_private.h 2018-07-28 13:20:19 UTC (rev 71287) @@ -74,6 +74,9 @@ #define DG_GED_MAX 2047.0 #define DG_GED_MIN -2048.0 +/* Default libged column width assumption */ +#define GED_TERMINAL_WIDTH 80 + struct _ged_funtab { char *ft_name; char *ft_parms; @@ -315,16 +318,6 @@ extern int _ged_cm_null(const int argc, const char **argv); - -/* defined in ls.c */ -extern void _ged_vls_col_pr4v(struct bu_vls *vls, - struct directory **list_of_names, - size_t num_in_list, - int no_decorate, - int ssflag); -extern struct directory ** _ged_getspace(struct db_i *dbip, - size_t num_entries); - /* defined in preview.c */ extern void _ged_setup_rt(struct ged *gedp, char **vp, @@ -532,6 +525,44 @@ extern int _ged_brep_to_csg(struct ged *gedp, const char *obj_name, int verify); extern int _ged_brep_tikz(struct ged *gedp, const char *obj_name, const char *outfile); + +/* defined in ged_util.c.c */ + +/** + * Given two pointers to pointers to directory entries, do a string + * compare on the respective names and return that value. + */ +int cmpdirname(const void *a, const void *b, void *arg); + +/** + * Given two pointers to pointers to directory entries, compare + * the dp->d_len sizes. + */ +int cmpdlen(const void *a, const void *b, void *arg); + + +/** + * Given a pointer to a list of pointers to names and the number of + * names in that list, sort and print that list in column order over + * four columns. + */ +extern void _ged_vls_col_pr4v(struct bu_vls *vls, + struct directory **list_of_names, + size_t num_in_list, + int no_decorate, + int ssflag); + +/** + * This routine walks through the directory entry list and mallocs + * enough space for pointers to hold the number of entries specified + * by the argument if > 0. + * + */ +extern struct directory ** _ged_getspace(struct db_i *dbip, + size_t num_entries); + + + __END_DECLS #endif /* LIBGED_GED_PRIVATE_H */ Modified: brlcad/trunk/src/libged/ged_util.c =================================================================== --- brlcad/trunk/src/libged/ged_util.c 2018-07-28 03:12:24 UTC (rev 71286) +++ brlcad/trunk/src/libged/ged_util.c 2018-07-28 13:20:19 UTC (rev 71287) @@ -28,7 +28,12 @@ #include "common.h" +#include <stdlib.h> +#include <string.h> +#include "bu/sort.h" +#include "bu/str.h" + #include "ged.h" #include "./ged_private.h" @@ -104,6 +109,156 @@ bu_free(results->results_tbl, "done with results ptbl"); } +/*********************************************************/ +/* comparison functions for bu_sort */ +/*********************************************************/ + +/** + * Given two pointers to pointers to directory entries, do a string + * compare on the respective names and return that value. + */ +int +cmpdirname(const void *a, const void *b, void *UNUSED(arg)) +{ + struct directory **dp1, **dp2; + + dp1 = (struct directory **)a; + dp2 = (struct directory **)b; + return bu_strcmp((*dp1)->d_namep, (*dp2)->d_namep); +} + +/** + * Given two pointers to pointers to directory entries, compare + * the dp->d_len sizes. + */ +int +cmpdlen(const void *a, const void *b, void *UNUSED(arg)) +{ + int cmp = 0; + struct directory **dp1, **dp2; + + dp1 = (struct directory **)a; + dp2 = (struct directory **)b; + if ((*dp1)->d_len > (*dp2)->d_len) cmp = 1; + if ((*dp1)->d_len < (*dp2)->d_len) cmp = -1; + return cmp; +} + +/*********************************************************/ +/* _ged_vls_col_pr4v */ +/*********************************************************/ + + +void +_ged_vls_col_pr4v(struct bu_vls *vls, + struct directory **list_of_names, + size_t num_in_list, + int no_decorate, + int ssflag) +{ + size_t lines, i, j, k, this_one; + size_t namelen; + size_t maxnamelen; /* longest name in list */ + size_t cwidth; /* column width */ + size_t numcol; /* number of columns */ + + if (!ssflag) { + bu_sort((void *)list_of_names, + (unsigned)num_in_list, (unsigned)sizeof(struct directory *), + cmpdirname, NULL); + } else { + bu_sort((void *)list_of_names, + (unsigned)num_in_list, (unsigned)sizeof(struct directory *), + cmpdlen, NULL); + } + + /* + * Traverse the list of names, find the longest name and set the + * the column width and number of columns accordingly. If the + * longest name is greater than 80 characters, the number of + * columns will be one. + */ + maxnamelen = 0; + for (k = 0; k < num_in_list; k++) { + namelen = strlen(list_of_names[k]->d_namep); + if (namelen > maxnamelen) + maxnamelen = namelen; + } + + if (maxnamelen <= 16) + maxnamelen = 16; + cwidth = maxnamelen + 4; + + if (cwidth > 80) + cwidth = 80; + numcol = GED_TERMINAL_WIDTH / cwidth; + + /* + * For the number of (full and partial) lines that will be needed, + * print in vertical format. + */ + lines = (num_in_list + (numcol - 1)) / numcol; + for (i = 0; i < lines; i++) { + for (j = 0; j < numcol; j++) { + this_one = j * lines + i; + bu_vls_printf(vls, "%s", list_of_names[this_one]->d_namep); + namelen = strlen(list_of_names[this_one]->d_namep); + + /* + * Region and ident checks here.... Since the code has + * been modified to push and sort on pointers, the + * printing of the region and ident flags must be delayed + * until now. There is no way to make the decision on + * where to place them before now. + */ + if (!no_decorate && list_of_names[this_one]->d_flags & RT_DIR_COMB) { + bu_vls_putc(vls, '/'); + namelen++; + } + + if (!no_decorate && list_of_names[this_one]->d_flags & RT_DIR_REGION) { + bu_vls_putc(vls, 'R'); + namelen++; + } + + /* + * Size check (partial lines), and line termination. Note + * that this will catch the end of the lines that are full + * too. + */ + if (this_one + lines >= num_in_list) { + bu_vls_putc(vls, '\n'); + break; + } else { + /* + * Pad to next boundary as there will be another entry + * to the right of this one. + */ + while (namelen++ < cwidth) + bu_vls_putc(vls, ' '); + } + } + } +} + +/*********************************************************/ + +struct directory ** +_ged_getspace(struct db_i *dbip, + size_t num_entries) +{ + struct directory **dir_basep; + + if (num_entries == 0) + num_entries = db_directory_size(dbip); + + /* Allocate and cast num_entries worth of pointers */ + dir_basep = (struct directory **) bu_calloc((num_entries+1), sizeof(struct directory *), "_ged_getspace *dir[]"); + return dir_basep; +} + + + /* * Local Variables: * mode: C Modified: brlcad/trunk/src/libged/ls.c =================================================================== --- brlcad/trunk/src/libged/ls.c 2018-07-28 03:12:24 UTC (rev 71286) +++ brlcad/trunk/src/libged/ls.c 2018-07-28 13:20:19 UTC (rev 71287) @@ -36,161 +36,6 @@ #include "./ged_private.h" -#define RT_TERMINAL_WIDTH 80 -#define RT_COLUMNS ((RT_TERMINAL_WIDTH + V4_MAXNAME - 1) / V4_MAXNAME) - - -/** - * This routine walks through the directory entry list and mallocs - * enough space for pointers to hold the number of entries specified - * by the argument if > 0. - * - */ -struct directory ** -_ged_getspace(struct db_i *dbip, - size_t num_entries) -{ - struct directory **dir_basep; - - if (num_entries == 0) - num_entries = db_directory_size(dbip); - - /* Allocate and cast num_entries worth of pointers */ - dir_basep = (struct directory **) bu_calloc((num_entries+1), sizeof(struct directory *), "_ged_getspace *dir[]"); - return dir_basep; -} - - -/** - * Given two pointers to pointers to directory entries, do a string - * compare on the respective names and return that value. - */ -static int -cmpdirname(const void *a, const void *b, void *UNUSED(arg)) -{ - struct directory **dp1, **dp2; - - dp1 = (struct directory **)a; - dp2 = (struct directory **)b; - return bu_strcmp((*dp1)->d_namep, (*dp2)->d_namep); -} - -/** - * Given two pointers to pointers to directory entries, compare - * the dp->d_len sizes. - */ -static int -cmpdlen(const void *a, const void *b, void *UNUSED(arg)) -{ - int cmp = 0; - struct directory **dp1, **dp2; - - dp1 = (struct directory **)a; - dp2 = (struct directory **)b; - if ((*dp1)->d_len > (*dp2)->d_len) cmp = 1; - if ((*dp1)->d_len < (*dp2)->d_len) cmp = -1; - return cmp; -} - - -/** - * Given a pointer to a list of pointers to names and the number of - * names in that list, sort and print that list in column order over - * four columns. - */ -void -_ged_vls_col_pr4v(struct bu_vls *vls, - struct directory **list_of_names, - size_t num_in_list, - int no_decorate, - int ssflag) -{ - size_t lines, i, j, k, this_one; - size_t namelen; - size_t maxnamelen; /* longest name in list */ - size_t cwidth; /* column width */ - size_t numcol; /* number of columns */ - - if (!ssflag) { - bu_sort((void *)list_of_names, - (unsigned)num_in_list, (unsigned)sizeof(struct directory *), - cmpdirname, NULL); - } else { - bu_sort((void *)list_of_names, - (unsigned)num_in_list, (unsigned)sizeof(struct directory *), - cmpdlen, NULL); - } - - /* - * Traverse the list of names, find the longest name and set the - * the column width and number of columns accordingly. If the - * longest name is greater than 80 characters, the number of - * columns will be one. - */ - maxnamelen = 0; - for (k = 0; k < num_in_list; k++) { - namelen = strlen(list_of_names[k]->d_namep); - if (namelen > maxnamelen) - maxnamelen = namelen; - } - - if (maxnamelen <= 16) - maxnamelen = 16; - cwidth = maxnamelen + 4; - - if (cwidth > 80) - cwidth = 80; - numcol = RT_TERMINAL_WIDTH / cwidth; - - /* - * For the number of (full and partial) lines that will be needed, - * print in vertical format. - */ - lines = (num_in_list + (numcol - 1)) / numcol; - for (i = 0; i < lines; i++) { - for (j = 0; j < numcol; j++) { - this_one = j * lines + i; - bu_vls_printf(vls, "%s", list_of_names[this_one]->d_namep); - namelen = strlen(list_of_names[this_one]->d_namep); - - /* - * Region and ident checks here.... Since the code has - * been modified to push and sort on pointers, the - * printing of the region and ident flags must be delayed - * until now. There is no way to make the decision on - * where to place them before now. - */ - if (!no_decorate && list_of_names[this_one]->d_flags & RT_DIR_COMB) { - bu_vls_putc(vls, '/'); - namelen++; - } - - if (!no_decorate && list_of_names[this_one]->d_flags & RT_DIR_REGION) { - bu_vls_putc(vls, 'R'); - namelen++; - } - - /* - * Size check (partial lines), and line termination. Note - * that this will catch the end of the lines that are full - * too. - */ - if (this_one + lines >= num_in_list) { - bu_vls_putc(vls, '\n'); - break; - } else { - /* - * Pad to next boundary as there will be another entry - * to the right of this one. - */ - while (namelen++ < cwidth) - bu_vls_putc(vls, ' '); - } - } - } -} - - static void vls_long_dpp(struct ged *gedp, struct directory **list_of_names, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-07-31 16:27:41
|
Revision: 71318 http://sourceforge.net/p/brlcad/code/71318 Author: starseeker Date: 2018-07-31 16:27:38 +0000 (Tue, 31 Jul 2018) Log Message: ----------- rename Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libged/pnts.cpp Removed Paths: ------------- brlcad/trunk/src/libged/pnts.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2018-07-31 15:02:28 UTC (rev 71317) +++ brlcad/trunk/src/libged/CMakeLists.txt 2018-07-31 16:27:38 UTC (rev 71318) @@ -212,7 +212,7 @@ pmodel2view.c png.c png2fb.c - pnts.c + pnts.cpp polyclip.cpp prcolor.c prefix.c Deleted: brlcad/trunk/src/libged/pnts.c =================================================================== --- brlcad/trunk/src/libged/pnts.c 2018-07-31 15:02:28 UTC (rev 71317) +++ brlcad/trunk/src/libged/pnts.c 2018-07-31 16:27:38 UTC (rev 71318) @@ -1,503 +0,0 @@ -/* P N T S . C - * BRL-CAD - * - * Copyright (c) 2008-2018 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/pnts.c - * - * pnts command for simple Point Set (pnts) primitive operations. - * - */ - -/* TODO - merge make_pnts in with this... */ - -#include "common.h" - -#include <stdlib.h> -#include <ctype.h> -#include <string.h> - -#include "bu/opt.h" -#include "bu/sort.h" -#include "rt/geom.h" -#include "wdb.h" -#include "analyze.h" -#include "./ged_private.h" - - -HIDDEN void -_pnts_cmd_help(struct ged *gedp, const char *usage, struct bu_opt_desc *d) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - const char *option_help; - - bu_vls_sprintf(&str, "%s", usage); - - if ((option_help = bu_opt_describe(d, NULL))) { - bu_vls_printf(&str, "Options:\n%s\n", option_help); - bu_free((char *)option_help, "help str"); - } - - bu_vls_vlscat(gedp->ged_result_str, &str); - bu_vls_free(&str); -} - - -HIDDEN void -_pnt_to_tri(point_t *p, vect_t *n, struct rt_bot_internal *bot_ip, fastf_t scale, unsigned long pntcnt) -{ - fastf_t ty1 = 0.57735026918962573 * scale; /* tan(PI/6) */ - fastf_t ty2 = -0.28867513459481287 * scale; /* 0.5 * tan(PI/6) */ - fastf_t tx1 = 0.5 * scale; - point_t v1, v2, v3; - vect_t n1; - vect_t v1p, v2p, v3p = {0.0, 0.0, 0.0}; - vect_t v1f, v2f, v3f = {0.0, 0.0, 0.0}; - mat_t rot; - struct bn_tol btol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST, 1e-6, 1.0 - 1e-6 }; - - VSET(n1, 0, 0, 1); - VSET(v1, 0, ty1, 0); - VSET(v2, -1*tx1, ty2, 0); - VSET(v3, tx1, ty2, 0); - - VMOVE(v1p, v1); - VMOVE(v2p, v2); - VMOVE(v3p, v3); - bn_mat_fromto(rot, n1, *n, &btol); - MAT4X3VEC(v1f, rot, v1p); - MAT4X3VEC(v2f, rot, v2p); - MAT4X3VEC(v3f, rot, v3p); - VADD2(v1p, v1f, *p); - VADD2(v2p, v2f, *p); - VADD2(v3p, v3f, *p); - VMOVE(&bot_ip->vertices[pntcnt*3*3], v1p); - VMOVE(&bot_ip->vertices[pntcnt*3*3+3], v2p); - VMOVE(&bot_ip->vertices[pntcnt*3*3+6], v3p); - bot_ip->faces[pntcnt*3] = pntcnt*3; - bot_ip->faces[pntcnt*3+1] = pntcnt*3+1; - bot_ip->faces[pntcnt*3+2] = pntcnt*3+2; -} - -HIDDEN int -_pnts_to_bot(struct ged *gedp, int argc, const char **argv) -{ - int have_normals = 1; - unsigned long pntcnt = 0; - struct rt_db_internal intern, internal; - struct rt_bot_internal *bot_ip; - struct directory *pnt_dp; - struct directory *dp; - int print_help = 0; - int opt_ret = 0; - fastf_t scale; - struct rt_pnts_internal *pnts = NULL; - const char *pnt_prim= NULL; - const char *bot_name = NULL; - const char *usage = "Usage: pnts tri [options] <pnts> <output_bot>\n\n"; - struct bu_opt_desc d[3]; - BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); - BU_OPT(d[1], "s", "scale", "#", &bu_opt_fastf_t, &scale, "Specify scale factor to apply to unit triangle - will scale the triangle size, with the triangle centered on the original point."); - BU_OPT_NULL(d[2]); - - argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ - - /* must be wanting help */ - if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); - return GED_OK; - } - - /* parse standard options */ - opt_ret = bu_opt_parse(NULL, argc, argv, d); - - if (print_help) { - _pnts_cmd_help(gedp, usage, d); - return GED_OK; - } - - /* adjust argc to match the leftovers of the options parsing */ - argc = opt_ret; - - if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); - return GED_ERROR; - } - - pnt_prim = argv[0]; - bot_name = argv[1]; - - /* get pnt */ - GED_DB_LOOKUP(gedp, pnt_dp, pnt_prim, LOOKUP_NOISY, GED_ERROR & GED_QUIET); - GED_DB_GET_INTERNAL(gedp, &intern, pnt_dp, bn_mat_identity, &rt_uniresource, GED_ERROR); - - if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_PNTS) { - bu_vls_printf(gedp->ged_result_str, "pnts tri: %s is not a pnts object!", pnt_prim); - rt_db_free_internal(&intern); - return GED_ERROR; - } - - pnts = (struct rt_pnts_internal *)intern.idb_ptr; - RT_PNTS_CK_MAGIC(pnts); - - /* Sanity */ - if (!bot_name || !gedp) return GED_ERROR; - if (db_lookup(gedp->ged_wdbp->dbip, bot_name, LOOKUP_QUIET) != RT_DIR_NULL) { - bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", bot_name); - return GED_ERROR; - } - - /* For the moment, only generate BoTs when we have a normal to guide us. Eventually, - * we might add logic to find the avg center point and calculate normals radiating out - * from that center, but for now skip anything that doesn't provide normals up front. */ - if (pnts->type == RT_PNT_TYPE_PNT) have_normals = 0; - if (pnts->type == RT_PNT_TYPE_COL) have_normals = 0; - if (pnts->type == RT_PNT_TYPE_SCA) have_normals = 0; - if (pnts->type == RT_PNT_TYPE_COL_SCA) have_normals = 0; - if (!have_normals) { - bu_vls_sprintf(gedp->ged_result_str, "Error: point cloud data does not define normals\n"); - return GED_ERROR; - } - - /* initialize */ - bu_vls_trunc(gedp->ged_result_str, 0); - - if (NEAR_ZERO(scale, SMALL_FASTF)) { - switch (pnts->type) { - case RT_PNT_TYPE_SCA_NRM: - scale = pnts->scale; - break; - case RT_PNT_TYPE_COL_SCA_NRM: - scale = pnts->scale; - break; - default: - scale = 1.0; - break; - } - } - - /* Set up BoT container */ - RT_DB_INTERNAL_INIT(&internal); - internal.idb_major_type = DB5_MAJORTYPE_BRLCAD; - internal.idb_type = ID_BOT; - internal.idb_meth = &OBJ[ID_BOT]; - BU_ALLOC(bot_ip, struct rt_bot_internal); - internal.idb_ptr = (void *)bot_ip; - bot_ip = (struct rt_bot_internal *)internal.idb_ptr; - bot_ip->magic = RT_BOT_INTERNAL_MAGIC; - bot_ip->mode = RT_BOT_SURFACE; - bot_ip->orientation = 2; - - /* Allocate BoT memory */ - bot_ip->num_vertices = pnts->count * 3; - bot_ip->num_faces = pnts->count; - bot_ip->faces = (int *)bu_calloc(bot_ip->num_faces * 3 + 3, sizeof(int), "bot faces"); - bot_ip->vertices = (fastf_t *)bu_calloc(bot_ip->num_vertices * 3 + 3, sizeof(fastf_t), "bot vertices"); - bot_ip->thickness = (fastf_t *)NULL; - bot_ip->face_mode = (struct bu_bitv *)NULL; - - pntcnt = 0; - if (pnts->type == RT_PNT_TYPE_NRM) { - struct pnt_normal *pn = NULL; - struct pnt_normal *pl = (struct pnt_normal *)pnts->point; - for (BU_LIST_FOR(pn, pnt_normal, &(pl->l))) { - _pnt_to_tri(&(pn->v), &(pn->n), bot_ip, scale, pntcnt); - pntcnt++; - } - } - if (pnts->type == RT_PNT_TYPE_COL_NRM) { - struct pnt_color_normal *pcn = NULL; - struct pnt_color_normal *pl = (struct pnt_color_normal *)pnts->point; - for (BU_LIST_FOR(pcn, pnt_color_normal, &(pl->l))) { - _pnt_to_tri(&(pcn->v), &(pcn->n), bot_ip, scale, pntcnt); - pntcnt++; - } - } - if (pnts->type == RT_PNT_TYPE_SCA_NRM) { - struct pnt_scale_normal *psn = NULL; - struct pnt_scale_normal *pl = (struct pnt_scale_normal *)pnts->point; - for (BU_LIST_FOR(psn, pnt_scale_normal, &(pl->l))) { - _pnt_to_tri(&(psn->v), &(psn->n), bot_ip, scale, pntcnt); - pntcnt++; - } - } - if (pnts->type == RT_PNT_TYPE_COL_SCA_NRM) { - struct pnt_color_scale_normal *pcsn = NULL; - struct pnt_color_scale_normal *pl = (struct pnt_color_scale_normal *)pnts->point; - for (BU_LIST_FOR(pcsn, pnt_color_scale_normal, &(pl->l))) { - _pnt_to_tri(&(pcsn->v), &(pcsn->n), bot_ip, scale, pntcnt); - pntcnt++; - } - } - - GED_DB_DIRADD(gedp, dp, bot_name, RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR); - GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR); - - bu_vls_printf(gedp->ged_result_str, "Generated BoT object %s with %d triangles", bot_name, pntcnt); - - rt_db_free_internal(&intern); - return GED_OK; -} - -HIDDEN int -_obj_to_pnts(struct ged *gedp, int argc, const char **argv) -{ - struct directory *dp; - int print_help = 0; - int opt_ret = 0; - fastf_t len_tol = 0.0; - int pnt_mode = 0; - struct rt_db_internal internal; - struct bn_tol btol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST, 1e-6, 1.0 - 1e-6 }; - struct rt_pnts_internal *pnts = NULL; - const char *pnt_prim= NULL; - const char *obj_name = NULL; - const char *usage = "Usage: pnts gen [options] <obj> <output_pnts>\n\n"; - struct bu_opt_desc d[4]; - BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); - BU_OPT(d[1], "t", "tolerance", "#", &bu_opt_fastf_t, &len_tol, "Specify sampling grid spacing (in mm)."); - BU_OPT(d[2], "S", "surface", "", NULL, &pnt_mode, "Save only first and last points along ray."); - BU_OPT_NULL(d[3]); - - argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ - - /* must be wanting help */ - if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); - return GED_OK; - } - - /* parse standard options */ - opt_ret = bu_opt_parse(NULL, argc, argv, d); - - if (print_help) { - _pnts_cmd_help(gedp, usage, d); - return GED_OK; - } - - /* adjust argc to match the leftovers of the options parsing */ - argc = opt_ret; - - if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); - return GED_ERROR; - } - - obj_name = argv[0]; - pnt_prim = argv[1]; - - /* Sanity */ - if (db_lookup(gedp->ged_wdbp->dbip, obj_name, LOOKUP_QUIET) == RT_DIR_NULL) { - bu_vls_sprintf(gedp->ged_result_str, "Error: object %s doesn't exist!\n", obj_name); - return GED_ERROR; - } - if (db_lookup(gedp->ged_wdbp->dbip, pnt_prim, LOOKUP_QUIET) != RT_DIR_NULL) { - bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", pnt_prim); - return GED_ERROR; - } - - /* If we don't have a tolerance, try to guess something sane from the bbox */ - if (NEAR_ZERO(len_tol, RT_LEN_TOL)) { - point_t rpp_min, rpp_max; - point_t obj_min, obj_max; - VSETALL(rpp_min, INFINITY); - VSETALL(rpp_max, -INFINITY); - ged_get_obj_bounds(gedp, 1, (const char **)&obj_name, 0, obj_min, obj_max); - VMINMAX(rpp_min, rpp_max, (double *)obj_min); - VMINMAX(rpp_min, rpp_max, (double *)obj_max); - len_tol = DIST_PT_PT(rpp_max, rpp_min) * 0.01; - bu_log("Note - no tolerance specified, using %f\n", len_tol); - } - btol.dist = len_tol; - - RT_DB_INTERNAL_INIT(&internal); - internal.idb_major_type = DB5_MAJORTYPE_BRLCAD; - internal.idb_type = ID_PNTS; - internal.idb_meth = &OBJ[ID_PNTS]; - BU_ALLOC(internal.idb_ptr, struct rt_pnts_internal); - pnts = (struct rt_pnts_internal *) internal.idb_ptr; - pnts->magic = RT_PNTS_INTERNAL_MAGIC; - pnts->scale = 0.0; - pnts->type = RT_PNT_TYPE_NRM; - - if (analyze_obj_to_pnts(pnts, gedp->ged_wdbp->dbip, obj_name, &btol, pnt_mode)) { - bu_vls_sprintf(gedp->ged_result_str, "Error: point generation failed\n"); - return GED_ERROR; - } - - GED_DB_DIRADD(gedp, dp, pnt_prim, RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR); - GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR); - - bu_vls_printf(gedp->ged_result_str, "Generated pnts object %s with %d points", pnt_prim, pnts->count); - - return GED_OK; -} - -HIDDEN void -_pnts_show_help(struct ged *gedp, struct bu_opt_desc *d) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - const char *option_help; - - bu_vls_sprintf(&str, "Usage: pnts [options] [subcommand] [subcommand arguments]\n\n"); - - if ((option_help = bu_opt_describe(d, NULL))) { - bu_vls_printf(&str, "Options:\n%s\n", option_help); - bu_free((char *)option_help, "help str"); - } - bu_vls_printf(&str, "Subcommands:\n\n"); - bu_vls_printf(&str, " get [-p][-n][-t dist_tol] [-k px py pz] (pnt_ind|pnt_ind_min-pnt_ind_max) <pnts> [new_pnts_obj]\n"); - bu_vls_printf(&str, " - Get specific subset (1 or more) points from a point set and\n"); - bu_vls_printf(&str, " print information. (todo - document subcmd options...)\n\n"); - bu_vls_printf(&str, " read <pnts> input_file format units pnt_size\n"); - bu_vls_printf(&str, " - Read data from an input file into a pnts object\n\n"); - bu_vls_printf(&str, " gen [-t tol] <obj> <output_pnts>\n"); - bu_vls_printf(&str, " - Generate a point set from the object and store the set in a points object.\n"); - bu_vls_printf(&str, " Collects the first and last hit and normal for any given ray, generating\n"); - bu_vls_printf(&str, " an \"outer surface\" point set.\n\n"); - bu_vls_printf(&str, " tri [-s scale] <pnts> <output_bot>\n"); - bu_vls_printf(&str, " - Generate unit or scaled triangles for each pnt in a point set. If no normal\n"); - bu_vls_printf(&str, " information is present, use origin at avg of all set points to make normals.\n\n"); - bu_vls_printf(&str, " [TODO] chull <pnts> <output_bot>\n"); - bu_vls_printf(&str, " - Store the convex hull of the point set in <output_bot>.\n\n"); - bu_vls_printf(&str, " [TODO] generate [-f format] <obj> [new_pnts_obj]\n"); - bu_vls_printf(&str, " - Generate a point set from an existing database object (terminate using the stability of a volume calculation? -- might be merged with get...)\n"); - bu_vls_vlscat(gedp->ged_result_str, &str); - bu_vls_free(&str); -} - - -#if 0 -HIDDEN int -pnts_get(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) -{ - struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; - return GED_OK; -} - -HIDDEN int -pnts_add(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) -{ - struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; - return GED_OK; -} - -HIDDEN int -pnts_rm(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) -{ - struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; - return GED_OK; -} - -HIDDEN int -pnts_chull(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) -{ - struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; - return GED_OK; -} - -#endif - - -int -ged_pnts(struct ged *gedp, int argc, const char *argv[]) -{ - const char *cmd = argv[0]; - size_t len; - int i; - int print_help = 0; - int opt_ret = 0; - int opt_argc = argc; - struct bu_opt_desc d[2]; - const char * const pnt_subcommands[] = {"gen", "get", "read", "tri", NULL}; - const char * const *subcmd; - - BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); - BU_OPT_NULL(d[1]); - - 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); - - argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ - - /* must be wanting help */ - if (argc < 1) { - _pnts_show_help(gedp, d); - return GED_OK; - } - - /* See if we have any options to deal with. Once we hit a subcommand, we're done */ - for (i = 0; i < argc; ++i) { - subcmd = pnt_subcommands; - for (; *subcmd != NULL; ++subcmd) { - if (BU_STR_EQUAL(argv[i], *subcmd)) { - opt_argc = i; - i = argc; - break; - } - } - } - - if (opt_argc > 0) { - /* parse standard options */ - opt_ret = bu_opt_parse(NULL, opt_argc, argv, d); - if (opt_ret < 0) { - _pnts_show_help(gedp, d); - return GED_ERROR; - } - } - - if (print_help) { - _pnts_show_help(gedp, d); - return GED_OK; - } - - /* shift argv to subcommand */ - argc -= opt_argc; - argv = &argv[opt_argc]; - - /* If we don't have a subcommand, we're done */ - if (argc < 1) { - _pnts_show_help(gedp, d); - return GED_ERROR; - } - - len = strlen(argv[0]); - if (bu_strncmp(argv[0], "tri", len) == 0) return _pnts_to_bot(gedp, argc, argv); - - if (bu_strncmp(argv[0], "gen", len) == 0) return _obj_to_pnts(gedp, argc, argv); - - /* If we don't have a valid subcommand, we're done */ - bu_vls_printf(gedp->ged_result_str, "%s: %s is not a known subcommand!\n", cmd, argv[0]); - _pnts_show_help(gedp, d); - return GED_ERROR; -} - - -/* - * Local Variables: - * tab-width: 8 - * mode: C - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Copied: brlcad/trunk/src/libged/pnts.cpp (from rev 71317, brlcad/trunk/src/libged/pnts.c) =================================================================== --- brlcad/trunk/src/libged/pnts.cpp (rev 0) +++ brlcad/trunk/src/libged/pnts.cpp 2018-07-31 16:27:38 UTC (rev 71318) @@ -0,0 +1,503 @@ +/* P N T S . C + * BRL-CAD + * + * Copyright (c) 2008-2018 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/pnts.c + * + * pnts command for simple Point Set (pnts) primitive operations. + * + */ + +/* TODO - merge make_pnts in with this... */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "bu/opt.h" +#include "bu/sort.h" +#include "rt/geom.h" +#include "wdb.h" +#include "analyze.h" +#include "./ged_private.h" + + +HIDDEN void +_pnts_cmd_help(struct ged *gedp, const char *usage, struct bu_opt_desc *d) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + const char *option_help; + + bu_vls_sprintf(&str, "%s", usage); + + if ((option_help = bu_opt_describe(d, NULL))) { + bu_vls_printf(&str, "Options:\n%s\n", option_help); + bu_free((char *)option_help, "help str"); + } + + bu_vls_vlscat(gedp->ged_result_str, &str); + bu_vls_free(&str); +} + + +HIDDEN void +_pnt_to_tri(point_t *p, vect_t *n, struct rt_bot_internal *bot_ip, fastf_t scale, unsigned long pntcnt) +{ + fastf_t ty1 = 0.57735026918962573 * scale; /* tan(PI/6) */ + fastf_t ty2 = -0.28867513459481287 * scale; /* 0.5 * tan(PI/6) */ + fastf_t tx1 = 0.5 * scale; + point_t v1, v2, v3; + vect_t n1; + vect_t v1p, v2p, v3p = {0.0, 0.0, 0.0}; + vect_t v1f, v2f, v3f = {0.0, 0.0, 0.0}; + mat_t rot; + struct bn_tol btol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST, 1e-6, 1.0 - 1e-6 }; + + VSET(n1, 0, 0, 1); + VSET(v1, 0, ty1, 0); + VSET(v2, -1*tx1, ty2, 0); + VSET(v3, tx1, ty2, 0); + + VMOVE(v1p, v1); + VMOVE(v2p, v2); + VMOVE(v3p, v3); + bn_mat_fromto(rot, n1, *n, &btol); + MAT4X3VEC(v1f, rot, v1p); + MAT4X3VEC(v2f, rot, v2p); + MAT4X3VEC(v3f, rot, v3p); + VADD2(v1p, v1f, *p); + VADD2(v2p, v2f, *p); + VADD2(v3p, v3f, *p); + VMOVE(&bot_ip->vertices[pntcnt*3*3], v1p); + VMOVE(&bot_ip->vertices[pntcnt*3*3+3], v2p); + VMOVE(&bot_ip->vertices[pntcnt*3*3+6], v3p); + bot_ip->faces[pntcnt*3] = pntcnt*3; + bot_ip->faces[pntcnt*3+1] = pntcnt*3+1; + bot_ip->faces[pntcnt*3+2] = pntcnt*3+2; +} + +HIDDEN int +_pnts_to_bot(struct ged *gedp, int argc, const char **argv) +{ + int have_normals = 1; + unsigned long pntcnt = 0; + struct rt_db_internal intern, internal; + struct rt_bot_internal *bot_ip; + struct directory *pnt_dp; + struct directory *dp; + int print_help = 0; + int opt_ret = 0; + fastf_t scale; + struct rt_pnts_internal *pnts = NULL; + const char *pnt_prim= NULL; + const char *bot_name = NULL; + const char *usage = "Usage: pnts tri [options] <pnts> <output_bot>\n\n"; + struct bu_opt_desc d[3]; + BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); + BU_OPT(d[1], "s", "scale", "#", &bu_opt_fastf_t, &scale, "Specify scale factor to apply to unit triangle - will scale the triangle size, with the triangle centered on the original point."); + BU_OPT_NULL(d[2]); + + argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ + + /* must be wanting help */ + if (argc < 1) { + _pnts_cmd_help(gedp, usage, d); + return GED_OK; + } + + /* parse standard options */ + opt_ret = bu_opt_parse(NULL, argc, argv, d); + + if (print_help) { + _pnts_cmd_help(gedp, usage, d); + return GED_OK; + } + + /* adjust argc to match the leftovers of the options parsing */ + argc = opt_ret; + + if (argc != 2) { + _pnts_cmd_help(gedp, usage, d); + return GED_ERROR; + } + + pnt_prim = argv[0]; + bot_name = argv[1]; + + /* get pnt */ + GED_DB_LOOKUP(gedp, pnt_dp, pnt_prim, LOOKUP_NOISY, GED_ERROR & GED_QUIET); + GED_DB_GET_INTERNAL(gedp, &intern, pnt_dp, bn_mat_identity, &rt_uniresource, GED_ERROR); + + if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_PNTS) { + bu_vls_printf(gedp->ged_result_str, "pnts tri: %s is not a pnts object!", pnt_prim); + rt_db_free_internal(&intern); + return GED_ERROR; + } + + pnts = (struct rt_pnts_internal *)intern.idb_ptr; + RT_PNTS_CK_MAGIC(pnts); + + /* Sanity */ + if (!bot_name || !gedp) return GED_ERROR; + if (db_lookup(gedp->ged_wdbp->dbip, bot_name, LOOKUP_QUIET) != RT_DIR_NULL) { + bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", bot_name); + return GED_ERROR; + } + + /* For the moment, only generate BoTs when we have a normal to guide us. Eventually, + * we might add logic to find the avg center point and calculate normals radiating out + * from that center, but for now skip anything that doesn't provide normals up front. */ + if (pnts->type == RT_PNT_TYPE_PNT) have_normals = 0; + if (pnts->type == RT_PNT_TYPE_COL) have_normals = 0; + if (pnts->type == RT_PNT_TYPE_SCA) have_normals = 0; + if (pnts->type == RT_PNT_TYPE_COL_SCA) have_normals = 0; + if (!have_normals) { + bu_vls_sprintf(gedp->ged_result_str, "Error: point cloud data does not define normals\n"); + return GED_ERROR; + } + + /* initialize */ + bu_vls_trunc(gedp->ged_result_str, 0); + + if (NEAR_ZERO(scale, SMALL_FASTF)) { + switch (pnts->type) { + case RT_PNT_TYPE_SCA_NRM: + scale = pnts->scale; + break; + case RT_PNT_TYPE_COL_SCA_NRM: + scale = pnts->scale; + break; + default: + scale = 1.0; + break; + } + } + + /* Set up BoT container */ + RT_DB_INTERNAL_INIT(&internal); + internal.idb_major_type = DB5_MAJORTYPE_BRLCAD; + internal.idb_type = ID_BOT; + internal.idb_meth = &OBJ[ID_BOT]; + BU_ALLOC(bot_ip, struct rt_bot_internal); + internal.idb_ptr = (void *)bot_ip; + bot_ip = (struct rt_bot_internal *)internal.idb_ptr; + bot_ip->magic = RT_BOT_INTERNAL_MAGIC; + bot_ip->mode = RT_BOT_SURFACE; + bot_ip->orientation = 2; + + /* Allocate BoT memory */ + bot_ip->num_vertices = pnts->count * 3; + bot_ip->num_faces = pnts->count; + bot_ip->faces = (int *)bu_calloc(bot_ip->num_faces * 3 + 3, sizeof(int), "bot faces"); + bot_ip->vertices = (fastf_t *)bu_calloc(bot_ip->num_vertices * 3 + 3, sizeof(fastf_t), "bot vertices"); + bot_ip->thickness = (fastf_t *)NULL; + bot_ip->face_mode = (struct bu_bitv *)NULL; + + pntcnt = 0; + if (pnts->type == RT_PNT_TYPE_NRM) { + struct pnt_normal *pn = NULL; + struct pnt_normal *pl = (struct pnt_normal *)pnts->point; + for (BU_LIST_FOR(pn, pnt_normal, &(pl->l))) { + _pnt_to_tri(&(pn->v), &(pn->n), bot_ip, scale, pntcnt); + pntcnt++; + } + } + if (pnts->type == RT_PNT_TYPE_COL_NRM) { + struct pnt_color_normal *pcn = NULL; + struct pnt_color_normal *pl = (struct pnt_color_normal *)pnts->point; + for (BU_LIST_FOR(pcn, pnt_color_normal, &(pl->l))) { + _pnt_to_tri(&(pcn->v), &(pcn->n), bot_ip, scale, pntcnt); + pntcnt++; + } + } + if (pnts->type == RT_PNT_TYPE_SCA_NRM) { + struct pnt_scale_normal *psn = NULL; + struct pnt_scale_normal *pl = (struct pnt_scale_normal *)pnts->point; + for (BU_LIST_FOR(psn, pnt_scale_normal, &(pl->l))) { + _pnt_to_tri(&(psn->v), &(psn->n), bot_ip, scale, pntcnt); + pntcnt++; + } + } + if (pnts->type == RT_PNT_TYPE_COL_SCA_NRM) { + struct pnt_color_scale_normal *pcsn = NULL; + struct pnt_color_scale_normal *pl = (struct pnt_color_scale_normal *)pnts->point; + for (BU_LIST_FOR(pcsn, pnt_color_scale_normal, &(pl->l))) { + _pnt_to_tri(&(pcsn->v), &(pcsn->n), bot_ip, scale, pntcnt); + pntcnt++; + } + } + + GED_DB_DIRADD(gedp, dp, bot_name, RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR); + GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR); + + bu_vls_printf(gedp->ged_result_str, "Generated BoT object %s with %d triangles", bot_name, pntcnt); + + rt_db_free_internal(&intern); + return GED_OK; +} + +HIDDEN int +_obj_to_pnts(struct ged *gedp, int argc, const char **argv) +{ + struct directory *dp; + int print_help = 0; + int opt_ret = 0; + fastf_t len_tol = 0.0; + int pnt_mode = 0; + struct rt_db_internal internal; + struct bn_tol btol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST, 1e-6, 1.0 - 1e-6 }; + struct rt_pnts_internal *pnts = NULL; + const char *pnt_prim= NULL; + const char *obj_name = NULL; + const char *usage = "Usage: pnts gen [options] <obj> <output_pnts>\n\n"; + struct bu_opt_desc d[4]; + BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); + BU_OPT(d[1], "t", "tolerance", "#", &bu_opt_fastf_t, &len_tol, "Specify sampling grid spacing (in mm)."); + BU_OPT(d[2], "S", "surface", "", NULL, &pnt_mode, "Save only first and last points along ray."); + BU_OPT_NULL(d[3]); + + argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ + + /* must be wanting help */ + if (argc < 1) { + _pnts_cmd_help(gedp, usage, d); + return GED_OK; + } + + /* parse standard options */ + opt_ret = bu_opt_parse(NULL, argc, argv, d); + + if (print_help) { + _pnts_cmd_help(gedp, usage, d); + return GED_OK; + } + + /* adjust argc to match the leftovers of the options parsing */ + argc = opt_ret; + + if (argc != 2) { + _pnts_cmd_help(gedp, usage, d); + return GED_ERROR; + } + + obj_name = argv[0]; + pnt_prim = argv[1]; + + /* Sanity */ + if (db_lookup(gedp->ged_wdbp->dbip, obj_name, LOOKUP_QUIET) == RT_DIR_NULL) { + bu_vls_sprintf(gedp->ged_result_str, "Error: object %s doesn't exist!\n", obj_name); + return GED_ERROR; + } + if (db_lookup(gedp->ged_wdbp->dbip, pnt_prim, LOOKUP_QUIET) != RT_DIR_NULL) { + bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", pnt_prim); + return GED_ERROR; + } + + /* If we don't have a tolerance, try to guess something sane from the bbox */ + if (NEAR_ZERO(len_tol, RT_LEN_TOL)) { + point_t rpp_min, rpp_max; + point_t obj_min, obj_max; + VSETALL(rpp_min, INFINITY); + VSETALL(rpp_max, -INFINITY); + ged_get_obj_bounds(gedp, 1, (const char **)&obj_name, 0, obj_min, obj_max); + VMINMAX(rpp_min, rpp_max, (double *)obj_min); + VMINMAX(rpp_min, rpp_max, (double *)obj_max); + len_tol = DIST_PT_PT(rpp_max, rpp_min) * 0.01; + bu_log("Note - no tolerance specified, using %f\n", len_tol); + } + btol.dist = len_tol; + + RT_DB_INTERNAL_INIT(&internal); + internal.idb_major_type = DB5_MAJORTYPE_BRLCAD; + internal.idb_type = ID_PNTS; + internal.idb_meth = &OBJ[ID_PNTS]; + BU_ALLOC(internal.idb_ptr, struct rt_pnts_internal); + pnts = (struct rt_pnts_internal *) internal.idb_ptr; + pnts->magic = RT_PNTS_INTERNAL_MAGIC; + pnts->scale = 0.0; + pnts->type = RT_PNT_TYPE_NRM; + + if (analyze_obj_to_pnts(pnts, gedp->ged_wdbp->dbip, obj_name, &btol, pnt_mode)) { + bu_vls_sprintf(gedp->ged_result_str, "Error: point generation failed\n"); + return GED_ERROR; + } + + GED_DB_DIRADD(gedp, dp, pnt_prim, RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR); + GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR); + + bu_vls_printf(gedp->ged_result_str, "Generated pnts object %s with %d points", pnt_prim, pnts->count); + + return GED_OK; +} + +HIDDEN void +_pnts_show_help(struct ged *gedp, struct bu_opt_desc *d) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + const char *option_help; + + bu_vls_sprintf(&str, "Usage: pnts [options] [subcommand] [subcommand arguments]\n\n"); + + if ((option_help = bu_opt_describe(d, NULL))) { + bu_vls_printf(&str, "Options:\n%s\n", option_help); + bu_free((char *)option_help, "help str"); + } + bu_vls_printf(&str, "Subcommands:\n\n"); + bu_vls_printf(&str, " get [-p][-n][-t dist_tol] [-k px py pz] (pnt_ind|pnt_ind_min-pnt_ind_max) <pnts> [new_pnts_obj]\n"); + bu_vls_printf(&str, " - Get specific subset (1 or more) points from a point set and\n"); + bu_vls_printf(&str, " print information. (todo - document subcmd options...)\n\n"); + bu_vls_printf(&str, " read <pnts> input_file format units pnt_size\n"); + bu_vls_printf(&str, " - Read data from an input file into a pnts object\n\n"); + bu_vls_printf(&str, " gen [-t tol] <obj> <output_pnts>\n"); + bu_vls_printf(&str, " - Generate a point set from the object and store the set in a points object.\n"); + bu_vls_printf(&str, " Collects the first and last hit and normal for any given ray, generating\n"); + bu_vls_printf(&str, " an \"outer surface\" point set.\n\n"); + bu_vls_printf(&str, " tri [-s scale] <pnts> <output_bot>\n"); + bu_vls_printf(&str, " - Generate unit or scaled triangles for each pnt in a point set. If no normal\n"); + bu_vls_printf(&str, " information is present, use origin at avg of all set points to make normals.\n\n"); + bu_vls_printf(&str, " [TODO] chull <pnts> <output_bot>\n"); + bu_vls_printf(&str, " - Store the convex hull of the point set in <output_bot>.\n\n"); + bu_vls_printf(&str, " [TODO] generate [-f format] <obj> [new_pnts_obj]\n"); + bu_vls_printf(&str, " - Generate a point set from an existing database object (terminate using the stability of a volume calculation? -- might be merged with get...)\n"); + bu_vls_vlscat(gedp->ged_result_str, &str); + bu_vls_free(&str); +} + + +#if 0 +HIDDEN int +pnts_get(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) +{ + struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; + return GED_OK; +} + +HIDDEN int +pnts_add(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) +{ + struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; + return GED_OK; +} + +HIDDEN int +pnts_rm(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) +{ + struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; + return GED_OK; +} + +HIDDEN int +pnts_chull(struct ged *gedp, int argc, const char *argv[], struct bu_opt_desc *d, struct rt_db_internal *ip) +{ + struct rt_pnts_internal *pnts = (struct rt_pnts_internal *)ip->idb_ptr; + return GED_OK; +} + +#endif + + +int +ged_pnts(struct ged *gedp, int argc, const char *argv[]) +{ + const char *cmd = argv[0]; + size_t len; + int i; + int print_help = 0; + int opt_ret = 0; + int opt_argc = argc; + struct bu_opt_desc d[2]; + const char * const pnt_subcommands[] = {"gen", "get", "read", "tri", NULL}; + const char * const *subcmd; + + BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); + BU_OPT_NULL(d[1]); + + 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); + + argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */ + + /* must be wanting help */ + if (argc < 1) { + _pnts_show_help(gedp, d); + return GED_OK; + } + + /* See if we have any options to deal with. Once we hit a subcommand, we're done */ + for (i = 0; i < argc; ++i) { + subcmd = pnt_subcommands; + for (; *subcmd != NULL; ++subcmd) { + if (BU_STR_EQUAL(argv[i], *subcmd)) { + opt_argc = i; + i = argc; + break; + } + } + } + + if (opt_argc > 0) { + /* parse standard options */ + opt_ret = bu_opt_parse(NULL, opt_argc, argv, d); + if (opt_ret < 0) { + _pnts_show_help(gedp, d); + return GED_ERROR; + } + } + + if (print_help) { + _pnts_show_help(gedp, d); + return GED_OK; + } + + /* shift argv to subcommand */ + argc -= opt_argc; + argv = &argv[opt_argc]; + + /* If we don't have a subcommand, we're done */ + if (argc < 1) { + _pnts_show_help(gedp, d); + return GED_ERROR; + } + + len = strlen(argv[0]); + if (bu_strncmp(argv[0], "tri", len) == 0) return _pnts_to_bot(gedp, argc, argv); + + if (bu_strncmp(argv[0], "gen", len) == 0) return _obj_to_pnts(gedp, argc, argv); + + /* If we don't have a valid subcommand, we're done */ + bu_vls_printf(gedp->ged_result_str, "%s: %s is not a known subcommand!\n", cmd, argv[0]); + _pnts_show_help(gedp, d); + return GED_ERROR; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-08-01 13:37:06
|
Revision: 71334 http://sourceforge.net/p/brlcad/code/71334 Author: starseeker Date: 2018-08-01 13:37:01 +0000 (Wed, 01 Aug 2018) Log Message: ----------- Move helper routines to their own file Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/ged_private.h brlcad/trunk/src/libged/ged_util.c brlcad/trunk/src/libged/pnts.cpp Added Paths: ----------- brlcad/trunk/src/libged/pnts_util.c brlcad/trunk/src/libged/pnts_util.h Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2018-08-01 00:43:27 UTC (rev 71333) +++ brlcad/trunk/src/libged/CMakeLists.txt 2018-08-01 13:37:01 UTC (rev 71334) @@ -212,6 +212,7 @@ pmodel2view.c png.c png2fb.c + pnts_util.c pnts.cpp polyclip.cpp prcolor.c @@ -376,6 +377,7 @@ set(ged_ignore_files TODO + pnts_util.h ged_private.h check/check_private.h joint.h Modified: brlcad/trunk/src/libged/ged_private.h =================================================================== --- brlcad/trunk/src/libged/ged_private.h 2018-08-01 00:43:27 UTC (rev 71333) +++ brlcad/trunk/src/libged/ged_private.h 2018-08-01 13:37:01 UTC (rev 71334) @@ -30,6 +30,7 @@ #include <time.h> +#include "bu/opt.h" #include "rt/db4.h" #include "raytrace.h" #include "rt/geom.h" @@ -526,19 +527,19 @@ extern int _ged_brep_tikz(struct ged *gedp, const char *obj_name, const char *outfile); -/* defined in ged_util.c.c */ +/* defined in ged_util.c */ /** * Given two pointers to pointers to directory entries, do a string * compare on the respective names and return that value. */ -int cmpdirname(const void *a, const void *b, void *arg); +extern int cmpdirname(const void *a, const void *b, void *arg); /** * Given two pointers to pointers to directory entries, compare * the dp->d_len sizes. */ -int cmpdlen(const void *a, const void *b, void *arg); +extern int cmpdlen(const void *a, const void *b, void *arg); /** @@ -561,8 +562,11 @@ extern struct directory ** _ged_getspace(struct db_i *dbip, size_t num_entries); +/** + * Routine for generic command help printing. + */ +extern void _ged_cmd_help(struct ged *gedp, const char *usage, struct bu_opt_desc *d); - __END_DECLS #endif /* LIBGED_GED_PRIVATE_H */ Modified: brlcad/trunk/src/libged/ged_util.c =================================================================== --- brlcad/trunk/src/libged/ged_util.c 2018-08-01 00:43:27 UTC (rev 71333) +++ brlcad/trunk/src/libged/ged_util.c 2018-08-01 13:37:01 UTC (rev 71334) @@ -258,7 +258,24 @@ } +void +_ged_cmd_help(struct ged *gedp, const char *usage, struct bu_opt_desc *d) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + const char *option_help; + bu_vls_sprintf(&str, "%s", usage); + + if ((option_help = bu_opt_describe(d, NULL))) { + bu_vls_printf(&str, "Options:\n%s\n", option_help); + bu_free((char *)option_help, "help str"); + } + + bu_vls_vlscat(gedp->ged_result_str, &str); + bu_vls_free(&str); +} + + /* * Local Variables: * mode: C Modified: brlcad/trunk/src/libged/pnts.cpp =================================================================== --- brlcad/trunk/src/libged/pnts.cpp 2018-08-01 00:43:27 UTC (rev 71333) +++ brlcad/trunk/src/libged/pnts.cpp 2018-08-01 13:37:01 UTC (rev 71334) @@ -27,9 +27,11 @@ #include "common.h" +extern "C" { #include <stdlib.h> #include <ctype.h> #include <string.h> +} #include <string> #include <sstream> @@ -36,6 +38,7 @@ #include <iomanip> #include <limits> +extern "C" { #include "bu/color.h" #include "bu/opt.h" #include "bu/sort.h" @@ -44,207 +47,10 @@ #include "wdb.h" #include "analyze.h" #include "./ged_private.h" - -#define PNT_V_IN(_pt, _key, _v) \ - switch (_key) { \ - case 'x': \ - ((struct _pt *)point)->v[X] = _v; \ - break; \ - case 'y': \ - ((struct _pt *)point)->v[Y] = _v; \ - break; \ - case 'z': \ - ((struct _pt *)point)->v[Z] = _v; \ - break; \ - } - -#define PNT_C_IN(_pt, _key, _v) \ - switch (_key) { \ - case 'r': \ - ((struct _pt *)point)->c.buc_rgb[0] = _v; \ - break; \ - case 'g': \ - ((struct _pt *)point)->c.buc_rgb[1] = _v; \ - break; \ - case 'b': \ - ((struct _pt *)point)->c.buc_rgb[2] = _v; \ - break; \ - } - -#define PNT_S_IN(_pt, _key, _v) \ - switch (_key) { \ - case 's': \ - ((struct _pt *)point)->s = _v; \ - break; \ - } - -#define PNT_N_IN(_pt, _key, _v) \ - switch (_key) { \ - case 'i': \ - ((struct _pt *)point)->n[X] = _v; \ - break; \ - case 'j': \ - ((struct _pt *)point)->n[Y] = _v; \ - break; \ - case 'k': \ - ((struct _pt *)point)->n[Z] = _v; \ - break; \ - } - -HIDDEN const char * -_pnt_default_fmt_str(rt_pnt_type type) { - static const char *pntfmt = "xyz"; - static const char *colfmt = "xyzrgb"; - static const char *scafmt = "xyzs"; - static const char *nrmfmt = "xyzijk"; - static const char *colscafmt = "xyzsrgb"; - static const char *colnrmfmt = "xyzijkrgb"; - static const char *scanrmfmt = "xyzijks"; - static const char *colscanrmfmt = "xyzijksrgb"; - - switch (type) { - case RT_PNT_TYPE_PNT: - return pntfmt; - break; - case RT_PNT_TYPE_COL: - return colfmt; - break; - case RT_PNT_TYPE_SCA: - return scafmt; - break; - case RT_PNT_TYPE_NRM: - return nrmfmt; - break; - case RT_PNT_TYPE_COL_SCA: - return colscafmt; - break; - case RT_PNT_TYPE_COL_NRM: - return colnrmfmt; - break; - case RT_PNT_TYPE_SCA_NRM: - return scanrmfmt; - break; - case RT_PNT_TYPE_COL_SCA_NRM: - return colscanrmfmt; - break; - default: - return NULL; - break; - } +#include "./pnts_util.h" } -void -pnt_v_set(void *point, rt_pnt_type type, char key, fastf_t val) { - switch (type) { - case RT_PNT_TYPE_PNT: - PNT_V_IN(pnt, key, val); - break; - case RT_PNT_TYPE_COL: - PNT_V_IN(pnt_color, key, val); - break; - case RT_PNT_TYPE_SCA: - PNT_V_IN(pnt_scale, key, val); - break; - case RT_PNT_TYPE_NRM: - PNT_V_IN(pnt_normal, key, val); - break; - case RT_PNT_TYPE_COL_SCA: - PNT_V_IN(pnt_color_scale, key, val); - break; - case RT_PNT_TYPE_COL_NRM: - PNT_V_IN(pnt_color_normal, key, val); - break; - case RT_PNT_TYPE_SCA_NRM: - PNT_V_IN(pnt_scale_normal, key, val); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - PNT_V_IN(pnt_color_scale_normal, key, val); - break; - default: - break; - } -} - -void -pnt_c_set(void *point, rt_pnt_type type, char key, fastf_t val) { - switch (type) { - case RT_PNT_TYPE_COL: - PNT_C_IN(pnt_color, key, val); - break; - case RT_PNT_TYPE_COL_SCA: - PNT_C_IN(pnt_color_scale, key, val); - break; - case RT_PNT_TYPE_COL_NRM: - PNT_C_IN(pnt_color_normal, key, val); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - PNT_C_IN(pnt_color_scale_normal, key, val); - break; - default: - break; - } -} - -void -pnt_s_set(void *point, rt_pnt_type type, char key, fastf_t val) { - switch (type) { - case RT_PNT_TYPE_SCA: - PNT_S_IN(pnt_scale, key, val); - break; - case RT_PNT_TYPE_COL_SCA: - PNT_S_IN(pnt_color_scale, key, val); - break; - case RT_PNT_TYPE_SCA_NRM: - PNT_S_IN(pnt_scale_normal, key, val); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - PNT_S_IN(pnt_color_scale_normal, key, val); - break; - default: - break; - } -} - -void -pnt_n_set(void *point, rt_pnt_type type, char key, fastf_t val) { - switch (type) { - case RT_PNT_TYPE_NRM: - PNT_N_IN(pnt_normal, key, val); - break; - case RT_PNT_TYPE_COL_NRM: - PNT_N_IN(pnt_color_normal, key, val); - break; - case RT_PNT_TYPE_SCA_NRM: - PNT_N_IN(pnt_scale_normal, key, val); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - PNT_N_IN(pnt_color_scale_normal, key, val); - break; - default: - break; - } -} - - HIDDEN void -_pnts_cmd_help(struct ged *gedp, const char *usage, struct bu_opt_desc *d) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - const char *option_help; - - bu_vls_sprintf(&str, "%s", usage); - - if ((option_help = bu_opt_describe(d, NULL))) { - bu_vls_printf(&str, "Options:\n%s\n", option_help); - bu_free((char *)option_help, "help str"); - } - - bu_vls_vlscat(gedp->ged_result_str, &str); - bu_vls_free(&str); -} - - -HIDDEN void _pnt_to_tri(point_t *p, vect_t *n, struct rt_bot_internal *bot_ip, fastf_t scale, unsigned long pntcnt) { fastf_t ty1 = 0.57735026918962573 * scale; /* tan(PI/6) */ @@ -317,7 +123,7 @@ /* must be wanting help */ if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -325,7 +131,7 @@ opt_ret = bu_opt_parse(NULL, argc, argv, d); if (print_help) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -333,7 +139,7 @@ argc = opt_ret; if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_ERROR; } @@ -476,7 +282,7 @@ /* must be wanting help */ if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -484,7 +290,7 @@ opt_ret = bu_opt_parse(NULL, argc, argv, d); if (print_help) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -492,7 +298,7 @@ argc = opt_ret; if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_ERROR; } @@ -546,190 +352,12 @@ return GED_OK; } -rt_pnt_type -_pnts_fmt_type(struct bu_vls *f) -{ - int has_pnt = 0; - int has_nrm = 0; - int has_s = 0; - int has_c = 0; - const char *fc = bu_vls_addr(f); - - if (!f || !bu_vls_strlen(f)) return RT_PNT_UNKNOWN; - if (strchr(fc, 'x') && strchr(fc, 'y') && strchr(fc, 'z')) has_pnt = 1; - if (strchr(fc, 'i') && strchr(fc, 'j') && strchr(fc, 'k')) has_nrm = 1; - if (strchr(fc, 's')) has_s = 1; - if (strchr(fc, 'r') && strchr(fc, 'g') && strchr(fc, 'b')) has_c = 1; - - if (has_pnt && has_nrm && has_s && has_c) return RT_PNT_TYPE_COL_SCA_NRM; - if (has_pnt && has_nrm && has_s) return RT_PNT_TYPE_SCA_NRM; - if (has_pnt && has_nrm && has_c) return RT_PNT_TYPE_COL_NRM; - if (has_pnt && has_nrm) return RT_PNT_TYPE_NRM; - if (has_pnt && has_s && has_c) return RT_PNT_TYPE_COL_SCA; - if (has_pnt && has_s) return RT_PNT_TYPE_SCA; - if (has_pnt && has_c) return RT_PNT_TYPE_SCA; - if (has_pnt) return RT_PNT_TYPE_PNT; - - return RT_PNT_UNKNOWN; -} - -rt_pnt_type -_pnts_fmt_guess(int numcnt) { - switch (numcnt) { - case 3: - return RT_PNT_TYPE_PNT; - break; - case 4: - return RT_PNT_TYPE_SCA; - break; - case 6: - bu_log("Warning - found 6 numbers, which is ambiguous - assuming RT_PNT_TYPE_NRM. To read in as RT_PNT_TYPE_COL, specify the format string \"xyzrgb\"\n"); - return RT_PNT_TYPE_NRM; - break; - case 7: - bu_log("Warning - found 7 numbers, which is ambiguous - assuming RT_PNT_TYPE_COL_SCA. To read in as RT_PNT_TYPE_SCA_NRM, specify the format string \"xyzijks\"\n"); - return RT_PNT_TYPE_COL_SCA; - break; - case 9: - return RT_PNT_TYPE_COL_NRM; - break; - case 10: - return RT_PNT_TYPE_COL_SCA_NRM; - break; - default: - return RT_PNT_UNKNOWN; - break; - } -} - int -_pnts_fmt_match(rt_pnt_type t, int numcnt) -{ - if (t == RT_PNT_UNKNOWN || numcnt < 3 || numcnt > 10) return 0; - - if (numcnt == 3 && t == RT_PNT_TYPE_PNT) return 1; - if (numcnt == 4 && t == RT_PNT_TYPE_SCA) return 1; - if (numcnt == 6 && t == RT_PNT_TYPE_NRM) return 1; - if (numcnt == 6 && t == RT_PNT_TYPE_COL) return 1; - if (numcnt == 7 && t == RT_PNT_TYPE_COL_SCA) return 1; - if (numcnt == 7 && t == RT_PNT_TYPE_SCA_NRM) return 1; - if (numcnt == 9 && t == RT_PNT_TYPE_COL_NRM) return 1; - if (numcnt == 10 && t == RT_PNT_TYPE_COL_SCA_NRM) return 1; - - return 0; -} - -void -_pnts_init_head_pnt(struct rt_pnts_internal *pnts) -{ - if (!pnts) return; - switch (pnts->type) { - case RT_PNT_TYPE_PNT: - BU_LIST_INIT(&(((struct pnt *)pnts->point)->l)); - break; - case RT_PNT_TYPE_COL: - BU_LIST_INIT(&(((struct pnt_color *)pnts->point)->l)); - break; - case RT_PNT_TYPE_SCA: - BU_LIST_INIT(&(((struct pnt_scale *)pnts->point)->l)); - break; - case RT_PNT_TYPE_NRM: - BU_LIST_INIT(&(((struct pnt_normal *)pnts->point)->l)); - break; - case RT_PNT_TYPE_COL_SCA: - BU_LIST_INIT(&(((struct pnt_color_scale *)pnts->point)->l)); - break; - case RT_PNT_TYPE_COL_NRM: - BU_LIST_INIT(&(((struct pnt_color_normal *)pnts->point)->l)); - break; - case RT_PNT_TYPE_SCA_NRM: - BU_LIST_INIT(&(((struct pnt_scale_normal *)pnts->point)->l)); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_LIST_INIT(&(((struct pnt_color_scale_normal *)pnts->point)->l)); - break; - default: - break; - } -} - - -void * -_pnts_new_pnt(rt_pnt_type t) -{ - void *point = NULL; - if (t == RT_PNT_UNKNOWN) return NULL; - switch (t) { - case RT_PNT_TYPE_PNT: - BU_ALLOC(point, struct pnt); - break; - case RT_PNT_TYPE_COL: - BU_ALLOC(point, struct pnt_color); - break; - case RT_PNT_TYPE_SCA: - BU_ALLOC(point, struct pnt_scale); - break; - case RT_PNT_TYPE_NRM: - BU_ALLOC(point, struct pnt_normal); - break; - case RT_PNT_TYPE_COL_SCA: - BU_ALLOC(point, struct pnt_color_scale); - break; - case RT_PNT_TYPE_COL_NRM: - BU_ALLOC(point, struct pnt_color_normal); - break; - case RT_PNT_TYPE_SCA_NRM: - BU_ALLOC(point, struct pnt_scale_normal); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_ALLOC(point, struct pnt_color_scale_normal); - break; - default: - break; - } - return point; -} - -void -_pnts_add(struct rt_pnts_internal *pnts, void *point) -{ - switch (pnts->type) { - case RT_PNT_TYPE_PNT: - BU_LIST_PUSH(&(((struct pnt *)pnts->point)->l), &((struct pnt *)point)->l); - break; - case RT_PNT_TYPE_COL: - BU_LIST_PUSH(&(((struct pnt_color *)pnts->point)->l), &((struct pnt_color *)point)->l); - break; - case RT_PNT_TYPE_SCA: - BU_LIST_PUSH(&(((struct pnt_scale *)pnts->point)->l), &((struct pnt_scale *)point)->l); - break; - case RT_PNT_TYPE_NRM: - BU_LIST_PUSH(&(((struct pnt_normal *)pnts->point)->l), &((struct pnt_normal *)point)->l); - break; - case RT_PNT_TYPE_COL_SCA: - BU_LIST_PUSH(&(((struct pnt_color_scale *)pnts->point)->l), &((struct pnt_color_scale *)point)->l); - break; - case RT_PNT_TYPE_COL_NRM: - BU_LIST_PUSH(&(((struct pnt_color_normal *)pnts->point)->l), &((struct pnt_color_normal *)point)->l); - break; - case RT_PNT_TYPE_SCA_NRM: - BU_LIST_PUSH(&(((struct pnt_scale_normal *)pnts->point)->l), &((struct pnt_scale_normal *)point)->l); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_LIST_PUSH(&(((struct pnt_color_scale_normal *)pnts->point)->l), &((struct pnt_color_scale_normal *)point)->l); - break; - default: - break; - } -} - - -int _pnt_read(struct rt_pnts_internal *pnts, int numcnt, const char **nums, const char *fmt, fastf_t conv_factor) { int i = 0; char fc = '\0'; - void *point = _pnts_new_pnt(pnts->type); + void *point = _ged_pnts_new_pnt(pnts->type); for (i = 0; i < numcnt; i++) { fastf_t val; fc = fmt[i]; @@ -738,24 +366,24 @@ return GED_ERROR; } if ((fc == 'x') || (fc == 'y') || (fc == 'z')) { - pnt_v_set(point, pnts->type, fc, val * conv_factor); + _ged_pnt_v_set(point, pnts->type, fc, val * conv_factor); continue; } if ((fc == 'i') || (fc == 'j') || (fc == 'k')) { - pnt_n_set(point, pnts->type, fc, val * conv_factor); + _ged_pnt_n_set(point, pnts->type, fc, val * conv_factor); continue; } if ((fc == 'r') || (fc == 'g') || (fc == 'b')) { - pnt_c_set(point, pnts->type, fc, val); + _ged_pnt_c_set(point, pnts->type, fc, val); continue; } if ((fc == 's')) { - pnt_s_set(point, pnts->type, fc, val); + _ged_pnt_s_set(point, pnts->type, fc, val); continue; } } - _pnts_add(pnts, point); + _ged_pnts_add(pnts, point); return GED_OK; } @@ -791,7 +419,7 @@ /* must be wanting help */ if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -799,7 +427,7 @@ opt_ret = bu_opt_parse(NULL, argc, argv, d); if (print_help) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -807,7 +435,7 @@ argc = opt_ret; if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_ERROR; } @@ -857,10 +485,10 @@ pnts = (struct rt_pnts_internal *) internal.idb_ptr; pnts->magic = RT_PNTS_INTERNAL_MAGIC; pnts->scale = 0.0; - pnts->type = _pnts_fmt_type(&fmt); + pnts->type = _ged_pnts_fmt_type(bu_vls_addr(&fmt)); if (pnts->type != RT_PNT_UNKNOWN) { - pnts->point = _pnts_new_pnt(pnts->type); - _pnts_init_head_pnt(pnts); + pnts->point = _ged_pnts_new_pnt(pnts->type); + _ged_pnts_init_head_pnt(pnts); } while (!(bu_vls_gets(&fl, fp) < 0)) { @@ -884,18 +512,18 @@ if (pnts->type == RT_PNT_UNKNOWN) { /* If we dont' have a specified format, try to guess */ - bu_log("Warning - no point format specified, trying to deduce format from input according to the template xyz[ijk][s][rgb]\n"); - pnts->type = _pnts_fmt_guess(numcnt); + bu_log("Warning - no point format specified, trying to match template xyz[ijk][s][rgb]\n"); + pnts->type = _ged_pnts_fmt_guess(numcnt); if (pnts->type != RT_PNT_UNKNOWN) { - pnts->point = _pnts_new_pnt(pnts->type); - _pnts_init_head_pnt(pnts); - bu_vls_sprintf(&fmt, "%s", _pnt_default_fmt_str(pnts->type)); + pnts->point = _ged_pnts_new_pnt(pnts->type); + _ged_pnts_init_head_pnt(pnts); + bu_vls_sprintf(&fmt, "%s", _ged_pnt_default_fmt_str(pnts->type)); bu_log("Assuming format %s\n", bu_vls_addr(&fmt)); } } /* Validate numcnt against type */ - if (!_pnts_fmt_match(pnts->type, numcnt)) { + if (!_ged_pnts_fmt_match(pnts->type, numcnt)) { if (pnts->type == RT_PNT_UNKNOWN) { bu_vls_sprintf(gedp->ged_result_str, "Error: could not determine point type, aborting\n"); } else { @@ -952,7 +580,7 @@ /* must be wanting help */ if (argc < 1) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -960,7 +588,7 @@ opt_ret = bu_opt_parse(NULL, argc, argv, d); if (print_help) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_OK; } @@ -968,7 +596,7 @@ argc = opt_ret; if (argc != 2) { - _pnts_cmd_help(gedp, usage, d); + _ged_cmd_help(gedp, usage, d); return GED_ERROR; } Added: brlcad/trunk/src/libged/pnts_util.c =================================================================== --- brlcad/trunk/src/libged/pnts_util.c (rev 0) +++ brlcad/trunk/src/libged/pnts_util.c 2018-08-01 13:37:01 UTC (rev 71334) @@ -0,0 +1,403 @@ +/* P N T S _ U T I L. C + * BRL-CAD + * + * Copyright (c) 2008-2018 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/pnts_util.c + * + * utility functionality for simple Point Set (pnts) primitive operations. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "bu/color.h" +#include "rt/geom.h" +#include "./ged_private.h" +#include "./pnts_util.h" + +#define PNT_V_IN(_pt, _key, _v) \ + switch (_key) { \ + case 'x': \ + ((struct _pt *)point)->v[X] = _v; \ + break; \ + case 'y': \ + ((struct _pt *)point)->v[Y] = _v; \ + break; \ + case 'z': \ + ((struct _pt *)point)->v[Z] = _v; \ + break; \ + } + +#define PNT_C_IN(_pt, _key, _v) \ + switch (_key) { \ + case 'r': \ + ((struct _pt *)point)->c.buc_rgb[0] = _v; \ + break; \ + case 'g': \ + ((struct _pt *)point)->c.buc_rgb[1] = _v; \ + break; \ + case 'b': \ + ((struct _pt *)point)->c.buc_rgb[2] = _v; \ + break; \ + } + +#define PNT_S_IN(_pt, _key, _v) \ + switch (_key) { \ + case 's': \ + ((struct _pt *)point)->s = _v; \ + break; \ + } + +#define PNT_N_IN(_pt, _key, _v) \ + switch (_key) { \ + case 'i': \ + ((struct _pt *)point)->n[X] = _v; \ + break; \ + case 'j': \ + ((struct _pt *)point)->n[Y] = _v; \ + break; \ + case 'k': \ + ((struct _pt *)point)->n[Z] = _v; \ + break; \ + } + + +const char * +_ged_pnt_default_fmt_str(rt_pnt_type type) { + static const char *pntfmt = "xyz"; + static const char *colfmt = "xyzrgb"; + static const char *scafmt = "xyzs"; + static const char *nrmfmt = "xyzijk"; + static const char *colscafmt = "xyzsrgb"; + static const char *colnrmfmt = "xyzijkrgb"; + static const char *scanrmfmt = "xyzijks"; + static const char *colscanrmfmt = "xyzijksrgb"; + + switch (type) { + case RT_PNT_TYPE_PNT: + return pntfmt; + break; + case RT_PNT_TYPE_COL: + return colfmt; + break; + case RT_PNT_TYPE_SCA: + return scafmt; + break; + case RT_PNT_TYPE_NRM: + return nrmfmt; + break; + case RT_PNT_TYPE_COL_SCA: + return colscafmt; + break; + case RT_PNT_TYPE_COL_NRM: + return colnrmfmt; + break; + case RT_PNT_TYPE_SCA_NRM: + return scanrmfmt; + break; + case RT_PNT_TYPE_COL_SCA_NRM: + return colscanrmfmt; + break; + default: + return NULL; + break; + } +} + +void +_ged_pnt_v_set(void *point, rt_pnt_type type, char key, fastf_t val) { + switch (type) { + case RT_PNT_TYPE_PNT: + PNT_V_IN(pnt, key, val); + break; + case RT_PNT_TYPE_COL: + PNT_V_IN(pnt_color, key, val); + break; + case RT_PNT_TYPE_SCA: + PNT_V_IN(pnt_scale, key, val); + break; + case RT_PNT_TYPE_NRM: + PNT_V_IN(pnt_normal, key, val); + break; + case RT_PNT_TYPE_COL_SCA: + PNT_V_IN(pnt_color_scale, key, val); + break; + case RT_PNT_TYPE_COL_NRM: + PNT_V_IN(pnt_color_normal, key, val); + break; + case RT_PNT_TYPE_SCA_NRM: + PNT_V_IN(pnt_scale_normal, key, val); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + PNT_V_IN(pnt_color_scale_normal, key, val); + break; + default: + break; + } +} + +void +_ged_pnt_c_set(void *point, rt_pnt_type type, char key, fastf_t val) { + switch (type) { + case RT_PNT_TYPE_COL: + PNT_C_IN(pnt_color, key, val); + break; + case RT_PNT_TYPE_COL_SCA: + PNT_C_IN(pnt_color_scale, key, val); + break; + case RT_PNT_TYPE_COL_NRM: + PNT_C_IN(pnt_color_normal, key, val); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + PNT_C_IN(pnt_color_scale_normal, key, val); + break; + default: + break; + } +} + +void +_ged_pnt_s_set(void *point, rt_pnt_type type, char key, fastf_t val) { + switch (type) { + case RT_PNT_TYPE_SCA: + PNT_S_IN(pnt_scale, key, val); + break; + case RT_PNT_TYPE_COL_SCA: + PNT_S_IN(pnt_color_scale, key, val); + break; + case RT_PNT_TYPE_SCA_NRM: + PNT_S_IN(pnt_scale_normal, key, val); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + PNT_S_IN(pnt_color_scale_normal, key, val); + break; + default: + break; + } +} + +void +_ged_pnt_n_set(void *point, rt_pnt_type type, char key, fastf_t val) { + switch (type) { + case RT_PNT_TYPE_NRM: + PNT_N_IN(pnt_normal, key, val); + break; + case RT_PNT_TYPE_COL_NRM: + PNT_N_IN(pnt_color_normal, key, val); + break; + case RT_PNT_TYPE_SCA_NRM: + PNT_N_IN(pnt_scale_normal, key, val); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + PNT_N_IN(pnt_color_scale_normal, key, val); + break; + default: + break; + } +} + + +rt_pnt_type +_ged_pnts_fmt_type(const char *fc) +{ + int has_pnt = 0; + int has_nrm = 0; + int has_s = 0; + int has_c = 0; + + if (!fc || !strlen(fc)) return RT_PNT_UNKNOWN; + if (strchr(fc, 'x') && strchr(fc, 'y') && strchr(fc, 'z')) has_pnt = 1; + if (strchr(fc, 'i') && strchr(fc, 'j') && strchr(fc, 'k')) has_nrm = 1; + if (strchr(fc, 's')) has_s = 1; + if (strchr(fc, 'r') && strchr(fc, 'g') && strchr(fc, 'b')) has_c = 1; + + if (has_pnt && has_nrm && has_s && has_c) return RT_PNT_TYPE_COL_SCA_NRM; + if (has_pnt && has_nrm && has_s) return RT_PNT_TYPE_SCA_NRM; + if (has_pnt && has_nrm && has_c) return RT_PNT_TYPE_COL_NRM; + if (has_pnt && has_nrm) return RT_PNT_TYPE_NRM; + if (has_pnt && has_s && has_c) return RT_PNT_TYPE_COL_SCA; + if (has_pnt && has_s) return RT_PNT_TYPE_SCA; + if (has_pnt && has_c) return RT_PNT_TYPE_SCA; + if (has_pnt) return RT_PNT_TYPE_PNT; + + return RT_PNT_UNKNOWN; +} + +rt_pnt_type +_ged_pnts_fmt_guess(int numcnt) { + switch (numcnt) { + case 3: + return RT_PNT_TYPE_PNT; + break; + case 4: + return RT_PNT_TYPE_SCA; + break; + case 6: + bu_log("Warning - found 6 numbers, which is ambiguous - assuming RT_PNT_TYPE_NRM. To read in as RT_PNT_TYPE_COL, specify the format string \"xyzrgb\"\n"); + return RT_PNT_TYPE_NRM; + break; + case 7: + bu_log("Warning - found 7 numbers, which is ambiguous - assuming RT_PNT_TYPE_COL_SCA. To read in as RT_PNT_TYPE_SCA_NRM, specify the format string \"xyzijks\"\n"); + return RT_PNT_TYPE_COL_SCA; + break; + case 9: + return RT_PNT_TYPE_COL_NRM; + break; + case 10: + return RT_PNT_TYPE_COL_SCA_NRM; + break; + default: + return RT_PNT_UNKNOWN; + break; + } +} + +int +_ged_pnts_fmt_match(rt_pnt_type t, int numcnt) +{ + if (t == RT_PNT_UNKNOWN || numcnt < 3 || numcnt > 10) return 0; + + if (numcnt == 3 && t == RT_PNT_TYPE_PNT) return 1; + if (numcnt == 4 && t == RT_PNT_TYPE_SCA) return 1; + if (numcnt == 6 && t == RT_PNT_TYPE_NRM) return 1; + if (numcnt == 6 && t == RT_PNT_TYPE_COL) return 1; + if (numcnt == 7 && t == RT_PNT_TYPE_COL_SCA) return 1; + if (numcnt == 7 && t == RT_PNT_TYPE_SCA_NRM) return 1; + if (numcnt == 9 && t == RT_PNT_TYPE_COL_NRM) return 1; + if (numcnt == 10 && t == RT_PNT_TYPE_COL_SCA_NRM) return 1; + + return 0; +} + +void +_ged_pnts_init_head_pnt(struct rt_pnts_internal *pnts) +{ + if (!pnts) return; + switch (pnts->type) { + case RT_PNT_TYPE_PNT: + BU_LIST_INIT(&(((struct pnt *)pnts->point)->l)); + break; + case RT_PNT_TYPE_COL: + BU_LIST_INIT(&(((struct pnt_color *)pnts->point)->l)); + break; + case RT_PNT_TYPE_SCA: + BU_LIST_INIT(&(((struct pnt_scale *)pnts->point)->l)); + break; + case RT_PNT_TYPE_NRM: + BU_LIST_INIT(&(((struct pnt_normal *)pnts->point)->l)); + break; + case RT_PNT_TYPE_COL_SCA: + BU_LIST_INIT(&(((struct pnt_color_scale *)pnts->point)->l)); + break; + case RT_PNT_TYPE_COL_NRM: + BU_LIST_INIT(&(((struct pnt_color_normal *)pnts->point)->l)); + break; + case RT_PNT_TYPE_SCA_NRM: + BU_LIST_INIT(&(((struct pnt_scale_normal *)pnts->point)->l)); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + BU_LIST_INIT(&(((struct pnt_color_scale_normal *)pnts->point)->l)); + break; + default: + break; + } +} + + +void * +_ged_pnts_new_pnt(rt_pnt_type t) +{ + void *point = NULL; + if (t == RT_PNT_UNKNOWN) return NULL; + switch (t) { + case RT_PNT_TYPE_PNT: + BU_ALLOC(point, struct pnt); + break; + case RT_PNT_TYPE_COL: + BU_ALLOC(point, struct pnt_color); + break; + case RT_PNT_TYPE_SCA: + BU_ALLOC(point, struct pnt_scale); + break; + case RT_PNT_TYPE_NRM: + BU_ALLOC(point, struct pnt_normal); + break; + case RT_PNT_TYPE_COL_SCA: + BU_ALLOC(point, struct pnt_color_scale); + break; + case RT_PNT_TYPE_COL_NRM: + BU_ALLOC(point, struct pnt_color_normal); + break; + case RT_PNT_TYPE_SCA_NRM: + BU_ALLOC(point, struct pnt_scale_normal); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + BU_ALLOC(point, struct pnt_color_scale_normal); + break; + default: + break; + } + return point; +} + +void +_ged_pnts_add(struct rt_pnts_internal *pnts, void *point) +{ + switch (pnts->type) { + case RT_PNT_TYPE_PNT: + BU_LIST_PUSH(&(((struct pnt *)pnts->point)->l), &((struct pnt *)point)->l); + break; + case RT_PNT_TYPE_COL: + BU_LIST_PUSH(&(((struct pnt_color *)pnts->point)->l), &((struct pnt_color *)point)->l); + break; + case RT_PNT_TYPE_SCA: + BU_LIST_PUSH(&(((struct pnt_scale *)pnts->point)->l), &((struct pnt_scale *)point)->l); + break; + case RT_PNT_TYPE_NRM: + BU_LIST_PUSH(&(((struct pnt_normal *)pnts->point)->l), &((struct pnt_normal *)point)->l); + break; + case RT_PNT_TYPE_COL_SCA: + BU_LIST_PUSH(&(((struct pnt_color_scale *)pnts->point)->l), &((struct pnt_color_scale *)point)->l); + break; + case RT_PNT_TYPE_COL_NRM: + BU_LIST_PUSH(&(((struct pnt_color_normal *)pnts->point)->l), &((struct pnt_color_normal *)point)->l); + break; + case RT_PNT_TYPE_SCA_NRM: + BU_LIST_PUSH(&(((struct pnt_scale_normal *)pnts->point)->l), &((struct pnt_scale_normal *)point)->l); + break; + case RT_PNT_TYPE_COL_SCA_NRM: + BU_LIST_PUSH(&(((struct pnt_color_scale_normal *)pnts->point)->l), &((struct pnt_color_scale_normal *)point)->l); + break; + default: + break; + } +} + +/* + * 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/pnts_util.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 Added: brlcad/trunk/src/libged/pnts_util.h =================================================================== --- brlcad/trunk/src/libged/pnts_util.h (rev 0) +++ brlcad/trunk/src/libged/pnts_util.h 2018-08-01 13:37:01 UTC (rev 71334) @@ -0,0 +1,66 @@ +/* P N T S _ U T I L. H + * BRL-CAD + * + * Copyright (c) 2008-2018 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/pnts_util.h + * + * utility functionality for simple Point Set (pnts) primitive operations. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "bu/color.h" +#include "rt/geom.h" +#include "./ged_private.h" + +extern const char *_ged_pnt_default_fmt_str(rt_pnt_type type); + +extern void _ged_pnt_v_set(void *point, rt_pnt_type type, char key, fastf_t val); + +extern void _ged_pnt_c_set(void *point, rt_pnt_type type, char key, fastf_t val); + +extern void _ged_pnt_s_set(void *point, rt_pnt_type type, char key, fastf_t val); + +extern void _ged_pnt_n_set(void *point, rt_pnt_type type, char key, fastf_t val); + +extern rt_pnt_type _ged_pnts_fmt_type(const char *fc); + +extern rt_pnt_type _ged_pnts_fmt_guess(int numcnt); + +extern int _ged_pnts_fmt_match(rt_pnt_type t, int numcnt); + +extern void _ged_pnts_init_head_pnt(struct rt_pnts_internal *pnts); + +extern void * _ged_pnts_new_pnt(rt_pnt_type t); + +extern void _ged_pnts_add(struct rt_pnts_internal *pnts, void *point); + +/* + * 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/pnts_util.h ___________________________________________________________________ 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-08-01 15:47:33
|
Revision: 71340 http://sourceforge.net/p/brlcad/code/71340 Author: starseeker Date: 2018-08-01 15:47:29 +0000 (Wed, 01 Aug 2018) Log Message: ----------- Replace make_pnts implementation with a wrapper calling the pnts read command. The logic is not completely identical as far as reading in numbers, but it should be very close and covers the design case for this feature (one point per line) well enough that it shouldn't introduce behaviorial surprises. Modified Paths: -------------- brlcad/trunk/src/libged/CMakeLists.txt brlcad/trunk/src/libged/pnts.cpp Removed Paths: ------------- brlcad/trunk/src/libged/make_pnts.c Modified: brlcad/trunk/src/libged/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libged/CMakeLists.txt 2018-08-01 15:00:27 UTC (rev 71339) +++ brlcad/trunk/src/libged/CMakeLists.txt 2018-08-01 15:47:29 UTC (rev 71340) @@ -172,7 +172,6 @@ m2v_point.c make.c make_name.c - make_pnts.c match.c mater.c mirror.c Deleted: brlcad/trunk/src/libged/make_pnts.c =================================================================== --- brlcad/trunk/src/libged/make_pnts.c 2018-08-01 15:00:27 UTC (rev 71339) +++ brlcad/trunk/src/libged/make_pnts.c 2018-08-01 15:47:29 UTC (rev 71340) @@ -1,698 +0,0 @@ -/* M A K E _ P N T S . C - * BRL-CAD - * - * Copyright (c) 2009-2018 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 libged/make_pnts.c - * - * The "make_pnts" command makes a point-cloud from a points data file. - * - */ - -#include "common.h" - -#include <stdlib.h> -#include <ctype.h> -#include <string.h> - -#include "bu/sort.h" -#include "bu/units.h" -#include "rt/geom.h" -#include "wdb.h" - -#include "./ged_private.h" - -#define INSERT_COORDINATE_INTO_STRUCTURE(_structure_type, _control_variable, _variable_to_insert) \ - switch (_control_variable) { \ - case 'x': \ - ((struct _structure_type *)point)->v[X] = _variable_to_insert; \ - break; \ - case 'y': \ - ((struct _structure_type *)point)->v[Y] = _variable_to_insert; \ - break; \ - case 'z': \ - ((struct _structure_type *)point)->v[Z] = _variable_to_insert; \ - break; \ - } - -#define INSERT_COLOR_INTO_STRUCTURE(_structure_type, _control_variable, _variable_to_insert) \ - switch (_control_variable) { \ - case 'r': \ - ((struct _structure_type *)point)->c.buc_rgb[0] = _variable_to_insert; \ - break; \ - case 'g': \ - ((struct _structure_type *)point)->c.buc_rgb[1] = _variable_to_insert; \ - break; \ - case 'b': \ - ((struct _structure_type *)point)->c.buc_rgb[2] = _variable_to_insert; \ - break; \ - } - -#define INSERT_SCALE_INTO_STRUCTURE(_structure_type, _control_variable, _variable_to_insert) \ - switch (_control_variable) { \ - case 's': \ - ((struct _structure_type *)point)->s = _variable_to_insert; \ - break; \ - } - -#define INSERT_NORMAL_INTO_STRUCTURE(_structure_type, _control_variable, _variable_to_insert) \ - switch (_control_variable) { \ - case 'i': \ - ((struct _structure_type *)point)->n[X] = _variable_to_insert; \ - break; \ - case 'j': \ - ((struct _structure_type *)point)->n[Y] = _variable_to_insert; \ - break; \ - case 'k': \ - ((struct _structure_type *)point)->n[Z] = _variable_to_insert; \ - break; \ - } - -static char *p_make_pnts[] = { - "Enter point-cloud name: ", - "Enter point file path and name: ", - "Enter file data format (xyzrgbsijk?): ", - "Enter file data units (um|mm|cm|m|km|in|ft|yd|mi)\nor conversion factor from file data units to millimeters: ", - "Enter default point size: " -}; - - -/* - * Character compare function used by bu_sort function. - */ -int -compare_char(const char *a, const char *b, void *UNUSED(arg)) -{ - return (int)(*a - *b); -} - - -/* - * Validate 'point file data format string', determine and output the - * point-cloud type. A valid null terminated string is expected as - * input. The function returns GED_ERROR if the format string is - * invalid or if null pointers were passed to the function. - */ -int -str2type(const char *format_string, rt_pnt_type *pnt_type, struct bu_vls *ged_result_str) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - char *temp_string = (char *)NULL; - size_t idx = 0; - size_t format_string_length = 0; - int ret = GED_OK; - - if ((format_string == (char *)NULL) || (pnt_type == (rt_pnt_type *)NULL)) { - bu_vls_printf(ged_result_str, "NULL pointer(s) passed to function 'str2type'.\n"); - ret = GED_ERROR; - } else { - format_string_length = strlen(format_string); - - /* remove any '?' from format string before testing for point-cloud type */ - for (idx = 0 ; idx < format_string_length ; idx++) { - if (format_string[idx] != '?') { - bu_vls_putc(&str, format_string[idx]); - } - } - - bu_vls_trimspace(&str); - - temp_string = bu_vls_addr(&str); - bu_sort(temp_string, strlen(temp_string), sizeof(char), (int (*)(const void *a, const void *b, void *arg))compare_char, NULL); - - if (BU_STR_EQUAL(temp_string, "xyz")) { - *pnt_type = RT_PNT_TYPE_PNT; - } else if (BU_STR_EQUAL(temp_string, "bgrxyz")) { - *pnt_type = RT_PNT_TYPE_COL; - } else if (BU_STR_EQUAL(temp_string, "sxyz")) { - *pnt_type = RT_PNT_TYPE_SCA; - } else if (BU_STR_EQUAL(temp_string, "ijkxyz")) { - *pnt_type = RT_PNT_TYPE_NRM; - } else if (BU_STR_EQUAL(temp_string, "bgrsxyz")) { - *pnt_type = RT_PNT_TYPE_COL_SCA; - } else if (BU_STR_EQUAL(temp_string, "bgijkrxyz")) { - *pnt_type = RT_PNT_TYPE_COL_NRM; - } else if (BU_STR_EQUAL(temp_string, "ijksxyz")) { - *pnt_type = RT_PNT_TYPE_SCA_NRM; - } else if (BU_STR_EQUAL(temp_string, "bgijkrsxyz")) { - *pnt_type = RT_PNT_TYPE_COL_SCA_NRM; - } else { - bu_vls_printf(ged_result_str, "Invalid format string '%s'", format_string); - ret = GED_ERROR; - } - } - - bu_vls_free(&str); - - return ret; -} - - -/* - * Validate points data file unit string and output conversion factor - * to millimeters. If string is not a standard units identifier, the - * function assumes a custom conversion factor was specified. A valid - * null terminated string is expected as input. The function returns - * GED_ERROR if the unit string is invalid or if null pointers were - * passed to the function. - */ -int -str2mm(const char *units_string, double *conv_factor, struct bu_vls *ged_result_str) -{ - struct bu_vls str = BU_VLS_INIT_ZERO; - double tmp_value = 0.0; - char *endp = (char *)NULL; - int ret = GED_OK; - - if ((units_string == (char *)NULL) || (conv_factor == (double *)NULL)) { - bu_vls_printf(ged_result_str, "NULL pointer(s) passed to function 'str2mm'.\n"); - ret = GED_ERROR; - } else { - bu_vls_strcat(&str, units_string); - bu_vls_trimspace(&str); - - tmp_value = strtod(bu_vls_addr(&str), &endp); - if ((endp != bu_vls_addr(&str)) && (*endp == '\0')) { - /* convert to double success */ - *conv_factor = tmp_value; - } else if ((tmp_value = bu_mm_value(bu_vls_addr(&str))) > 0.0) { - *conv_factor = tmp_value; - } else { - bu_vls_printf(ged_result_str, "Invalid units string '%s'\n", units_string); - ret = GED_ERROR; - } - } - - bu_vls_free(&str); - - return ret; -} - - -void -report_import_error_location(unsigned long int num_doubles_read, unsigned int num_doubles_per_point, - unsigned long int start_offset_of_current_double, char field, struct bu_vls *ged_result_str) -{ - /* The num_doubles_read is the number of doubles successfully read. This error - * report is for the double where the error occurred, i.e. the next double. - */ - unsigned long int point_number = ceil((num_doubles_read + 1) / (double)num_doubles_per_point); - - bu_vls_printf(ged_result_str, "Failed reading point %lu field '%c' at file byte %lu.\n", - point_number, field, start_offset_of_current_double); -} - - -/* - * 'make_pnts' command for importing point-cloud data into a 'pnts' - * primitive. - * - * Input values: - * argv[1] object name - * argv[2] filename with path - * argv[3] point data file format string - * argv[4] point data file units string or conversion factor to millimeters - * argv[5] default size of each point - * - */ -int -ged_make_pnts(struct ged *gedp, int argc, const char *argv[]) -{ - struct directory *dp; - struct rt_db_internal internal; - - rt_pnt_type type; - double local2base; - unsigned long numPoints = 0; - struct rt_pnts_internal *pnts; - - double defaultSize = 0.0; - void *headPoint = NULL; - - FILE *fp; - - int temp_string_index = 0; /* index into temp_string, set to first character in temp_string, i.e. the start */ - unsigned long int num_doubles_read = 0; /* counters of double read from file */ - - int current_character_double = 0; /* flag indicating if current character read is part of a double or delimiter */ - int previous_character_double = 0; /* flag indicating if previously read character was part of a double or delimiter */ - - unsigned long int num_characters_read_from_file = 0; /* counter of number of characters read from file */ - unsigned long int start_offset_of_current_double = 0; /* character offset from start of file for current double */ - int found_double = 0; /* flag indicating if double encountered in file and needs to be processed */ - int found_eof = 0; /* flag indicating if end-of-file encountered when reading file */ - int done_processing_format_string = 0; /* flag indicating if loop processing format string should be exited */ - - char *temp_char_ptr = (char *)NULL; - - int buf = 0; /* raw character read from file */ - double temp_double = 0.0; - char temp_string[1024]; - int temp_string_size = 1024; /* number of characters that can be stored in temp_string including null terminator character */ - /* it is expected that the character representation of a double will never exceed this size string */ - char *endp = (char *)NULL; - - struct bu_vls format_string = BU_VLS_INIT_ZERO; - size_t format_string_index = 0; - - unsigned int num_doubles_per_point = 0; - - void *point = NULL; - - char **prompt; - - static const char *usage = "point_cloud_name filename_with_path file_format file_data_units default_point_size"; - - prompt = &p_make_pnts[0]; - - 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); - - if (argc > 6) { - bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); - return GED_ERROR; - } - - /* prompt for point-cloud name */ - if (argc < 2) { - bu_vls_printf(gedp->ged_result_str, "%s", prompt[0]); - return GED_MORE; - } - - GED_CHECK_EXISTS(gedp, argv[1], LOOKUP_QUIET, GED_ERROR); - - /* prompt for data file name with path */ - if (argc < 3) { - bu_vls_printf(gedp->ged_result_str, "%s", prompt[1]); - return GED_MORE; - } - - /* prompt for data file format */ - if (argc < 4) { - bu_vls_printf(gedp->ged_result_str, "%s", prompt[2]); - return GED_MORE; - } - - /* Validate 'point file data format string' and return point-cloud type. */ - if (str2type(argv[3], &type, gedp->ged_result_str) == GED_ERROR) { - return GED_ERROR; - } - - /* prompt for data file units */ - if (argc < 5) { - bu_vls_printf(gedp->ged_result_str, "%s", prompt[3]); - return GED_MORE; - } - - /* Validate the unit string and return conversion factor to millimeters. */ - if (str2mm(argv[4], &local2base, gedp->ged_result_str) == GED_ERROR) { - return GED_ERROR; - } - - /* prompt for default point size */ - if (argc < 6) { - bu_vls_printf(gedp->ged_result_str, "%s", prompt[4]); - return GED_MORE; - } - - defaultSize = strtod(argv[5], &endp); - if ((endp != argv[5]) && (*endp == '\0')) { - /* convert to double success */ - if (defaultSize < 0.0) { - bu_vls_printf(gedp->ged_result_str, "Default point size '%lf' must be non-negative.\n", defaultSize); - return GED_ERROR; - } - } else { - bu_vls_printf(gedp->ged_result_str, "Invalid default point size '%s'\n", argv[5]); - return GED_ERROR; - } - - bu_vls_strcat(&format_string, argv[3]); - bu_vls_trimspace(&format_string); - - /* init database structure */ - RT_DB_INTERNAL_INIT(&internal); - internal.idb_major_type = DB5_MAJORTYPE_BRLCAD; - internal.idb_type = ID_PNTS; - internal.idb_meth = &OBJ[ID_PNTS]; - BU_ALLOC(internal.idb_ptr, struct rt_pnts_internal); - - /* init internal structure */ - pnts = (struct rt_pnts_internal *) internal.idb_ptr; - pnts->magic = RT_PNTS_INTERNAL_MAGIC; - pnts->scale = defaultSize; - pnts->type = type; - pnts->count = numPoints; /* set again later */ - pnts->point = NULL; - - /* empty list head */ - switch (type) { - case RT_PNT_TYPE_PNT: - BU_ALLOC(headPoint, struct pnt); - BU_LIST_INIT(&(((struct pnt *)headPoint)->l)); - num_doubles_per_point = 3; - break; - case RT_PNT_TYPE_COL: - BU_ALLOC(headPoint, struct pnt_color); - BU_LIST_INIT(&(((struct pnt_color *)headPoint)->l)); - num_doubles_per_point = 6; - break; - case RT_PNT_TYPE_SCA: - BU_ALLOC(headPoint, struct pnt_scale); - BU_LIST_INIT(&(((struct pnt_scale *)headPoint)->l)); - num_doubles_per_point = 4; - break; - case RT_PNT_TYPE_NRM: - BU_ALLOC(headPoint, struct pnt_normal); - BU_LIST_INIT(&(((struct pnt_normal *)headPoint)->l)); - num_doubles_per_point = 6; - break; - case RT_PNT_TYPE_COL_SCA: - BU_ALLOC(headPoint, struct pnt_color_scale); - BU_LIST_INIT(&(((struct pnt_color_scale *)headPoint)->l)); - num_doubles_per_point = 7; - break; - case RT_PNT_TYPE_COL_NRM: - BU_ALLOC(headPoint, struct pnt_color_normal); - BU_LIST_INIT(&(((struct pnt_color_normal *)headPoint)->l)); - num_doubles_per_point = 9; - break; - case RT_PNT_TYPE_SCA_NRM: - BU_ALLOC(headPoint, struct pnt_scale_normal); - BU_LIST_INIT(&(((struct pnt_scale_normal *)headPoint)->l)); - num_doubles_per_point = 7; - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_ALLOC(headPoint, struct pnt_color_scale_normal); - BU_LIST_INIT(&(((struct pnt_color_scale_normal *)headPoint)->l)); - num_doubles_per_point = 10; - break; - default: - break; - } - BU_ASSERT(headPoint != NULL); - pnts->point = headPoint; - - if ((fp=fopen(argv[2], "rb")) == NULL) { - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "Could not open file '%s'.\n", argv[2]); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - - while (!found_eof) { - /* points_loop */ - /* allocate memory for single point structure for current point-cloud type */ - switch (type) { - case RT_PNT_TYPE_PNT: - BU_ALLOC(point, struct pnt); - break; - case RT_PNT_TYPE_COL: - BU_ALLOC(point, struct pnt_color); - break; - case RT_PNT_TYPE_SCA: - BU_ALLOC(point, struct pnt_scale); - break; - case RT_PNT_TYPE_NRM: - BU_ALLOC(point, struct pnt_normal); - break; - case RT_PNT_TYPE_COL_SCA: - BU_ALLOC(point, struct pnt_color_scale); - break; - case RT_PNT_TYPE_COL_NRM: - BU_ALLOC(point, struct pnt_color_normal); - break; - case RT_PNT_TYPE_SCA_NRM: - BU_ALLOC(point, struct pnt_scale_normal); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_ALLOC(point, struct pnt_color_scale_normal); - break; - default: - break; - } - - /* make sure we have something */ - BU_ASSERT(point != NULL); - - while (!found_eof && !done_processing_format_string) { - /* format_string_loop */ - char format = '\0'; - - while (!found_eof && !found_double) { - /* find_doubles_loop */ - format = bu_vls_addr(&format_string)[format_string_index]; - - buf = fgetc(fp); - - num_characters_read_from_file++; - - if (feof(fp)) { - if (ferror(fp)) { - perror("ERROR: Problem reading file, system error message"); - fclose(fp); - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "Unable to read file at byte '%lu'.\n", num_characters_read_from_file); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } else { - found_eof = 1; - } - } - - if (found_eof) { - fclose(fp); - current_character_double = 0; - if (num_doubles_read == 0) { - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "No data in file '%s'.\n", argv[2]); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - } else { - temp_char_ptr = strchr("0123456789.+-eE", buf); - if (temp_char_ptr != NULL) { - /* character read is part of a double */ - current_character_double = 1; - } else { - current_character_double = 0; - } - } - - if (previous_character_double && current_character_double) { - if (temp_string_index >= temp_string_size) { - fclose(fp); - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "String representing double too large, exceeds '%d' character limit. ", temp_string_size - 1); - report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double, - format, gedp->ged_result_str); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - temp_string[temp_string_index] = (char)buf; - temp_string_index++; - } - - if (previous_character_double && !current_character_double) { - if (temp_string_index >= temp_string_size) { - fclose(fp); - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "String representing double too large, exceeds '%d' character limit. ", temp_string_size - 1); - report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double, - format, gedp->ged_result_str); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - temp_string[temp_string_index] = '\0'; - - /* do not convert string to double for format character '?' */ - if (format != '?') { - temp_double = strtod(temp_string, &endp); - if (!((endp != temp_string) && (*endp == '\0'))) { - fclose(fp); - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "Unable to convert string '%s' to double. ", temp_string); - report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double, - format, gedp->ged_result_str); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - num_doubles_read++; - } else { - temp_double = 0.0; - } - - temp_string_index = 0; - found_double = 1; - previous_character_double = current_character_double; - } - - if (!previous_character_double && current_character_double) { - temp_string[temp_string_index] = (char)buf; - temp_string_index++; - start_offset_of_current_double = num_characters_read_from_file; - previous_character_double = current_character_double; - } - - } /* loop exits when eof encountered (and/or) double found */ - - if (found_double) { - - /* insert double into point structure for current point-cloud type */ - /* do not attempt to insert double into point structure for format character '?' */ - if (format != '?') { - switch (type) { - case RT_PNT_TYPE_PNT: - INSERT_COORDINATE_INTO_STRUCTURE(pnt, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_COL: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_color, format, (temp_double * local2base)); - INSERT_COLOR_INTO_STRUCTURE(pnt_color, format, temp_double); - break; - case RT_PNT_TYPE_SCA: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_scale, format, (temp_double * local2base)); - INSERT_SCALE_INTO_STRUCTURE(pnt_scale, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_NRM: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_normal, format, (temp_double * local2base)); - INSERT_NORMAL_INTO_STRUCTURE(pnt_normal, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_COL_SCA: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_scale, format, (temp_double * local2base)); - INSERT_COLOR_INTO_STRUCTURE(pnt_color_scale, format, temp_double); - INSERT_SCALE_INTO_STRUCTURE(pnt_color_scale, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_COL_NRM: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_normal, format, (temp_double * local2base)); - INSERT_COLOR_INTO_STRUCTURE(pnt_color_normal, format, temp_double); - INSERT_NORMAL_INTO_STRUCTURE(pnt_color_normal, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_SCA_NRM: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base)); - INSERT_SCALE_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base)); - INSERT_NORMAL_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base)); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base)); - INSERT_COLOR_INTO_STRUCTURE(pnt_color_scale_normal, format, temp_double); - INSERT_SCALE_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base)); - INSERT_NORMAL_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base)); - break; - default: - break; - } - } - found_double = 0; /* allows loop to continue */ - format_string_index++; - if (format_string_index >= bu_vls_strlen(&format_string)) { - done_processing_format_string = 1; - } - } - - } /* loop exits when eof encountered (and/or) all doubles for - * a single point are stored in point structure - */ - - if (done_processing_format_string) { - /* push single point structure onto linked-list of points - * which makeup the point-cloud. - */ - switch (type) { - case RT_PNT_TYPE_PNT: - BU_LIST_PUSH(&(((struct pnt *)headPoint)->l), &((struct pnt *)point)->l); - break; - case RT_PNT_TYPE_COL: - BU_LIST_PUSH(&(((struct pnt_color *)headPoint)->l), &((struct pnt_color *)point)->l); - break; - case RT_PNT_TYPE_SCA: - BU_LIST_PUSH(&(((struct pnt_scale *)headPoint)->l), &((struct pnt_scale *)point)->l); - break; - case RT_PNT_TYPE_NRM: - BU_LIST_PUSH(&(((struct pnt_normal *)headPoint)->l), &((struct pnt_normal *)point)->l); - break; - case RT_PNT_TYPE_COL_SCA: - BU_LIST_PUSH(&(((struct pnt_color_scale *)headPoint)->l), &((struct pnt_color_scale *)point)->l); - break; - case RT_PNT_TYPE_COL_NRM: - BU_LIST_PUSH(&(((struct pnt_color_normal *)headPoint)->l), &((struct pnt_color_normal *)point)->l); - break; - case RT_PNT_TYPE_SCA_NRM: - BU_LIST_PUSH(&(((struct pnt_scale_normal *)headPoint)->l), &((struct pnt_scale_normal *)point)->l); - break; - case RT_PNT_TYPE_COL_SCA_NRM: - BU_LIST_PUSH(&(((struct pnt_color_scale_normal *)headPoint)->l), &((struct pnt_color_scale_normal *)point)->l); - break; - default: - break; - } - numPoints++; - format_string_index = 0; - done_processing_format_string = 0; - } - - } /* loop exits when eof encountered */ - - if (num_doubles_read < num_doubles_per_point) { - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. Number of values read inconsistent with point-cloud type ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "defined by format string '%s'. The number of values read must be an even ", bu_vls_addr(&format_string)); - bu_vls_printf(gedp->ged_result_str, "multiple of %d but read %lu values.\n", num_doubles_per_point, num_doubles_read); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - - if (num_doubles_read % num_doubles_per_point) { - bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. Number of values read inconsistent with point-cloud type ", argv[1]); - bu_vls_printf(gedp->ged_result_str, "defined by format string '%s'. The number of values read must be an even ", bu_vls_addr(&format_string)); - bu_vls_printf(gedp->ged_result_str, "multiple of %d but read %lu values.\n", num_doubles_per_point, num_doubles_read); - bu_vls_free(&format_string); - rt_db_free_internal(&internal); - return GED_ERROR; - } - - pnts->count = numPoints; - - GED_DB_DIRADD(gedp, dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR); - GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR); - - bu_vls_free(&format_string); - - bu_vls_printf(gedp->ged_result_str, "Make '%s' success, %lu values read, %lu points imported.\n", argv[1], num_doubles_read, numPoints); - - return GED_OK; -} - - -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Modified: brlcad/trunk/src/libged/pnts.cpp =================================================================== --- brlcad/trunk/src/libged/pnts.cpp 2018-08-01 15:00:27 UTC (rev 71339) +++ brlcad/trunk/src/libged/pnts.cpp 2018-08-01 15:47:29 UTC (rev 71340) @@ -23,8 +23,6 @@ * */ -/* TODO - merge make_pnts in with this... */ - #include "common.h" extern "C" { @@ -161,10 +159,7 @@ /* Sanity */ if (!bot_name || !gedp) return GED_ERROR; - if (db_lookup(gedp->ged_wdbp->dbip, bot_name, LOOKUP_QUIET) != RT_DIR_NULL) { - bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", bot_name); - return GED_ERROR; - } + GED_CHECK_EXISTS(gedp, bot_name, LOOKUP_QUIET, GED_ERROR); /* For the moment, only generate BoTs when we have a normal to guide us. Eventually, * we might add logic to find the avg center point and calculate normals radiating out @@ -310,10 +305,7 @@ bu_vls_sprintf(gedp->ged_result_str, "Error: object %s doesn't exist!\n", obj_name); return GED_ERROR; } - if (db_lookup(gedp->ged_wdbp->dbip, pnt_prim, LOOKUP_QUIET) != RT_DIR_NULL) { - bu_vls_sprintf(gedp->ged_result_str, "Error: object %s already exists!\n", pnt_prim); - return GED_ERROR; - } + GED_CHECK_EXISTS(gedp, pnt_prim, LOOKUP_QUIET, GED_ERROR); /* If we don't have a tolerance, try to guess something sane from the bbox */ if (NEAR_ZERO(len_tol, RT_LEN_TOL)) { @@ -513,7 +505,7 @@ } if (pnts->type == RT_PNT_UNKNOWN) { - /* If we dont' have a specified format, try to guess */ + /* If we don't have a specified format, try to guess */ bu_log("Warning - no point format specified, trying to match template xyz[ijk][s][rgb]\n"); pnts->type = _ged_pnts_fmt_guess(numcnt); if (pnts->type != RT_PNT_UNKNOWN) { @@ -928,7 +920,116 @@ return GED_ERROR; } +/* Compatibility wrapper for the old make_pnts command ordering/prompting: + * + * Input values: + * argv[1] object name + * argv[2] filename with path + * argv[3] point data file format string + * argv[4] point data file units string or conversion factor to millimeters + * argv[5] default size of each point + */ +int +ged_make_pnts(struct ged *gedp, int argc, const char *argv[]) +{ + double conv_factor = -1.0; + double psize = -1.0; + char *endp = (char *)NULL; + static const char *usage = "point_cloud_name filename_with_path file_format file_data_units default_point_size"; + static const char *prompt[] = { + "Enter point-cloud name: ", + "Enter point file path and name: ", + "Enter file data format (xyzrgbsijk?): ", + "Enter file data units (um|mm|cm|m|km|in|ft|yd|mi)\nor conversion factor from file data units to millimeters: ", + "Enter default point size: " + }; + static const char *r_cmd = "read"; + static const char *s_opt = "--size"; + static const char *f_opt = "--format"; + static const char *u_opt = "--units"; + const char *nargv[10]; + /* initialize result */ + bu_vls_trunc(gedp->ged_result_str, 0); + + if (argc > 6) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return GED_ERROR; + } + + /* prompt for point-cloud name */ + if (argc < 2) { + bu_vls_printf(gedp->ged_result_str, "%s", prompt[0]); + return GED_MORE; + } + + GED_CHECK_EXISTS(gedp, argv[1], LOOKUP_QUIET, GED_ERROR); + + /* prompt for data file name with path */ + if (argc < 3) { + bu_vls_printf(gedp->ged_result_str, "%s", prompt[1]); + return GED_MORE; + } + + /* prompt for data file format */ + if (argc < 4) { + bu_vls_printf(gedp->ged_result_str, "%s", prompt[2]); + return GED_MORE; + } + + /* Validate 'point file data format string' and return point-cloud type. */ + if ((_ged_pnts_fmt_type(argv[3]) == RT_PNT_UNKNOWN)) { + bu_vls_printf(gedp->ged_result_str, "could not validate format string: %s\n", argv[3]); + return GED_ERROR; + } + + /* prompt for data file units */ + if (argc < 5) { + bu_vls_printf(gedp->ged_result_str, "%s", prompt[3]); + return GED_MORE; + } + + /* Validate unit */ + if (bu_opt_fastf_t(NULL, 1, (const char **)&argv[4], (void *)&conv_factor) == -1) { + conv_factor = bu_mm_value(argv[4]); + } + if (conv_factor < 0) { + bu_vls_sprintf(gedp->ged_result_str, "invalid unit specification: %s\n", argv[4]); + return GED_ERROR; + } + + /* prompt for default point size */ + if (argc < 6) { + bu_vls_printf(gedp->ged_result_str, "%s", prompt[4]); + return GED_MORE; + } + + psize = strtod(argv[5], &endp); + if ((endp != argv[5]) && (*endp == '\0')) { + /* convert to double success */ + if (psize < 0.0) { + bu_vls_printf(gedp->ged_result_str, "Default point size '%lf' must be non-negative.\n", psize); + return GED_ERROR; + } + } else { + bu_vls_printf(gedp->ged_result_str, "Invalid default point size '%s'\n", argv[5]); + return GED_ERROR; + } + + nargv[0] = argv[0]; + nargv[1] = r_cmd; + nargv[2] = s_opt; + nargv[3] = argv[5]; + nargv[4] = f_opt; + nargv[5] = argv[3]; + nargv[6] = u_opt; + nargv[7] = argv[4]; + nargv[8] = argv[2]; + nargv[9] = argv[1]; + + return ged_pnts(gedp, 10, (const char **)nargv); +} + /* * Local Variables: * tab-width: 8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2018-08-04 17:38:24
|
Revision: 71377 http://sourceforge.net/p/brlcad/code/71377 Author: sharannyn Date: 2018-08-04 17:38:21 +0000 (Sat, 04 Aug 2018) Log Message: ----------- add an appropriate prefix to the function log_overlaps() defined in different files Modified Paths: -------------- brlcad/trunk/src/libged/check/check_overlaps.c brlcad/trunk/src/libged/check_overlaps.c Modified: brlcad/trunk/src/libged/check/check_overlaps.c =================================================================== --- brlcad/trunk/src/libged/check/check_overlaps.c 2018-08-04 17:29:20 UTC (rev 71376) +++ brlcad/trunk/src/libged/check/check_overlaps.c 2018-08-04 17:38:21 UTC (rev 71377) @@ -56,7 +56,7 @@ HIDDEN void -log_overlaps(const char *reg1, const char *reg2, double depth, vect_t ihit, vect_t ohit, void *context) +check_log_overlaps(const char *reg1, const char *reg2, double depth, vect_t ihit, vect_t ohit, void *context) { struct overlaps_context *callbackdata = (struct overlaps_context*)context; struct overlap_list *olist= (struct overlap_list *)callbackdata->overlapList; @@ -259,7 +259,7 @@ } bu_semaphore_acquire(GED_SEM_LIST); - log_overlaps(reg1->reg_name, reg2->reg_name, depth, ihit, ohit, context); + check_log_overlaps(reg1->reg_name, reg2->reg_name, depth, ihit, ohit, context); bu_semaphore_release(GED_SEM_LIST); if (context->plot_overlaps) { Modified: brlcad/trunk/src/libged/check_overlaps.c =================================================================== --- brlcad/trunk/src/libged/check_overlaps.c 2018-08-04 17:29:20 UTC (rev 71376) +++ brlcad/trunk/src/libged/check_overlaps.c 2018-08-04 17:38:21 UTC (rev 71377) @@ -63,7 +63,7 @@ HIDDEN void -log_overlaps(const char *reg1, const char *reg2, double depth, vect_t ihit, vect_t ohit, void *context) +ck_ov_log_overlaps(const char *reg1, const char *reg2, double depth, vect_t ihit, vect_t ohit, void *context) { struct overlaps_context *callbackdata = (struct overlaps_context*)context; struct overlap_list **olist = (struct overlap_list **) callbackdata->list; @@ -127,7 +127,7 @@ reg2 = (struct region *)BU_PTBL_GET(regiontable, 1); RT_CK_REGION(reg2); bu_semaphore_acquire(BU_SEM_SYSCALL); - log_overlaps(reg1->reg_name, reg2->reg_name, depth, ihit, ohit, context); + ck_ov_log_overlaps(reg1->reg_name, reg2->reg_name, depth, ihit, ohit, context); bu_semaphore_release(BU_SEM_SYSCALL); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-08-07 00:59:23
|
Revision: 71406 http://sourceforge.net/p/brlcad/code/71406 Author: starseeker Date: 2018-08-07 00:59:20 +0000 (Tue, 07 Aug 2018) Log Message: ----------- Start laying out the broad flow of the per-region facetization logic. Modified Paths: -------------- brlcad/trunk/src/libged/comb.c brlcad/trunk/src/libged/facetize.c brlcad/trunk/src/libged/ged_private.h brlcad/trunk/src/libged/group.c Modified: brlcad/trunk/src/libged/comb.c =================================================================== --- brlcad/trunk/src/libged/comb.c 2018-08-06 23:51:59 UTC (rev 71405) +++ brlcad/trunk/src/libged/comb.c 2018-08-07 00:59:20 UTC (rev 71406) @@ -698,7 +698,7 @@ av[0] = objp->d_namep; av[1] = NULL; - if (_ged_combadd2(gedp, combname, ac, av, region_flag, relation, ident, air) == GED_ERROR) + if (_ged_combadd2(gedp, combname, ac, av, region_flag, relation, ident, air, 1) == GED_ERROR) return RT_DIR_NULL; /* Done changing stuff - update nref. */ @@ -723,7 +723,8 @@ int region_flag, /* true if adding region */ db_op_t relation, /* = UNION, SUBTRACT, INTERSECT */ int ident, /* "Region ID" */ - int air /* Air code */) + int air, /* Air code */ + int validate /* 1 to check if new members exist, 0 to just add them */) { struct directory *dp; struct directory *objp; @@ -818,9 +819,11 @@ } for (i = 0; i < argc; ++i) { - if ((objp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) { - bu_vls_printf(gedp->ged_result_str, "skip member %s\n", argv[i]); - continue; + if (validate) { + if ((objp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) { + bu_vls_printf(gedp->ged_result_str, "skip member %s\n", argv[i]); + continue; + } } /* insert new member at end */ @@ -844,7 +847,7 @@ RT_TREE_INIT(tp); tree_list[curr_count].tl_tree = tp; tp->tr_l.tl_op = OP_DB_LEAF; - tp->tr_l.tl_name = bu_strdup(objp->d_namep); + tp->tr_l.tl_name = bu_strdup(argv[i]); tp->tr_l.tl_mat = (matp_t)NULL; ++curr_count; Modified: brlcad/trunk/src/libged/facetize.c =================================================================== --- brlcad/trunk/src/libged/facetize.c 2018-08-06 23:51:59 UTC (rev 71405) +++ brlcad/trunk/src/libged/facetize.c 2018-08-07 00:59:20 UTC (rev 71406) @@ -206,7 +206,7 @@ int nmg_use_tnurbs; int regions; - /* Poisson specific options */ + /* Poisson specific options */ int pnt_surf_mode; int pnt_grid_mode; int pnt_rand_mode; @@ -214,7 +214,7 @@ int max_pnts; int max_time; fastf_t len_tol; - struct bu_vls *cp_suffix; + struct bu_vls *faceted_suffix; struct bg_3d_spsr_opts s_opts; }; @@ -230,9 +230,9 @@ o->screened_poisson = 0; o->nmg_use_tnurbs = 0; o->regions = 0; - BU_GET(o->cp_suffix, struct bu_vls); - bu_vls_init(o->cp_suffix); - bu_vls_sprintf(o->cp_suffix, "_f"); + BU_GET(o->faceted_suffix, struct bu_vls); + bu_vls_init(o->faceted_suffix); + bu_vls_sprintf(o->faceted_suffix, ".bot"); o->pnt_surf_mode = 0; o->pnt_grid_mode = 0; @@ -247,26 +247,42 @@ void _ged_facetize_opts_destroy(struct _ged_facetize_opts *o) { if (!o) return; - if (o->cp_suffix) { - bu_vls_free(o->cp_suffix); - BU_PUT(o->cp_suffix, struct bu_vls); + if (o->faceted_suffix) { + bu_vls_free(o->faceted_suffix); + BU_PUT(o->faceted_suffix, struct bu_vls); } BU_PUT(o, struct _ged_facetize_opts); } int -_ged_facetize_regions(struct ged *gedp, int argc, const char **argv, struct _ged_facetize_opts *UNUSED(opts)) +_db_uniq_test(struct bu_vls *n, void *data) { - int newobj_cnt; + struct ged *gedp = (struct ged *)data; + if (db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(n), LOOKUP_QUIET) == RT_DIR_NULL) return 1; + return 0; +} + +int +_ged_facetize_regions(struct ged *gedp, int argc, const char **argv, struct _ged_facetize_opts *opts) +{ + char *newname = NULL; + int newobj_cnt = 0; int ret = GED_OK; - unsigned int i; + unsigned int i = 0; + struct bu_vls tmp = BU_VLS_INIT_ZERO; + /* When we start making lots of combs, see if we can (re) use a bu_ptbl as + * a dynamic storage for the argv array to feed to ged_combadd2... + struct bu_ptbl avtbl = BU_PTBL_INIT_ZERO; */ + struct bu_attribute_value_set nmap = BU_AVS_INIT_ZERO; struct directory **dpa = NULL; struct db_i *dbip = gedp->ged_wdbp->dbip; + const char **ntop; /* We need to copy combs above regions that are not themselves regions. * Also, facetize will need all "active" regions that will define shapes. * Construct searches to get these sets. */ - struct bu_ptbl *pc, *ar; - struct bu_ptbl *ar_failed_nmg; + struct bu_ptbl *pc = NULL; + struct bu_ptbl *ar = NULL; + struct bu_ptbl *ar_failed_nmg = NULL; const char *preserve_combs = "-type c ! -type r ! -below -type r"; const char *active_regions = "-type r ! -below -type r"; @@ -276,8 +292,10 @@ return GED_ERROR; } + newname = (char *)argv[argc-1]; argc--; + BU_ALLOC(pc, struct bu_ptbl); BU_ALLOC(ar, struct bu_ptbl); if (db_search(pc, DB_SEARCH_RETURN_UNIQ_DP, preserve_combs, newobj_cnt, dpa, dbip, NULL) < 0) { @@ -305,15 +323,34 @@ bu_ptbl_init(ar_failed_nmg, 64, "failed list init"); for (i = 0; i < BU_PTBL_LEN(ar); i++) { struct directory *n = (struct directory *)BU_PTBL_GET(ar, i); - printf("NMG tessellating %s\n", n->d_namep); + bu_vls_sprintf(&tmp, "%s%s", n->d_namep, bu_vls_addr(opts->faceted_suffix)); + if (db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&tmp), LOOKUP_QUIET) != RT_DIR_NULL) { + bu_vls_incr(&tmp, NULL, "0:0:0:0:-", &_db_uniq_test, (void *)gedp); + } + bu_avs_add(&nmap, n->d_namep, bu_vls_addr(&tmp)); + + bu_vls_printf(gedp->ged_result_str, "NMG tessellating %s from %s\n", bu_avs_get(&nmap, n->d_namep), n->d_namep); } - /* + /* For all the pc combs, make new versions with the suffixed names */ for (i = 0; i < BU_PTBL_LEN(pc); i++) { + struct directory *n = (struct directory *)BU_PTBL_GET(pc, i); + bu_vls_sprintf(&tmp, "%s", n->d_namep); + bu_vls_incr(&tmp, NULL, "0:0:0:0:-", &_db_uniq_test, (void *)gedp); + bu_avs_add(&nmap, n->d_namep, bu_vls_addr(&tmp)); + bu_vls_printf(gedp->ged_result_str, "Making new comb %s from %s\n", bu_avs_get(&nmap, n->d_namep), n->d_namep); } - */ + /* Last one - add the new toplevel comb to hold all the new geometry */ + ntop = (const char **)bu_calloc(argc, sizeof(const char *), "new top level names"); + for (i = 0; i < (unsigned int)argc; i++) { + ntop[i] = bu_avs_get(&nmap, argv[i]); + } + ret = _ged_combadd2(gedp, newname, argc, ntop, 0, DB_OP_UNION, 0, 0, 0); + /* Done changing stuff - update nref. */ + db_update_nref(gedp->ged_wdbp->dbip, &rt_uniresource); + ged_facetize_regions_memfree: bu_ptbl_free(pc); bu_ptbl_free(ar); @@ -650,6 +687,14 @@ /* parse standard options */ argc = bu_opt_parse(NULL, argc, argv, d); + /* Enforce type matching on suffix */ + if (opts->make_nmg && BU_STR_EQUAL(bu_vls_addr(opts->faceted_suffix), ".bot")) { + bu_vls_sprintf(opts->faceted_suffix, ".nmg"); + } + if (!opts->make_nmg && BU_STR_EQUAL(bu_vls_addr(opts->faceted_suffix), ".nmg")) { + bu_vls_sprintf(opts->faceted_suffix, ".bot"); + } + /* If we're in multi-region mode, we may employ more than one technique, so a * lot of options may make sense here - just pull the other options out and * let the subsequent logic use them (or not). */ Modified: brlcad/trunk/src/libged/ged_private.h =================================================================== --- brlcad/trunk/src/libged/ged_private.h 2018-08-06 23:51:59 UTC (rev 71405) +++ brlcad/trunk/src/libged/ged_private.h 2018-08-07 00:59:20 UTC (rev 71406) @@ -171,7 +171,8 @@ int region_flag, db_op_t relation, int ident, - int air); + int air, + int validate); /* defined in display_list.c */ extern void _dl_eraseAllNamesFromDisplay(struct bu_list *hdlp, struct db_i *dbip, Modified: brlcad/trunk/src/libged/group.c =================================================================== --- brlcad/trunk/src/libged/group.c 2018-08-06 23:51:59 UTC (rev 71405) +++ brlcad/trunk/src/libged/group.c 2018-08-07 00:59:20 UTC (rev 71406) @@ -56,7 +56,7 @@ return GED_ERROR; } - return _ged_combadd2(gedp, (char *)argv[1], argc-2, argv+2, 0, WMOP_UNION, 0, 0); + return _ged_combadd2(gedp, (char *)argv[1], argc-2, argv+2, 0, WMOP_UNION, 0, 0, 1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |