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 6, 2023
2 parents 859831f + b58d315 commit 15c56c6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 30 deletions.
6 changes: 5 additions & 1 deletion apps/test_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ int main(int argc, char* argv[])

gproshan::rt::raytracing * rt_embree = new gproshan::rt::embree({mesh_ply}, {model_mat}, false, pc_radius);

gproshan::che * ptx_mesh = scanner_ptx(mesh_ply, rt_embree, n_rows, n_cols, {0, 0, 0}, jpg_folder);
gproshan::che * ptx_mesh = gproshan::scanner_ptx_jpg(rt_embree, n_rows, n_cols, {0, 0, 0}, jpg_folder + mesh_ply->name());

std::string ptx_filename = ptx_folder + mesh_ply->name();
gproshan::che_ptx::write_file(ptx_mesh, ptx_filename, n_rows, n_cols);

delete mesh_ply;
delete rt_embree;
delete ptx_mesh;

return 0;
}

2 changes: 1 addition & 1 deletion include/gproshan/mesh/che.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class che
void reload();
mat4 normalize_sphere(const real_t & r = 1) const;
mat4 normalize_box(const real_t & side = 2) const;
che * merge(const che * mesh, const std::vector<index_t> & com_vertices);
che * merge(const che * mesh, const std::vector<index_t> & com_vertices = {});
void update_vertices(const vertex * positions, const size_t & n = 0, const index_t & v_i = 0);
void update_heatmap(const real_t * hm = nullptr);
void update_normals();
Expand Down
12 changes: 6 additions & 6 deletions include/gproshan/raytracing/embree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class embree : public raytracing
);
virtual ~embree();

virtual index_t closest_vertex(const vertex & org, const vertex & dir);
virtual eval_hit intersect(const vertex & org, const vertex & dir);
virtual index_t closest_vertex(const vertex & org, const vertex & dir) const;
virtual eval_hit intersect(const vertex & org, const vertex & dir) const;


protected:
Expand All @@ -59,12 +59,12 @@ class embree : public raytracing

virtual index_t add_pointcloud(const che * mesh, const mat4 & model_mat);

virtual vec3 closesthit_radiance(const vertex & org, const vertex & dir, const light & ambient, const light * lights, const int & n_lights, const vertex & cam_pos, const bool & flat);
virtual vec3 closesthit_radiance(const vertex & org, const vertex & dir, const light & ambient, const light * lights, const int & n_lights, const vertex & cam_pos, const bool & flat) const;

float intersect_depth(const vertex & org, const vertex & dir);
float intersect_depth(const vertex & org, const vertex & dir) const;

bool intersect(ray_hit & r);
bool occluded(ray_hit & r);
bool intersect(ray_hit & r) const;
bool occluded(ray_hit & r) const;
};


Expand Down
10 changes: 5 additions & 5 deletions include/gproshan/raytracing/raytracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class raytracing
const mat4 & inv_proj_view,
const vertex & cam_pos,
const index_t & samples = 4
);
) const;

virtual eval_hit intersect( const vertex &, // org
const vertex & //dir
) { return {}; }
) const { return {}; }

virtual index_t closest_vertex( const vertex &, // org,
const vertex & // dir
) { return NIL; };
) const { return NIL; }

protected:
virtual vec3 closesthit_radiance( const vertex &, // org
Expand All @@ -45,11 +45,11 @@ class raytracing
const int &, // n_lights
const vertex &, // cam_pos
const bool & // flat
) { return {}; };
) const { return {}; };

virtual float intersect_depth( const vertex &, // org,
const vertex & // dir
) { return 0; };
) const { return 0; };
};


Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/scenes/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace gproshan {

che * scanner_ptx(const rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos);

che * scanner_ptx(const che * mesh, rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos, const std::string & file_jpg = "");
che * scanner_ptx_jpg(const rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos, const std::string & file_jpg = "");


} // namespace gproshan
Expand Down
2 changes: 1 addition & 1 deletion src/gproshan/app_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool app_viewer::process_simulate_scanner(viewer * p_view)

if(ImGui::Button("Scan"))
{
che * ptx_mesh = scanner_ptx(mesh, mesh.rt_embree, n_rows, n_cols, cam_pos);
che * ptx_mesh = scanner_ptx_jpg(mesh.rt_embree, n_rows, n_cols, cam_pos, mesh->filename);
che_ptx::write_file(ptx_mesh, mesh->filename, n_rows, n_cols);
view->add_mesh(ptx_mesh);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gproshan/mesh/che.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ che * che::merge(const che * mesh, const std::vector<index_t> & vcommon)

memcpy(new_mesh->GT, GT, sizeof(vertex) * n_vertices);
memcpy(new_mesh->GT + n_vertices, mesh->GT + n_vcommon, sizeof(vertex) * n_vnew);
memcpy(new_mesh->VN, VN, sizeof(vertex) * n_vertices);
memcpy(new_mesh->VN + n_vertices, mesh->VN + n_vcommon, sizeof(vertex) * n_vnew);
memcpy(new_mesh->VC, VC, sizeof(rgb_t) * n_vertices);
memcpy(new_mesh->VC + n_vertices, mesh->VC + n_vcommon, sizeof(rgb_t) * n_vnew);
memcpy(new_mesh->VHC, VHC, sizeof(real_t) * n_vertices);
Expand All @@ -307,8 +309,6 @@ che * che::merge(const che * mesh, const std::vector<index_t> & vcommon)
new_mesh->update_evt_ot_et();
new_mesh->update_eht();

new_mesh->update_normals();

return new_mesh;
}

