Skip to content

Commit

Permalink
Merge branch 'branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 24, 2024
2 parents c63b1f4 + 8364306 commit 2311f69
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 216 deletions.
34 changes: 10 additions & 24 deletions include/vclib/algorithms/create/dodecahedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ MeshType createDodecahedron(LogType& log = nullLogger)
const ScalarType s2 = std::pow(fi, 2);
const ScalarType s3 = 1;

if constexpr (isLoggerValid<LogType>()) {
log.log(0, "Adding vertices to PolyMesh...");
}
log.log(0, "Adding vertices to PolyMesh...");

mesh.addVertices(
CoordType(-s1, -s1, s1),
Expand All @@ -80,10 +78,8 @@ MeshType createDodecahedron(LogType& log = nullLogger)
CoordType(s1, -s1, s1),
CoordType(-s1, -s1, -s1));

if constexpr (isLoggerValid<LogType>()) {
log.log(50, "Vertices added to PolyMesh.");
log.log(50, "Adding faces to PolyMesh...");
}
log.log(50, "Vertices added to PolyMesh.");
log.log(50, "Adding faces to PolyMesh...");

mesh.reserveFaces(12);
mesh.addFace(14, 11, 18, 2, 1);
Expand All @@ -99,9 +95,7 @@ MeshType createDodecahedron(LogType& log = nullLogger)
mesh.addFace(16, 12, 11, 14, 5);
mesh.addFace(18, 11, 12, 0, 10);

if constexpr (isLoggerValid<LogType>()) {
log.log(100, "Faces added to PolyMesh.");
}
log.log(100, "Faces added to PolyMesh.");

return mesh;
}
Expand All @@ -121,17 +115,13 @@ MeshType createDodecahedron(LogType& log = nullLogger)
template<TriangleMeshConcept MeshType, LoggerConcept LogType = NullLogger>
MeshType createDodecahedron(LogType& log = nullLogger)
{
if constexpr (isLoggerValid<LogType>()) {
log.startNewTask(0, 75, "Create Polygonal Dodecahedron.");
}
log.startNewTask(0, 75, "Create Polygonal Dodecahedron.");

detail::TMPSimplePolyMesh pmesh =
createDodecahedron<detail::TMPSimplePolyMesh>(log);

if constexpr (isLoggerValid<LogType>()) {
log.endTask("Create Polygonal Dodecahedron.");
log.log(75, "Copying vertices into TriMesh...");
}
log.endTask("Create Polygonal Dodecahedron.");
log.log(75, "Copying vertices into TriMesh...");

MeshType mesh;
using ST = MeshType::VertexType::CoordType::ScalarType;
Expand All @@ -140,10 +130,8 @@ MeshType createDodecahedron(LogType& log = nullLogger)
mesh.addVertex(v.coord().cast<ST>());
}

if constexpr (isLoggerValid<LogType>()) {
log.log(80, "Vertices copied into TriMesh.");
log.log(80, "Triangularize and copy Faces into TriMesh...");
}
log.log(80, "Vertices copied into TriMesh.");
log.log(80, "Triangularize and copy Faces into TriMesh...");

for (const auto& f : pmesh.faces()) {
std::vector<uint> ind = earCut(f);
Expand All @@ -155,9 +143,7 @@ MeshType createDodecahedron(LogType& log = nullLogger)
}
}

if constexpr (isLoggerValid<LogType>()) {
log.log(100, "Faces triangularized and copied into TriMesh.");
}
log.log(100, "Faces triangularized and copied into TriMesh.");

return mesh;
}
Expand Down
92 changes: 30 additions & 62 deletions include/vclib/algorithms/distance/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#ifndef VCL_ALGORITHMS_DISTANCE_MESH_H
#define VCL_ALGORITHMS_DISTANCE_MESH_H

#include <mutex>

#include <vclib/algorithms/point_sampling.h>
#include <vclib/math/histogram.h>
#include <vclib/mesh/requirements.h>
Expand Down Expand Up @@ -69,16 +67,11 @@ HausdorffDistResult hausdorffDist(
HausdorffDistResult res;
res.histogram = Histogramd(0, m.boundingBox().diagonal() / 100, 100);

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(
5,
"Computing distances for " + std::to_string(s.size()) +
" samples...");
}
log.log(
5,
"Computing distances for " + std::to_string(s.size()) + " samples...");

