Skip to content

Commit

Permalink
labelvert -i option working. however, code uses new struct vtxlabel t…
Browse files Browse the repository at this point in the history
…o avoid potential lists already used by nmg datastructure (struct vertex). also, there is no freeing of label list. todo: either use struct vertex instead if there is no list in nmg structure using struct vertex, or free list appropriately after usage.
  • Loading branch information
Brad Eric Hollister committed Aug 18, 2015
1 parent 0e1b539 commit b7d0636
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 61 deletions.
7 changes: 6 additions & 1 deletion include/bn/vlist.h
Expand Up @@ -156,7 +156,12 @@ struct bn_vlist {
BN_EXPORT extern int bn_vlist_cmd_cnt(struct bn_vlist *vlist);
BN_EXPORT extern int bn_vlist_bbox(struct bn_vlist *vp, point_t *bmin, point_t *bmax);


/* Stores vertex info for labelling with NMG index. */
struct vtxlabel {
struct bu_list l;
point_t coord;
long int index;
};

/**
* For plotting, a way of separating plots into separate color vlists:
Expand Down
8 changes: 4 additions & 4 deletions src/librt/vlist.c
Expand Up @@ -514,14 +514,14 @@ rt_label_vidx_verts(struct bn_vlblock *vbp, struct bu_list *v_list, fastf_t *mat
double sz, double UNUSED(mm2local))
{
struct bu_list* vhead;
struct vertex* curr_v;
struct vtxlabel* curr_vl;
char label[256];

vhead = bn_vlblock_find(vbp, 255, 255, 255); /* white */

for( BU_LIST_FOR(curr_v, vertex, v_list) ) {
sprintf(label, " %d", (int)curr_v->index );
bn_vlist_3string(vhead, vbp->free_vlist_hd, label, curr_v->vg_p->coord, mat, sz);
for( BU_LIST_FOR(curr_vl, vtxlabel, v_list) ) {
sprintf(label, " %lu", curr_vl->index );
bn_vlist_3string(vhead, vbp->free_vlist_hd, label, curr_vl->coord, mat, sz);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/mged/mged.h
Expand Up @@ -407,7 +407,6 @@ struct mged_hist {
int mh_status;
};


/* internal variables related to the command window(s) */
struct cmd_list {
struct bu_list l;
Expand Down
126 changes: 71 additions & 55 deletions src/mged/overlay.c
Expand Up @@ -28,6 +28,7 @@

#include "vmath.h"
#include "raytrace.h"
#include "bn/vlist.h"

#include "./mged.h"
#include "./sedit.h"
Expand Down Expand Up @@ -79,6 +80,21 @@ cmd_overlay(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const c
return ret;
}

void insert_index_label( struct bu_list* v_list, struct vertex* vert ) {

/* Copies data from struct vertex and
* insert into bu_list of index labels.
*/

struct vtxlabel* v_info = (struct vtxlabel*)malloc(sizeof(struct 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];
v_info->index = vert->index;

BU_LIST_INSERT( v_list, &v_info->l);
}

void get_vertex_list( const struct model* m, struct bu_list* v_list )
{
struct nmgregion *r;
Expand All @@ -91,7 +107,7 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )
struct edge *e;
struct vertexuse *vu;
struct vertex *v;
struct vertex *curr_v;
struct vtxlabel *curr_v;
int found = 0;

NMG_CK_MODEL(m);
Expand Down Expand Up @@ -137,25 +153,24 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )
/* Loop of Lone vertex */
vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);

/* check and remove vertexuse */
/* check vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );
if ( !found ) {
insert_index_label( v_list, v );
}

found = 0;

continue;
}

for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
Expand All @@ -174,21 +189,22 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )

vu = eu->vu_p;

/* check and remove vertexuse */
/* check vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );
if ( !found ) {
insert_index_label( v_list, v );
}

found = 0;
}
Expand All @@ -214,18 +230,18 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );
if ( !found ) {
insert_index_label( v_list, v );
}

found = 0;
continue;
}

for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
Expand All @@ -241,21 +257,22 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )
}
vu = eu->vu_p;

/* check and remove vertexuse */
/* check vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );
if ( !found ) {
insert_index_label( v_list, v );
}

found = 0;
}
Expand All @@ -278,47 +295,46 @@ void get_vertex_list( const struct model* m, struct bu_list* v_list )

vu = eu->vu_p;

/* check and remove vertexuse */
/* check vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );

found = 0;

if ( !found ) {
insert_index_label( v_list, v );
found = 0;
}
}

/* Lone vertex in shell */
vu = s->vu_p;

if (vu) {
/* check and remove vertexuse */
/* check vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

/* check for duplicate vertex struct */
for (BU_LIST_FOR(curr_v, vertex, v_list)) {
for (BU_LIST_FOR(curr_v, vtxlabel, v_list)) {
if (curr_v->index == v->index) {
found = 1;
break;
}
}

if ( !found )
BU_LIST_INSERT( v_list, &(v->vu_hd) );

found = 0;
if ( !found ) {
insert_index_label( v_list, v );
found = 0;
}
}
}
}
Expand All @@ -336,7 +352,7 @@ f_labelvert(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const c
mat_t mat;
fastf_t scale;
char opt[2] = {'c','\0'};
int i = 1;
int i=1;
struct bu_list v_list;
struct model* m;
const char* name;
Expand Down Expand Up @@ -399,28 +415,28 @@ f_labelvert(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const c
bn_mat_inv(mat, view_state->vs_gvp->gv_rotation);
scale = view_state->vs_gvp->gv_size / 100; /* divide by # chars/screen */

for (; i<argc; i++) {
struct solid *s;
if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL)
continue;
/* Find uses of this solid in the solid table */
gdlp = BU_LIST_NEXT(display_list, gedp->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, gedp->ged_gdp->gd_headDisplay)) {
next_gdlp = BU_LIST_PNEXT(display_list, gdlp);

FOR_ALL_SOLIDS(s, &gdlp->dl_headSolid) {
if (db_full_path_search(&s->s_fullpath, dp)) {
if ( BU_STR_EQUIV( "i", opt ) ) {
get_vertex_list(m, &v_list);
rt_label_vidx_verts(vbp, &v_list, mat, scale, base2local);
} else {
rt_label_vlist_verts(vbp, &s->s_vlist, mat, scale, base2local);
}
}
}

gdlp = next_gdlp;
}
if ( BU_STR_EQUIV( "i", opt ) ) {
get_vertex_list(m, &v_list);
rt_label_vidx_verts(vbp, &v_list, mat, scale, base2local);
} else {
for (; i<argc; i++) {
struct solid *s;
if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL)
continue;
/* Find uses of this solid in the solid table */
gdlp = BU_LIST_NEXT(display_list, gedp->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, gedp->ged_gdp->gd_headDisplay)) {
next_gdlp = BU_LIST_PNEXT(display_list, gdlp);

FOR_ALL_SOLIDS(s, &gdlp->dl_headSolid) {
if (db_full_path_search(&s->s_fullpath, dp)) {
rt_label_vlist_verts(vbp, &s->s_vlist, mat, scale, base2local);
}
}

gdlp = next_gdlp;
}
}
}

cvt_vlblock_to_solids(vbp, "_LABELVERT_", 0);
Expand Down

0 comments on commit b7d0636

Please sign in to comment.