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 Mar 27, 2024
2 parents f518e58 + 79cfd5e commit 477f08f
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 267 deletions.
34 changes: 13 additions & 21 deletions include/gproshan/geodesics/geodesics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ class geodesics
using fm_function_t = std::function<bool (const index_t)>;

public:
enum algorithm { FM, ///< Execute Fast Marching algorithm
PTP_CPU, ///< Execute Parallel Toplesets Propagation CPU algorithm
HEAT_METHOD, ///< Execute Heat Method - cholmod (CPU)
enum algorithm { FM, ///< Execute Fast Marching algorithm
PTP_CPU, ///< Execute Parallel Toplesets Propagation CPU algorithm
HEAT_METHOD, ///< Execute Heat Method - cholmod (CPU)
#ifdef GPROSHAN_CUDA
PTP_GPU, ///< Execute Parallel Toplesets Propagation GPU algorithm
HEAT_METHOD_GPU ///< Execute Heat Method - cusparse (GPU)
PTP_GPU, ///< Execute Parallel Toplesets Propagation GPU algorithm
HEAT_METHOD_GPU ///< Execute Heat Method - cusparse (GPU)
#endif // GPROSHAN_CUDA
};

struct params
{
algorithm alg = FM; ///< specific the algorithm to execute.
size_t n_iter = 0; ///< maximum number of iterations.
float radio = INFINITY; ///< execute until the specific radio.
float * dist_alloc = nullptr; ///< external dist allocation
bool cluster = false; ///< to cluster vertices to closest source.
fm_function_t fun = nullptr; ///< fun is executed inside FM loop
algorithm alg = FM; ///< specific the algorithm to execute.
size_t n_iter = 0; ///< maximum number of iterations.
float radio = INFINITY; ///< execute until the specific radio.
float * dist_alloc = nullptr; ///< external dist allocation
bool cluster = false; ///< to cluster vertices to closest source.
fm_function_t fun = nullptr; ///< fun is executed inside FM loop
};

public:
Expand Down Expand Up @@ -69,16 +69,8 @@ class geodesics
void normalize();

private:
void execute(che * mesh, const std::vector<index_t> & sources, const params & p);
void run_fastmarching(che * mesh, const std::vector<index_t> & sources, const size_t n_iter, const float radio, const fm_function_t & fun);
void run_parallel_toplesets_propagation_cpu(che * mesh, const std::vector<index_t> & sources);
void run_heat_method(che * mesh, const std::vector<index_t> & sources);

#ifdef GPROSHAN_CUDA
void run_parallel_toplesets_propagation_gpu(che * mesh, const std::vector<index_t> & sources);
void run_heat_method_gpu(che * mesh, const std::vector<index_t> & sources);
#endif // GPROSHAN_CUDA

double execute(che * mesh, const std::vector<index_t> & sources, const params & p);
double run_fastmarching(che * mesh, const std::vector<index_t> & sources, const size_t n_iter, const float radio, const fm_function_t & fun);
};


Expand Down
21 changes: 14 additions & 7 deletions include/gproshan/geodesics/geodesics_ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <gproshan/mesh/che.h>
#include <gproshan/mesh/toplesets.h>

#include <functional>

Expand Down Expand Up @@ -57,10 +58,16 @@ struct ptp_out_t
ptp_out_t(float *const d, index_t *const c = nullptr);
};

struct toplesets_t

struct coalescence_ptp
{
const std::vector<index_t> & limits;
const index_t * index;
che * mesh = nullptr;
index_t * inv = nullptr;

coalescence_ptp(const che * mesh, const toplesets & tps);
~coalescence_ptp();

operator const index_t * () const;
};


Expand All @@ -71,23 +78,23 @@ using f_ptp = std::function<void(T *, index_t, index_t, index_t, index_t)>;
double parallel_toplesets_propagation_gpu( const ptp_out_t & ptp_out,
const che * mesh,
const std::vector<index_t> & sources,
const toplesets_t & toplesets,
const toplesets & tps,
const bool coalescence = true,
const bool set_inf = true,
const f_ptp<float> & fun = nullptr
);

