Revision: 77698
http://sourceforge.net/p/brlcad/code/77698
Author: brlcad
Date: 2020-11-06 16:54:58 +0000 (Fri, 06 Nov 2020)
Log Message:
-----------
accept sf patch #556 (in database support for vol primitive) from sumagna das.
via the struct-parsing, this looks to be conveniently forwards-compatible and
backwards-compatible for the 'file' type data sources.
Modified Paths:
--------------
brlcad/trunk/include/rt/geom.h
brlcad/trunk/include/wdb.h
brlcad/trunk/src/libged/search/search.c
brlcad/trunk/src/libged/typein/typein.c
brlcad/trunk/src/librt/db_fullpath.c
brlcad/trunk/src/librt/primitives/vol/vol.c
brlcad/trunk/src/libwdb/vol.c
brlcad/trunk/src/mged/edsol.c
Modified: brlcad/trunk/include/rt/geom.h
===================================================================
--- brlcad/trunk/include/rt/geom.h 2020-11-06 06:05:16 UTC (rev 77697)
+++ brlcad/trunk/include/rt/geom.h 2020-11-06 16:54:58 UTC (rev 77698)
@@ -348,7 +348,7 @@
#define RT_VOL_NAME_LEN 128
struct rt_vol_internal {
uint32_t magic;
- char file[RT_VOL_NAME_LEN];
+ char name[RT_VOL_NAME_LEN];
/* NOTE: [xyz]dim/lo/hi cannot be size_t until rel8 as they are
* written out to disk via bu_vls_struct_print() as 32-bit ints.
*/
@@ -359,6 +359,10 @@
uint32_t hi; /**< @brief High threshold */
vect_t cellsize; /**< @brief ideal coords: size of each cell */
mat_t mat; /**< @brief convert local coords to model space */
+ struct rt_db_internal *bip; /* @brief db object for data*/
+#define RT_VOL_SRC_FILE 'f'
+#define RT_VOL_SRC_OBJ 'o'
+ char datasrc;/**< @brief which type of data source */
/* REMAINING ELEMENTS PROVIDED BY IMPORT, UNUSED BY EXPORT */
unsigned char *map;
};
Modified: brlcad/trunk/include/wdb.h
===================================================================
--- brlcad/trunk/include/wdb.h 2020-11-06 06:05:16 UTC (rev 77697)
+++ brlcad/trunk/include/wdb.h 2020-11-06 16:54:58 UTC (rev 77698)
@@ -648,7 +648,7 @@
/**
* 3-D Volume primitive.
*/
-WDB_EXPORT extern int mk_vol(struct rt_wdb *fp, const char *name, const char
*file,
+WDB_EXPORT extern int mk_vol(struct rt_wdb *fp, const char *name, char
datasrc, const char *file,
size_t xdim, size_t ydim, size_t zdim, size_t lo,
size_t hi,
const vect_t cellsize, const matp_t mat);
Modified: brlcad/trunk/src/libged/search/search.c
===================================================================
--- brlcad/trunk/src/libged/search/search.c 2020-11-06 06:05:16 UTC (rev
77697)
+++ brlcad/trunk/src/libged/search/search.c 2020-11-06 16:54:58 UTC (rev
77698)
@@ -38,6 +38,7 @@
#include "bu/getopt.h"
#include "bu/path.h"
#include "bu/sort.h"
+#include "bu/defines.h"
#include "../alphanum.h"
#include "../ged_private.h"
@@ -47,8 +48,13 @@
{
struct directory *dp1 = *(struct directory **)d1;
struct directory *dp2 = *(struct directory **)d2;
- int ret = alphanum_impl((const char *)dp2->d_namep, (const char
*)dp1->d_namep, arg);
- return ret;
+ if (dp1 == dp2)
+ return 0;
+ else if (!dp1)
+ return 1;
+ else if (!dp2)
+ return -1;
+ return alphanum_impl((const char *)dp2->d_namep, (const char
*)dp1->d_namep, arg);
}
struct fp_cmp_vls {
@@ -63,12 +69,23 @@
struct db_full_path *fp1 = *(struct db_full_path **)d1;
struct db_full_path *fp2 = *(struct db_full_path **)d2;
struct fp_cmp_vls *data = (struct fp_cmp_vls *)arg;
+
+ BU_ASSERT(data != NULL);
+
+ if (fp1 == fp2)
+ return 0;
+ else if (!fp1)
+ return 1;
+ else if (!fp2)
+ return -1;
+
bu_vls_trunc(data->left, 0);
bu_vls_trunc(data->right, 0);
+
db_fullpath_to_vls(data->left, fp1, data->dbip, data->print_verbose_info);
db_fullpath_to_vls(data->right, fp2, data->dbip, data->print_verbose_info);
- int ret = alphanum_impl(bu_vls_cstr(data->right), bu_vls_cstr(data->left),
arg);
- return ret;
+
+ return alphanum_impl(bu_vls_cstr(data->right), bu_vls_cstr(data->left),
arg);
}
Modified: brlcad/trunk/src/libged/typein/typein.c
===================================================================
--- brlcad/trunk/src/libged/typein/typein.c 2020-11-06 06:05:16 UTC (rev
77697)
+++ brlcad/trunk/src/libged/typein/typein.c 2020-11-06 16:54:58 UTC (rev
77698)
@@ -107,7 +107,8 @@
static const char *p_vol[] = {
- "Enter name of file containing voxel data: ",
+ "Take data from file or database binary object [f|o]: ",
+ "Enter name of file/object: ",
"Enter X, Y, Z dimensions of file (number of cells): ",
"Enter Y dimension of file (number of cells): ",
"Enter Z dimension of file (number of cells): ",
@@ -998,15 +999,23 @@
intern->idb_ptr = (void *)vol;
vol->magic = RT_VOL_INTERNAL_MAGIC;
- bu_strlcpy(vol->file, cmd_argvs[3], sizeof(vol->file));
- vol->xdim = atoi(cmd_argvs[4]);
- vol->ydim = atoi(cmd_argvs[5]);
- vol->zdim = atoi(cmd_argvs[6]);
- vol->lo = atoi(cmd_argvs[7]);
- vol->hi = atoi(cmd_argvs[8]);
- vol->cellsize[0] = atof(cmd_argvs[9]) *
gedp->ged_wdbp->dbip->dbi_local2base;
- vol->cellsize[1] = atof(cmd_argvs[10]) *
gedp->ged_wdbp->dbip->dbi_local2base;
- vol->cellsize[2] = atof(cmd_argvs[11]) *
gedp->ged_wdbp->dbip->dbi_local2base;
+ bu_strlcpy(vol->name, cmd_argvs[4], sizeof(vol->name));
+ vol->xdim = atoi(cmd_argvs[5]);
+ vol->ydim = atoi(cmd_argvs[6]);
+ vol->zdim = atoi(cmd_argvs[7]);
+ vol->lo = atoi(cmd_argvs[8]);
+ vol->hi = atoi(cmd_argvs[9]);
+ vol->cellsize[0] = atof(cmd_argvs[10]) *
gedp->ged_wdbp->dbip->dbi_local2base;
+ vol->cellsize[1] = atof(cmd_argvs[11]) *
gedp->ged_wdbp->dbip->dbi_local2base;
+ vol->cellsize[2] = atof(cmd_argvs[12]) *
gedp->ged_wdbp->dbip->dbi_local2base;
+
+ if (*cmd_argvs[3] == 'f' || *cmd_argvs[3] == 'F')
+ vol->datasrc = RT_VOL_SRC_FILE;
+ else if (*cmd_argvs[3] == 'o' || *cmd_argvs[3] == 'O')
+ vol->datasrc = RT_VOL_SRC_OBJ;
+ else
+ return GED_ERROR;
+
MAT_IDN(vol->mat);
return GED_OK;
@@ -3206,7 +3215,7 @@
menu = p_submodel;
fn_in = submodel_in;
} else if (BU_STR_EQUAL(argv[2], "vol")) {
- nvals = 9;
+ nvals = 10;
menu = p_vol;
fn_in = vol_in;
} else if (BU_STR_EQUAL(argv[2], "hf")) {
Modified: brlcad/trunk/src/librt/db_fullpath.c
===================================================================
--- brlcad/trunk/src/librt/db_fullpath.c 2020-11-06 06:05:16 UTC (rev
77697)
+++ brlcad/trunk/src/librt/db_fullpath.c 2020-11-06 16:54:58 UTC (rev
77698)
@@ -257,13 +257,13 @@
int type;
const struct bn_tol tol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST *
BN_TOL_DIST, 1e-6, 1.0 - 1e-6 };
- if (!full_path)
+ if (!full_path || full_path->fp_len == 0)
return;
BU_CK_VLS(vls);
RT_CK_FULL_PATH(full_path);
- if (!full_path->fp_names) {
+ if (full_path->fp_names == NULL) {
bu_vls_strcat(vls, "**NULL**");
return;
}
Modified: brlcad/trunk/src/librt/primitives/vol/vol.c
===================================================================
--- brlcad/trunk/src/librt/primitives/vol/vol.c 2020-11-06 06:05:16 UTC (rev
77697)
+++ brlcad/trunk/src/librt/primitives/vol/vol.c 2020-11-06 16:54:58 UTC (rev
77698)
@@ -65,7 +65,9 @@
#define VOL_O(m) bu_offsetof(struct rt_vol_internal, m)
const struct bu_structparse rt_vol_parse[] = {
- {"%s", RT_VOL_NAME_LEN, "file", bu_offsetof(struct rt_vol_internal, file),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%s", RT_VOL_NAME_LEN, "file", bu_offsetof(struct rt_vol_internal, name),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%s", RT_VOL_NAME_LEN, "name", bu_offsetof(struct rt_vol_internal, name),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%c", 1, "src", VOL_O(datasrc), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "w", VOL_O(xdim), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "n", VOL_O(ydim), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "d", VOL_O(zdim), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
@@ -79,7 +81,8 @@
extern void rt_vol_plate(point_t a, point_t b, point_t c, point_t d,
mat_t mat, struct bu_list *vhead, struct
rt_vol_internal *vip);
-
+extern int rt_retrieve_binunif(struct rt_db_internal *intern, const struct
db_i *dbip, const char *name);
+extern int rt_binunif_describe(struct bu_vls *str, const struct
rt_db_internal *ip, int verbose, double mm2local);
/*
* Codes to represent surface normals.
* In a bitmap, there are only 4 possible normals.
@@ -115,7 +118,6 @@
static int rt_vol_normtab[3] = { NORM_XPOS, NORM_YPOS, NORM_ZPOS };
-
/**
* Transform the ray into local coordinates of the volume ("ideal space").
* Step through the 3-D array, in local coordinates.
@@ -472,7 +474,7 @@
bu_vls_free(&str);
/* Check for reasonable values */
- if (vip->file[0] == '\0' || vip->xdim < 1 ||
+ if (vip->name[0] == '\0' || vip->xdim < 1 ||
vip->ydim < 1 || vip->zdim < 1 || vip->mat[15] <= 0.0 ||
vip->hi > 255) {
bu_struct_print("Unreasonable VOL parameters", rt_vol_parse,
@@ -492,8 +494,8 @@
vip->map = (unsigned char *)bu_calloc(1, nbytes, "vol_import4 bitmap");
bu_semaphore_acquire(BU_SEM_SYSCALL); /* lock */
- if ((fp = fopen(vip->file, "rb")) == NULL) {
- perror(vip->file);
+ if ((fp = fopen(vip->name, "rb")) == NULL) {
+ perror(vip->name);
bu_semaphore_release(BU_SEM_SYSCALL); /* unlock */
return -1;
}
@@ -508,7 +510,7 @@
bu_semaphore_release(BU_SEM_SYSCALL); /* unlock */
if (ret < 1) {
bu_log("rt_vol_import4(%s): Unable to read whole VOL, y=%zu,
z=%zu\n",
- vip->file, y, z);
+ vip->name, y, z);
bu_semaphore_acquire(BU_SEM_SYSCALL); /* lock */
fclose(fp);
bu_semaphore_release(BU_SEM_SYSCALL); /* unlock */
@@ -612,6 +614,163 @@
/**
+ * Read VOL data from external file
+ * Returns :
+ * 0 success
+ * !0 fail
+ */
+static int
+vol_file_data(struct rt_vol_internal *vip)
+{
+ size_t nbytes;
+
+ size_t bytes = vip->xdim * vip->ydim * vip->zdim;
+ nbytes = vol_from_file(vip->name, vip->xdim, vip->ydim, vip->zdim,
&vip->map);
+ if (nbytes != bytes) {
+ bu_log("WARNING: unexpected VOL bytes (read %zu, expected %zu) in
%s\n", nbytes, bytes, vip->name);
+ }
+
+ return 0;
+}
+
+
+/**
+ * Read VOL data from in database object
+ * Returns :
+ * 0 success
+ * !0 fail
+ */
+static int
+get_obj_data(struct rt_vol_internal *vip, const struct db_i *dbip)
+{
+ struct rt_binunif_internal *bip;
+ int ret;
+ int nbytes;
+
+ BU_ALLOC(vip->bip, struct rt_db_internal);
+
+ ret = rt_retrieve_binunif(vip->bip, dbip, vip->name);
+ if (ret)
+ return -1;
+
+ if (RT_G_DEBUG & RT_DEBUG_HF) {
+ bu_log("db_internal magic: 0x%08x major: %d minor: %d\n",
+ vip->bip->idb_magic,
+ vip->bip->idb_major_type,
+ vip->bip->idb_minor_type);
+ }
+
+ bip = (struct rt_binunif_internal *)vip->bip->idb_ptr;
+
+ if (RT_G_DEBUG & RT_DEBUG_HF)
+ bu_log("binunif magic: 0x%08x type: %d count:%zu data[0]:%u\n",
+ bip->magic, bip->type, bip->count, bip->u.uint8[0]);
+
+ if (bip->type != DB5_MINORTYPE_BINU_8BITINT_U
+ || (size_t)bip->count != (size_t)(vip->xdim*vip->ydim*vip->zdim))
+ {
+ size_t i = 0;
+ size_t size;
+ struct bu_vls binudesc = BU_VLS_INIT_ZERO;
+ rt_binunif_describe(&binudesc, vip->bip, 0, dbip->dbi_base2local);
+
+ /* skip the first title line*/
+ size = bu_vls_strlen(&binudesc);
+ while (size > 0 && i < size && bu_vls_cstr(&binudesc)[0] != '\n') {
+ bu_vls_nibble(&binudesc, 1);
+ }
+ if (bu_vls_cstr(&binudesc)[0] == '\n')
+ bu_vls_nibble(&binudesc, 1);
+
+ bu_log("ERROR: Binary object '%s' has invalid data (expected type %d,
found %d).\n"
+ " Expecting %zu 8-bit unsigned char (nuc) integer data
values.\n"
+ " Encountered %s\n",
+ vip->name,
+ DB5_MINORTYPE_BINU_8BITINT_U,
+ bip->type,
+ (size_t)(vip->xdim*vip->ydim*vip->zdim),
+ bu_vls_cstr(&binudesc));
+ return -2;
+ }
+
+ nbytes =
(vip->xdim+VOL_XWIDEN*2)*(vip->ydim+VOL_YWIDEN*2)*(vip->zdim+VOL_ZWIDEN*2);
+
+ size_t y, z;
+ if (!vip->map) {
+ unsigned char* cp;
+
+ vip->map = (unsigned char *)bu_calloc(1, nbytes, "vol_import4 bitmap");
+ cp = (unsigned char *)bip->u.uint8;
+
+ for (z = 0; z < vip->zdim; z++) {
+ for (y = 0; y < vip->ydim; y++) {
+ void *data = &VOLMAP(vip->map, vip->xdim, vip->ydim, 0, y, z);
+
+ memcpy(data, cp, vip->xdim);
+ cp+= vip->xdim;
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * Retrieve VOL data from data source
+ * Returns :
+ * 0 success
+ * !0 fail
+ */
+static int
+get_vol_data(struct rt_vol_internal *vip, const mat_t mat, const struct db_i
*dbip)
+{
+ mat_t tmp;
+ char *p;
+
+ /* Apply Modelling transform */
+ bn_mat_mul(tmp, mat, vip->mat);
+ MAT_COPY(vip->mat, tmp);
+ p = vip->name;
+
+ switch (vip->datasrc) {
+case RT_VOL_SRC_FILE:
+ /* Retrieve the data from an external file */
+ if (RT_G_DEBUG & RT_DEBUG_HF)
+ bu_log("getting data from file \"%s\"\n", p);
+
+ if(vol_file_data(vip) != 0) {
+ return 1;
+ p = "file";
+ }
+ else {
+ return 0;
+ }
+ break;
+case RT_VOL_SRC_OBJ:
+ /* Retrieve the data from an internal db object */
+ if (RT_G_DEBUG & RT_DEBUG_HF)
+ bu_log("getting data from object \"%s\"\n", p);
+
+ if (get_obj_data(vip, dbip) != 0) {
+ p = "object";
+ return 1;
+ } else {
+ RT_CK_DB_INTERNAL(vip->bip);
+ RT_CK_BINUNIF(vip->bip->idb_ptr);
+ return 0;
+ }
+ break;
+default:
+bu_log("%s:%d Odd vol data src '%c' s/b '%c' or '%c'\n",
+ __FILE__, __LINE__, vip->datasrc,
+ RT_VOL_SRC_FILE, RT_VOL_SRC_OBJ);
+ }
+
+ bu_log("%s", dbip->dbi_filename);
+ return 0; //temporary
+}
+
+
+/**
* Read in the information from the string solid record.
* Then, as a service to the application, read in the bitmap
* and set up some of the associated internal variables.
@@ -621,7 +780,6 @@
{
register struct rt_vol_internal *vip;
struct bu_vls str = BU_VLS_INIT_ZERO;
- size_t nbytes;
mat_t tmat;
if (dbip) RT_CK_DBI(dbip);
@@ -651,9 +809,8 @@
return -2;
}
bu_vls_free(&str);
-
/* Check for reasonable values */
- if (vip->file[0] == '\0'
+ if (vip->name[0] == '\0'
|| vip->xdim < 1 || vip->ydim < 1 || vip->zdim < 1
|| vip->mat[15] <= 0.0 || vip->hi > 255)
{
@@ -668,15 +825,8 @@
bn_mat_mul(tmat, mat, vip->mat);
MAT_COPY(vip->mat, tmat);
- if (bu_file_exists(vip->file, NULL)) {
- size_t bytes = vip->xdim * vip->ydim * vip->zdim;
- nbytes = vol_from_file(vip->file, vip->xdim, vip->ydim, vip->zdim,
&vip->map);
- if (nbytes != bytes) {
- bu_log("WARNING: unexpected VOL bytes (read %zu, expected %zu) in
%s\n", nbytes, bytes, vip->file);
- }
- } else {
- bu_log("WARNING: VOL data file missing [%s]\n", vip->file);
- }
+ if (get_vol_data(vip, mat, dbip) == 1)
+ bu_log("Couldn't find the associated file/object %s",vip->name);
return 0;
}
@@ -735,10 +885,18 @@
/* pretty-print dimensions in local, not storage (mm) units */
VSCALE(local, vip->cellsize, mm2local);
+ if (vip->datasrc == RT_VOL_SRC_FILE) {
bu_vls_printf(&substr, "\tfile=\"%s\"\n\tw=%u n=%u d=%u\n\tlo=%u
hi=%u\n\tsize=%g,%g,%g\n",
- vip->file,
+ vip->name,
vip->xdim, vip->ydim, vip->zdim, vip->lo, vip->hi,
V3INTCLAMPARGS(local));
+ } else {
+ bu_vls_printf(&substr, "\tobject name=\"%s\"\n\tw=%u n=%u d=%u\n\tlo=%u
hi=%u\n\tsize=%g,%g,%g\n",
+ vip->name,
+ vip->xdim, vip->ydim, vip->zdim, vip->lo, vip->hi,
+ V3INTCLAMPARGS(local));
+ }
+
bu_vls_vlscat(str, &substr);
bu_vls_strcat(str, "\tmat=");
@@ -868,7 +1026,7 @@
register const struct rt_vol_specific *volp =
(struct rt_vol_specific *)stp->st_specific;
- bu_log("vol file = %s\n", volp->vol_i.file);
+ bu_log("vol file = %s\n", volp->vol_i.name);
bu_log("dimensions = (%u, %u, %u)\n",
volp->vol_i.xdim, volp->vol_i.ydim,
volp->vol_i.zdim);
Modified: brlcad/trunk/src/libwdb/vol.c
===================================================================
--- brlcad/trunk/src/libwdb/vol.c 2020-11-06 06:05:16 UTC (rev 77697)
+++ brlcad/trunk/src/libwdb/vol.c 2020-11-06 16:54:58 UTC (rev 77698)
@@ -35,8 +35,9 @@
int
-mk_vol(struct rt_wdb *fp, const char *name, const char *file, size_t xdim,
size_t ydim, size_t zdim, size_t lo, size_t hi, const fastf_t *cellsize, const
matp_t mat)
- /* name of file containing bitmap */
+mk_vol(struct rt_wdb *fp, const char *name, char datasrc, const char *file,
size_t xdim, size_t ydim, size_t zdim, size_t lo, size_t hi, const fastf_t
*cellsize, const matp_t mat)
+ /* type of data source */
+ /* name of file/object containing bitmap */
/* X dimension of file (w cells) */
/* Y dimension of file (n cells) */
/* Z dimension of file (d cells) */
@@ -49,7 +50,8 @@
BU_ALLOC(vol, struct rt_vol_internal);
vol->magic = RT_VOL_INTERNAL_MAGIC;
- bu_strlcpy(vol->file, file, RT_VOL_NAME_LEN);
+ vol->datasrc = datasrc;
+ bu_strlcpy(vol->name, file, RT_VOL_NAME_LEN);
vol->xdim = xdim;
vol->ydim = ydim;
vol->zdim = zdim;
Modified: brlcad/trunk/src/mged/edsol.c
===================================================================
--- brlcad/trunk/src/mged/edsol.c 2020-11-06 06:05:16 UTC (rev 77697)
+++ brlcad/trunk/src/mged/edsol.c 2020-11-06 16:54:58 UTC (rev 77698)
@@ -4135,14 +4135,14 @@
RT_VOL_CK_MAGIC(vol);
if (inpara == 3) {
- if (stat(vol->file, &stat_buf)) {
- Tcl_AppendResult(INTERP, "Cannot get status of file ",
vol->file, (char *)NULL);
+ if (stat(vol->name, &stat_buf)) {
+ Tcl_AppendResult(INTERP, "Cannot get status of file ",
vol->name, (char *)NULL);
mged_print_result(TCL_ERROR);
return;
}
need_size = es_para[0] * es_para[1] * es_para[2] *
sizeof(unsigned char);
if (stat_buf.st_size < need_size) {
- Tcl_AppendResult(INTERP, "File (", vol->file,
+ Tcl_AppendResult(INTERP, "File (", vol->name,
") is too small, set file name first",
(char *)NULL);
mged_print_result(TCL_ERROR);
return;
@@ -4220,7 +4220,7 @@
RT_VOL_CK_MAGIC(vol);
- fname = get_file_name(vol->file);
+ fname = get_file_name(vol->name);
if (fname) {
struct bu_vls message = BU_VLS_INIT_ZERO;
@@ -4239,7 +4239,7 @@
mged_print_result(TCL_ERROR);
return;
}
- bu_strlcpy(vol->file, fname, RT_VOL_NAME_LEN);
+ bu_strlcpy(vol->name, fname, RT_VOL_NAME_LEN);
}
break;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits