Skip to content

Commit 91ead56

Browse files
Merge pull request #2026 from alicevision/dev/meshSfm
Cleanup mesh usage for sfm
2 parents 04c2804 + 1ffa948 commit 91ead56

22 files changed

+721
-200
lines changed

meshroom/aliceVision/ImportAlembic.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.0"
1+
__version__ = "1.1"
22

33
from meshroom.core import desc
44
from meshroom.core.utils import VERBOSE_LEVEL
@@ -19,18 +19,20 @@ class ImportAlembic(desc.AVCommandLineNode):
1919
description="The external Alembic file to import.",
2020
value="",
2121
),
22-
desc.File(
23-
name="imagesDir",
24-
label="Images Directory",
25-
description="Directory containing the images.",
26-
value="",
22+
desc.FloatParam(
23+
name="framerate",
24+
label="Frame rate",
25+
description="Alembic frame rate to compute frame id from time",
26+
value=24.0,
27+
range=(10.0, 50.0, 1.0),
2728
),
28-
desc.ChoiceParam(
29-
name="extension",
30-
label="Images Extension",
31-
description="File extension for the images in the directory to be taken into account.",
32-
value=".exr",
33-
values=[".exr", ".jpg", ".png"],
29+
desc.IntParam(
30+
name="imageWidth",
31+
label="Image(s) Width",
32+
description="Alembic does not export the camera resolutions. \n"
33+
"Setup the image width for all images, the height will depend on the sensor size ratio.",
34+
value=1920,
35+
range=(640, 10000, 10),
3436
),
3537
desc.ChoiceParam(
3638
name="verboseLevel",
@@ -46,6 +48,6 @@ class ImportAlembic(desc.AVCommandLineNode):
4648
name="output",
4749
label="SfMData",
4850
description="SfMData file populated with the camera poses from the external Alembic file.",
49-
value="{nodeCacheFolder}/importedAbc.sfm",
51+
value="{nodeCacheFolder}/importedAbc.abc",
5052
),
5153
]

meshroom/aliceVision/SfMPoseInjecting.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from meshroom.core.utils import VERBOSE_LEVEL
55

66
import json
7+
import pathlib
78

89
class SfMPoseInjecting(desc.AVCommandLineNode):
910

@@ -23,16 +24,25 @@ class SfMPoseInjecting(desc.AVCommandLineNode):
2324
desc.File(
2425
name="posesFilename",
2526
label="Poses",
26-
description="Input JSON file containing the poses.",
27+
description="Input file containing the poses (Json or ABC).",
2728
value="",
2829
),
30+
desc.FloatParam(
31+
name="framerate",
32+
label="Frame rate",
33+
description="Alembic frame rate to compute frame id from time",
34+
value=24.0,
35+
range=(10.0, 50.0, 1.0),
36+
enabled=lambda node: pathlib.Path(node.posesFilename.value).suffix.lower() == ".abc"
37+
),
2938
desc.ChoiceParam(
3039
name="rotationFormat",
3140
label="Rotation Format",
3241
description="Defines the rotation format for the input poses:\n"
3342
" - EulerZXY: Euler rotation in degrees (Y*X*Z)",
3443
values=["EulerZXY"],
3544
value="EulerZXY",
45+
enabled=lambda node: pathlib.Path(node.posesFilename.value).suffix.lower() == ".json"
3646
),
3747
desc.ChoiceParam(
3848
name="verboseLevel",

meshroom/aliceVision/SfmBootstrapping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "4.1"
1+
__version__ = "4.2"
22

33
from meshroom.core import desc
44
from meshroom.core.utils import VERBOSE_LEVEL
@@ -21,8 +21,8 @@ class SfMBootStrapping(desc.AVCommandLineNode):
2121
desc.ChoiceParam(
2222
name="method",
2323
label="Method",
24-
description="Bootstrapping method: classic (epipolar geometry), mesh (3D mesh constraints), or depth (depth map information).",
25-
values=["classic", "mesh", "depth"],
24+
description="Bootstrapping method: classic (epipolar geometry), mesh (3D mesh constraints), mesh_single (mesh without visual parallax), or depth (depth map information).",
25+
values=["classic", "mesh", "mesh_single", "depth"],
2626
value="classic",
2727
),
2828
desc.File(
@@ -36,7 +36,7 @@ class SfMBootStrapping(desc.AVCommandLineNode):
3636
label="Mesh File",
3737
description="Mesh file (*.obj).",
3838
value="",
39-
enabled=lambda node: node.method.value == "mesh"
39+
enabled=lambda node: node.method.value.startswith("mesh")
4040
),
4141
desc.File(
4242
name="pairs",

src/aliceVision/dataio/json.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ std::vector<boost::json::value> readJsons(std::istream& is, boost::system::error
1616
while (true)
1717
{
1818
totalRead = p.write_some(content, ec);
19+
20+
//remove processed string from content
21+
content = content.substr(totalRead);
1922

2023
// If the parser did not find a value, then it won't
2124
// find anything more.
@@ -28,9 +31,6 @@ std::vector<boost::json::value> readJsons(std::istream& is, boost::system::error
2831
// content
2932
jvs.push_back(p.release());
3033
p.reset();
31-
32-
//remove processed string from content
33-
content = content.substr(totalRead);
3434
}
3535
}
3636

src/aliceVision/sfm/bundle/BundleAdjustmentCeres.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ void BundleAdjustmentCeres::addLandmarksToProblem(const sfmData::SfMData& sfmDat
630630
problem.AddResidualBlock(costFunction, nullptr, params);
631631
}
632632

633-
if (!refineStructure || landmark.state == EEstimatorParameterState::CONSTANT)
633+
if (!refineStructure || landmark.state == EEstimatorParameterState::CONSTANT || landmark.isPrecise())
634634
{
635635
// set the whole landmark parameter block as constant.
636636
_statistics.addState(EParameter::LANDMARK, EEstimatorParameterState::CONSTANT);

src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.cpp

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHand
159159
{
160160
return false;
161161
}
162-
163-
if (_pointFetcherHandler)
164-
{
165-
setConstraints(sfmData, tracksHandler, validViewIds);
166-
}
167162

168163
_historyHandler->saveState(sfmData);
169164

@@ -174,18 +169,17 @@ bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHand
174169

175170
bool ExpansionChunk::triangulate(sfmData::SfMData & sfmData, const track::TracksHandler & tracksHandler, const std::set<IndexT> & viewIds)
176171
{
177-
ALICEVISION_LOG_INFO("ExpansionChunk::triangulate start");
178-
SfmTriangulation triangulation(_triangulationMinPoints, _maxTriangulationError);
179-
180-
172+
ALICEVISION_LOG_INFO("ExpansionChunk::triangulate start");
181173
const bool enableMultiviewTriangulation = true;
182174

175+
const size_t minPoints = _triangulationHandler->getMinObservations();
176+
183177
if (enableMultiviewTriangulation)
184178
{
185179
std::set<IndexT> evaluatedTracks;
186180
std::map<IndexT, sfmData::Landmark> outputLandmarks;
187181
std::mt19937 randomNumberGenerator;
188-
if (!triangulation.process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
182+
if (!_triangulationHandler->process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
189183
randomNumberGenerator, viewIds,
190184
evaluatedTracks, outputLandmarks, false))
191185
{
@@ -204,7 +198,7 @@ bool ExpansionChunk::triangulate(sfmData::SfMData & sfmData, const track::Tracks
204198
landmarks.erase(pl.first);
205199
}
206200

207-
if (landmark.getObservations().size() < _triangulationMinPoints)
201+
if (landmark.getObservations().size() < minPoints)
208202
{
209203
continue;
210204
}
@@ -232,7 +226,51 @@ bool ExpansionChunk::triangulate(sfmData::SfMData & sfmData, const track::Tracks
232226
std::set<IndexT> evaluatedTracks;
233227
std::map<IndexT, sfmData::Landmark> outputLandmarks;
234228
std::mt19937 randomNumberGenerator;
235-
if (!triangulation.process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
229+
if (!_triangulationHandler->process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
230+
randomNumberGenerator, viewIds,
231+
evaluatedTracks, outputLandmarks, true))
232+
{
233+
return false;
234+
}
235+
236+
auto & landmarks = sfmData.getLandmarks();
237+
ALICEVISION_LOG_INFO("Existing landmarks : " << landmarks.size());
238+
239+
for (const auto & pl : outputLandmarks)
240+
{
241+
const auto & landmark = pl.second;
242+
243+
if (landmarks.find(pl.first) != landmarks.end())
244+
{
245+
if (!_ignoreMultiviewOnPrior)
246+
{
247+
continue;
248+
}
249+
}
250+
251+
if (landmark.getObservations().size() < minPoints)
252+
{
253+
continue;
254+
}
255+
256+
if (!SfmTriangulation::checkChierality(sfmData, landmark))
257+
{
258+
continue;
259+
}
260+
261+
landmarks.insert(pl);
262+
}
263+
264+
ALICEVISION_LOG_INFO("New landmarks count : " << landmarks.size());
265+
ALICEVISION_LOG_INFO("ExpansionChunk::triangulate end");
266+
}
267+
268+
if (_enableMeshPrior)
269+
{
270+
std::set<IndexT> evaluatedTracks;
271+
std::map<IndexT, sfmData::Landmark> outputLandmarks;
272+
std::mt19937 randomNumberGenerator;
273+
if (!_triangulationHandler->process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
236274
randomNumberGenerator, viewIds,
237275
evaluatedTracks, outputLandmarks, true))
238276
{
@@ -254,7 +292,7 @@ bool ExpansionChunk::triangulate(sfmData::SfMData & sfmData, const track::Tracks
254292
}
255293
}
256294

257-
if (landmark.getObservations().size() < _triangulationMinPoints)
295+
if (landmark.getObservations().size() < minPoints)
258296
{
259297
continue;
260298
}
@@ -285,7 +323,7 @@ void ExpansionChunk::addPose(sfmData::SfMData & sfmData, IndexT viewId, const Ei
285323

286324
void ExpansionChunk::setConstraints(sfmData::SfMData & sfmData, const track::TracksHandler & tracksHandler, const std::set<IndexT> & viewIds)
287325
{
288-
ALICEVISION_LOG_INFO("ExpansionChunk::setConstraints start");
326+
/*ALICEVISION_LOG_INFO("ExpansionChunk::setConstraints start");
289327
const track::TracksMap & tracks = tracksHandler.getAllTracks();
290328
const track::TracksPerView & tracksPerView = tracksHandler.getTracksPerView();
291329
@@ -399,7 +437,7 @@ void ExpansionChunk::setConstraints(sfmData::SfMData & sfmData, const track::Tra
399437
}
400438
401439
ALICEVISION_LOG_INFO("ExpansionChunk::setConstraints added " << constraints.size() << " constraints");
402-
ALICEVISION_LOG_INFO("ExpansionChunk::setConstraints end");
440+
ALICEVISION_LOG_INFO("ExpansionChunk::setConstraints end");*/
403441
}
404442

405443
} // namespace sfm

src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.hpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <aliceVision/sfmData/SfMData.hpp>
1212
#include <aliceVision/sfm/pipeline/expanding/ExpansionHistory.hpp>
1313
#include <aliceVision/sfm/pipeline/expanding/SfmBundle.hpp>
14-
#include <aliceVision/sfm/pipeline/expanding/PointFetcher.hpp>
1514
#include <aliceVision/sfm/pipeline/expanding/SfmResection.hpp>
15+
#include <aliceVision/sfm/pipeline/expanding/SfmTriangulation.hpp>
1616

1717
namespace aliceVision {
1818
namespace sfm {
@@ -45,7 +45,7 @@ class ExpansionChunk
4545
}
4646

4747
/**
48-
* brief setup the expansion history handler
48+
* @brief setup the expansion history handler
4949
* @param expansionHistory a shared ptr
5050
*/
5151
void setExpansionHistoryHandler(ExpansionHistory::sptr & expansionHistory)
@@ -54,16 +54,7 @@ class ExpansionChunk
5454
}
5555

5656
/**
57-
* brief setup the point fetcher handler
58-
* @param pointFetcher a unique ptr. the Ownership will be taken
59-
*/
60-
void setPointFetcherHandler(PointFetcher::uptr & pointFetcherHandler)
61-
{
62-
_pointFetcherHandler = std::move(pointFetcherHandler);
63-
}
64-
65-
/**
66-
* brief setup the point fetcher handler
57+
* @brief setup the Resection handler
6758
* @param resectionHandler a unique ptr. the Ownership will be taken
6859
*/
6960
void setResectionHandler(SfmResection::uptr & resectionHandler)
@@ -72,21 +63,12 @@ class ExpansionChunk
7263
}
7364

7465
/**
75-
* @brief set the minimal number of points to enable triangulation of a track
76-
* @param count the number of points
77-
*/
78-
void setTriangulationMinPoints(size_t count)
79-
{
80-
_triangulationMinPoints = count;
81-
}
82-
83-
/**
84-
* @brief set the maximal reprojection error in the triangulation process.
85-
* @param count the number of points
66+
* @brief setup the Triangulation handler
67+
* @param triangulationHandler a unique ptr. the Ownership will be taken
8668
*/
87-
void setTriangulationMaxError(double error)
69+
void setTriangulationHandler(SfmTriangulation::uptr & triangulationHandler)
8870
{
89-
_maxTriangulationError = error;
71+
_triangulationHandler = std::move(triangulationHandler);
9072
}
9173

9274
/**
@@ -159,16 +141,15 @@ class ExpansionChunk
159141
private:
160142
SfmBundle::uptr _bundleHandler;
161143
ExpansionHistory::sptr _historyHandler;
162-
PointFetcher::uptr _pointFetcherHandler;
163144
std::set<IndexT> _ignoredViews;
164145
SfmResection::uptr _resectionHandler;
146+
SfmTriangulation::uptr _triangulationHandler;
165147

166148
private:
167-
size_t _triangulationMinPoints = 2;
168149
double _minTriangulationAngleDegrees = 3.0;
169-
double _maxTriangulationError = 8.0;
170150
size_t _weakResectionSize = 100;
171151
bool _enableDepthPrior = true;
152+
bool _enableMeshPrior = true;
172153
bool _ignoreMultiviewOnPrior = false;
173154
};
174155

src/aliceVision/sfm/pipeline/expanding/ExpansionIteration.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ExpansionIteration
4242
}
4343

4444
/**
45-
* brief setup the expansion history handler
45+
* @brief setup the expansion history handler
4646
* @param expansionHistory a shared ptr
4747
*/
4848
void setExpansionHistoryHandler(ExpansionHistory::sptr & expansionHistory)
@@ -51,7 +51,7 @@ class ExpansionIteration
5151
}
5252

5353
/**
54-
* brief setup the expansion history handler
54+
* @brief setup the expansion history handler
5555
* @param expansionPolicy a unique ptr. Ownership will be taken
5656
*/
5757
void setExpansionPolicyHandler(ExpansionPolicy::uptr & expansionPolicy)
@@ -60,7 +60,7 @@ class ExpansionIteration
6060
}
6161

6262
/**
63-
* brief setup the expansion chunk handler
63+
* @brief setup the expansion chunk handler
6464
* @param expansionChunk a unique ptr. Ownership will be taken
6565
*/
6666
void setExpansionChunkHandler(ExpansionChunk::uptr & expansionChunk)

src/aliceVision/sfm/pipeline/expanding/ExpansionProcess.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ExpansionProcess{
4040
}
4141

4242
/**
43-
* brief setup the expansion history handler
43+
* @brief setup the expansion history handler
4444
* @param expansionHistory a shared ptr
4545
*/
4646
void setExpansionHistoryHandler(ExpansionHistory::sptr & expansionHistory)
@@ -49,7 +49,7 @@ class ExpansionProcess{
4949
}
5050

5151
/**
52-
* brief setup the expansion iteration handler
52+
* @brief setup the expansion iteration handler
5353
* @param expansionIteration a unique ptr. Ownership will be taken
5454
*/
5555
void setExpansionIterationHandler(ExpansionIteration::uptr & expansionIteration)
@@ -58,7 +58,7 @@ class ExpansionProcess{
5858
}
5959

6060
/**
61-
* brief setup the expansion iteration post process handler
61+
* @brief setup the expansion iteration post process handler
6262
* @param expansionPostProcess a unique ptr. Ownership will be taken
6363
*/
6464
void setExpansionIterationPostProcessHandler(ExpansionPostProcess::uptr & expansionPostProcess)

0 commit comments

Comments
 (0)