BRL-CAD
#include "common.h"
#include <stddef.h>
#include <string.h>
#include <math.h>
#include "bio.h"
#include "vmath.h"
#include "nmg.h"
#include "raytrace.h"
Include dependency graph for nmg_index.c:

Go to the source code of this file.

Macros

#define NMG_HIGH_BIT   0x80000000
 
#define NMG_MARK_INDEX(_p)   ((_p)->index |= NMG_HIGH_BIT)
 
#define NMG_ASSIGN_NEW_INDEX(_p)
 
#define MARK_VU(_vu)
 
#define ASSIGN_VU(_vu)
 
#define NMG_UNIQ_INDEX(_p, _type)
 
#define UNIQ_VU(_vu)
 
#define CHECK_INDEX(_p)   if ((_p)->index > maxindex) maxindex = (_p)->index
 
#define CHECK_VU_INDEX(_vu)
 

Functions

int nmg_index_of_struct (register const uint32_t *p)
 
void nmg_m_set_high_bit (struct model *m)
 
void nmg_m_reindex (struct model *m, register long int newindex)
 
void nmg_vls_struct_counts (struct bu_vls *str, const struct nmg_struct_counts *ctr)
 
void nmg_pr_struct_counts (const struct nmg_struct_counts *ctr, const char *str)
 
uint32_t ** nmg_m_struct_count (register struct nmg_struct_counts *ctr, const struct model *m)
 
void nmg_pr_m_struct_counts (const struct model *m, const char *str)
 
void nmg_merge_models (struct model *m1, struct model *m2)
 
long nmg_find_max_index (const struct model *m)
 

Detailed Description

Handle counting and re-indexing of NMG data structures.

Definition in file nmg_index.c.

Macro Definition Documentation

#define NMG_HIGH_BIT   0x80000000

Definition at line 107 of file nmg_index.c.

#define NMG_MARK_INDEX (   _p)    ((_p)->index |= NMG_HIGH_BIT)

Definition at line 109 of file nmg_index.c.

Referenced by nmg_m_set_high_bit().

#define NMG_ASSIGN_NEW_INDEX (   _p)
Value:
{ if (((_p)->index & NMG_HIGH_BIT) != 0) \
(_p)->index = newindex++; }
#define NMG_HIGH_BIT
Definition: nmg_index.c:107

Definition at line 111 of file nmg_index.c.

Referenced by nmg_m_reindex().

#define MARK_VU (   _vu)
Value:
{ \
struct vertex *v; \
NMG_CK_VERTEXUSE(_vu); \
if (_vu->a.magic_p) switch (*_vu->a.magic_p) { \
NMG_MARK_INDEX(_vu->a.plane_p); \
break; \
NMG_MARK_INDEX(_vu->a.cnurb_p); \
break; \
} \
v = _vu->v_p; \
NMG_CK_VERTEX(v); \
if (v->vg_p) { \
NMG_CK_VERTEX_G(v->vg_p); \
NMG_MARK_INDEX(v->vg_p); \
} \
}
if(share_geom)
Definition: nmg_mod.c:3829
#define NMG_VERTEXUSE_A_CNURB_MAGIC
Definition: magic.h:143
#define NMG_MARK_INDEX(_p)
Definition: nmg_index.c:109
eu1 up magic_p
Definition: nmg_mod.c:3915
#define NMG_VERTEXUSE_A_PLANE_MAGIC
Definition: magic.h:144

Referenced by nmg_m_set_high_bit().

#define ASSIGN_VU (   _vu)
Value:
{ \
NMG_CK_VERTEXUSE(_vu); \
if (_vu->a.magic_p) switch (*_vu->a.magic_p) { \
NMG_ASSIGN_NEW_INDEX(_vu->a.plane_p); \
break; \
NMG_ASSIGN_NEW_INDEX(_vu->a.cnurb_p); \
break; \
} \
v = _vu->v_p; \
NMG_CK_VERTEX(v); \
if (v->vg_p) NMG_ASSIGN_NEW_INDEX(v->vg_p); \
}
#define NMG_ASSIGN_NEW_INDEX(_p)
Definition: nmg_index.c:111
if(share_geom)
Definition: nmg_mod.c:3829
#define NMG_VERTEXUSE_A_CNURB_MAGIC
Definition: magic.h:143
eu1 up magic_p
Definition: nmg_mod.c:3915
#define NMG_VERTEXUSE_A_PLANE_MAGIC
Definition: magic.h:144

Referenced by nmg_m_reindex().

#define NMG_UNIQ_INDEX (   _p,
  _type 
)
Value:
if ((_p)->index > m->maxindex) { \
bu_log("%p (%s) has index %ld, m->maxindex=%ld\n", (void *)(_p), \
bu_identify_magic(*((uint32_t *)(_p))), (_p)->index, m->maxindex); \
bu_bomb("nmg_m_struct_count index overflow\n"); \
} \
if (ptrs[(_p)->index] == NULL) { \
ptrs[(_p)->index] = (uint32_t *)(_p); \
ctr->_type++; \
}
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
if(share_geom)
Definition: nmg_mod.c:3829
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91
const char * bu_identify_magic(uint32_t magic)

Referenced by nmg_m_struct_count().

#define UNIQ_VU (   _vu)
Value:
{ \
NMG_CK_VERTEXUSE(_vu); \
NMG_UNIQ_INDEX(_vu, vertexuse); \
if (_vu->a.magic_p) switch (*_vu->a.magic_p) { \
NMG_UNIQ_INDEX(_vu->a.plane_p, vertexuse_a_plane); \
break; \
NMG_UNIQ_INDEX(_vu->a.cnurb_p, vertexuse_a_cnurb); \
break; \
} \
v = _vu->v_p; \
NMG_CK_VERTEX(v); \
NMG_UNIQ_INDEX(v, vertex); \
if (v->vg_p) { \
NMG_CK_VERTEX_G(v->vg_p); \
NMG_UNIQ_INDEX(v->vg_p, vertex_g); \
} \
}
#define NMG_UNIQ_INDEX(_p, _type)
if(share_geom)
Definition: nmg_mod.c:3829
#define NMG_VERTEXUSE_A_CNURB_MAGIC
Definition: magic.h:143
eu1 up magic_p
Definition: nmg_mod.c:3915
#define NMG_VERTEXUSE_A_PLANE_MAGIC
Definition: magic.h:144

Referenced by nmg_m_struct_count().

#define CHECK_INDEX (   _p)    if ((_p)->index > maxindex) maxindex = (_p)->index

Definition at line 789 of file nmg_index.c.

Referenced by nmg_find_max_index().

#define CHECK_VU_INDEX (   _vu)
Value:
{\
NMG_CK_VERTEXUSE(_vu); \
if (_vu->a.magic_p) switch (*_vu->a.magic_p) { \
CHECK_INDEX(_vu->a.plane_p); \
break; \
CHECK_INDEX(_vu->a.cnurb_p); \
break; \
} \
v = _vu->v_p; \
NMG_CK_VERTEX(v); \
if (v->vg_p) CHECK_INDEX(v->vg_p); \
}
if(share_geom)
Definition: nmg_mod.c:3829
#define CHECK_INDEX(_p)
Definition: nmg_index.c:789
#define NMG_VERTEXUSE_A_CNURB_MAGIC
Definition: magic.h:143
eu1 up magic_p
Definition: nmg_mod.c:3915
#define NMG_VERTEXUSE_A_PLANE_MAGIC
Definition: magic.h:144

Definition at line 790 of file nmg_index.c.

Referenced by nmg_find_max_index().

Function Documentation

int nmg_index_of_struct ( register const uint32_t *  p)

Return the structure index number of an arbitrary NMG structure.

Returns - >=0 index number -1 pointed at struct bu_list embedded within NMG structure. -2 error: unknown magic number

Definition at line 49 of file nmg_index.c.

References BU_LIST_HEAD_MAGIC, BU_LIST_MAIN_PTR, bu_log(), NMG_EDGE_G_CNURB_MAGIC, NMG_EDGE_G_LSEG_MAGIC, NMG_EDGE_MAGIC, NMG_EDGEUSE2_MAGIC, NMG_EDGEUSE_MAGIC, NMG_FACE_G_PLANE_MAGIC, NMG_FACE_G_SNURB_MAGIC, NMG_FACE_MAGIC, NMG_FACEUSE_MAGIC, NMG_LOOP_G_MAGIC, NMG_LOOP_MAGIC, NMG_LOOPUSE_MAGIC, NMG_MODEL_MAGIC, NMG_REGION_A_MAGIC, NMG_REGION_MAGIC, NMG_SHELL_A_MAGIC, NMG_SHELL_MAGIC, NMG_VERTEX_G_MAGIC, NMG_VERTEX_MAGIC, NMG_VERTEXUSE_A_CNURB_MAGIC, NMG_VERTEXUSE_A_PLANE_MAGIC, and NMG_VERTEXUSE_MAGIC.

Referenced by nmg_eval_action(), reindex(), rt_nmg_export4_internal(), rt_nmg_export5(), and rt_nmg_ialloc().

Here is the call graph for this function:

void nmg_m_set_high_bit ( struct model *  m)

First pass: just set the high bit on all index words

This is a separate function largely for the benefit of global optimizers, which tended to blow their brains out on such a large subroutine.