if constexpr (vcl::isLoggerValid<LogType>()) {
log.startProgress("", s.size());
}
log.startProgress("", s.size());

std::mutex mutex;

Expand All @@ -102,26 +95,19 @@ HausdorffDistResult hausdorffDist(
mutex.unlock();
}

if constexpr (vcl::isLoggerValid<LogType>()) {
mutex.lock();
++i;
log.progress(i);
mutex.unlock();
}
log.progress(++i);
// }
});

if constexpr (vcl::isLoggerValid<LogType>()) {
log.endProgress();
log.log(100, "Computed " + std::to_string(ns) + " distances.");
if (ns != s.size()) {
log.log(
100,
LogType::WARNING,
std::to_string(s.size() - ns) +
" samples were not counted because no closest vertex/face "
"was found.");
}
log.endProgress();
log.log(100, "Computed " + std::to_string(ns) + " distances.");
if (ns != s.size()) {
log.log(
100,
LogType::WARNING,
std::to_string(s.size() - ns) +
" samples were not counted because no closest vertex/face "
"was found.");
}

res.meanDist /= ns;
Expand All @@ -145,16 +131,13 @@ HausdorffDistResult samplerMeshHausdorff(
if constexpr (HasName<MeshType>) {
meshName = m.name();
}
if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Building Grid on " + meshName + " vertices...");
}

log.log(0, "Building Grid on " + meshName + " vertices...");

vcl::StaticGrid3<const VertexType*> grid(m.vertices() | views::addrOf);
grid.build();

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(5, "Grid built.");
}
log.log(5, "Grid built.");

return hausdorffDist(m, s, grid, log);
}
Expand All @@ -177,31 +160,24 @@ HausdorffDistResult samplerMeshHausdorff(
meshName = m.name();
}
if (m.faceNumber() == 0) {
if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Building Grid on " + meshName + " vertices...");
}
log.log(0, "Building Grid on " + meshName + " vertices...");

vcl::StaticGrid3<const VertexType*, ScalarType> grid(
m.vertices() | views::addrOf);
grid.build();

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(5, "Grid built.");
}
log.log(5, "Grid built.");

return hausdorffDist(m, s, grid, log);
}
else {
if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Building Grid on " + meshName + " faces...");
}
log.log(0, "Building Grid on " + meshName + " faces...");

vcl::StaticGrid3<const FaceType*, ScalarType> grid(
m.faces() | views::addrOf);
grid.build();

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(5, "Grid built.");
}
log.log(5, "Grid built.");

return hausdorffDist(m, s, grid, log);
}
Expand Down Expand Up @@ -231,12 +207,10 @@ HausdorffDistResult hausdorffDistance(
meshName2 = m2.name();
}

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(
0,
"Sampling " + meshName2 + " with " + std::to_string(nSamples) +
" samples...");
}
log.log(
0,
"Sampling " + meshName2 + " with " + std::to_string(nSamples) +
" samples...");

if constexpr (METHOD == HAUSDORFF_VERTEX_UNIFORM) {
sampler = vcl::vertexUniformPointSampling<SamplerType>(
Expand All @@ -250,19 +224,13 @@ HausdorffDistResult hausdorffDistance(
m2, nSamples, birth, deterministic);
}

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(5, meshName2 + " sampled.");
log.startNewTask(
5,
100,
"Computing distance between samples and " + meshName1 + "...");
}
log.log(5, meshName2 + " sampled.");
log.startNewTask(
5, 100, "Computing distance between samples and " + meshName1 + "...");

auto res = samplerMeshHausdorff(m1, sampler, log);

if constexpr (vcl::isLoggerValid<LogType>()) {
log.endTask("Distance between samples and " + meshName1 + " computed.");
}
log.endTask("Distance between samples and " + meshName1 + " computed.");

return res;
}
Expand Down
8 changes: 4 additions & 4 deletions include/vclib/algorithms/import/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ void importElementNormalsFromMatrix(MeshType& mesh, const NMatrix& normals)

if (normals.cols() != 3)
throw WrongSizeException(
"The input " + std::string(elementEnumString<ELEM_ID>()) +
"The input " + elementEnumString<ELEM_ID>() +
" normal matrix must have 3 columns");

