-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating basic type command for VDB #89
base: vdb
Are you sure you want to change the base?
Changes from 3 commits
1718390
2cc02d9
2dbae76
84e1149
2a23f83
203d497
bbe83dc
5f6dd18
96cbd50
bb53683
08716b5
e270334
a3cf433
2d44086
e7c4455
3e4936e
278b1d6
cfdc624
7ec838d
1c2a949
c271e5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
#include <set> | ||
#include <string> | ||
#include <vector> | ||
#include <iterator> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that because I was getting an error on line 261 and 262: error C2039: 'inserter': is not a member of 'std'. That was fixed by adding the include. |
||
|
||
#include "bu/app.h" | ||
#include "bu/cmd.h" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
#include "common.h" | ||
|
||
#include <stddef.h> | ||
#include <string.h> | ||
#include <math.h> | ||
#include "bio.h" | ||
|
||
#include "bu/cv.h" | ||
#include "vmath.h" | ||
#include "rt/db4.h" | ||
#include "nmg.h" | ||
#include "rt/geom.h" | ||
#include "raytrace.h" | ||
|
||
#include "../../librt_private.h" | ||
|
||
|
||
// Initially with a bounding box, later with vdb | ||
struct vdb_specific { | ||
vect_t minBB; | ||
vect_t maxBB; | ||
|
||
}; | ||
|
||
int rt_vdb_import5(struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip) | ||
{ | ||
|
||
struct rt_vdb_internal *eip; | ||
|
||
/* must be double for import and export */ | ||
double vec[ELEMENTS_PER_VECT * 2]; // min and max = 2 | ||
|
||
if (dbip) RT_CK_DBI(dbip); | ||
RT_CK_DB_INTERNAL(ip); | ||
BU_CK_EXTERNAL(ep); | ||
|
||
BU_ASSERT(ep->ext_nbytes == SIZEOF_NETWORK_DOUBLE * ELEMENTS_PER_VECT * 2); // min and max = 2 | ||
|
||
ip->idb_major_type = DB5_MAJORTYPE_BRLCAD; | ||
ip->idb_type = ID_VDB; | ||
ip->idb_meth = &OBJ[ID_VDB]; | ||
BU_ALLOC(ip->idb_ptr, struct rt_vdb_internal); | ||
|
||
eip = (struct rt_vdb_internal *)ip->idb_ptr; | ||
eip->magic = RT_VDB_INTERNAL_MAGIC; | ||
|
||
/* Convert from database (network) to internal (host) format */ | ||
bu_cv_ntohd((unsigned char *)vec, ep->ext_buf, ELEMENTS_PER_VECT * 2); // min and max = 2 | ||
|
||
/* Apply modeling transformations */ | ||
mat = bn_mat_identity; | ||
MAT4X3PNT(eip->minBB, mat, &vec[0 * ELEMENTS_PER_VECT]); | ||
MAT4X3VEC(eip->maxBB, mat, &vec[1 * ELEMENTS_PER_VECT]); | ||
|
||
//bu_log("min eip: %g %g %g \n", eip->minBB[0], eip->minBB[1], eip->minBB[2]); | ||
//bu_log("max eip: %g %g %g \n", eip->maxBB[0], eip->maxBB[1], eip->maxBB[2]); | ||
|
||
//bu_log("min vec: %g %g %g \n", vec[0], vec[1], vec[2]); | ||
//bu_log("max vec: %g %g %g \n", vec[1], vec[4], vec[5]); | ||
|
||
|
||
return 0; /* OK */ | ||
} | ||
|
||
/** | ||
* The external format is: min vector and max vector | ||
* later it will be a vdb | ||
*/ | ||
int rt_vdb_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip) | ||
{ | ||
struct rt_vdb_internal *eip; | ||
|
||
/* must be double for import and export */ | ||
double vec[ELEMENTS_PER_VECT * 2]; | ||
|
||
if (dbip) RT_CK_DBI(dbip); | ||
|
||
RT_CK_DB_INTERNAL(ip); | ||
if (ip->idb_type != ID_VDB) return -1; | ||
eip = (struct rt_vdb_internal *)ip->idb_ptr; | ||
RT_VDB_CK_MAGIC(eip); | ||
|
||
BU_CK_EXTERNAL(ep); | ||
ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * ELEMENTS_PER_VECT * 2; | ||
ep->ext_buf = (uint8_t *)bu_malloc(ep->ext_nbytes, "vdb external"); | ||
|
||
/* scale 'em into local buffer */ | ||
VSCALE(&vec[0 * ELEMENTS_PER_VECT], eip->minBB, local2mm); | ||
VSCALE(&vec[1 * ELEMENTS_PER_VECT], eip->maxBB, local2mm); | ||
|
||
|
||
/* Convert from internal (host) to database (network) format */ | ||
bu_cv_htond(ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT * 2); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* Compute the bounding | ||
*/ | ||
int | ||
rt_vdb_bbox(struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *UNUSED(tol)) { | ||
|
||
struct rt_vdb_internal *eip = (struct rt_vdb_internal *)ip->idb_ptr; | ||
RT_VDB_CK_MAGIC(eip); | ||
|
||
|
||
(*min)[X] = eip->minBB[X]; | ||
(*max)[X] = eip->maxBB[X]; | ||
|
||
(*min)[Y] = eip->minBB[Y]; | ||
(*max)[Y] = eip->maxBB[Y]; | ||
|
||
(*min)[Z] = eip->minBB[Z]; | ||
(*max)[Z] = eip->maxBB[Z]; | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int rt_vdb_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip) | ||
{ | ||
register struct vdb_specific *vdb; | ||
struct rt_vdb_internal *eip2; | ||
|
||
eip2 = (struct rt_vdb_internal *)ip->idb_ptr; | ||
RT_VDB_CK_MAGIC(eip2); | ||
|
||
|
||
|
||
/* Solid is OK, compute constant terms now */ | ||
BU_GET(vdb, struct vdb_specific); | ||
stp->st_specific = (void *)vdb; | ||
|
||
VMOVE(vdb->minBB, eip2->minBB); | ||
VMOVE(vdb->maxBB, eip2->maxBB); | ||
/*fprintf(stderr, "bb %lf %lf\n", eip2->minBB, eip2->maxBB); | ||
fprintf(stderr, "bb2 %lf %lf\n", vdb->minBB, vdb->maxBB);*/ | ||
//bu_log("eip min: %g %g %g \n", eip2->minBB[0], eip2->minBB[1], eip2->minBB[2]); | ||
//bu_log("eip max: %g %g %g \n", eip2->maxBB[0], eip2->maxBB[1], eip2->maxBB[2]); | ||
// | ||
//bu_log("min vec: %g %g %g \n", vdb->minBB[0], vdb->minBB[1], vdb->minBB[2]); | ||
//bu_log("max vec: %g %g %g \n", vdb->maxBB[0], vdb->maxBB[1], vdb->maxBB[2]); | ||
|
||
|
||
/* Compute bounding sphere */ | ||
vect_t center; | ||
VSUB2(center, eip2->maxBB, eip2->minBB); | ||
VMOVE(stp->st_center, center); | ||
|
||
stp->st_aradius = stp->st_bradius = 3.4f; | ||
|
||
if (rt_vdb_bbox(ip, &(stp->st_min), &(stp->st_max), &rtip->rti_tol)) return 1; | ||
|
||
return 0; /* OK */ | ||
} | ||
|
||
|
||
/** | ||
* Intersect a ray with an the bouding box - later it will be with vdb | ||
* Returns - | ||
* 0 MISS | ||
* >0 HIT | ||
*/ | ||
int | ||
rt_vdb_shot(struct soltab *stp, register struct xray *rp, struct application *ap, struct seg *seghead) | ||
{ | ||
//fprintf(stderr, "shot\n"); | ||
register struct vdb_specific *vdb = | ||
(struct vdb_specific *)stp->st_specific; | ||
register struct seg *segp; | ||
|
||
fastf_t tmin, tmax, tymin, tymax, tzmin, tzmax; | ||
int sign[3]; | ||
|
||
sign[0] = ((1.0/ rp->r_dir[0]) < 0); | ||
sign[1] = ((1.0/ rp->r_dir[1]) < 0); | ||
sign[2] = ((1.0/ rp->r_dir[2]) < 0); | ||
|
||
vect_t bounds[2]; | ||
VMOVE(bounds[0], vdb->minBB); | ||
VMOVE(bounds[1], vdb->maxBB); | ||
|
||
/*bu_log("min vec: %g %g %g \n", vdb->minBB[0], vdb->minBB[1], vdb->minBB[2]); | ||
bu_log("max vec: %g %g %g \n", vdb->maxBB[0], vdb->maxBB[1], vdb->maxBB[2]);*/ | ||
|
||
tmin = (bounds[sign[0]][0] - rp->r_pt[0]) * (1.0 / rp->r_dir[0]); | ||
tmax = (bounds[1 - sign[0]][0] - rp->r_pt[0]) * (1.0 / rp->r_dir[0]); | ||
tymin = (bounds[sign[1]][1] - rp->r_pt[1]) * (1.0 / rp->r_dir[1]); | ||
tymax = (bounds[1 - sign[1]][1] - rp->r_pt[1]) * (1.0 / rp->r_dir[1]); | ||
|
||
if ((tmin > tymax) || (tymin > tmax)) | ||
return 0; | ||
|
||
if (tymin > tmin) | ||
tmin = tymin; | ||
if (tymax < tmax) | ||
tmax = tymax; | ||
|
||
tzmin = (bounds[sign[2]][2] - rp->r_pt[2]) * (1.0 / rp->r_dir[2]); | ||
tzmax = (bounds[1 - sign[2]][2] - rp->r_pt[2]) * (1.0 / rp->r_dir[2]); | ||
|
||
if ((tmin > tzmax) || (tzmin > tmax)) | ||
return 0; | ||
|
||
if (tzmin > tmin) | ||
tmin = tzmin; | ||
if (tzmax < tmax) | ||
tmax = tzmax; | ||
|
||
fprintf(stderr, "hit\n"); | ||
|
||
return 2; | ||
|
||
} | ||
|
||
/** | ||
* return a single normal | ||
*/ | ||
void | ||
rt_vdb_norm(register struct hit *hitp, struct soltab *stp, register struct xray *rp) | ||
{ | ||
|
||
vect_t xlated; | ||
fastf_t scale; | ||
|
||
VSET(hitp->hit_normal, 1, 0, 0); | ||
hitp->hit_vpriv[X] = 1.0; | ||
|
||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all the macro name corresponds to ASCII representation of the hex numbers which gives a hint of what they means. For e.g. below
706e7473
meanspnts
. So similarly you can changevdb
to76646220
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I will do that.