Definition at line 145 of file nmg_index.c.

References BU_LIST_FIRST, BU_LIST_FIRST_MAGIC, BU_LIST_FOR, lu, MARK_VU, NMG_CK_LOOPUSE(), NMG_CK_SHELL(), NMG_FACE_G_PLANE_MAGIC, NMG_FACE_G_SNURB_MAGIC, NMG_MARK_INDEX, NMG_VERTEXUSE_MAGIC, and s.

Referenced by nmg_m_reindex().

Here is the call graph for this function:

void nmg_m_reindex ( struct model *  m,
register long int  newindex 
)

Reassign index numbers to all the data structures in a model. The model structure will get index 0, all others will be sequentially assigned after that.

Because the first pass has done extensive error checking, the second pass can do less.

Definition at line 298 of file nmg_index.c.

References ASSIGN_VU, BU_LIST_FIRST, BU_LIST_FIRST_MAGIC, BU_LIST_FOR, bu_log(), lu, NMG_ASSIGN_NEW_INDEX, NMG_CK_LOOPUSE(), NMG_CK_SHELL(), rt_g::NMG_debug, NMG_EDGE_G_CNURB_MAGIC, NMG_EDGE_G_LSEG_MAGIC, NMG_FACE_G_PLANE_MAGIC, NMG_FACE_G_SNURB_MAGIC, nmg_m_set_high_bit(), NMG_VERTEXUSE_MAGIC, RTG, s, and OSL::Strings::v.

Referenced by ged_shells(), nmg_merge_models(), and nmg_mk_model_from_region().

Here is the call graph for this function:

void nmg_vls_struct_counts ( struct bu_vls str,
const struct nmg_struct_counts *  ctr 
)

Definition at line 464 of file nmg_index.c.

References BU_CK_VLS, and bu_vls_printf().

Referenced by nmg_pr_struct_counts().

Here is the call graph for this function:

void nmg_pr_struct_counts ( const struct nmg_struct_counts *  ctr,
const char *  str 
)

Definition at line 504 of file nmg_index.c.

References bu_log(), bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, and nmg_vls_struct_counts().

Referenced by nmg_pr_m_struct_counts().

Here is the call graph for this function:

uint32_t** nmg_m_struct_count ( register struct nmg_struct_counts *  ctr,
const struct model *  m 
)

Returns - Pointer to magic-number/structure-base pointer array, indexed by nmg structure index. Caller is responsible for freeing it.

Definition at line 523 of file nmg_index.c.

References bu_calloc(), BU_LIST_FIRST, BU_LIST_FIRST_MAGIC, BU_LIST_FOR, lu, memset(), NMG_CK_LOOPUSE(), NMG_CK_SHELL(), NMG_EDGE_G_CNURB_MAGIC, NMG_EDGE_G_LSEG_MAGIC, NMG_FACE_G_PLANE_MAGIC, NMG_FACE_G_SNURB_MAGIC, NMG_UNIQ_INDEX, NMG_VERTEXUSE_MAGIC, s, UNIQ_VU, and OSL::Strings::v.

Referenced by nmg_pr_m_struct_counts(), rt_nmg_export4_internal(), and rt_nmg_export5().

Here is the call graph for this function:

void nmg_pr_m_struct_counts ( const struct model *  m,
const char *  str 
)

Count 'em up, and print 'em out.

Definition at line 719 of file nmg_index.c.

References bu_free(), nmg_m_struct_count(), and nmg_pr_struct_counts().

Here is the call graph for this function:

void nmg_merge_models ( struct model *  m1,
struct model *  m2 
)

Combine two NMG model trees into one single NMG model. The first model inherits the nmgregions of the second. The second model pointer is freed before return.

Definition at line 738 of file nmg_index.c.

References bu_free(), BU_LIST_APPEND_LIST, BU_LIST_FOR, and nmg_m_reindex().

Referenced by nmg_boolean(), nmg_booltree_evaluate(), rt_nmg_tess(), and rt_vol_tess().

Here is the call graph for this function:

long nmg_find_max_index ( const struct model *  m)

Definition at line 808 of file nmg_index.c.

References BU_LIST_FIRST, BU_LIST_FIRST_MAGIC, BU_LIST_FOR, CHECK_INDEX, CHECK_VU_INDEX, lu, NMG_CK_LOOPUSE(), NMG_CK_SHELL(), NMG_EDGE_G_CNURB_MAGIC, NMG_EDGE_G_LSEG_MAGIC, NMG_FACE_G_PLANE_MAGIC, NMG_FACE_G_SNURB_MAGIC, NMG_VERTEXUSE_MAGIC, s, and OSL::Strings::v.

Referenced by nmg_mk_model_from_region().

Here is the call graph for this function: