Skip to content

Commit

Permalink
che: #14 - normalize sphere model_mat
Browse files Browse the repository at this point in the history
  • Loading branch information
larc committed Nov 8, 2022
1 parent c33c9a3 commit aa9da27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/gproshan/mesh/che.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class che

// update methods
void reload();
void normalize_sphere(const real_t & r = 1);
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);
void update_vertices(const vertex * positions, const size_t & n = 0, const index_t & v_i = 0);
Expand Down
26 changes: 17 additions & 9 deletions src/gproshan/mesh/che.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void che::reload()
init(filename);
}

void che::normalize_sphere(const real_t & r)
mat4 che::normalize_sphere(const real_t & r) const
{
vertex center;

Expand All @@ -207,16 +207,24 @@ void che::normalize_sphere(const real_t & r)

real_t max_norm = 0;

#pragma omp parallel for reduction(max: max_norm)
#pragma omp parallel for reduction(+: max_norm)
for(index_t v = 0; v < n_vertices; ++v)
{
GT[v] -= center;
max_norm = std::max(max_norm, norm(GT[v]));
}
max_norm += norm(GT[v] - center);

#pragma omp parallel for
for(index_t v = 0; v < n_vertices; ++v)
GT[v] *= r / max_norm;
max_norm /= n_vertices;

mat4 model_mat;

const real_t & scale = r / max_norm;
model_mat(0, 0) = model_mat(1, 1) = model_mat(2, 2) = scale;

center *= -scale;
model_mat(0, 3) = center.x();
model_mat(1, 3) = center.y();
model_mat(2, 3) = center.z();
model_mat(3, 3) = 1;

return model_mat;
}

mat4 che::normalize_box(const real_t & side) const
Expand Down

0 comments on commit aa9da27

Please sign in to comment.