Skip to content

Commit

Permalink
Standardize math types (see #94). API breaking changes. Clean up type…
Browse files Browse the repository at this point in the history
… warnings.

- Matrix4F objects are now defined to be column-major, and a matrix `M` now
transforms a vector `v` by multiplying with the column vector on the right, like
`Mv`. This shouldn't impact your code unless you were using `GetRowVec` or `GetF`

- `sample_utils`' `vec.h`, `vec.cpp`, `camera.h`, and `camera.cpp` have been removed.
These were copies of their corresponding GVDB classes that were slowly diverging
over time, and are not needed (the only sample impacted as a result is `gFluidSurface`).
If you were using these, include the GVDB headers for drop-in replacements.

- `Vector3DI` and `Vector3DF` are now templatized instantiations of a single
`Vector3D` class. To accomodate this, its functions have been moved inline to
`gvdb_vec.h`. This might increase compilation times a bit - sorry about that!

- `Matrix4F::operator* (const Vector3DF &op)` now returns a `Vector3DF`, the result
of transforming the vector by the matrix, instead of a `Matrix4F`, the result of
multiplying the matrix by `diag(op.x, op.y, op.z, 1)`. The old behavior has been
renamed to `Matrix4F::ScaleInPlace`.

- `ActivateSpaceAtLevel` and `isActive` now take a `Vector3DI` pos instead of a
`Vector3DF`. Previously, the `Vector3DF` was internally casted to a `Vector3DI`.

- `getNumNodes`, `getNumUsedNodes`, and `getNumTotalNodes` now return 64-bit
unsigned integers in order to represent the underlying `DataPtr` structure more
accurately. However, most users of these functions cast them to `ints` in any case.

- The order of arguments in `mmult` have been swapped.

- Removes unused variables `camivprow0...camivprow3` from `ScnInfo`.

- `AllocateNeighbors` now takes a `uint64` instead of an `int`. However, this
change is not very impactful.

- Renames the variables in `Matrix4F::operator()`. By coincidence, this produces
exactly the same behavior as before, so no code changes are needed.

Also includes changes throughout the codebase to fix the type casting warnings
VS 2019 was warning about, removes the `GVDB_VEC`... variables, and adds
documentation for math class functions.

Note that you may have to do a clean rebuild of the project after pulling this
commit, as the mangled type names for the `Vector3` classes have changed.
  • Loading branch information
NBickford-NV committed Jul 6, 2020
1 parent f0d05bb commit 34928fa
Show file tree
Hide file tree
Showing 33 changed files with 760 additions and 3,043 deletions.
15 changes: 8 additions & 7 deletions source/g3DPrint/main_3dprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void Sample::revoxelize()
// allows the application to setup rendering to convert from unit voxel grid to world coordinates.
// To apply voxel size for 3D printing, we include it in the xform matrix for SolidVoxelize.
switch (m_voxelsize_select) {
case 0: m_voxel_size = 0.5; break;
case 1: m_voxel_size = 0.4; break;
case 2: m_voxel_size = 0.3; break;
case 3: m_voxel_size = 0.2; break;
case 0: m_voxel_size = 0.5f; break;
case 1: m_voxel_size = 0.4f; break;
case 2: m_voxel_size = 0.3f; break;
case 3: m_voxel_size = 0.2f; break;
};

// Create a transform
Expand Down Expand Up @@ -283,14 +283,15 @@ void Sample::render_section ()
float h = (float) getHeight();
Vector3DF world;
world = m_pivot * m_part_size / m_voxel_size; // GVDB voxel grid to world coordinates
world.y *= 1.0 - getCurY() / h; // Select cross-section on world y-axis
world.y *= 1.0f - getCurY() / h; // Select cross-section on world y-axis
gvdb1.getScene()->SetCrossSection ( world, Vector3DF(world.x, 1.f, world.z) );

gvdb1.Render ( SHADE_SECTION2D, 0, 1 );

gvdb1.ReadRenderTexGL ( 1, gl_section_tex );

renderScreenQuadGL ( gl_section_tex, -1, 0, 0, getWidth()/4, getHeight()/4, 0 );
renderScreenQuadGL ( gl_section_tex, -1, 0, 0,
static_cast<float>(getWidth())/4, static_cast<float>(getHeight())/4, 0 );
}

