Skip to content

Commit

Permalink
using bu_malloc and bu_free now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Eric Hollister committed Aug 19, 2015
1 parent 931eb78 commit 2f95767
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 245 deletions.
328 changes: 85 additions & 243 deletions src/libged/nmg_make_v.c
Expand Up @@ -32,288 +32,130 @@

#include "./ged_private.h"

#if 0
void remove_vertex(const struct model* m, point_t rv)
{
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);
#include "common.h"
#include "nmg.h"

/* Traverse NMG model and remove instances of vertexuses.
* In addition to vertex being removed, associated faceuses, loopuses
* and edgeuses need to be removed that contained the deleted vertexuse.
*/
#include <signal.h>
#include <string.h>

for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) {
NMG_CK_REGION(r);
#include "bu/cmd.h"
#include "rt/geom.h"

if (r->ra_p) {
NMG_CK_REGION_A(r->ra_p);
}
#include "./ged_private.h"

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, rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
nmg_klu(lu);
}
}

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,
rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
nmg_keu(eu);
nmg_klu(lu);
}
}
}
}
}

/* 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, rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
nmg_klu(lu);
}
}
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, rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
nmg_keu(eu);
nmg_klu(lu);
}
}
}
}

/* 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, rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
nmg_keu(eu);
}
}
}

/* 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, rv, BN_TOL_DIST) ) {
nmg_kvu(vu);
}
}
}
}
}
}
#endif
struct tmp_v {
point_t pt;
struct vertex *v;
};

int
ged_nmg_make_v(struct ged* gedp, int argc, const char* argv[])
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;
#if 0
point_t vt;
struct tmp_v* verts;
struct faceuse *fu;
struct bn_tol tol;
struct vertex ***face_verts;
int idx;
int num_verts;
#endif

static const char *usage = "make V x1 y1 z1 ... xn yn zn";
static const char *usage = "make V x0 y0 z0 ... xn yn zn";

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);
#if 0
num_verts = (argc - 3) / 3;
#endif

/* must be wanting help */
if (argc < 6) {
bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
return GED_HELP;
/* check for less than three vertices or incomplete vertex coordinates */
if (argc < ELEMENTS_PER_POINT * 3 + 2 || (argc - 2) % 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;
== 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;
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;
bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name);
rt_db_free_internal(&internal);
return GED_ERROR;
}

#if 0
vt[0] = atof(argv[3]); vt[1] = atof(argv[4]); vt[2] = atof(argv[5]);
#endif

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);

#if 0
add_vertex(m, vt);
verts = (struct tmp_v *)NULL;
verts = (struct tmp_v *)bu_calloc(num_verts,
sizeof(struct tmp_v), "verts");
face_verts = (struct vertex ***) bu_calloc( num_verts,
sizeof(struct vertex **), "face_verts");

for (idx=0; idx < num_verts; idx++){
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]);
face_verts[idx] = &verts[idx].v;
}

fu = nmg_cmface( s, face_verts, num_verts );
bu_free((char *) face_verts, "face_verts");

/* assign geometry for entire vertex list (if we have one) */
for (idx=0; idx < num_verts; idx++) {
if (verts[idx].v) nmg_vertex_gv(verts[idx].v, verts[idx].pt);
}

/* assign face geometry */
if (s) {
for (BU_LIST_FOR (fu, faceuse, &s->fu_hd)) {
if (fu->orientation != OT_SAME) continue;
nmg_calc_face_g(fu);
}
}

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);
#endif

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);
Expand Down
5 changes: 3 additions & 2 deletions src/mged/overlay.c
Expand Up @@ -87,7 +87,8 @@ insert_index_label( struct bu_list* v_list, struct vertex* vert )
* insert into bu_list of index labels.
*/

struct vtxlabel* v_info = (struct vtxlabel*)malloc(sizeof(struct vtxlabel));
struct vtxlabel* v_info =
(struct vtxlabel*)bu_malloc(sizeof(struct vtxlabel), "vtxlabel");
v_info->coord[0] = vert->vg_p->coord[0];
v_info->coord[1] = vert->vg_p->coord[1];
v_info->coord[2] = vert->vg_p->coord[2];
Expand All @@ -102,7 +103,7 @@ free_index_label_list( struct bu_list* v_list )
struct vtxlabel* curr_vl;
while (BU_LIST_WHILE(curr_vl, vtxlabel, v_list)) {
BU_LIST_DEQUEUE(&(curr_vl->l));
free(curr_vl);
bu_free(curr_vl, "vtxlabel");
}
}

Expand Down

0 comments on commit 2f95767

Please sign in to comment.