/* * Given that the color table has been built up by successive calls * to rt_color_addrec(), write it into the database. */ int mk_write_color_table( struct rt_wdb *ofp ) { RT_CK_WDB(ofp); if ( ofp->dbip->dbi_version <= 4 ) { register const struct mater *mp; BU_ASSERT_LONG( mk_version, ==, 4 ); for ( mp = rt_material_head(); mp != MATER_NULL; mp = mp->mt_forw ) { #if 0 union record record; record.md.md_id = ID_MATERIAL; record.md.md_flags = 0; record.md.md_low = mp->mt_low; record.md.md_hi = mp->mt_high; record.md.md_r = mp->mt_r; record.md.md_g = mp->mt_g; record.md.md_b = mp->mt_b; /* This record has no name field! */ /* XXX examine mged/mater.c: color_putrec() */ /* Write out the record */ (void)fwrite( (char *)&record, sizeof record, 1, ofpxx ); #else bu_log("mk_write_color_table(): not implemented for v4 database yet\n"); #endif } } else { return db5_put_color_table( ofp->dbip );
/* * Supports for the 'keep' method. * Write each node encountered exactly once. */ HIDDEN void node_write(struct db_i *dbip, struct directory *dp, void *ptr) { struct keep_node_data *kndp = (struct keep_node_data *)ptr; struct rt_db_internal intern; RT_CK_WDB(kndp->wdbp); if (dp->d_nref++ > 0) return; /* already written */ if (rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource) < 0) { bu_vls_printf(kndp->gedp->ged_result_str, "Database read error, aborting\n"); return; } if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_EXTRUDE) { /* if this is an extrusion, keep the referenced sketch */ struct rt_extrude_internal *extr; struct directory *dp2; extr = (struct rt_extrude_internal *)intern.idb_ptr; RT_EXTRUDE_CK_MAGIC(extr); if ((dp2 = db_lookup(dbip, extr->sketch_name, LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } else if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_REVOLVE) { /* if this is a revolve, keep the referenced sketch */ struct rt_revolve_internal *rev; struct directory *dp2; rev = (struct rt_revolve_internal *)intern.idb_ptr; RT_REVOLVE_CK_MAGIC(rev); if ((dp2 = db_lookup(dbip, bu_vls_addr(&rev->sketch_name), LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } else if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_DSP) { /* if this is a DSP, keep the referenced binary object too */ struct rt_dsp_internal *dsp; struct directory *dp2; dsp = (struct rt_dsp_internal *)intern.idb_ptr; RT_DSP_CK_MAGIC(dsp); if (dsp->dsp_datasrc == RT_DSP_SRC_OBJ) { /* need to keep this object */ if ((dp2 = db_lookup(dbip, bu_vls_addr(&dsp->dsp_name), LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } } if (wdb_put_internal(kndp->wdbp, dp->d_namep, &intern, 1.0) < 0) { bu_vls_printf(kndp->gedp->ged_result_str, "Database write error, aborting\n"); return; } }
int mk_id_editunits( struct rt_wdb *wdbp, const char *title, double local2mm) { RT_CK_WDB(wdbp); return db_update_ident(wdbp->dbip, title, local2mm); }
/** * Creates one metaball object with 'count' random points using * LIBWDB's mk_metaball() interface. */ static void make_meatballs(struct rt_wdb *fp, const char *name, long count) { static float *ctx; /* random context */ static const int method = 1; /* 1==ISO */ static const fastf_t threshold = 1.0; static const fastf_t SZ = 1000.0; long i; fastf_t **pts; RT_CK_WDB(fp); bn_rand_init(ctx, rand()); bu_log("Creating [%s] object with %ld random point%s\n", name, count, count > 1 ? "s" : ""); /* allocate a dynamic array of pointers to points. this may be * subject to change but is presently the format mk_metaball() * wants. */ pts = (fastf_t **)bu_calloc(count, sizeof(fastf_t*), "alloc metaball pts array"); for (i=0; i < count; i++) { pts[i] = (fastf_t *)bu_malloc(sizeof(fastf_t)*5, "alloc metaball point"); } /* create random metaball point values positioned randomly within * a cube with random field strengths. */ for (i=0; i < count; i++) { /* just for explicit clarity */ fastf_t x = bn_rand_half(ctx) * SZ; fastf_t y = bn_rand_half(ctx) * SZ; fastf_t z = bn_rand_half(ctx) * SZ; fastf_t field_strength = bn_rand0to1(ctx) * SZ / (2.0 * sqrt(count)); VSET(pts[i], x, y, z); pts[i][3] = field_strength; /* something blobbly random */ pts[i][4] = 0.0; /* sweat/goo field is unused with iso method */ } /* pack the meat, create the metaball */ mk_metaball(fp, name, count, method, threshold, (const fastf_t **)pts); /* free up our junk */ for (i=0; i < count; i++) { bu_free(pts[i], "dealloc metaball point"); } bu_free(pts, "dealloc metaball pts array"); }
int db_dump(struct rt_wdb *wdbp, struct db_i *dbip) /* output */ /* input */ { register int i; register struct directory *dp; struct bu_external ext; RT_CK_DBI(dbip); RT_CK_WDB(wdbp); /* just in case since we don't actually handle it below */ if (db_version(dbip) != db_version(wdbp->dbip)) { bu_log("Internal Error: dumping a v%d database into a v%d database is untested\n", db_version(dbip), db_version(wdbp->dbip)); return -1; } /* Output all directory entries */ for (i = 0; i < RT_DBNHASH; i++) { for (dp = dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) { RT_CK_DIR(dp); /* XXX Need to go to internal form, if database versions don't match */ if (db_get_external(&ext, dp, dbip) < 0) { bu_log("db_dump() read failed on %s, skipping\n", dp->d_namep); continue; } if (wdb_export_external(wdbp, &ext, dp->d_namep, dp->d_flags & ~(RT_DIR_INMEM), dp->d_minor_type) < 0) { bu_log("db_dump() write failed on %s, aborting\n", dp->d_namep); bu_free_external(&ext); return -1; } bu_free_external(&ext); } } return 0; }