Skip to content

Commit

Permalink
Merge branch 'dev' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
larc committed Nov 16, 2023
2 parents 15c56c6 + eb04e79 commit cb5d967
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 35 deletions.
24 changes: 17 additions & 7 deletions include/gproshan/geometry/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ class vec
return res;
}

///< scalar division
///< element wise division & scalar division
__host_device__
vec<T, N> operator / (const T & a) const
vec<T, N> operator / (const vec<T, N> & v) const
{
vec<T, N> res;
for(index_t i = 0; i < N; ++i)
res[i] = values[i] / a;
res[i] = values[i] / v[i];
return res;
}

Expand Down Expand Up @@ -193,12 +193,12 @@ class vec
return *this;
}

///< scalar division self assign
///< element wise division self assign
__host_device__
const vec<T, N> & operator /= (const T & a)
const vec<T, N> & operator /= (const vec<T, N> & v)
{
for(T & v: values)
v /= a;
for(index_t i = 0; i < N; ++i)
values[i] /= v[i];
return *this;
}

Expand Down Expand Up @@ -263,6 +263,16 @@ vec<T, N> operator * (const T & a, const vec<T, N> & v)
return v * a;
}

///< scalar product
template<class T, size_t N>
__host_device__
vec<T, N> operator / (const T & a, const vec<T, N> & v)
{
vec<T, N> res;
for(index_t i = 0; i < N; ++i)
res[i] = a / v[i];
return res;
}

///< cross product
template<class T>
Expand Down
1 change: 0 additions & 1 deletion include/gproshan/mesh/che.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class che

rgb_t() = default;
rgb_t(const vertex & v);
rgb_t(const float & fr, const float & fg, const float & fb);
rgb_t(const unsigned char & cr, const unsigned char & cg, const unsigned char & cb);
unsigned char & operator [] (const index_t & i);
operator vertex () const;
Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/raytracing/embree.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class embree : public raytracing
{
ray_hit(const vertex & p_org = {0, 0, 0},
const vertex & v_dir = {0, 0, 0},
float near = 0,
float near = 1e-5f,
float far = 1e20f);

vertex org() const;
Expand Down
16 changes: 9 additions & 7 deletions include/gproshan/raytracing/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,22 @@ struct t_eval_hit
__host_device__
t_eval_hit() {}

__host_device__
t_eval_hit(const CHE & pc, const index_t & aprimID)
{
primID = aprimID;
normal = pc.VN[primID];
}

__host_device__
t_eval_hit(const CHE & mesh, const index_t & aprimID, const T & au, const T & av, const scene_data & sc)
{
primID = aprimID;
u = au;
v = av;

if(!mesh.n_trigs) // pointcloud
{
const che::rgb_t & c = mesh.VC[aprimID];
Kd = {T(c.r), T(c.g), T(c.b)};
Kd /= 255;
normal = mesh.VN[aprimID];
return;
}

const index_t he = primID * che::mtrig;

const index_t a = mesh.VT[he];
Expand Down
3 changes: 3 additions & 0 deletions include/gproshan/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class partitions
index_t * sorted = nullptr;

public:
partitions(index_t * s = nullptr);
void add(const index_t & size);
size_t size(const index_t & i) const;
part operator () (const index_t & i) const;
};

Expand Down
1 change: 1 addition & 0 deletions include/gproshan/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class viewer

static bool m_help(viewer * view);
static bool m_close(viewer * view);
static bool m_maximize(viewer * view);
static bool m_hide_show_imgui(viewer * view);

static bool m_save_load_view(viewer * view);
Expand Down
10 changes: 4 additions & 6 deletions src/gproshan/mesh/che.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ size_t & che::rw(const size_t & n)
}


che::rgb_t::rgb_t(const vertex & v): rgb_t(v.x(), v.y(), v.z()) {}

che::rgb_t::rgb_t(const float & fr, const float & fg, const float & fb)
che::rgb_t::rgb_t(const vertex & v)
{
r = (unsigned char) (fr * 255);
g = (unsigned char) (fg * 255);
b = (unsigned char) (fb * 255);
r = (unsigned char) (v.x() * 255);
g = (unsigned char) (v.y() * 255);
b = (unsigned char) (v.z() * 255);
}

