|
| 1 | +// This file is part of the AliceVision project. |
| 2 | +// Copyright (c) 2025 AliceVision contributors. |
| 3 | +// This Source Code Form is subject to the terms of the Mozilla Public License, |
| 4 | +// v. 2.0. If a copy of the MPL was not distributed with this file, |
| 5 | +// You can obtain one at https://mozilla.org/MPL/2.0/. |
| 6 | + |
| 7 | +#include <aliceVision/cmdline/cmdline.hpp> |
| 8 | +#include <aliceVision/system/main.hpp> |
| 9 | +#include <boost/program_options.hpp> |
| 10 | + |
| 11 | +#include <aliceVision/track/Track.hpp> |
| 12 | +#include <aliceVision/track/trackIO.hpp> |
| 13 | +#include <aliceVision/track/TracksMerger.cpp> |
| 14 | + |
| 15 | +#include <string> |
| 16 | +#include <sstream> |
| 17 | +#include <random> |
| 18 | + |
| 19 | +// These constants define the current software version. |
| 20 | +// They must be updated when the command line is changed. |
| 21 | +#define ALICEVISION_SOFTWARE_VERSION_MAJOR 1 |
| 22 | +#define ALICEVISION_SOFTWARE_VERSION_MINOR 0 |
| 23 | + |
| 24 | +using namespace aliceVision; |
| 25 | + |
| 26 | +namespace po = boost::program_options; |
| 27 | + |
| 28 | +int aliceVision_main(int argc, char** argv) |
| 29 | +{ |
| 30 | + // command-line parameters |
| 31 | + std::vector<std::string> tracksFilenames; |
| 32 | + std::string outFilename; |
| 33 | + |
| 34 | + // clang-format off |
| 35 | + po::options_description requiredParams("Required parameters"); |
| 36 | + requiredParams.add_options() |
| 37 | + ("inputs,i", po::value<std::vector<std::string>>(&tracksFilenames)->multitoken(), |
| 38 | + "Path to sfmDatas to merge.") |
| 39 | + ("output,o", po::value<std::string>(&outFilename)->required(), |
| 40 | + "Output SfMData scene."); |
| 41 | + // clang-format on |
| 42 | + |
| 43 | + CmdLine cmdline("AliceVision sfmMerge"); |
| 44 | + cmdline.add(requiredParams); |
| 45 | + if (!cmdline.execute(argc, argv)) |
| 46 | + { |
| 47 | + return EXIT_FAILURE; |
| 48 | + } |
| 49 | + |
| 50 | + if (tracksFilenames.empty()) |
| 51 | + { |
| 52 | + ALICEVISION_LOG_ERROR("At least one tracks input should be given."); |
| 53 | + return EXIT_FAILURE; |
| 54 | + } |
| 55 | + |
| 56 | + //viewId, featureId is a unique identifier for an observation |
| 57 | + using TuplePoint = std::tuple<feature::EImageDescriberType, IndexT, std::size_t>; |
| 58 | + |
| 59 | + track::TracksMerger merger; |
| 60 | + |
| 61 | + for (const auto & path : tracksFilenames) |
| 62 | + { |
| 63 | + track::TracksMap mapTracks; |
| 64 | + |
| 65 | + ALICEVISION_LOG_INFO("Loading " << path); |
| 66 | + if (!track::loadTracks(mapTracks, path)) |
| 67 | + { |
| 68 | + continue; |
| 69 | + } |
| 70 | + |
| 71 | + ALICEVISION_LOG_INFO("File has " << mapTracks.size() << " tracks."); |
| 72 | + |
| 73 | + if (!merger.addTrackMap(mapTracks)) |
| 74 | + { |
| 75 | + ALICEVISION_LOG_ERROR("addTrackMap failed, abort"); |
| 76 | + return EXIT_FAILURE; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + const auto & resultTracks = merger.getOutputTracks(); |
| 81 | + |
| 82 | + ALICEVISION_LOG_INFO("Saving to " << outFilename); |
| 83 | + ALICEVISION_LOG_INFO("File has " << resultTracks.size() << " tracks."); |
| 84 | + if (!track::saveTracks(resultTracks, outFilename)) |
| 85 | + { |
| 86 | + ALICEVISION_LOG_ERROR("Failed to save file"); |
| 87 | + return EXIT_FAILURE; |
| 88 | + } |
| 89 | + |
| 90 | + return EXIT_SUCCESS; |
| 91 | +} |
0 commit comments