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 25, 2024
2 parents 0100f16 + 602888d commit f518e58
Show file tree
Hide file tree
Showing 76 changed files with 488 additions and 559 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ endif(CUDAToolkit_FOUND)
set(GPROSHAN_DIR "${gproshan_SOURCE_DIR}")

option(GPROSHAN_LOG "Enables logging gproshan messages." ON)
option(GPROSHAN_FLOAT "Compile gproshan with float precision." ON)

set(GPROSHAN_CUDA ${CUDAToolkit_FOUND})
set(GPROSHAN_OPTIX ${OptiX_INCLUDE})
Expand Down
1 change: 0 additions & 1 deletion include/gproshan/config.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#cmakedefine GPROSHAN_FLOAT
#cmakedefine GPROSHAN_LOG
#cmakedefine GPROSHAN_CUDA
#cmakedefine GPROSHAN_OPTIX
Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/features/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class descriptor
operator bool () const;

///< return norm of the descriptor for the vertex v
real_t operator () (const index_t v) const;
float operator () (const index_t v) const;

private:
void compute_gps();
Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/features/key_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace gproshan {
class key_components
{
private:
real_t radio = 0;
float radio = 0;
size_t n_vertices = 0;
size_t n_comp = 0;
index_t * comp = nullptr;
size_t * comp_size = nullptr;
std::map<index_t, index_t> comp_idx;

public:
key_components(che * mesh, const std::vector<index_t> & kps, const real_t r);
key_components(che * mesh, const std::vector<index_t> & kps, const float r);
~key_components();
index_t operator()(const index_t i);
operator size_t () const;
Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/features/key_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class key_points
std::vector<bool> is_kp;

public:
key_points(che * mesh, const real_t percent = 0.10);
key_points(che * mesh, const float percent = 0.10);
operator const std::vector<index_t> & () const;

private:
void compute_kps_areas(che * mesh, const real_t percent);
void compute_kps_areas(che * mesh, const float percent);
};


Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/geodesics/dijkstra.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace gproshan {
class dijkstra
{
private:
real_t * weights;
float * weights;
index_t * predecessors;
size_t n_vertices;
index_t source;

public:
dijkstra(che * mesh, index_t src);
~dijkstra();
real_t & operator()(index_t i);
float & operator()(index_t i);
index_t & operator[](index_t i);
void print(std::ostream & os);

Expand Down
14 changes: 7 additions & 7 deletions include/gproshan/geodesics/geodesics.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class geodesics
{
algorithm alg = FM; ///< specific the algorithm to execute.
size_t n_iter = 0; ///< maximum number of iterations.
real_t radio = INFINITY; ///< execute until the specific radio.
real_t * dist_alloc = nullptr; ///< external dist allocation
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
};
Expand All @@ -45,7 +45,7 @@ class geodesics
index_t * clusters; ///< Clustering vertices to closest source.

private:
real_t * dist; ///< Results of computation geodesic distances.
float * dist; ///< Results of computation geodesic distances.
index_t * sorted_index; ///< Sort vertices by topological level or geodesic distance.
size_t n_sorted; ///< Number of vertices sorted by their geodesics distance.
bool free_dist;
Expand All @@ -59,18 +59,18 @@ class geodesics
);

virtual ~geodesics();
operator const real_t * () const;
real_t operator[](const index_t i) const;
operator const float * () const;
float operator[](const index_t i) const;
index_t operator()(const index_t i) const;
real_t radio() const;
float radio() const;
index_t farthest() const;
size_t n_sorted_index() const;
void copy_sorted_index(index_t * indexes, const size_t n) const;
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 real_t radio, const fm_function_t & fun);
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);