void Sample::display()
Expand Down Expand Up @@ -357,7 +358,7 @@ void Sample::draw_topology ( VolumeGVDB* gvdb )
Vector3DF bmin, bmax;
Node* node;
for (int lev=0; lev < 5; lev++ ) { // draw all levels
int node_cnt = gvdb->getNumNodes(lev);
int node_cnt = static_cast<int>(gvdb->getNumNodes(lev));
for (int n=0; n < node_cnt; n++) { // draw all nodes at this level
node = gvdb->getNodeAtLevel ( n, lev );
bmin = gvdb->getWorldMin ( node ) * vs; // get node bounding box
Expand Down
11 changes: 5 additions & 6 deletions source/gDepthMap/main_depthmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ bool Sample::init()
gvdb.UpdateApron();

// Set volume params
gvdb.getScene()->SetSteps ( .1, 16, .1 ); // Set raycasting steps
gvdb.getScene()->SetSteps ( .1f, 16, .1f ); // Set raycasting steps
gvdb.getScene()->SetExtinct ( -1.0f, 1.0f, 0.0f ); // Set volume extinction
gvdb.getScene()->SetVolumeRange ( 0.1f, 0.0f, 0.5f ); // Set volume value range
gvdb.getScene()->SetCutoff ( 0.005f, 0.005f, 0.0f );
gvdb.getScene()->SetBackgroundClr ( 0.1f, 0.2f, 0.4f, 1.0 );
gvdb.getScene()->LinearTransferFunc ( 0.00f, 0.10f, Vector4DF(0,0,0,0), Vector4DF(0,0,0,0.0f) );
gvdb.getScene()->LinearTransferFunc ( 0.10f, 0.50f, Vector4DF(1,1,0,0.1f), Vector4DF(1,0,0,0.3f) );
gvdb.getScene()->LinearTransferFunc ( 0.50f, 0.75f, Vector4DF(1,0,0,0.3f), Vector4DF(.2f,.2f,0.2f,0.1f) );
gvdb.getScene()->LinearTransferFunc ( 0.75f, 1.00f, Vector4DF(.2f,.2f,0.2f,0.1f), Vector4DF(0.1,0.1,.1,0.3) );
gvdb.getScene()->LinearTransferFunc ( 0.75f, 1.00f, Vector4DF(.2f,.2f,0.2f,0.1f), Vector4DF(0.1f,0.1f,.1f,0.3f) );
gvdb.CommitTransferFunc ();
gvdb.SetTransform(Vector3DF(-125, -160, -125), Vector3DF(.5, .5, .5), m_rotate, m_translate );

Expand Down Expand Up @@ -194,7 +194,6 @@ void Sample::update_camera_gl (int w, int h )
double aspect = float(w)/float(h);
GLfloat proj_mtx[16];
GLfloat view_mtx[16];
GLfloat invmodel_mtx[16];

// construct & read back projection matrix
glMatrixMode ( GL_PROJECTION );
Expand Down Expand Up @@ -256,7 +255,7 @@ void Sample::render_depth (int w, int h)
renderCamSetupGL(gvdb.getScene(), simple_id, &model_mtx);
renderLightSetupGL(gvdb.getScene(), simple_id);
checkGL ( "lights" );
renderSetMaterialGL(gvdb.getScene(), simple_id, Vector4DF(.1, .1, .1, 1), Vector4DF(.5, .5, .5, 1), Vector4DF(1, 1, 1, 1));
renderSetMaterialGL(gvdb.getScene(), simple_id, Vector4DF(.1f, .1f, .1f, 1), Vector4DF(.5f, .5f, .5f, 1), Vector4DF(1, 1, 1, 1));
checkGL ( "mats" );

// Render polygons for color and depth
Expand Down Expand Up @@ -336,8 +335,8 @@ void Sample::motion(int x, int y, int dx, int dy)
m_translate.z -= dy;
gvdb.SetTransform(Vector3DF(-125, -160, -125), Vector3DF(.5, .5, .5), m_rotate, m_translate);
} else if (ctrl) {
m_rotate.y += dx*0.1;
m_rotate.x += dy*0.1;
m_rotate.y += dx*0.1f;
m_rotate.x += dy*0.1f;
gvdb.SetTransform(Vector3DF(-125, -160, -125), Vector3DF(.5, .5, .5), m_rotate, m_translate);
} else {
// Adjust orbit angles
Expand Down
6 changes: 3 additions & 3 deletions source/gFluidSurface/cutil_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ inline __host__ __device__ float2 normalize(float2 v)
// floor
inline __host__ __device__ float2 floor(const float2 v)
{
return make_float2(floor(v.x), floor(v.y));
return make_float2(floorf(v.x), floorf(v.y));
}

// reflect
Expand Down Expand Up @@ -416,7 +416,7 @@ inline __host__ __device__ float3 normalize(float3 v)
// floor
inline __host__ __device__ float3 floor(const float3 v)
{
return make_float3(floor(v.x), floor(v.y), floor(v.z));
return make_float3(floorf(v.x), floorf(v.y), floorf(v.z));
}

// reflect
Expand Down Expand Up @@ -558,7 +558,7 @@ inline __host__ __device__ float4 normalize(float4 v)
// floor
inline __host__ __device__ float4 floor(const float4 v)
{
return make_float4(floor(v.x), floor(v.y), floor(v.z), floor(v.w));
return make_float4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w));
}

