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 Jan 10, 2024
2 parents c9e683f + accd707 commit b8db78d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 33 deletions.
12 changes: 5 additions & 7 deletions apps/test_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@

int main(int argc, char* argv[])
{
if(argc < 2 || argc > 7)
if(argc != 6)
{
std::cerr << "Correct usage: ./apps/test_scanner n_rows n_cols pc_radius ptx_folder jpg_folder" << std::endl;
std::cerr << "Correct usage: ./apps/test_scanner mesh n_rows n_cols ptx_folder jpg_folder" << std::endl;
return -1;
}

size_t n_rows = atoi(argv[2]);
size_t n_cols = atoi(argv[3]);

float pc_radius = atof(argv[4]);

char * ptx_folder = argv[5];
char * jpg_folder = argv[6];
char * ptx_folder = argv[4];
char * jpg_folder = argv[5];

gproshan_log_var(ptx_folder);
gproshan_log_var(jpg_folder);
Expand All @@ -30,7 +28,7 @@ int main(int argc, char* argv[])

const gproshan::mat4 & model_mat = mesh_ply->normalize_box();

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

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

Expand Down
23 changes: 16 additions & 7 deletions include/gproshan/raytracing/embree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ namespace gproshan::rt {

class embree : public raytracing
{
public:
struct pc_opts
{
bool enable = false;
bool normals = false;
float radius = 0.01;
int knn = 0;

pc_opts() {};
};

protected:
struct ray_hit : public RTCRayHit
{
ray_hit(const vertex & p_org = {0, 0, 0},
const vertex & v_dir = {0, 0, 0},
float near = 1e-5f,
float far = 1e20f);
float far = 1e20f
);

vertex org() const;
vertex dir() const;
Expand All @@ -37,14 +49,11 @@ class embree : public raytracing
std::vector<CHE *> g_meshes;
scene_data sc;

float pc_radius = 0.01;

public:
embree();
embree( const std::vector<che *> & meshes,
const std::vector<mat4> & model_mats,
const bool & pointcloud = false,
const float pcr = 0.01
const pc_opts & pc = pc_opts()
);
virtual ~embree();

Expand All @@ -55,13 +64,13 @@ class embree : public raytracing
protected:
void build_bvh( const std::vector<che *> & meshes,
const std::vector<mat4> & model_mats,
const bool & pointcloud = false
const pc_opts & pc = pc_opts()
);

index_t add_sphere(const vec4 & xyzr);
index_t add_mesh(const che * mesh, const mat4 & model_mat);

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

virtual bool closesthit_radiance( vertex & color,
vertex & attenuation,
Expand Down
53 changes: 35 additions & 18 deletions src/gproshan/raytracing/embree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


#include <gproshan/util.h>
#include <gproshan/pointcloud/knn.h>

#include <random>
#include <cstring>
Expand Down Expand Up @@ -67,10 +68,9 @@ embree::embree()
rtcSetDeviceErrorFunction(rtc_device, embree_error, NULL);
}

embree::embree(const std::vector<che *> & meshes, const std::vector<mat4> & model_mats, const bool & pointcloud, const float pcr): embree()
embree::embree(const std::vector<che *> & meshes, const std::vector<mat4> & model_mats, const pc_opts & pc): embree()
{
pc_radius = pcr;
build_bvh(meshes, model_mats, pointcloud);
build_bvh(meshes, model_mats, pc);
}

embree::~embree()
Expand Down Expand Up @@ -122,20 +122,20 @@ eval_hit embree::intersect(const vertex & org, const vertex & dir, const bool &
return hit;
}

void embree::build_bvh(const std::vector<che *> & meshes, const std::vector<mat4> & model_mats, const bool & pointcloud)
void embree::build_bvh(const std::vector<che *> & meshes, const std::vector<mat4> & model_mats, const pc_opts & pc)
{
g_meshes.resize(size(meshes));
for(index_t i = 0; i < size(meshes); ++i)
{
g_meshes[i] = new CHE(meshes[i]);

if(!meshes[i]->n_trigs || pointcloud)
if(!meshes[i]->n_trigs || pc.enable)
g_meshes[i]->n_trigs = 0;

[[maybe_unused]]
const index_t geomID = g_meshes[i]->n_trigs || meshes[i]->is_scene() ?
add_mesh(meshes[i], model_mats[i]) :
add_pointcloud(meshes[i], model_mats[i]);
add_pointcloud(meshes[i], model_mats[i], pc);

gproshan_debug_var(i == geomID);
}
Expand Down Expand Up @@ -214,30 +214,47 @@ index_t embree::add_mesh(const che * mesh, const mat4 & model_mat)
return geom_id;
}

index_t embree::add_pointcloud(const che * mesh, const mat4 & model_mat)
index_t embree::add_pointcloud(const che * mesh, const mat4 & model_mat, const pc_opts & pc)
{
RTCGeometry geom = rtcNewGeometry(rtc_device, RTC_GEOMETRY_TYPE_DISC_POINT);
RTCGeometry geom = rtcNewGeometry(rtc_device, pc.normals ? RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT
: RTC_GEOMETRY_TYPE_DISC_POINT);

vec4 * pxyzr = (vec4 *) rtcSetNewGeometryBuffer( geom,
RTC_BUFFER_TYPE_VERTEX, 0,
RTC_FORMAT_FLOAT4,
4 * sizeof(float),
mesh->n_vertices
);
/*
vertex * normal = (vertex *) rtcSetNewGeometryBuffer( geom,
RTC_BUFFER_TYPE_NORMAL, 0,
RTC_FORMAT_FLOAT3,
3 * sizeof(float),
mesh->n_vertices
);
*/

vertex * normals = !pc.normals ? nullptr
: (vertex *) rtcSetNewGeometryBuffer( geom,
RTC_BUFFER_TYPE_NORMAL, 0,
RTC_FORMAT_FLOAT3,
3 * sizeof(float),
mesh->n_vertices
);


knn::k3tree * nn = !pc.knn ? nullptr
: new knn::k3tree(&mesh->point(0), mesh->n_vertices, pc.knn);


#pragma omp parallel for
for(index_t i = 0; i < mesh->n_vertices; ++i)
{
pxyzr[i] = model_mat * (mesh->point(i), 1);
pxyzr[i][3] = pc_radius;
// normal[i] = mesh->normal(i);
pxyzr[i][3] = nn ? length(model_mat * (mesh->point(i), 1) - model_mat * (mesh->point((*nn)(i, pc.knn - 1)), 1)) : pc.radius;
}


delete nn;


if(normals)
{
#pragma omp parallel for
for(index_t i = 0; i < mesh->n_vertices; ++i)
normals[i] = mesh->normal(i);
}

rtcCommitGeometry(geom);
Expand Down
14 changes: 13 additions & 1 deletion src/gproshan/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,21 +977,33 @@ bool viewer::m_setup_raytracing(viewer * view)

static int rt = 0;
static double time = 0;
static rt::embree::pc_opts pc;

ImGui::SliderInt("depth", (int *) &view->render_params.depth, 1, 1 << 5);
ImGui::SliderInt("n_samples", (int *) &view->render_params.n_samples, 1, 1 << 5);
ImGui::Combo("rt", &rt, "Select\0Embree\0OptiX\0\0");

if(rt == R_EMBREE && (mesh.render_pointcloud || mesh->is_pointcloud()))
{
ImGui::Indent();
ImGui::SliderInt("pc.knn", &pc.knn, 0, 1 << 5);
ImGui::SliderFloat("pc.radius", &pc.radius, 0, 1);
ImGui::Checkbox("pc.normals", &pc.normals);
ImGui::Unindent();
}

if(ImGui::Button("Build"))
{
pc.enable |= mesh.render_pointcloud;

switch(rt)
{
case R_GL: break;

case R_EMBREE:
delete mesh.rt_embree;
TIC(time);
mesh.rt_embree = new rt::embree({mesh}, {mesh.model_mat}, mesh.render_pointcloud);
mesh.rt_embree = new rt::embree({mesh}, {mesh.model_mat}, pc);
TOC(time);
view->update_status_message("build embree in %.3fs", time);
break;
Expand Down

0 comments on commit b8db78d

Please sign in to comment.