db_flags.c

Go to the documentation of this file.
00001 /*                     D B _ F L A G S . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 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 
00022 /** @addtogroup db4 */
00023 
00024 /*@{*/
00025 /** @file db_flags.c
00026  *
00027  *  Given an internal representation of a geometry object, there are
00028  *  particular directory flags associated with it (at least for
00029  *  geometric objects) that we may need to obtain.  The directory
00030  *  flags are mostly based on the major and minor type of the object
00031  *  so these routines consolidate that logic.
00032  *
00033  *  Functions
00034  *    db_flags_internal - given an rt_db_internal, return the flags
00035  *    db_flags_raw_internal - given a db5_raw_internal, return flags
00036  *
00037  *  Authors -
00038  *      Christopher Sean Morrison
00039  *
00040  *  Source -
00041  *      SECAD/VLD Computing Consortium, Bldg 394
00042  *      The U. S. Army Ballistic Research Laboratory
00043  *      Aberdeen Proving Ground, Maryland  21005-5066
00044  *
00045  */
00046 
00047 #include "common.h"
00048 
00049 #include "machine.h"
00050 #include "bu.h"
00051 #include "vmath.h"
00052 #include "db.h"
00053 #include "raytrace.h"
00054 
00055 
00056 /**
00057  *  D B _ F L A G S _ I N T E R N A L
00058  *
00059  * Given the internal form of a database object, return the
00060  * appropriate 'flags' word for stashing in the in-memory directory of
00061  * objects.
00062  */
00063 int
00064 db_flags_internal(const struct rt_db_internal *intern)
00065 {
00066         const struct rt_comb_internal   *comb;
00067 
00068         RT_CK_DB_INTERNAL(intern);
00069 
00070         if( intern->idb_type != ID_COMBINATION )
00071                 return DIR_SOLID;
00072 
00073         comb = (struct rt_comb_internal *)intern->idb_ptr;
00074         RT_CK_COMB(comb);
00075 
00076         if( comb->region_flag )
00077                 return DIR_COMB | DIR_REGION;
00078         return DIR_COMB;
00079 }
00080 
00081 
00082 /* XXX - should use in db5_diradd() */
00083 /**
00084  * d b _ f l a g s _ r a w _ i n t e r n a l
00085  *
00086  * Given a database object in "raw" internal form, return the
00087  * appropriate 'flags' word for stashing in the in-memory directory of
00088  * objects.
00089  */
00090 int
00091 db_flags_raw_internal(const struct db5_raw_internal *raw)
00092 {
00093     struct bu_attribute_value_set avs;
00094 
00095     if (raw->major_type != DB5_MAJORTYPE_BRLCAD) {
00096         return DIR_NON_GEOM;
00097     }
00098     if (raw->minor_type == DB5_MINORTYPE_BRLCAD_COMBINATION) {
00099         if (raw->attributes.ext_buf) {
00100             bu_avs_init_empty(&avs);
00101             if (db5_import_attributes(&avs, &raw->attributes) < 0) {
00102                 /* could not load attributes, so presume not a region */
00103                 return DIR_COMB;
00104             }
00105             if (avs.count == 0) {
00106                 return DIR_COMB;
00107             }
00108             if (bu_avs_get( &avs, "region" ) != NULL) {
00109                 return DIR_COMB|DIR_REGION;
00110             }
00111         }
00112         return DIR_COMB;
00113     }
00114 
00115     /* anything else is a solid? */
00116     return DIR_SOLID;
00117 }
00118 
00119 /*@}*/
00120 /*
00121  * Local Variables:
00122  * mode: C
00123  * tab-width: 8
00124  * c-basic-offset: 4
00125  * indent-tabs-mode: t
00126  * End:
00127  * ex: shiftwidth=4 tabstop=8
00128  */

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