// int3 functions
Expand Down
4 changes: 2 additions & 2 deletions source/gFluidSurface/main_fluid_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace nvdb;
// Sample utils
#include "main.h" // window system
#include "nv_gui.h" // gui system
#include "vec.h"
#include "gvdb_vec.h"
#include <GL/glew.h>

#ifdef USE_OPTIX
Expand Down Expand Up @@ -425,7 +425,7 @@ void Sample::draw_topology ()
Vector3DF bmin, bmax;
Node* node;
for (int lev=0; lev < 5; lev++ ) { // draw all levels
int node_cnt = gvdb.getNumNodes(lev);
int node_cnt = static_cast<int>(gvdb.getNumNodes(lev));
for (int n=0; n < node_cnt; n++) { // draw all nodes at this level
node = gvdb.getNodeAtLevel ( n, lev );
bmin = gvdb.getWorldMin ( node ); // get node bounding box
Expand Down
2 changes: 1 addition & 1 deletion source/gInteractiveGL/main_interactive_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Sample::reshape (int w, int h)

void Sample::display()
{
m_angs.y += 0.05;
m_angs.y += 0.05f;
gvdb.SetTransform(m_pretrans, m_scale, m_angs, m_trans);

// Render volume
Expand Down
7 changes: 3 additions & 4 deletions source/gInteractiveOptix/main_interactive_optix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Sample::RebuildOptixGraph ( int shading )
matp->spec_power = 80.0;
matp->env_color = Vector3DF(0, 0, 0);
matp->refl_width = 0.3f;
matp->refl_color = Vector3DF(.8, .8, .8 );
matp->refl_color = Vector3DF(.8f, .8f, .8f );
matp->refr_width = 0.0f;
matp->refr_color = Vector3DF(0, 0, 0);
matp->refr_ior = 1.2f;
Expand Down Expand Up @@ -181,7 +181,7 @@ bool Sample::init()

// Set volume params
gvdb.SetTransform(Vector3DF(-125, -160, -125), Vector3DF(.25, .25, .25), Vector3DF(0, 0, 0), m_translate);
gvdb.SetEpsilon(0.001, 256);
gvdb.SetEpsilon(0.001f, 256);
gvdb.getScene()->SetSteps ( 0.2f, 16, 0.2f ); // SCN_PSTEP, SCN_SSTEP, SCN_FSTEP - Raycasting steps
gvdb.getScene()->SetExtinct ( -1.0f, 1.0f, 0.0f ); // SCN_EXTINCT, SCN_ALBEDO - Volume extinction
gvdb.getScene()->SetVolumeRange(0.1f, 0.0f, 0.3f); // Threshold: Isoval, Vmin, Vmax
Expand Down Expand Up @@ -254,10 +254,9 @@ void Sample::draw_topology()
start3D(gvdb.getScene()->getCamera()); // start 3D drawing
Vector3DF bmin, bmax;
Node* node;
Node* node2;

for (int lev = 0; lev < 5; lev++) { // draw all levels
int node_cnt = gvdb.getNumTotalNodes(lev);
int node_cnt = static_cast<int>(gvdb.getNumTotalNodes(lev));
for (int n = 0; n < node_cnt; n++) { // draw all nodes at this level
node = gvdb.getNodeAtLevel(n, lev);
if (!int(node->mFlags)) continue;
Expand Down
48 changes: 23 additions & 25 deletions source/gPointCloud/main_point_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ void Sample::RebuildOptixGraph(int shading)
sprintf ( filepath, "%s%s", model_list[n].fpath, model_list[n].fname );
}
nvprintf ( "Load model %s...", filepath );
id = gvdb.getScene()->AddModel( filepath, model_list[n].scal, model_list[n].offs.x, model_list[n].offs.y, model_list[n].offs.z);
id = static_cast<int>(gvdb.getScene()->AddModel(filepath,
model_list[n].scal, model_list[n].offs.x, model_list[n].offs.y, model_list[n].offs.z));
gvdb.CommitGeometry( id );

m = gvdb.getScene()->getModel ( id );
Expand Down Expand Up @@ -272,19 +273,19 @@ void Sample::parse_value ( int mode, std::string tag, std::string val )
case M_POINTS:
if (strEq(tag,"path")) m_pntpath = strTrim(val);
if (strEq(tag,"file")) m_pntfile = strTrim(val);
if (strEq(tag,"mat")) m_pntmat= strToNum(val);
if (strEq(tag,"frame")) m_frame = strToNum(val);
if (strEq(tag,"fstep")) m_fstep = strToNum(val);
if (strEq(tag,"mat")) m_pntmat= static_cast<int>(strToNum(val));
if (strEq(tag,"frame")) m_frame = static_cast<int>(strToNum(val));
if (strEq(tag, "fstep")) m_fstep = static_cast<int>(strToNum(val));
break;
case M_POLYS:
if (strEq(tag,"path")) m_polypath = val;
if (strEq(tag,"file")) m_polyfile = val;
if (strEq(tag,"mat")) m_polymat= strToNum(val);
if (strEq(tag,"frame")) m_pframe = strToNum(val);
if (strEq(tag,"fstep")) m_pfstep = strToNum(val);
if (strEq(tag, "mat")) m_polymat = static_cast<int>(strToNum(val));
if (strEq(tag, "frame")) m_pframe = static_cast<int>(strToNum(val));
if (strEq(tag, "fstep")) m_pfstep = static_cast<int>(strToNum(val));
break;
case M_MATERIAL: {
int i = mat_list.size()-1;
int i = static_cast<int>(mat_list.size()-1);
matp = &mat_list[i];
if (strEq(tag,"lightwid")) matp->light_width = strToNum(val);
if (strEq(tag,"shwid")) matp->shadow_width = strToNum(val);
Expand All @@ -305,9 +306,9 @@ void Sample::parse_value ( int mode, std::string tag, std::string val )
if (strEq(tag,"reframt")) matp->refr_amount = strToNum(val);
} break;
case M_RENDER:
if (strEq(tag,"width")) m_w = strToNum(val);
if (strEq(tag,"height")) m_h = strToNum(val);
if (strEq(tag,"samples")) m_max_samples = strToNum(val);
if (strEq(tag,"width")) m_w = static_cast<int>(strToNum(val));
if (strEq(tag,"height")) m_h = static_cast<int>(strToNum(val));
if (strEq(tag,"samples")) m_max_samples = static_cast<int>(strToNum(val));
if (strEq(tag,"backclr")) { strToVec3( val, "<",",",">", &vec.x); gvdb.getScene()->SetBackgroundClr(vec.x,vec.y,vec.z, 1.0); }
if (strEq(tag,"envmap")) m_envfile = val;
if (strEq(tag,"outpath")) m_outpath = val;
Expand All @@ -321,7 +322,7 @@ void Sample::parse_value ( int mode, std::string tag, std::string val )
if (strEq(tag,"extinct")) { strToVec3( val, "<",",",">", &vec.x); scn->SetExtinct(vec.x,vec.y,vec.z); }
if (strEq(tag,"range")) { strToVec3( val, "<",",",">", &vec.x); scn->SetVolumeRange(vec.x,vec.y,vec.z); }
if (strEq(tag,"cutoff")) { strToVec3( val, "<",",",">", &vec.x); scn->SetCutoff(vec.x,vec.y,vec.z); }
if (strEq(tag,"smooth")) m_smooth = strToNum(val);
if (strEq(tag,"smooth")) m_smooth = static_cast<int>(strToNum(val));
if (strEq(tag,"smoothp")) { strToVec3(val, "<", ",", ">", &vec.x); m_smoothp = vec; }
} break;
case M_CAMERA: {
Expand All @@ -341,10 +342,10 @@ void Sample::parse_value ( int mode, std::string tag, std::string val )
lgt->setOrbit ( lgt->getAng(), lgt->getToPos(), lgt->getOrbitDist(), lgt->getDolly() );
} break;
case M_MODEL: {
int id = model_list.size()-1;
int id = static_cast<int>(model_list.size()-1);
if (strEq(tag,"path")) strncpy( model_list[id].fpath, val.c_str(), 1024);
if (strEq(tag,"file")) strncpy( model_list[id].fname, val.c_str(), 1024);
if (strEq(tag,"mat")) model_list[id].mat = strToNum(val);
if (strEq(tag,"mat")) model_list[id].mat = static_cast<int>(strToNum(val));
if (strEq(tag,"scale")) model_list[id].scal = strToNum(val);
if (strEq(tag,"offset")) { strToVec3( val, "<",",",">", &vec.x); model_list[id].offs = vec; }
} break;
Expand Down Expand Up @@ -395,7 +396,7 @@ void Sample::on_arg(std::string arg, std::string val)
}

if (arg.compare("-frame") == 0) {
m_frame = strToNum(val);
m_frame = static_cast<int>(strToNum(val));
nvprintf("frame: %d\n", m_frame);
}

Expand All @@ -412,7 +413,7 @@ void Sample::on_arg(std::string arg, std::string val)
nvprintf("render scale: %f\n", m_renderscale);
}
if (arg.compare("-io") == 0) {
m_io_method = strToNum(val);
m_io_method = static_cast<int>(strToNum(val));
nvprintf("io method: %d\n", m_io_method);
}
}
Expand Down Expand Up @@ -559,8 +560,6 @@ void Sample::load_points ( std::string pntpath, std::string pntfile, int frame )
}