che::rgb_t::rgb_t(const unsigned char & cr, const unsigned char & cg, const unsigned char & cb): r(cr), g(cg), b(cb) {}
Expand Down
14 changes: 7 additions & 7 deletions src/gproshan/mesh/che_ply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ void che_ply::write_file(const che * mesh, const std::string & file, const bool
fprintf(fp, "property %s x\n", type);
fprintf(fp, "property %s y\n", type);
fprintf(fp, "property %s z\n", type);
fprintf(fp, "property %s nx\n", type);
fprintf(fp, "property %s ny\n", type);
fprintf(fp, "property %s nz\n", type);
if(color)
{
fprintf(fp, "property uchar red\n");
Expand All @@ -276,15 +279,12 @@ void che_ply::write_file(const che * mesh, const std::string & file, const bool
fprintf(fp, "property list uchar uint vertex_index\n");
fprintf(fp, "end_header\n");

if(color)
for(index_t v = 0; v < mesh->n_vertices; ++v)
{
for(index_t v = 0; v < mesh->n_vertices; ++v)
{
fwrite(&mesh->point(v), sizeof(vertex), 1, fp);
fwrite(&mesh->rgb(v), sizeof(rgb_t), 1, fp);
}
fwrite(&mesh->point(v), sizeof(vertex), 1, fp);
fwrite(&mesh->normal(v), sizeof(vertex), 1, fp);
if(color) fwrite(&mesh->rgb(v), sizeof(rgb_t), 1, fp);
}
else fwrite(&mesh->point(0), sizeof(vertex), mesh->n_vertices, fp);

unsigned char mtrig = che::mtrig;
for(index_t he = 0; he < mesh->n_half_edges; he += che::mtrig)
Expand Down
4 changes: 1 addition & 3 deletions src/gproshan/raytracing/embree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ vec3 embree::closesthit_radiance(const vertex & org, const vertex & dir, const l

const CHE * mesh = g_meshes[r.hit.geomID];

eval_hit hit;
if(mesh->n_trigs)
hit = {*mesh, r.hit.primID, r.hit.u, r.hit.v, sc};
eval_hit hit(*mesh, r.hit.primID, r.hit.u, r.hit.v, sc);
hit.position = r.pos();
hit.normal = flat ? r.normal() : hit.normal;

Expand Down
2 changes: 1 addition & 1 deletion src/gproshan/raytracing/optix.cu
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extern "C" __global__ void __raygen__render_frame()
optixTrace( optix_params.traversable,
* (float3 *) &optix_params.cam_pos,
* (float3 *) &ray_dir,
0.f, // tmin
1e-5f, // tmin
1e20f, // tmax
0.0f, // rayTime
OptixVisibilityMask(255),
Expand Down
12 changes: 11 additions & 1 deletion src/gproshan/scenes/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ che * scanner_ptx(const rt::raytracing * rt, const size_t & n_rows, const size_t

mesh_ptx->point(v) = h.position;
mesh_ptx->normal(v) = h.normal;
mesh_ptx->heatmap(v) = h.dist / M_SQRT2;
mesh_ptx->heatmap(v) = h.dist;
mesh_ptx->rgb(v) = h.Kd;
}

real_t max_dist = 0;

#pragma omp parallel for reduction(std::max: max_dist)
for(index_t v = 0; v < mesh_ptx->n_vertices; ++v)
max_dist = std::max(max_dist, mesh_ptx->heatmap(v));

#pragma omp parallel for
for(index_t v = 0; v < mesh_ptx->n_vertices; ++v)
mesh_ptx->heatmap(v) /= max_dist;

return mesh_ptx;
}

Expand Down
17 changes: 16 additions & 1 deletion src/gproshan/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@
namespace gproshan {


partitions::partitions(index_t * s): sorted(s)
{
splits.push_back(0);
}

void partitions::add(const index_t & size)
{
return splits.push_back(size + splits.back());
}

size_t partitions::size(const index_t & i) const
{
return splits[i + 1] - splits[i];
}

partitions::part partitions::operator () (const index_t & i) const
{
assert(i > 0 && i < splits.size());
return {splits[i - 1], splits[i], sorted};
return {splits[i], splits[i + 1], sorted};
}


Expand Down
7 changes: 7 additions & 0 deletions src/gproshan/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void viewer::init_menus()
sub_menus.push_back("Viewer");
add_process(GLFW_KEY_F1, "F1", "Help", m_help);
add_process(GLFW_KEY_ESCAPE, "ESCAPE", "Close", m_close);
add_process(GLFW_KEY_F11, "F11", "Maximize", m_maximize);
add_process(GLFW_KEY_I, "F1", "Hide/Show ImGui", m_hide_show_imgui);
add_process(GLFW_KEY_PERIOD, "PERIOD", "Save/Load view", m_save_load_view);
add_process(GLFW_KEY_UP, "UP", "Zoom in", m_zoom_in);
Expand Down Expand Up @@ -650,6 +651,12 @@ bool viewer::m_close(viewer * view)
return false;
}

bool viewer::m_maximize(viewer * view)
{
glfwMaximizeWindow(view->window);
return false;
}

bool viewer::m_hide_show_imgui(viewer * view)
{
view->hide_imgui = !view->hide_imgui;
Expand Down

0 comments on commit cb5d967

Please sign in to comment.