1010#include < aliceVision/system/Timer.hpp>
1111#include < aliceVision/system/Logger.hpp>
1212#include < aliceVision/system/main.hpp>
13+ #include < aliceVision/system/Parallelization.hpp>
1314#include < aliceVision/cmdline/cmdline.hpp>
1415
1516#include < aliceVision/sfmData/SfMData.hpp>
@@ -140,8 +141,8 @@ int aliceVision_main(int argc, char** argv)
140141 std::string sfmDataFilename;
141142 std::string tracksFilename;
142143 std::string outputDirectory;
143- int rangeStart = - 1 ;
144- int rangeSize = 1 ;
144+ int rangeIteration = 0 ;
145+ int rangeBlocksCount = 1 ;
145146 size_t minInliers = 35 ;
146147 bool enforcePureRotation = false ;
147148 size_t countIterations = 1024 ;
@@ -166,8 +167,8 @@ int aliceVision_main(int argc, char** argv)
166167 (" minInliers" , po::value<size_t >(&minInliers)->default_value (minInliers), " Minimal number of inliers for a valid ransac." )
167168 (" imagePairsList,l" , po::value<std::vector<std::string>>(&predefinedPairList)->multitoken (),
168169 " Path(s) to one or more files which contain the list of image pairs to match." )
169- (" rangeStart " , po::value<int >(&rangeStart )->default_value (rangeStart ), " Range image index start ." )
170- (" rangeSize " , po::value<int >(&rangeSize )->default_value (rangeSize ), " Range size ." );
170+ (" rangeIteration " , po::value<int >(&rangeIteration )->default_value (rangeIteration ), " Chunk id ." )
171+ (" rangeBlocksCount " , po::value<int >(&rangeBlocksCount )->default_value (rangeBlocksCount ), " Chunk count ." );
171172 // clang-format on
172173
173174 CmdLine cmdline (" AliceVision relativePoseEstimating" );
@@ -193,33 +194,6 @@ int aliceVision_main(int argc, char** argv)
193194 return EXIT_FAILURE;
194195 }
195196
196- // Define range to compute
197- if (rangeStart != -1 )
198- {
199- if (rangeStart < 0 || rangeSize < 0 )
200- {
201- ALICEVISION_LOG_ERROR (" Range is incorrect" );
202- return EXIT_FAILURE;
203- }
204-
205- if (rangeStart > sfmData.getViews ().size ())
206- {
207- ALICEVISION_LOG_INFO (" Empty range to compute" );
208- return EXIT_SUCCESS;
209- }
210-
211- if (rangeStart + rangeSize > sfmData.getViews ().size ())
212- {
213- rangeSize = sfmData.getViews ().size () - rangeStart;
214- }
215- }
216- else
217- {
218- rangeStart = 0 ;
219- rangeSize = sfmData.getViews ().size ();
220- }
221- ALICEVISION_LOG_DEBUG (" Range to compute: rangeStart=" << rangeStart << " , rangeSize=" << rangeSize);
222-
223197
224198 // Load tracks
225199 ALICEVISION_LOG_INFO (" Load tracks from " << tracksFilename << " ." );
@@ -233,20 +207,14 @@ int aliceVision_main(int argc, char** argv)
233207 ALICEVISION_LOG_INFO (" Compute co-visibility" );
234208 std::map<Pair, unsigned int > covisibility;
235209
236- int chunkStart = 0 ;
237- int chunkEnd = 0 ;
210+
238211
239212 if (predefinedPairList.empty ())
240213 {
241214 // Compute covisibility for tracks
242215 // This will get the list of pair of views which observe common features
243216 ALICEVISION_LOG_INFO (" Automatically select pairs." );
244217 track::computeCovisibility (covisibility, tracksHandler.getAllTracks ());
245-
246- // Divide the work among chunks
247- double ratioChunk = double (covisibility.size ()) / double (sfmData.getViews ().size ());
248- chunkStart = int (double (rangeStart) * ratioChunk);
249- chunkEnd = int (double (rangeStart + rangeSize) * ratioChunk);
250218 }
251219 else
252220 {
@@ -256,7 +224,7 @@ int aliceVision_main(int argc, char** argv)
256224 PairSet pairs;
257225
258226 ALICEVISION_LOG_INFO (" Load pair list from file: " << imagePairsFile);
259- if (!matchingImageCollection::loadPairsFromFile (imagePairsFile, pairs, rangeStart, rangeSize ))
227+ if (!matchingImageCollection::loadPairsFromFile (imagePairsFile, pairs, 0 , - 1 ))
260228 {
261229 return EXIT_FAILURE;
262230 }
@@ -273,10 +241,12 @@ int aliceVision_main(int argc, char** argv)
273241 covisibility[other] = 1 ;
274242 }
275243 }
244+ }
276245
277- // Just process everything as it was already filtered during file loading
278- chunkStart = 0 ;
279- chunkEnd = covisibility.size ();
246+ int chunkStart, chunkEnd;
247+ if (!rangeComputation (chunkStart, chunkEnd, rangeIteration, rangeBlocksCount, covisibility.size ()))
248+ {
249+ ALICEVISION_LOG_INFO (" Nothing to compute in this chunk" );
280250 }
281251
282252 ALICEVISION_LOG_INFO (" A total of " << covisibility.size () << " pairs has to be processed." );
@@ -287,11 +257,11 @@ int aliceVision_main(int argc, char** argv)
287257
288258 ALICEVISION_LOG_INFO (" Process co-visibility" );
289259 std::stringstream ss;
290- ss << outputDirectory << " /pairs_" << rangeStart << " .json" ;
260+ ss << outputDirectory << " /pairs_" << rangeIteration << " .json" ;
291261 std::ofstream of (ss.str ());
292262
293263 // For each covisible pair
294- #pragma omp parallel for
264+ #pragma omp parallel for schedule(dynamic)
295265 for (int posPairs = chunkStart; posPairs < chunkEnd; posPairs++)
296266 {
297267 auto iterPairs = covisibility.begin ();
@@ -311,6 +281,11 @@ int aliceVision_main(int argc, char** argv)
311281 aliceVision::track::TracksMap mapTracksCommon;
312282 track::getCommonTracksInImagesFast ({refImage, nextImage}, tracksHandler.getAllTracks (), tracksHandler.getTracksPerView (), mapTracksCommon);
313283
284+ if (mapTracksCommon.size () == 0 )
285+ {
286+ continue ;
287+ }
288+
314289 // Build features coordinates matrices
315290 const std::size_t n = mapTracksCommon.size ();
316291 std::vector<Eigen::Vector2d> refpts, nextpts;
0 commit comments