00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef lint
00046 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/nmg_visit.c,v 14.11 2006/09/16 02:04:25 lbutler Exp $ (BRL)";
00047 #endif
00048
00049 #include "common.h"
00050
00051
00052 #include <stdio.h>
00053 #include <math.h>
00054 #include "machine.h"
00055 #include "vmath.h"
00056 #include "nmg.h"
00057 #include "raytrace.h"
00058
00059
00060
00061
00062
00063 void
00064 nmg_visit_vertex(struct vertex *v, const struct nmg_visit_handlers *htab, genptr_t state)
00065
00066
00067
00068 {
00069 NMG_CK_VERTEX(v);
00070
00071 if(htab->vis_vertex) htab->vis_vertex( (long *)v, state, 0 );
00072
00073 if(htab->vis_vertex_g && v->vg_p)
00074 htab->vis_vertex_g( (long *)v->vg_p, state, 0 );
00075 }
00076
00077
00078
00079
00080 void
00081 nmg_visit_vertexuse(struct vertexuse *vu, const struct nmg_visit_handlers *htab, genptr_t state)
00082
00083
00084
00085 {
00086 NMG_CK_VERTEXUSE(vu);
00087
00088 if(htab->bef_vertexuse) htab->bef_vertexuse( (long *)vu, state, 0 );
00089
00090 nmg_visit_vertex( vu->v_p, htab, state );
00091
00092 if(htab->vis_vertexuse_a && vu->a.magic_p)
00093 htab->vis_vertexuse_a( vu->a.magic_p, state, 0 );
00094
00095 if(htab->aft_vertexuse) htab->aft_vertexuse( (long *)vu, state, 1 );
00096 }
00097
00098
00099
00100
00101 void
00102 nmg_visit_edge(struct edge *e, const struct nmg_visit_handlers *htab, genptr_t state)
00103
00104
00105
00106 {
00107 NMG_CK_EDGE( e );
00108
00109 if(htab->vis_edge) htab->vis_edge( (long *)e, state, 0 );
00110 }
00111
00112
00113
00114
00115 void
00116 nmg_visit_edgeuse(struct edgeuse *eu, const struct nmg_visit_handlers *htab, genptr_t state)
00117
00118
00119
00120 {
00121 NMG_CK_EDGEUSE(eu);
00122
00123 if(htab->bef_edgeuse) htab->bef_edgeuse( (long *)eu, state, 0 );
00124
00125 nmg_visit_vertexuse( eu->vu_p, htab, state );
00126 nmg_visit_edge( eu->e_p, htab, state );
00127
00128 if(htab->vis_edge_g && eu->g.magic_p)
00129 htab->vis_edge_g( eu->g.magic_p, state, 0 );
00130
00131 if(htab->aft_edgeuse) htab->aft_edgeuse( (long *)eu, state, 1 );
00132 }
00133
00134
00135
00136
00137 void
00138 nmg_visit_loop(struct loop *l, const struct nmg_visit_handlers *htab, genptr_t state)
00139
00140
00141
00142 {
00143 NMG_CK_LOOP(l);
00144
00145 if(htab->vis_loop) htab->vis_loop( (long *)l, state, 0 );
00146
00147 if(htab->vis_loop_g && l->lg_p)
00148 htab->vis_loop_g( (long *)l->lg_p, state, 0 );
00149 }
00150
00151
00152
00153
00154 void
00155 nmg_visit_loopuse(struct loopuse *lu, const struct nmg_visit_handlers *htab, genptr_t state)
00156
00157
00158
00159 {
00160 NMG_CK_LOOPUSE( lu );
00161
00162 if(htab->bef_loopuse) htab->bef_loopuse( (long *)lu, state, 0 );
00163
00164 if( BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC ) {
00165 struct vertexuse *vu;
00166 vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);
00167 nmg_visit_vertexuse( vu, htab, state );
00168 } else {
00169 struct edgeuse *eu;
00170 for( BU_LIST_FOR( eu, edgeuse, &lu->down_hd ) ) {
00171 nmg_visit_edgeuse( eu, htab, state );
00172 }
00173 }
00174 nmg_visit_loop( lu->l_p, htab, state );
00175
00176 if(htab->aft_loopuse) htab->aft_loopuse( (long *)lu, state, 1 );
00177 }
00178
00179
00180
00181
00182 void
00183 nmg_visit_face(struct face *f, const struct nmg_visit_handlers *htab, genptr_t state)
00184
00185
00186
00187 {
00188
00189 if(htab->vis_face) htab->vis_face( (long *)f, state, 0 );
00190
00191 if(htab->vis_face_g && f->g.plane_p)
00192 htab->vis_face_g( (long *)f->g.plane_p, state, 0 );
00193 }
00194
00195
00196
00197
00198 void
00199 nmg_visit_faceuse(struct faceuse *fu, const struct nmg_visit_handlers *htab, genptr_t state)
00200
00201
00202
00203 {
00204 struct loopuse *lu;
00205
00206 NMG_CK_FACEUSE(fu);
00207
00208 if(htab->bef_faceuse) htab->bef_faceuse( (long *)fu, state, 0 );
00209
00210 for( BU_LIST_FOR( lu, loopuse, &fu->lu_hd ) ) {
00211 nmg_visit_loopuse( lu, htab, state );
00212 }
00213
00214 nmg_visit_face( fu->f_p, htab, state );
00215
00216 if(htab->aft_faceuse) htab->aft_faceuse( (long *)fu, state, 1 );
00217 }
00218
00219
00220
00221
00222 void
00223 nmg_visit_shell(struct shell *s, const struct nmg_visit_handlers *htab, genptr_t state)
00224
00225
00226
00227 {
00228 struct faceuse *fu;
00229 struct loopuse *lu;
00230 struct edgeuse *eu;
00231
00232 NMG_CK_SHELL(s);
00233
00234 if(htab->bef_shell) htab->bef_shell( (long *)s, state, 0 );
00235
00236 for( BU_LIST_FOR( fu, faceuse, &s->fu_hd ) ) {
00237 nmg_visit_faceuse( fu, htab, state );
00238 }
00239 for( BU_LIST_FOR( lu, loopuse, &s->lu_hd ) ) {
00240 nmg_visit_loopuse( lu, htab, state );
00241 }
00242 for( BU_LIST_FOR( eu, edgeuse, &s->eu_hd ) ) {
00243 nmg_visit_edgeuse( eu, htab, state );
00244 }
00245 if( s->vu_p ) nmg_visit_vertexuse( s->vu_p, htab, state );
00246 if(htab->vis_shell_a && s->sa_p)
00247 htab->vis_shell_a( (long *)s->sa_p, state, 0 );
00248
00249 if(htab->aft_shell) htab->aft_shell( (long *)s, state, 1 );
00250 }
00251
00252
00253
00254
00255 void
00256 nmg_visit_region(struct nmgregion *r, const struct nmg_visit_handlers *htab, genptr_t state)
00257
00258
00259
00260 {
00261 struct shell *s;
00262
00263 NMG_CK_REGION(r);
00264
00265 if(htab->bef_region) htab->bef_region( (long *)r, state, 0 );
00266
00267 for( BU_LIST_FOR( s, shell, &r->s_hd ) ) {
00268 nmg_visit_shell( s, htab, state );
00269 }
00270 if(htab->vis_region_a && r->ra_p)
00271 htab->vis_region_a( (long *)r->ra_p, state, 0 );
00272
00273 if(htab->aft_region) htab->aft_region( (long *)r, state, 1 );
00274 }
00275
00276
00277
00278 void
00279 nmg_visit_model(struct model *model, const struct nmg_visit_handlers *htab, genptr_t state)
00280
00281
00282
00283 {
00284 struct nmgregion *r;
00285
00286 NMG_CK_MODEL(model);
00287
00288 if(htab->bef_model) htab->bef_model( (long *)model, state, 0 );
00289
00290 for( BU_LIST_FOR( r, nmgregion, &model->r_hd ) ) {
00291 nmg_visit_region( r, htab, state );
00292 }
00293
00294 if(htab->aft_model) htab->aft_model( (long *)model, state, 1 );
00295 }
00296
00297
00298
00299
00300 void
00301 nmg_visit(const long int *magicp, const struct nmg_visit_handlers *htab, genptr_t state)
00302
00303 {
00304 switch( *magicp ) {
00305 default:
00306 bu_log("nmg_visit() Can't visit %s directly\n", bu_identify_magic( *magicp ));
00307 rt_bomb("nmg_visit()\n");
00308
00309 case NMG_MODEL_MAGIC:
00310 nmg_visit_model( (struct model *)magicp, htab, state );
00311 break;
00312 case NMG_REGION_MAGIC:
00313 nmg_visit_region( (struct nmgregion *)magicp, htab, state );
00314 break;
00315 case NMG_SHELL_MAGIC:
00316 nmg_visit_shell( (struct shell *)magicp, htab, state );
00317 break;
00318 case NMG_FACEUSE_MAGIC:
00319 nmg_visit_faceuse( (struct faceuse *)magicp, htab, state );
00320 break;
00321 case NMG_LOOPUSE_MAGIC:
00322 nmg_visit_loopuse( (struct loopuse *)magicp, htab, state );
00323 break;
00324 case NMG_EDGEUSE_MAGIC:
00325 nmg_visit_edgeuse( (struct edgeuse *)magicp, htab, state );
00326 break;
00327 case NMG_VERTEXUSE_MAGIC:
00328 nmg_visit_vertexuse( (struct vertexuse *)magicp, htab, state );
00329 break;
00330 }
00331 }
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341