BRL-CAD
prcomb.c
Go to the documentation of this file.
1 /* P R C O M B . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1996-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 /** @file librt/prcomb.c
21  *
22  */
23 
24 #include "common.h"
25 
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <math.h>
29 #include <string.h>
30 
31 
32 #include "vmath.h"
33 #include "bn.h"
34 #include "rtgeom.h"
35 #include "raytrace.h"
36 
37 
38 /* --- Begin John's pretty-printer --- */
39 
40 void
42 {
43  char *str;
44 
45  str = (char *)rt_pr_tree_str(tree);
46  if (str != NULL) {
47  printf("%s\n", str);
48  bu_free(str, "Print_tree");
49  } else
50  printf("NULL Tree\n");
51 }
52 
53 
54 int
55 main(int argc, char *argv[])
56 {
57  struct db_i *dbip;
58  struct directory *dp;
59  struct rt_db_internal ip;
60  struct rt_comb_internal *comb;
61  mat_t identity_mat;
62  int i;
63 
65 
66  if (argc < 3) {
67  fprintf(stderr, "Usage:\n\t%s db_file object1 object2 ...\n", argv[0]);
68  return 1;
69  }
70 
71  MAT_IDN(identity_mat);
72 
73  if ((dbip = db_open(argv[1], DB_OPEN_READONLY)) == NULL) {
74  fprintf(stderr, "Cannot open geometry database file %s\n", argv[1]);
75  perror("test");
76  return 1;
77  }
78 
79  /* Scan the database */
80  db_dirbuild(dbip);
81 
82  for (i=2; i<argc; i++) {
83  printf("%s\n", argv[i]);
84 
85  dp = db_lookup(dbip, argv[i], 1);
86  if (!dp) {
87  bu_log("WARNING: Unable to locate %s in %s, skipping\n", argv[i], argv[1]);
88  continue;
89  }
90 
91  if (rt_db_get_internal(&ip, dp, dbip, NULL, &rt_uniresource) < 0) {
92  bu_log("import of %s failed\n", dp->d_namep);
93  continue;
94  }
95 
96  RT_CK_DB_INTERNAL(&ip);
98 
99  if (ip.idb_type != ID_COMBINATION) {
100  bu_log("idb_type = %d\n", ip.idb_type);
101  rt_db_free_internal(&ip);
102  continue;
103  }
104 
105  comb = (struct rt_comb_internal *)ip.idb_ptr;
106  RT_CK_COMB(comb);
107  if (comb->region_flag) {
108  bu_log("\tRegion id = %d, aircode = %d GIFTmater = %d, los = %d\n",
109  comb->region_id, comb->aircode, comb->GIFTmater, comb->los);
110  }
111  bu_log("\trgb_valid = %d, color = %d/%d/%d\n", comb->rgb_valid, V3ARGS(comb->rgb));
112  bu_log("\tshader = %s (%s)\n" ,
113  bu_vls_addr(&comb->shader),
114  bu_vls_addr(&comb->material)
115  );
116 
117  /* John's way */
118  bu_log("Pretty print:\n");
119  Print_tree(comb->tree);
120 
121  /* Standard way */
122  bu_log("Standard print:\n");
123  rt_pr_tree(comb->tree, 1);
124 
125  /* Compact way */
126  {
127  struct bu_vls str = BU_VLS_INIT_ZERO;
128  rt_pr_tree_vls(&str, comb->tree);
129  bu_log("%s\n", bu_vls_addr(&str));
130  bu_vls_free(&str);
131  }
132 
133  /* Test the support routines */
134  if (db_ck_v4gift_tree(comb->tree) < 0)
135  bu_log("ERROR: db_ck_v4gift_tree is unhappy\n");
136 
137  /* Test the lumberjacks */
138  rt_db_free_internal(&ip);
139 
140  }
141 
142  return 0;
143 }
144 
145 
146 /*
147  * Local Variables:
148  * mode: C
149  * tab-width: 8
150  * indent-tabs-mode: t
151  * c-file-style: "stroustrup"
152  * End:
153  * ex: shiftwidth=4 tabstop=8
154  */
int main(int argc, char *argv[])
Definition: prcomb.c:55
char * d_namep
pointer to name string
Definition: raytrace.h:859
Definition: raytrace.h:800
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
Definition: dir.c:76
char region_flag
!0 ==> this COMB is a REGION
Definition: raytrace.h:939
#define BU_DEBUG_MEM_CHECK
Definition: debug.h:54
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
Header file for the BRL-CAD common definitions.
void rt_pr_tree_vls(struct bu_vls *vls, const union tree *tp)
unsigned char rgb[3]
Definition: raytrace.h:948
#define ID_COMBINATION
Combination Record.
Definition: raytrace.h:499
void rt_pr_tree(const union tree *tp, int lvl)
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define V3ARGS(a)
Definition: color.c:56
struct bu_vls shader
Definition: raytrace.h:950
void Print_tree(union tree *tree)
Definition: prcomb.c:41
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls material
Definition: raytrace.h:951
int bu_mem_barriercheck(void)
Definition: malloc.c:660
#define BU_DEBUG_COREDUMP
Definition: debug.h:53
int bu_debug
Definition: globals.c:87
void * idb_ptr
Definition: raytrace.h:195
union tree * tree
Leading to tree_db_leaf leaves.
Definition: raytrace.h:938
#define DB_OPEN_READONLY
Definition: raytrace.h:3550
char * rt_pr_tree_str(const union tree *tree)
Definition: pr.c:460
struct db_i * db_open(const char *name, const char *mode)
Definition: db_open.c:59
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
char rgb_valid
!0 ==> rgb[] has valid color
Definition: raytrace.h:947
int db_dirbuild(struct db_i *dbip)
Definition: db5_scan.c:301
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
Definition: vls.h:56
int db_ck_v4gift_tree(const union tree *tp)
Definition: db_comb.c:927
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216