Skip to content

Commit 8364306

Browse files
committed
logger does not need to be checked before it is used
1 parent e8947ac commit 8364306

File tree

20 files changed

+149
-215
lines changed

20 files changed

+149
-215
lines changed

include/vclib/algorithms/create/dodecahedron.h

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ MeshType createDodecahedron(LogType& log = nullLogger)
5454
const ScalarType s2 = std::pow(fi, 2);
5555
const ScalarType s3 = 1;
5656

57-
if constexpr (isLoggerValid<LogType>()) {
58-
log.log(0, "Adding vertices to PolyMesh...");
59-
}
57+
log.log(0, "Adding vertices to PolyMesh...");
6058

6159
mesh.addVertices(
6260
CoordType(-s1, -s1, s1),
@@ -80,10 +78,8 @@ MeshType createDodecahedron(LogType& log = nullLogger)
8078
CoordType(s1, -s1, s1),
8179
CoordType(-s1, -s1, -s1));
8280

83-
if constexpr (isLoggerValid<LogType>()) {
84-
log.log(50, "Vertices added to PolyMesh.");
85-
log.log(50, "Adding faces to PolyMesh...");
86-
}
81+
log.log(50, "Vertices added to PolyMesh.");
82+
log.log(50, "Adding faces to PolyMesh...");
8783

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

102-
if constexpr (isLoggerValid<LogType>()) {
103-
log.log(100, "Faces added to PolyMesh.");
104-
}
98+
log.log(100, "Faces added to PolyMesh.");
10599

106100
return mesh;
107101
}
@@ -121,17 +115,13 @@ MeshType createDodecahedron(LogType& log = nullLogger)
121115
template<TriangleMeshConcept MeshType, LoggerConcept LogType = NullLogger>
122116
MeshType createDodecahedron(LogType& log = nullLogger)
123117
{
124-
if constexpr (isLoggerValid<LogType>()) {
125-
log.startNewTask(0, 75, "Create Polygonal Dodecahedron.");
126-
}
118+
log.startNewTask(0, 75, "Create Polygonal Dodecahedron.");
127119

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

131-
if constexpr (isLoggerValid<LogType>()) {
132-
log.endTask("Create Polygonal Dodecahedron.");
133-
log.log(75, "Copying vertices into TriMesh...");
134-
}
123+
log.endTask("Create Polygonal Dodecahedron.");
124+
log.log(75, "Copying vertices into TriMesh...");
135125

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

143-
if constexpr (isLoggerValid<LogType>()) {
144-
log.log(80, "Vertices copied into TriMesh.");
145-
log.log(80, "Triangularize and copy Faces into TriMesh...");
146-
}
133+
log.log(80, "Vertices copied into TriMesh.");
134+
log.log(80, "Triangularize and copy Faces into TriMesh...");
147135

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

158-
if constexpr (isLoggerValid<LogType>()) {
159-
log.log(100, "Faces triangularized and copied into TriMesh.");
160-
}
146+
log.log(100, "Faces triangularized and copied into TriMesh.");
161147

162148
return mesh;
163149
}

include/vclib/algorithms/distance/mesh.h

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#ifndef VCL_ALGORITHMS_DISTANCE_MESH_H
2424
#define VCL_ALGORITHMS_DISTANCE_MESH_H
2525

26-
#include <mutex>
27-
2826
#include <vclib/algorithms/point_sampling.h>
2927
#include <vclib/math/histogram.h>
3028
#include <vclib/mesh/requirements.h>
@@ -69,16 +67,11 @@ HausdorffDistResult hausdorffDist(
6967
HausdorffDistResult res;
7068
res.histogram = Histogramd(0, m.boundingBox().diagonal() / 100, 100);
7169

72-
if constexpr (vcl::isLoggerValid<LogType>()) {
73-
log.log(
74-
5,
75-
"Computing distances for " + std::to_string(s.size()) +
76-
" samples...");
77-
}
70+
log.log(
71+
5,
72+
"Computing distances for " + std::to_string(s.size()) + " samples...");
7873

79-
if constexpr (vcl::isLoggerValid<LogType>()) {
80-
log.startProgress("", s.size());
81-
}
74+
log.startProgress("", s.size());
8275

8376
std::mutex mutex;
8477

@@ -102,26 +95,19 @@ HausdorffDistResult hausdorffDist(
10295
mutex.unlock();
10396
}
10497

105-
if constexpr (vcl::isLoggerValid<LogType>()) {
106-
mutex.lock();
107-
++i;
108-
log.progress(i);
109-
mutex.unlock();
110-
}
98+
log.progress(++i);
11199
// }
112100
});
113101

