BRL-CAD
db_flags.c
Go to the documentation of this file.
1 /* D B _ F L A G S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2006-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup db4 */
21 /** @{ */
22 /** @file librt/db_flags.c
23  *
24  * Given an internal representation of a geometry object, there are
25  * particular directory flags associated with it (at least for
26  * geometric objects) that we may need to obtain. The directory flags
27  * are mostly based on the major and minor type of the object so these
28  * routines consolidate that logic.
29  *
30  */
31 
32 #include "common.h"
33 
34 #include "bio.h"
35 
36 
37 #include "vmath.h"
38 #include "db.h"
39 #include "raytrace.h"
40 
41 
42 int
43 db_flags_internal(const struct rt_db_internal *intern)
44 {
45  const struct rt_comb_internal *comb;
46 
47  RT_CK_DB_INTERNAL(intern);
48 
49  if (intern->idb_type != ID_COMBINATION)
50  return RT_DIR_SOLID;
51 
52  comb = (struct rt_comb_internal *)intern->idb_ptr;
53  RT_CK_COMB(comb);
54 
55  if (comb->region_flag)
56  return RT_DIR_COMB | RT_DIR_REGION;
57  return RT_DIR_COMB;
58 }
59 
60 int
61 db_flags_raw_internal(const struct db5_raw_internal *raw)
62 {
63  struct bu_attribute_value_set avs;
64 
65  if (raw->major_type != DB5_MAJORTYPE_BRLCAD) {
66  return RT_DIR_NON_GEOM;
67  }
68  if (raw->minor_type == DB5_MINORTYPE_BRLCAD_COMBINATION) {
69  if (raw->attributes.ext_buf) {
70  bu_avs_init_empty(&avs);
71  if (db5_import_attributes(&avs, &raw->attributes) < 0) {
72  /* could not load attributes, so presume not a region */
73  return RT_DIR_COMB;
74  }
75  if (avs.count == 0) {
76  return RT_DIR_COMB;
77  }
78  if (bu_avs_get(&avs, "region") != NULL) {
80  }
81  }
82  return RT_DIR_COMB;
83  }
84 
85  /* anything else is a solid? */
86  return RT_DIR_SOLID;
87 }
88 
89 
90 /** @} */
91 /*
92  * Local Variables:
93  * mode: C
94  * tab-width: 8
95  * indent-tabs-mode: t
96  * c-file-style: "stroustrup"
97  * End:
98  * ex: shiftwidth=4 tabstop=8
99  */
void bu_avs_init_empty(struct bu_attribute_value_set *avp)
Definition: avs.c:36
char region_flag
!0 ==> this COMB is a REGION
Definition: raytrace.h:939
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
Header file for the BRL-CAD common definitions.
#define RT_DIR_REGION
region
Definition: raytrace.h:885
#define ID_COMBINATION
Combination Record.
Definition: raytrace.h:499
const char * bu_avs_get(const struct bu_attribute_value_set *avp, const char *attribute)
Definition: avs.c:172
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define RT_DIR_NON_GEOM
object is not geometry (e.g. binary object)
Definition: raytrace.h:887
#define RT_DIR_SOLID
this name is a solid
Definition: raytrace.h:883
int db5_import_attributes(struct bu_attribute_value_set *avs, const struct bu_external *ap)
Definition: attributes.c:30
void * idb_ptr
Definition: raytrace.h:195
#define RT_DIR_COMB
combination
Definition: raytrace.h:884
int db_flags_internal(const struct rt_db_internal *intern)
Definition: db_flags.c:43
int db_flags_raw_internal(const struct db5_raw_internal *raw)
Definition: db_flags.c:61