Expand Down
10 changes: 7 additions & 3 deletions src/gproshan/mesh/che_ply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ void che_ply::read_file(const std::string & file)

if(format[0] == 'a') // ascii
{
float x, y, z;
float x, y, z, nx, ny, nz;
unsigned char r, g, b;
for(index_t v = 0; v < n_vertices; ++v)
{
fgets(line, sizeof(line), fp);
if(sscanf(line, "%f %f %f %hhu %hhu %hhu", &x, &y, &z, &r, &g, &b) > 5)
VC[v] = {r, g, b};

rgb ? sscanf(line, "%f %f %f %hhu %hhu %hhu %f %f %f", &x, &y, &z, &r, &g, &b, &nx, &ny, &nz)
: sscanf(line, "%f %f %f %f %f %f", &x, &y, &z, &nx, &ny, &nz);

GT[v] = {x, y, z};
if(rgb) VC[v] = {r, g, b};
if(normal) VN[v] = {nx, ny, nz};
}

while(nf--)
Expand Down
12 changes: 6 additions & 6 deletions src/gproshan/raytracing/embree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ embree::~embree()
rtcReleaseDevice(rtc_device);
}

index_t embree::closest_vertex(const vertex & org, const vertex & dir)
index_t embree::closest_vertex(const vertex & org, const vertex & dir) const
{
ray_hit r(org, dir);
if(!intersect(r)) return NIL;
Expand All @@ -109,7 +109,7 @@ index_t embree::closest_vertex(const vertex & org, const vertex & dir)
return mesh->VT[he];
}

eval_hit embree::intersect(const vertex & org, const vertex & dir)
eval_hit embree::intersect(const vertex & org, const vertex & dir) const
{
ray_hit r(org, dir);
if(!intersect(r)) return {};
Expand Down Expand Up @@ -246,7 +246,7 @@ index_t embree::add_pointcloud(const che * mesh, const mat4 & model_mat)
return geom_id;
}

vec3 embree::closesthit_radiance(const vertex & org, const vertex & dir, const light & ambient, const light * lights, const int & n_lights, const vertex & cam_pos, const bool & flat)
vec3 embree::closesthit_radiance(const vertex & org, const vertex & dir, const light & ambient, const light * lights, const int & n_lights, const vertex & cam_pos, const bool & flat) const
{
ray_hit r(org, dir);
if(!intersect(r)) return {};
Expand All @@ -267,19 +267,19 @@ vec3 embree::closesthit_radiance(const vertex & org, const vertex & dir, const l
});
}

float embree::intersect_depth(const vertex & org, const vertex & dir)
float embree::intersect_depth(const vertex & org, const vertex & dir) const
{
ray_hit r(org, dir);
return intersect(r) ? r.ray.tfar : 0.f;
}

bool embree::intersect(ray_hit & r)
bool embree::intersect(ray_hit & r) const
{
rtcIntersect1(rtc_scene, &r);
return r.hit.geomID != RTC_INVALID_GEOMETRY_ID;
}

bool embree::occluded(ray_hit & r)
bool embree::occluded(ray_hit & r) const
{
rtcIntersect1(rtc_scene, &r);
return r.hit.geomID != RTC_INVALID_GEOMETRY_ID;
Expand Down
2 changes: 1 addition & 1 deletion src/gproshan/raytracing/raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void raytracing::render(vec4 * img, const render_params & params, const bool & f
float * raytracing::raycaster( const ivec2 & windows_size,
const mat4 & inv_proj_view,
const vertex & cam_pos,
const index_t & samples )
const index_t & samples ) const
{
float * frame = new float[windows_size.x() * windows_size.y()];

Expand Down
6 changes: 3 additions & 3 deletions src/gproshan/scenes/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace cimg_library;
namespace gproshan {


che * scanner_ptx(rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos)
che * scanner_ptx(const rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos)
{
che * mesh_ptx = new che(n_cols * n_rows);

Expand Down Expand Up @@ -47,14 +47,14 @@ che * scanner_ptx(rt::raytracing * rt, const size_t & n_rows, const size_t & n_c
return mesh_ptx;
}

che * scanner_ptx(const che * mesh, rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos, const std::string & file_jpg)
che * scanner_ptx_jpg(const rt::raytracing * rt, const size_t & n_rows, const size_t & n_cols, const vertex & cam_pos, const std::string & file_jpg)
{
che * mesh_ptx = scanner_ptx(rt, n_rows, n_cols, cam_pos);

CImg<unsigned char> img((unsigned char *) &mesh_ptx->rgb(0), 3, n_cols, n_rows);
img.permute_axes("zycx");

std::string img_filename = file_jpg + mesh->name() + ".jpg";
std::string img_filename = file_jpg + ".jpg";
img.save(img_filename.c_str());

std::thread([](const CImg<unsigned char> & img) { img.display(); }, img).detach();
Expand Down

0 comments on commit 15c56c6

Please sign in to comment.