114-
if constexpr (vcl::isLoggerValid<LogType>()) {
115-
log.endProgress();
116-
log.log(100, "Computed " + std::to_string(ns) + " distances.");
117-
if (ns != s.size()) {
118-
log.log(
119-
100,
120-
LogType::WARNING,
121-
std::to_string(s.size() - ns) +
122-
" samples were not counted because no closest vertex/face "
123-
"was found.");
124-
}
102+
log.endProgress();
103+
log.log(100, "Computed " + std::to_string(ns) + " distances.");
104+
if (ns != s.size()) {
105+
log.log(
106+
100,
107+
LogType::WARNING,
108+
std::to_string(s.size() - ns) +
109+
" samples were not counted because no closest vertex/face "
110+
"was found.");
125111
}
126112

127113
res.meanDist /= ns;
@@ -145,16 +131,13 @@ HausdorffDistResult samplerMeshHausdorff(
145131
if constexpr (HasName<MeshType>) {
146132
meshName = m.name();
147133
}
148-
if constexpr (vcl::isLoggerValid<LogType>()) {
149-
log.log(0, "Building Grid on " + meshName + " vertices...");
150-
}
134+
135+
log.log(0, "Building Grid on " + meshName + " vertices...");
151136

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

155-
if constexpr (vcl::isLoggerValid<LogType>()) {
156-
log.log(5, "Grid built.");
157-
}
140+
log.log(5, "Grid built.");
158141

159142
return hausdorffDist(m, s, grid, log);
160143
}
@@ -177,31 +160,24 @@ HausdorffDistResult samplerMeshHausdorff(
177160
meshName = m.name();
178161
}
179162
if (m.faceNumber() == 0) {
180-
if constexpr (vcl::isLoggerValid<LogType>()) {
181-
log.log(0, "Building Grid on " + meshName + " vertices...");
182-
}
163+
log.log(0, "Building Grid on " + meshName + " vertices...");
183164

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

188-
if constexpr (vcl::isLoggerValid<LogType>()) {
189-
log.log(5, "Grid built.");
190-
}
169+
log.log(5, "Grid built.");
191170

192171
return hausdorffDist(m, s, grid, log);
193172
}
194173
else {
195-
if constexpr (vcl::isLoggerValid<LogType>()) {
196-
log.log(0, "Building Grid on " + meshName + " faces...");
197-
}
174+
log.log(0, "Building Grid on " + meshName + " faces...");
175+
198176
vcl::StaticGrid3<const FaceType*, ScalarType> grid(
199177
m.faces() | views::addrOf);
200178
grid.build();
201179

202-
if constexpr (vcl::isLoggerValid<LogType>()) {
203-
log.log(5, "Grid built.");
204-
}
180+
log.log(5, "Grid built.");
205181

206182
return hausdorffDist(m, s, grid, log);
207183
}
@@ -231,12 +207,10 @@ HausdorffDistResult hausdorffDistance(
231207
meshName2 = m2.name();
232208
}
233209

234-
if constexpr (vcl::isLoggerValid<LogType>()) {
235-
log.log(
236-
0,
237-
"Sampling " + meshName2 + " with " + std::to_string(nSamples) +
238-
" samples...");
239-
}
210+
log.log(
211+
0,
212+
"Sampling " + meshName2 + " with " + std::to_string(nSamples) +
213+
" samples...");
240214

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

253-
if constexpr (vcl::isLoggerValid<LogType>()) {
254-
log.log(5, meshName2 + " sampled.");
255-
log.startNewTask(
256-
5,
257-
100,
258-
"Computing distance between samples and " + meshName1 + "...");
259-
}
227+
log.log(5, meshName2 + " sampled.");
228+
log.startNewTask(
229+
5, 100, "Computing distance between samples and " + meshName1 + "...");
260230

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

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

267235
return res;
268236
}

include/vclib/algorithms/import/matrix.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ void importElementNormalsFromMatrix(MeshType& mesh, const NMatrix& normals)
5252

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

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

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

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

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

9292
enableIfPerElementComponentOptional<ELEM_ID, COLOR>(mesh);
9393
requirePerElementComponent<ELEM_ID, COLOR>(mesh);

