Skip to content

Commit ed277cf

Browse files
authored
Fix issue with anisotropic surface reconstruction (#132)
This revision fixes Issue #130 which was caused by the singular value clamping (taking max instead of absmax). It also includes VSCode setting fix which was outdated.
1 parent 8b59ad4 commit ed277cf

4 files changed

Lines changed: 52 additions & 25 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
// Place your settings in this file to overwrite the default settings
22
{
33
"editor.tabSize": 4,
4-
54
"editor.insertSpaces": true,
6-
75
"files.trimTrailingWhitespace": true,
8-
9-
"files.insertFinalNewline": false,
10-
11-
"C_Cpp.clang_format_style": "file",
12-
13-
"C_Cpp.clang_format_formatOnSave": true
6+
"files.insertFinalNewline": true,
7+
"C_Cpp.clang_format_style": "file"
148
}

scripts/travis_build.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ cd build
77
cmake ..
88
make
99
bin/unit_tests
10-
cd ..
11-
pip install --user -r requirements.txt
12-
pip install --user .
13-
python src/tests/python_tests/main.py
10+
11+
unamestr=`uname`
12+
if [[ "$unamestr" == 'Darwin' ]]; then
13+
echo "Disabling pip test for macOS"
14+
else
15+
cd ..
16+
pip install --user -r requirements.txt
17+
pip install --user .
18+
python src/tests/python_tests/main.py
19+
fi

src/jet/anisotropic_points_to_implicit2.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ void AnisotropicPointsToImplicit2::convert(
8282
PointKdTreeSearcher2::builder().makeShared();
8383
meanNeighborSearcher->build(points);
8484

85+
JET_INFO << "Built neighbor searcher.";
86+
8587
SphSystemData2 meanParticles;
8688
meanParticles.addParticles(points);
8789
meanParticles.setNeighborSearcher(meanNeighborSearcher);
@@ -136,21 +138,26 @@ void AnisotropicPointsToImplicit2::convert(
136138
Matrix2x2D w;
137139
svd(cov, u, v, w);
138140

141+
// Take off the sign
142+
v.x = std::fabs(v.x);
143+
v.y = std::fabs(v.y);
144+
139145
// Constrain Sigma
140-
const double maxSingularVal = v.absmax();
146+
const double maxSingularVal = v.max();
141147
const double kr = 4.0;
142-
v[0] = std::max(v[0], maxSingularVal / kr);
143-
v[1] = std::max(v[1], maxSingularVal / kr);
148+
v.x = std::max(v.x, maxSingularVal / kr);
149+
v.y = std::max(v.y, maxSingularVal / kr);
144150
const auto invSigma = Matrix2x2D::makeScaleMatrix(1.0 / v);
145151

146152
// Compute G
147-
const double relA = v[0] * v[1]; // area preservation
148-
const Matrix2x2D g =
149-
invH * std::sqrt(relA) * (w * invSigma * u.transposed());
153+
const double scale = std::sqrt(v.x * v.y); // area preservation
154+
const Matrix2x2D g = invH * scale * (w * invSigma * u.transposed());
150155
gs[i] = g;
151156
}
152157
});
153158

159+
JET_INFO << "Computed G and means.";
160+
154161
// SPH estimator
155162
meanParticles.setKernelRadius(h);
156163
meanParticles.updateDensities();
@@ -173,10 +180,16 @@ void AnisotropicPointsToImplicit2::convert(
173180
return _cutOffDensity - sum;
174181
});
175182

183+
JET_INFO << "Computed SDF.";
184+
176185
if (_isOutputSdf) {
177186
FmmLevelSetSolver2 solver;
178187
solver.reinitialize(*temp, kMaxD, output);
188+
189+
JET_INFO << "Completed einitialization.";
179190
} else {
180191
temp->swap(output);
181192
}
193+
194+
JET_INFO << "Done converting points to implicit surface.";
182195
}

src/jet/anisotropic_points_to_implicit3.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void AnisotropicPointsToImplicit3::convert(
8585
PointKdTreeSearcher3::builder().makeShared();
8686
meanNeighborSearcher->build(points);
8787

88+
JET_INFO << "Built neighbor searcher.";
89+
8890
SphSystemData3 meanParticles;
8991
meanParticles.addParticles(points);
9092
meanParticles.setNeighborSearcher(meanNeighborSearcher);
@@ -139,22 +141,30 @@ void AnisotropicPointsToImplicit3::convert(
139141
Matrix3x3D w;
140142
svd(cov, u, v, w);
141143

144+
// Take off the sign
145+
v.x = std::fabs(v.x);
146+
v.y = std::fabs(v.y);
147+
v.z = std::fabs(v.z);
148+
142149
// Constrain Sigma
143-
const double maxSingularVal = v.absmax();
150+
const double maxSingularVal = v.max();
144151
const double kr = 4.0;
145-
v[0] = std::max(v[0], maxSingularVal / kr);
146-
v[1] = std::max(v[1], maxSingularVal / kr);
147-
v[2] = std::max(v[2], maxSingularVal / kr);
152+
v.x = std::max(v.x, maxSingularVal / kr);
153+
v.y = std::max(v.y, maxSingularVal / kr);
154+
v.z = std::max(v.z, maxSingularVal / kr);
155+
148156
const auto invSigma = Matrix3x3D::makeScaleMatrix(1.0 / v);
149157

150158
// Compute G
151-
const double relV = v[0] * v[1] * v[2]; // area preservation
152-
const Matrix3x3D g = invH * std::pow(relV, 1.0 / 3.0) *
153-
(w * invSigma * u.transposed());
159+
const double scale =
160+
std::pow(v.x * v.y * v.z, 1.0 / 3.0); // volume preservation
161+
const Matrix3x3D g = invH * scale * (w * invSigma * u.transposed());
154162
gs[i] = g;
155163
}
156164
});
157165

166+
JET_INFO << "Computed G and means.";
167+
158168
// SPH estimator
159169
meanParticles.setKernelRadius(h);
160170
meanParticles.updateDensities();
@@ -177,9 +187,13 @@ void AnisotropicPointsToImplicit3::convert(
177187
return _cutOffDensity - sum;
178188
});
179189

190+
JET_INFO << "Computed SDF.";
191+
180192
if (_isOutputSdf) {
181193
FmmLevelSetSolver3 solver;
182194
solver.reinitialize(*temp, kMaxD, output);
195+
196+
JET_INFO << "Completed einitialization.";
183197
} else {
184198
temp->swap(output);
185199
}

0 commit comments

Comments
 (0)