diff --git a/include/gproshan/geometry/vec.h b/include/gproshan/geometry/vec.h index 9083c3ae..922f742c 100644 --- a/include/gproshan/geometry/vec.h +++ b/include/gproshan/geometry/vec.h @@ -144,13 +144,13 @@ class vec return res; } - ///< scalar division + ///< element wise division & scalar division __host_device__ - vec operator / (const T & a) const + vec operator / (const vec & v) const { vec res; for(index_t i = 0; i < N; ++i) - res[i] = values[i] / a; + res[i] = values[i] / v[i]; return res; } @@ -193,12 +193,12 @@ class vec return *this; } - ///< scalar division self assign + ///< element wise division self assign __host_device__ - const vec & operator /= (const T & a) + const vec & operator /= (const vec & v) { - for(T & v: values) - v /= a; + for(index_t i = 0; i < N; ++i) + values[i] /= v[i]; return *this; } @@ -263,6 +263,16 @@ vec operator * (const T & a, const vec & v) return v * a; } +///< scalar product +template +__host_device__ +vec operator / (const T & a, const vec & v) +{ + vec res; + for(index_t i = 0; i < N; ++i) + res[i] = a / v[i]; + return res; +} ///< cross product template diff --git a/include/gproshan/mesh/che.h b/include/gproshan/mesh/che.h index 4b8e3b78..5c524d54 100644 --- a/include/gproshan/mesh/che.h +++ b/include/gproshan/mesh/che.h @@ -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; diff --git a/include/gproshan/raytracing/embree.h b/include/gproshan/raytracing/embree.h index c1fe92c6..fa6c8f86 100644 --- a/include/gproshan/raytracing/embree.h +++ b/include/gproshan/raytracing/embree.h @@ -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; diff --git a/include/gproshan/raytracing/utils.h b/include/gproshan/raytracing/utils.h index cad89df9..93514412 100644 --- a/include/gproshan/raytracing/utils.h +++ b/include/gproshan/raytracing/utils.h @@ -78,13 +78,6 @@ 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) { @@ -92,6 +85,15 @@ struct t_eval_hit 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]; diff --git a/include/gproshan/util.h b/include/gproshan/util.h index 9b088a50..64d31e0a 100644 --- a/include/gproshan/util.h +++ b/include/gproshan/util.h @@ -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; }; diff --git a/include/gproshan/viewer/viewer.h b/include/gproshan/viewer/viewer.h index fd7a9200..3e3acc4e 100644 --- a/include/gproshan/viewer/viewer.h +++ b/include/gproshan/viewer/viewer.h @@ -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); diff --git a/src/gproshan/mesh/che.cpp b/src/gproshan/mesh/che.cpp index 1d206688..e6e9d325 100644 --- a/src/gproshan/mesh/che.cpp +++ b/src/gproshan/mesh/che.cpp @@ -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) {} diff --git a/src/gproshan/mesh/che_ply.cpp b/src/gproshan/mesh/che_ply.cpp index 01a7ef4e..29afb253 100644 --- a/src/gproshan/mesh/che_ply.cpp +++ b/src/gproshan/mesh/che_ply.cpp @@ -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"); @@ -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) diff --git a/src/gproshan/raytracing/embree.cpp b/src/gproshan/raytracing/embree.cpp index 7f35e9e7..f0b25a7a 100644 --- a/src/gproshan/raytracing/embree.cpp +++ b/src/gproshan/raytracing/embree.cpp @@ -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; diff --git a/src/gproshan/raytracing/optix.cu b/src/gproshan/raytracing/optix.cu index b42dabec..de3c95e4 100644 --- a/src/gproshan/raytracing/optix.cu +++ b/src/gproshan/raytracing/optix.cu @@ -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), diff --git a/src/gproshan/scenes/scanner.cpp b/src/gproshan/scenes/scanner.cpp index 8057a52e..5da52172 100644 --- a/src/gproshan/scenes/scanner.cpp +++ b/src/gproshan/scenes/scanner.cpp @@ -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; } diff --git a/src/gproshan/util.cpp b/src/gproshan/util.cpp index b81b31a7..2d736bc4 100644 --- a/src/gproshan/util.cpp +++ b/src/gproshan/util.cpp @@ -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}; } diff --git a/src/gproshan/viewer/viewer.cpp b/src/gproshan/viewer/viewer.cpp index 04a27523..6dde08da 100644 --- a/src/gproshan/viewer/viewer.cpp +++ b/src/gproshan/viewer/viewer.cpp @@ -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); @@ -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;