include/vclib/algorithms/update/curvature.h

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ void updatePrincipalCurvatureTaubin95(MeshType& m, LogType& log)
6767
bool isBorder;
6868
};
6969

70-
if constexpr (vcl::isLoggerValid<LogType>()) {
71-
log.log(0, "Updating per vertex normals...");
72-
}
70+
log.log(0, "Updating per vertex normals...");
7371

7472
vcl::updatePerVertexNormalsAngleWeighted(m);
7573
vcl::normalizePerVertexNormals(m);
7674

77-
if constexpr (vcl::isLoggerValid<LogType>()) {
78-
log.log(5, "Computing per vertex curvature...");
79-
// log every 5%, starting from 5% to 100%
80-
log.startProgress("", m.vertexNumber(), 5, 5, 100);
81-
}
75+
log.log(5, "Computing per vertex curvature...");
76+
// log every 5%, starting from 5% to 100%
77+
log.startProgress("", m.vertexNumber(), 5, 5, 100);
8278

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

235-
if constexpr (vcl::isLoggerValid<LogType>()) {
236-
log.progress(m.index(v));
237-
}
231+
log.progress(m.index(v));
238232
}
239233

240-
if constexpr (vcl::isLoggerValid<LogType>()) {
241-
log.endProgress();
242-
log.log(100, "Per vertex curvature computed.");
243-
}
234+
log.endProgress();
235+
log.log(100, "Per vertex curvature computed.");
244236
}
245237

246238
/**
@@ -274,17 +266,13 @@ void updatePrincipalCurvaturePCA(
274266
VGrid pGrid;
275267
ScalarType area;
276268

277-
if constexpr (vcl::isLoggerValid<LogType>()) {
278-
log.log(0, "Updating per vertex normals...");
279-
}
269+
log.log(0, "Updating per vertex normals...");
280270

281271
vcl::updatePerVertexNormalsAngleWeighted(m);
282272
vcl::normalizePerVertexNormals(m);
283273

284-
if constexpr (vcl::isLoggerValid<LogType>()) {
285-
log.log(0, "Computing per vertex curvature...");
286-
log.startProgress("", m.vertexNumber());
287-
}
274+
log.log(0, "Computing per vertex curvature...");
275+
log.startProgress("", m.vertexNumber());
288276

289277
if (montecarloSampling) {
290278
area = vcl::surfaceArea(m);
@@ -377,16 +365,12 @@ void updatePrincipalCurvaturePCA(
377365
v.principalCurvature().maxDir());
378366
}
379367

380-
if constexpr (vcl::isLoggerValid<LogType>()) {
381-
log.progress(m.index(v));
382-
}
368+
log.progress(m.index(v));
383369
//}
384370
});
385371

386-
if constexpr (vcl::isLoggerValid<LogType>()) {
387-
log.endProgress();
388-
log.log(100, "Per vertex curvature computed.");
389-
}
372+
log.endProgress();
373+
log.log(100, "Per vertex curvature computed.");
390374
}
391375

392376
template<FaceMeshConcept MeshType, LoggerConcept LogType = NullLogger>

include/vclib/algorithms/update/normal.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,24 @@ void normalizePerElementNormals(
3939
{
4040
vcl::requirePerElementComponent<ELEM_ID, NORMAL>(mesh);
4141

42-
if constexpr (isLoggerValid<LogType>()) {
43-
log.log(
44-
0, "Normalizing per-" + elementEnumString<ELEM_ID>() + " normals");
45-
}
42+
log.log(0, "Normalizing per-" + elementEnumString<ELEM_ID>() + " normals");
4643

4744
for (auto& elem : mesh.template elements<ELEM_ID>()) {
4845
try {
4946
elem.normal().normalize();
5047
}
5148
catch (const std::exception& e) {
5249
if (noThrow) {
53-
if constexpr (isLoggerValid<LogType>()) {
54-
log.log(LogType::WARNING, e.what());
55-
}
50+
log.log(LogType::WARNING, e.what());
5651
}
5752
else {
5853
throw e;
5954
}
6055
}
6156
}
6257

63-
if constexpr (isLoggerValid<LogType>()) {
64-
log.log(
65-
100, "Per-" + elementEnumString<ELEM_ID>() + " normals normalized.");
66-
}
58+
log.log(
59+
100, "Per-" + elementEnumString<ELEM_ID>() + " normals normalized.");
6760
}
6861

6962
template<uint ELEM_ID, MeshConcept MeshType>

0 commit comments

Comments
 (0)