Skip to content
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

Open
wants to merge 21 commits into
base: vdb
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1718390
created id, magic number, internal structure and make command to crea…
cjsb Jul 26, 2023
2cc02d9
fixing unnecessary indentation
cjsb Jul 31, 2023
2dbae76
adding function to table of the vdb, at the moment it has only a boun…
cjsb Jul 31, 2023
84e1149
fixing rt_vdb_shot method - now it is showing something in the ray tr…
cjsb Aug 24, 2023
2a23f83
adjusting cmakelist to add vdb.c file
cjsb Sep 7, 2023
203d497
adding includes for openvdb and ray tracing a vdb structure - very sl…
cjsb Sep 8, 2023
bbe83dc
loading vdb on prep method and adjusting CMakeList to add vdb.cpp
cjsb Sep 12, 2023
5f6dd18
getting the normal for the hit, there is something wrong, it is not g…
cjsb Sep 12, 2023
96cbd50
loading nvdb file working
cjsb Sep 15, 2023
bb53683
loading from file name - changed from make to in - need to remove mak…
cjsb Sep 17, 2023
08716b5
fixing cmakelist to work on release
cjsb Sep 19, 2023
e270334
adjusting cmakelist with debug lib and removing empty files to avoid …
cjsb Sep 20, 2023
a3cf433
adjusting cmakelist from librt to remove vdb.c
cjsb Sep 20, 2023
2d44086
adding plot functio to vdb primitive
cjsb Sep 23, 2023
e7c4455
removing old make function for vdb (now it is only created by using i…
cjsb Sep 27, 2023
3e4936e
code refactoring and cmakelist adjustments
cjsb Oct 5, 2023
278b1d6
adding files and changing cmakelists to build correctly
Oct 6, 2023
cfdc624
more adjustments on cmakelists
Oct 6, 2023
7ec838d
adjustments on cmaklists file for librt to copy dll in the end
cjsb Oct 6, 2023
1c2a949
fixing parsing problem
cjsb Oct 6, 2023
c271e5d
fixing librt cmakelists for debug
cjsb Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/bu/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ __BEGIN_DECLS
#define RT_TGC_INTERNAL_MAGIC 0xaabbdd87 /**< ???? */
#define RT_TOR_INTERNAL_MAGIC 0x9bffed87 /**< ???? */
#define RT_VOL_INTERNAL_MAGIC 0x987ba1d0 /**< ?{?? */
#define RT_VDB_INTERNAL_MAGIC 0xa7a3d52a /**< vdb */
Copy link
Contributor

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 means pnts. So similarly you can change vdb to 76646220.

Copy link
Author

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.

#define RT_PNTS_INTERNAL_MAGIC 0x706e7473 /**< pnts */
#define RT_ANNOT_INTERNAL_MAGIC 0x616e6e6f /**< anno */
#define RT_HRT_INTERNAL_MAGIC 0x6872743f /**< hrt? */
Expand Down
5 changes: 3 additions & 2 deletions include/rt/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
* NOTE: must update the non-geometric object id's below the
* ADD_BELOW_HERE marker
*/
#define ID_MAX_SOLID 47 /**< @brief Maximum defined ID_xxx for solids */
#define ID_MAX_SOLID 48 /**< @brief Maximum defined ID_xxx for solids */

/*
* Non-geometric objects
Expand All @@ -133,7 +133,8 @@
#define ID_HRT 43 /**< @brief Heart */
#define ID_DATUM 44 /**< @brief Datum references */
#define ID_SCRIPT 45 /**< @brief Script */
#define ID_MAXIMUM 47 /**< @brief Maximum defined ID_xxx value */
#define ID_VDB 47
#define ID_MAXIMUM 48 /**< @brief Maximum defined ID_xxx value */

/**
* DEPRECATED: external applications should use other LIBRT API to
Expand Down
19 changes: 19 additions & 0 deletions include/rt/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,25 @@ struct rt_vol_internal {
unsigned char *map;
};
#define RT_VOL_CK_MAGIC(_p) BU_CKMAG(_p, RT_VOL_INTERNAL_MAGIC, "rt_vol_internal")

/** @addtogroup rt_vdb */
/** @{ */
/*
* ID_VOL
*/
#define RT_VDB_NAME_LEN 128
struct rt_vdb_internal {
uint32_t magic;
char name[RT_VDB_NAME_LEN];

//to start, it will save the min and max of a bounding box - that will be changed to the vdb structure
vect_t minBB;
vect_t maxBB;

};
#define RT_VDB_CK_MAGIC(_p) BU_CKMAG(_p, RT_VDB_INTERNAL_MAGIC, "rt_vdb_internal")


/** @} */

/** @addtogroup rt_hf */
Expand Down
1 change: 1 addition & 0 deletions src/libged/garbage_collect/garbage_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <set>
#include <string>
#include <vector>
#include <iterator>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set library already has member type iterator that is used here in line 76 std::set<std::string>::iterator s_it;. So no need to include iterator library.

Copy link
Author

Choose a reason for hiding this comment

The 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"
Expand Down
19 changes: 18 additions & 1 deletion src/libged/make/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ged_make_core(struct ged *gedp, int argc, const char *argv[])
struct rt_arbn_internal *arbn_ip;
struct rt_superell_internal *superell_ip;
struct rt_metaball_internal *metaball_ip;
struct rt_vdb_internal *vdb_ip;
struct rt_pnts_internal *pnts_ip;
struct rt_cline_internal *cline_ip;
struct rt_brep_internal *brep_ip;
Expand Down Expand Up @@ -792,7 +793,23 @@ ged_make_core(struct ged *gedp, int argc, const char *argv[])
superell_ip->e = 1.0;
fprintf(stdout, "superell being made with %f and %f\n", superell_ip->n, superell_ip->e);

} else if (BU_STR_EQUAL(argv[bu_optind+1], "cline")) {
}
else if (BU_STR_EQUAL(argv[bu_optind + 1], "vdb")) {

internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
internal.idb_type = ID_VDB;
internal.idb_meth = &OBJ[ID_VDB];
BU_ALLOC(internal.idb_ptr, struct rt_vdb_internal);
vdb_ip = (struct rt_vdb_internal *)internal.idb_ptr;
vdb_ip->magic = RT_VDB_INTERNAL_MAGIC;

VSET(vdb_ip->minBB, 0, 0, 0);
VSET(vdb_ip->maxBB, 1, 1, 1);

bu_log("it will create a vdb\n");

}
else if (BU_STR_EQUAL(argv[bu_optind+1], "cline")) {

internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
internal.idb_type = ID_CLINE;
Expand Down
48 changes: 48 additions & 0 deletions src/librt/primitives/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ RT_DECLARE_INTERFACE(cline);
RT_DECLARE_INTERFACE(bot);
RT_DECLARE_INTERFACE(superell);
RT_DECLARE_INTERFACE(metaball);
RT_DECLARE_INTERFACE(vdb);
RT_DECLARE_INTERFACE(hyp);
RT_DECLARE_INTERFACE(revolve);
RT_DECLARE_INTERFACE(constraint);
Expand Down Expand Up @@ -2422,6 +2423,53 @@ const struct rt_functab OBJ[] = {
NULL /* label */
},

{
/* 47 */
RT_FUNCTAB_MAGIC, "ID_VDB", "vdb",
0, /* ft_use_rpp */
RTFUNCTAB_FUNC_PREP_CAST(rt_vdb_prep),
RTFUNCTAB_FUNC_SHOT_CAST(rt_vdb_shot),
NULL, /* print */
RTFUNCTAB_FUNC_NORM_CAST(rt_vdb_norm),
NULL, /* piece_shot */
NULL, /* piece_hitsegs */
NULL, /* uv */
NULL, /* curve */
NULL, /* classify */
NULL, /* free */
NULL, /* plot */
NULL, /* adaptive_plot */
NULL, /* vshot */
NULL, /* tess */
NULL, /* tnurb */
NULL, /* brep */
RTFUNCTAB_FUNC_IMPORT5_CAST(rt_vdb_import5),
RTFUNCTAB_FUNC_EXPORT5_CAST(rt_vdb_export5),
NULL, /* import4 */
NULL, /* export4 */
NULL, /* ifree */
NULL, /* describe */
RTFUNCTAB_FUNC_XFORM_CAST(rt_generic_xform),
NULL, /* parse */
sizeof(struct rt_vdb_internal), /* sizeof(internal) */
RT_VDB_INTERNAL_MAGIC, /* magic */
RTFUNCTAB_FUNC_GET_CAST(rt_generic_get),
RTFUNCTAB_FUNC_ADJUST_CAST(rt_generic_adjust),
RTFUNCTAB_FUNC_FORM_CAST(rt_generic_form),
NULL, /* make */
NULL, /* params */
RTFUNCTAB_FUNC_BBOX_CAST(rt_vdb_bbox),
NULL, /* volume */
NULL, /* surf_area */
NULL, /* centroid */
NULL, /* oriented_bbox */
NULL, /* find_selections */
NULL, /* evaluate_selection */
NULL, /* process_selection */
NULL, /* serialize */
NULL /* label */
},

{
/* this entry for sanity only */
0L, ">ID_MAXIMUM", ">id_max",
Expand Down
232 changes: 232 additions & 0 deletions src/librt/primitives/vdb/vdb.c
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;


}