// matrix rows must be equal to the number of elements of the given type
if (normals.rows() != mesh.template number<ELEM_ID>())
throw WrongSizeException(
"The input normal matrix must have the same number of rows "
"as the number of " +
std::string(elementEnumString<ELEM_ID>()) + " element in the mesh");
elementEnumString<ELEM_ID>() + " element in the mesh");

enableIfPerElementComponentOptional<ELEM_ID, NORMAL>(mesh);
requirePerElementComponent<ELEM_ID, NORMAL>(mesh);
Expand All @@ -79,15 +79,15 @@ void importElementColorsFromMatrix(MeshType& mesh, const CMatrix& colors)

if (colors.cols() != 3 && colors.cols() != 4)
throw WrongSizeException(
"The input " + std::string(elementEnumString<ELEM_ID>()) +
"The input " + elementEnumString<ELEM_ID>() +
" color matrix must have 3 or 4 columns");

// matrix rows must be equal to the number of elements of the given type
if (colors.rows() != mesh.template number<ELEM_ID>())
throw WrongSizeException(
"The input color matrix must have the same number of rows "
"as the number of " +
std::string(elementEnumString<ELEM_ID>()) + " element in the mesh");
elementEnumString<ELEM_ID>() + " element in the mesh");

enableIfPerElementComponentOptional<ELEM_ID, COLOR>(mesh);
requirePerElementComponent<ELEM_ID, COLOR>(mesh);
Expand Down
42 changes: 13 additions & 29 deletions include/vclib/algorithms/update/curvature.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ void updatePrincipalCurvatureTaubin95(MeshType& m, LogType& log)
bool isBorder;
};

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Updating per vertex normals...");
}
log.log(0, "Updating per vertex normals...");

vcl::updatePerVertexNormalsAngleWeighted(m);
vcl::normalizePerVertexNormals(m);

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(5, "Computing per vertex curvature...");
// log every 5%, starting from 5% to 100%
log.startProgress("", m.vertexNumber(), 5, 5, 100);
}
log.log(5, "Computing per vertex curvature...");
// log every 5%, starting from 5% to 100%
log.startProgress("", m.vertexNumber(), 5, 5, 100);

for (VertexType& v : m.vertices()) {
std::vector<ScalarType> weights;
Expand Down Expand Up @@ -232,15 +228,11 @@ void updatePrincipalCurvatureTaubin95(MeshType& m, LogType& log)
v.principalCurvature().maxValue() = principalCurv1;
v.principalCurvature().minValue() = principalCurv2;

if constexpr (vcl::isLoggerValid<LogType>()) {
log.progress(m.index(v));
}
log.progress(m.index(v));
}

if constexpr (vcl::isLoggerValid<LogType>()) {
log.endProgress();
log.log(100, "Per vertex curvature computed.");
}
log.endProgress();
log.log(100, "Per vertex curvature computed.");
}

/**
Expand Down Expand Up @@ -274,17 +266,13 @@ void updatePrincipalCurvaturePCA(
VGrid pGrid;
ScalarType area;

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Updating per vertex normals...");
}
log.log(0, "Updating per vertex normals...");

vcl::updatePerVertexNormalsAngleWeighted(m);
vcl::normalizePerVertexNormals(m);

if constexpr (vcl::isLoggerValid<LogType>()) {
log.log(0, "Computing per vertex curvature...");
log.startProgress("", m.vertexNumber());
}
log.log(0, "Computing per vertex curvature...");
log.startProgress("", m.vertexNumber());

if (montecarloSampling) {
area = vcl::surfaceArea(m);
Expand Down Expand Up @@ -377,16 +365,12 @@ void updatePrincipalCurvaturePCA(
v.principalCurvature().maxDir());
}

if constexpr (vcl::isLoggerValid<LogType>()) {
log.progress(m.index(v));
}
log.progress(m.index(v));
//}
});

if constexpr (vcl::isLoggerValid<LogType>()) {
log.endProgress();
log.log(100, "Per vertex curvature computed.");
}
log.endProgress();
log.log(100, "Per vertex curvature computed.");
}

template<FaceMeshConcept MeshType, LoggerConcept LogType = NullLogger>
Expand Down
Loading

0 comments on commit 2311f69

Please sign in to comment.