nmg_visit.c

Go to the documentation of this file.
00001 /*                     N M G _ V I S I T . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1993-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup nmg */
00022 /*@{*/
00023 /** @file nmg_visit.c
00024  *  A generalized, object-oriented subroutine family to
00025  *  visit all the data structures "below" a given structure.
00026  *
00027  *  The caller provides a pointer to the structure to start at,
00028  *  a table of "handlers" for each kind of strucuture,
00029  *  and a generic pointer for private state which will be sent along
00030  *  to the user's handlers.
00031  *  For non-leaf structures, there are two handlers, one called
00032  *  before any recursion starts, and the other called when
00033  *  recursion is finished.  Either or both may be omitted.
00034  *
00035  *  Author -
00036  *      Michael John Muuss
00037  *
00038  *  Source -
00039  *      The U. S. Army Research Laboratory
00040  *      Aberdeen Proving Ground, Maryland  21005-5066
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  *                      N M G _ V I S I T _ V E R T E X
00062  */
00063 void
00064 nmg_visit_vertex(struct vertex *v, const struct nmg_visit_handlers *htab, genptr_t state)
00065 
00066 
00067                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ V E R T E X U S E
00079  */
00080 void
00081 nmg_visit_vertexuse(struct vertexuse *vu, const struct nmg_visit_handlers *htab, genptr_t state)
00082 
00083 
00084                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ E D G E
00100  */
00101 void
00102 nmg_visit_edge(struct edge *e, const struct nmg_visit_handlers *htab, genptr_t state)
00103 
00104 
00105                                                 /* Handler's private state */
00106 {
00107         NMG_CK_EDGE( e );
00108 
00109         if(htab->vis_edge) htab->vis_edge( (long *)e, state, 0 );
00110 }
00111 
00112 /**
00113  *                      N M G _ V I S I T _ E D G E U S E
00114  */
00115 void
00116 nmg_visit_edgeuse(struct edgeuse *eu, const struct nmg_visit_handlers *htab, genptr_t state)
00117 
00118 
00119                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ L O O P
00136  */
00137 void
00138 nmg_visit_loop(struct loop *l, const struct nmg_visit_handlers *htab, genptr_t state)
00139 
00140 
00141                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ L O O P U S E
00153  */
00154 void
00155 nmg_visit_loopuse(struct loopuse *lu, const struct nmg_visit_handlers *htab, genptr_t state)
00156 
00157 
00158                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ F A C E
00181  */
00182 void
00183 nmg_visit_face(struct face *f, const struct nmg_visit_handlers *htab, genptr_t state)
00184 
00185 
00186                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ F A C E U S E
00197  */
00198 void
00199 nmg_visit_faceuse(struct faceuse *fu, const struct nmg_visit_handlers *htab, genptr_t state)
00200 
00201 
00202                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ S H E L L
00221  */
00222 void
00223 nmg_visit_shell(struct shell *s, const struct nmg_visit_handlers *htab, genptr_t state)
00224 
00225 
00226                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ R E G I O N
00254  */
00255 void
00256 nmg_visit_region(struct nmgregion *r, const struct nmg_visit_handlers *htab, genptr_t state)
00257 
00258 
00259                                                 /* Handler's private state */
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  *                      N M G _ V I S I T _ M O D E L
00277  */
00278 void
00279 nmg_visit_model(struct model *model, const struct nmg_visit_handlers *htab, genptr_t state)
00280 
00281 
00282                                                 /* Handler's private state */
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  *                      N M G _ V I S I T
00299  */
00300 void
00301 nmg_visit(const long int *magicp, const struct nmg_visit_handlers *htab, genptr_t state)
00302                                                 /* Handler's private state */
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                 /* NOTREACHED */
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  * Local Variables:
00335  * mode: C
00336  * tab-width: 8
00337  * c-basic-offset: 4
00338  * indent-tabs-mode: t
00339  * End:
00340  * ex: shiftwidth=4 tabstop=8
00341  */

Generated on Mon Sep 18 01:24:55 2006 for BRL-CAD by  doxygen 1.4.6