nvprintf ( "Load points from %s...", filepath );

float buf[3];

// Read # of points
m_numpnts = 0;
Expand Down Expand Up @@ -645,7 +644,6 @@ void Sample::load_points ( std::string pntpath, std::string pntfile, int frame )
fread(&wMax.z, sizeof(float), 1, fph);

// Allocate memory for points
ushort outbuf[3];
PERF_PUSH(" Buffer alloc");
gvdb.AllocData(m_pnt1, m_numpnts, sizeof(ushort) * 3, true);
gvdb.AllocData(m_pnts, m_numpnts, sizeof(Vector3DF), false);
Expand Down Expand Up @@ -721,7 +719,7 @@ void Sample::render_update()
// Rebuild GVDB Render topology
PERF_PUSH("Dynamic Topology");
//gvdb.RequestFullRebuild ( true );
gvdb.RebuildTopology(m_numpnts, m_radius*2.0, m_origin);
gvdb.RebuildTopology(m_numpnts, m_radius*2.0f, m_origin);
gvdb.FinishTopology(false, true); // false. no commit pool false. no compute bounds
gvdb.UpdateAtlas();
PERF_POP();
Expand All @@ -732,8 +730,8 @@ void Sample::render_update()

int scPntLen = 0;
int subcell_size = 4;
gvdb.InsertPointsSubcell_FP16 (subcell_size, m_numpnts, m_radius, m_origin, scPntLen);
gvdb.GatherLevelSet_FP16 (subcell_size, m_numpnts, m_radius, m_origin, scPntLen, 0, 0);
gvdb.InsertPointsSubcell_FP16 (subcell_size, m_numpnts, static_cast<float>(m_radius), m_origin, scPntLen);
gvdb.GatherLevelSet_FP16 (subcell_size, m_numpnts, static_cast<float>(m_radius), m_origin, scPntLen, 0, 0);
gvdb.UpdateApron(0, 3.0f);
PERF_POP();