void parallel_toplesets_propagation_cpu( const ptp_out_t & ptp_out,
double parallel_toplesets_propagation_cpu( const ptp_out_t & ptp_out,
const che * mesh,
const std::vector<index_t> & sources,
const toplesets_t & toplesets,
const toplesets & tps,
const bool coalescence = true,
const bool set_inf = true,
const f_ptp<float> & fun = nullptr
);


float farthest_point_sampling_ptp_gpu(che * mesh, std::vector<index_t> & samples, double & time_fps, size_t n, float radio = 0);
double farthest_point_sampling_ptp_gpu(che * mesh, std::vector<index_t> & samples, size_t n, float radio = 0);

void normalize_ptp(float * dist, const size_t n);

Expand Down
18 changes: 9 additions & 9 deletions include/gproshan/geodesics/heat_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
// geometry processing and shape analysis framework
namespace gproshan {

enum heat_method_opt {
HEAT_ARMA,
HEAT_CHOLMOD,
#ifdef GPROSHAN_CUDA
HEAT_CUDA
#endif // GPROSHAN_CUDA
};
enum hm_opt {
HEAT_ARMA,
HEAT_CHOLMOD,
#ifdef GPROSHAN_CUDA
HEAT_CUDA
#endif // GPROSHAN_CUDA
};

double heat_method(float * dist, const che * mesh, const std::vector<index_t> & sources, const heat_method_opt & opt);
double heat_method(float * dist, const che * mesh, const std::vector<index_t> & sources, const hm_opt & opt);

arma::vec compute_divergence(const che * mesh, const arma::vec & u);


#ifdef GPROSHAN_CUDA

double solve_positive_definite_gpu(arma::mat & x, const arma::sp_mat & A, const arma::mat & b);
double solve_positive_definite_cusolver(const int m, const int nnz, const double * hA_values, const int * hA_col_ptrs, const int * hA_row_indices, const double * hb, double * hx, const bool host = 0);
double solve_positive_definite_cusolver(const int m, const int nnz, const double * hA_values, const int * hA_col_ptrs, const int * hA_row_indices, const double * hb, double * hx);

#endif // GPROSHAN_CUDA

Expand Down
9 changes: 2 additions & 7 deletions include/gproshan/mesh/che.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ using vertex = vec3;

class che
{
protected:

static size_t & rw(const size_t & n);


public:
static size_t & rw(const size_t & n);

struct options
{
Expand Down Expand Up @@ -91,7 +87,7 @@ class che

vertex * VN = nullptr; ///< vertex normals : v -> normal(v)
rgb_t * VC = nullptr; ///< vertex color : v -> color(v)
float * VHC = nullptr; ///< vertex color heatmap : v -> heatmap(v)
float * VHC = nullptr; ///< vertex color heatmap : v -> heatmap(v)
float scale_hm = 1; ///< vertex color heatmap scale factor

bool manifold = true;
Expand Down Expand Up @@ -277,7 +273,6 @@ class che

std::vector<index_t> link(const index_t v) const;
void edge_collapse(const std::vector<index_t> & sort_edges);
void compute_toplesets(index_t * rings, index_t * sorted, std::vector<index_t> & limites, const std::vector<index_t> & sources, const index_t k = NIL);

std::vector<index_t> bounds() const;
std::vector<index_t> boundary(const index_t v) const;
Expand Down
80 changes: 80 additions & 0 deletions include/gproshan/mesh/toplesets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef TOPLESETS_H
#define TOPLESETS_H

#include <gproshan/mesh/che.h>


// geometry processing and shape analysis framework
namespace gproshan {


class toplesets: public partitions
{
std::vector<index_t> level;

public:
const size_t n_levels = 0;

public:
toplesets(const che * mesh, const std::vector<index_t> & sources, const index_t max_level = NIL)
{
reset(mesh, sources, max_level);
}

~toplesets()
{
delete [] sorted;
}

index_t operator [] (const index_t i) const
{
return level[i];
}

void reset(const che * mesh, const std::vector<index_t> & sources, const index_t max_level = NIL)
{
if(std::size(level) < mesh->n_vertices)
{
delete [] sorted;
sorted = new index_t[mesh->n_vertices];
}
level.assign(mesh->n_vertices, NIL);

index_t l = 0;
index_t n = 0;
for(index_t s: sources)
{
sorted[n++] = s;
level[s] = l;
}

splits.clear();
splits.push_back(0);
for(index_t i = 0; i < n; ++i)
{
const index_t v = sorted[i];

if(level[v] > l)
{
if(++l > max_level) break;
splits.push_back(i);
}

for(index_t u: mesh->link(v))
if(level[u] == NIL)
{
level[u] = level[v] + 1;
sorted[n++] = u;
}
}
splits.push_back(n);

che::rw(n_levels) = std::size(splits) - 1;
}
};


} // namespace gproshan

#endif // TOPLESETS_H

5 changes: 3 additions & 2 deletions include/gproshan/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class partitions
{
struct part;

std::vector<index_t> splits;
index_t * sorted = nullptr;
public:
std::vector<index_t> splits;
index_t * sorted = nullptr;

public:
partitions(index_t * s = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class viewer
virtual bool run();

void info_gl();
void init_gl(const char * title);
bool init_gl(const char * title);
void init_imgui();
void init_menus();
void init_glsl();
Expand Down
19 changes: 4 additions & 15 deletions src/gproshan/app_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,27 +614,16 @@ bool app_viewer::process_compute_toplesets(viewer * p_view)
if(!size(mesh.selected))
mesh.selected.push_back(0);

index_t * toplesets = new index_t[mesh->n_vertices];
index_t * sorted = new index_t[mesh->n_vertices];
std::vector<index_t> limites;
mesh->compute_toplesets(toplesets, sorted, limites, mesh.selected);

size_t n_toplesets = size(limites) - 1;
toplesets tps(mesh, mesh.selected);
size_t n_levels = tps.n_levels;

#pragma omp parallel for
for(index_t v = 0; v < mesh->n_vertices; ++v)
{
if(toplesets[v] < n_toplesets)
mesh->heatmap(v) = float(toplesets[v]) / (n_toplesets);
}
mesh->heatmap(v) = tps[v] < n_levels ? float(tps[v]) / n_levels : -1;

mesh.update_vbo_heatmap();

gproshan_debug_var(n_toplesets);

delete [] toplesets;
delete [] sorted;

gproshan_debug_var(n_levels);
return false;
}

Expand Down
Loading

0 comments on commit 477f08f

Please sign in to comment.