Expand Down
30 changes: 13 additions & 17 deletions include/gproshan/geodesics/geodesics_ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ namespace gproshan {
#ifdef __CUDACC__

__global__
void relax_ptp(const che * mesh, real_t * new_dist, real_t * old_dist, index_t * new_clusters, index_t * old_clusters, const index_t start, const index_t end, const index_t * sorted = nullptr);
void relax_ptp(const che * mesh, float * new_dist, float * old_dist, index_t * new_clusters, index_t * old_clusters, const index_t start, const index_t end, const index_t * sorted = nullptr);

__global__
void relative_error(real_t * error, const real_t * new_dist, const real_t * old_dist, const index_t start, const index_t end, const index_t * sorted = nullptr);
void relative_error(float * error, const float * new_dist, const float * old_dist, const index_t start, const index_t end, const index_t * sorted = nullptr);

struct is_ok
{
const real_t * error = nullptr;
const float * error = nullptr;

__host_device__
bool operator()(const real_t val) const;
bool operator()(const float val) const;

__host_device__
bool operator()(const index_t val) const;
Expand All @@ -51,10 +51,10 @@ struct is_ok

struct ptp_out_t
{
real_t * dist = nullptr;
float * dist = nullptr;
index_t * clusters = nullptr;

ptp_out_t(real_t *const d, index_t *const c = nullptr);
ptp_out_t(float *const d, index_t *const c = nullptr);
};

struct toplesets_t
Expand All @@ -74,7 +74,7 @@ double parallel_toplesets_propagation_gpu( const ptp_out_t & ptp_out,
const toplesets_t & toplesets,
const bool coalescence = true,
const bool set_inf = true,
const f_ptp<real_t> & fun = nullptr
const f_ptp<float> & fun = nullptr
);

void parallel_toplesets_propagation_cpu( const ptp_out_t & ptp_out,
Expand All @@ -83,21 +83,21 @@ void parallel_toplesets_propagation_cpu( const ptp_out_t & ptp_out,
const toplesets_t & toplesets,
const bool coalescence = true,
const bool set_inf = true,
const f_ptp<real_t> & fun = nullptr
const f_ptp<float> & fun = nullptr
);


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

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


template<class T>
#ifdef __CUDACC__
__forceinline__
#endif
__host_device__
real_t update_step(const che * mesh, const T * dist, const uvec3 & x)
float update_step(const che * mesh, const T * dist, const uvec3 & x)
{
const vec<T, 3> X[2] = {mesh->point(x[0]) - mesh->point(x[2]),
mesh->point(x[1]) - mesh->point(x[2])
Expand All @@ -124,11 +124,7 @@ real_t update_step(const che * mesh, const T * dist, const uvec3 & x)
(Q[0][0] + Q[0][1] + Q[1][0] + Q[1][1]) *
(t[0] * t[0] * Q[0][0] + t[0] * t[1] * (Q[1][0] + Q[0][1]) + t[1] * t[1] * Q[1][1] - 1);

#ifdef GPROSHAN_FLOAT
T p = (delta + sqrtf(dis)) / (Q[0][0] + Q[0][1] + Q[1][0] + Q[1][1]);
#else
T p = (delta + sqrt(dis)) / (Q[0][0] + Q[0][1] + Q[1][0] + Q[1][1]);
#endif

const vec<T, 2> tp = t - p;
const vec<T, 3> n = { tp[0] * (X[0][0]*Q[0][0] + X[1][0]*Q[1][0]) + tp[1] * (X[0][0]*Q[0][1] + X[1][0]*Q[1][1]),
Expand All @@ -155,7 +151,7 @@ __forceinline__
__host_device__
void relax_ptp(const che * mesh, T * new_dist, T * old_dist, index_t * new_clusters, index_t * old_clusters, const index_t v)
{
real_t & ndv = new_dist[v] = old_dist[v];
float & ndv = new_dist[v] = old_dist[v];
if(new_clusters) new_clusters[v] = old_clusters[v];

for(const index_t he: mesh->star(v))
Expand All @@ -165,7 +161,7 @@ void relax_ptp(const che * mesh, T * new_dist, T * old_dist, index_t * new_clust
mesh->halfedge(he)
};

real_t d = update_step(mesh, old_dist, i);
float d = update_step(mesh, old_dist, i);

if(d < ndv)
{
Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/geodesics/heat_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum heat_method_opt {
#endif // GPROSHAN_CUDA
};

double heat_method(real_t * 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 heat_method_opt & opt);

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

Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/geodesics/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace gproshan {


index_t ** sampling_shape(std::vector<index_t> & points, size_t *& sizes, vertex *& normals, che * mesh, size_t n_points, real_t radio);
index_t ** sampling_shape(std::vector<index_t> & points, size_t *& sizes, vertex *& normals, che * mesh, size_t n_points, float radio);

bool load_sampling(std::vector<index_t> & points, real_t & radio, che * mesh, size_t M);
bool load_sampling(std::vector<index_t> & points, float & radio, che * mesh, size_t M);


} // namespace gproshan
Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/geometry/convex_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class convex_hull
std::vector<index_t> CH; ///< convex hull points clockwise

public:
convex_hull(const std::vector<vertex> & points, const real_t precision = 1000);
convex_hull(const vertex * points, const size_t n_points, const real_t precision = 1000);
convex_hull(const std::vector<vertex> & points, const float precision = 1000);
convex_hull(const vertex * points, const size_t n_points, const float precision = 1000);
operator const std::vector<index_t> & () const;

private:
Expand Down
6 changes: 3 additions & 3 deletions include/gproshan/geometry/mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ mat<T, N> inverse(const mat<T, N> & m)
#endif // __CUDACC__


using mat2 = mat<real_t, 2>;
using mat3 = mat<real_t, 3>;
using mat4 = mat<real_t, 4>;
using mat2 = mat<float, 2>;
using mat3 = mat<float, 3>;
using mat4 = mat<float, 4>;


} // namespace gproshan
Expand Down
8 changes: 2 additions & 6 deletions include/gproshan/include.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ namespace gproshan {

using index_t = unsigned int;

#ifdef GPROSHAN_FLOAT
using real_t = float;
#else
using real_t = double;
#endif


inline std::string tmp_file_path(const std::string & file)
{
Expand All @@ -40,8 +34,10 @@ inline std::string tmp_file_path(const std::string & file)
return gproshan_home + "/" + file;
}


#define shaders_path(file) (std::string(GPROSHAN_DIR) + "/shaders/" + file)


#ifdef GPROSHAN_LOG
#define gproshan_log_var(vari) std::cerr << "\033[0;33m[LOG] " << std::setprecision(3) << std::scientific << #vari << ":\033[0m " << (vari) << std::endl
#define gproshan_log(message) fprintf(stderr, "\033[1;31m[LOG] %s: %s\n\033[0m", #message, __FUNCTION__)
Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/laplacian/fairing_taubin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace gproshan {
class fairing_taubin : public fairing
{
public:
real_t step;
float step;

public:
fairing_taubin(const real_t step_ = 0.001);
fairing_taubin(const float step_ = 0.001);
virtual ~fairing_taubin() = default;

private:
Expand Down
8 changes: 4 additions & 4 deletions include/gproshan/mdict/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ namespace gproshan::mdict {
class basis
{
protected:
real_t _radio;
float _radio;
size_t _dim;

public:
basis(const real_t r, const size_t d);
basis(const float r, const size_t d);
virtual ~basis() = default;
virtual void discrete(arma::fmat & phi, const arma::fvec & x, const arma::fvec & y) = 0;
virtual void d_discrete(arma::fmat & phi, const arma::fvec & x, const arma::fvec & y, const bool b) = 0;
virtual real_t freq(const index_t idx) = 0;
real_t & radio();
virtual float freq(const index_t idx) = 0;
float & radio();
size_t dim() const;
void plot_basis();
void plot_atoms(const arma::fmat & A);
Expand Down
6 changes: 3 additions & 3 deletions include/gproshan/mdict/basis_cosine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class basis_cosine: public basis
size_t n_freq; ///< frequency

public:
basis_cosine(const size_t nr, const size_t nf, const real_t r = 0);
basis_cosine(const size_t nr, const size_t nf, const float r = 0);
void discrete(arma::fmat & phi, const arma::fvec & x, const arma::fvec & y);

private:
void plot_basis(std::ostream & os);
void plot_atoms(std::ostream & os, const arma::fvec & A);
arma::fvec cosine(const arma::fvec & x, const arma::fvec & y, const real_t c, const real_t alpha);
void cosine(std::ostream & os, const real_t c, const real_t alpha);
arma::fvec cosine(const arma::fvec & x, const arma::fvec & y, const float c, const float alpha);
void cosine(std::ostream & os, const float c, const float alpha);
};


Expand Down
4 changes: 2 additions & 2 deletions include/gproshan/mdict/basis_dct.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class basis_dct: public basis
size_t n_freq; ///< frequency

public:
basis_dct(const size_t n, const real_t r = 1);
basis_dct(const size_t n, const float r = 1);
void discrete(arma::fmat & phi, const arma::fvec & x, const arma::fvec & y);
void d_discrete(arma::fmat & phi, const arma::fvec & x, const arma::fvec & y, const bool b);
real_t freq(const index_t idx);
float freq(const index_t idx);

private:
void plot_basis(std::ostream & os);
Expand Down
2 changes: 1 addition & 1 deletion include/gproshan/mdict/mdict.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace gproshan::mdict {
struct locval_t
{
arma::uword i, j;
real_t val;
float val;
};


Expand Down
Loading

0 comments on commit f518e58

Please sign in to comment.