Expand Down Expand Up @@ -814,7 +812,7 @@ void Sample::draw_topology ()
Camera3D* cam = gvdb.getScene()->getCamera();
start3D(cam);
for (int lev=0; lev < 5; lev++ ) { // draw all levels
int node_cnt = g->getNumTotalNodes(lev);
int node_cnt = static_cast<int>(g->getNumTotalNodes(lev));
for (int n=0; n < node_cnt; n++) { // draw all nodes at this level
node = g->getNodeAtLevel ( n, lev );
if (!int(node->mFlags)) continue;
Expand All @@ -839,7 +837,7 @@ void Sample::draw_points ()
start3D(cam);
for (int n=0; n < m_numpnts; n++ ) {
p1 = *fpos++;
p2 = p1+Vector3DF(0.01,0.01,0.01);
p2 = p1+Vector3DF(0.01f,0.01f,0.01f);
c = p1 / Vector3DF(256.0,256,256);
drawLine3D ( p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, c.x, c.y, c.z, 1);
}
Expand All @@ -859,7 +857,7 @@ void Sample::display()
if (m_key && m_frame >= 1100 && m_frame <= 1340 ) {
float u = float(m_frame - 1100) / (1340 - 1100);
Vector3DF a0, t0, d0;
a0 = interp(Vector3DF(0,35,0), Vector3DF(0, 24.6,0), u);
a0 = interp(Vector3DF(0,35,0), Vector3DF(0, 24.6f,0), u);
t0 = interp(Vector3DF(240, 0, 0), Vector3DF(362, -201, 20), u);
d0 = interp(Vector3DF(1600, 0, 0), Vector3DF(2132, 0, 0), u);
Camera3D* cam = gvdb.getScene()->getCamera();
Expand Down
Loading

0 comments on commit 34928fa

Please sign in to comment.