ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
database.cc
Go to the documentation of this file.
1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 // its contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #include "exe/database.h"
33 
34 #include "base/database.h"
35 #include "util/misc.h"
36 #include "util/option_manager.h"
37 
38 namespace colmap {
39 
40 int RunDatabaseCleaner(int argc, char** argv) {
41  std::string type;
42 
43  OptionManager options;
44  options.AddRequiredOption("type", &type, "{all, images, features, matches}");
45  options.AddDatabaseOptions();
46  options.Parse(argc, argv);
47 
49  Database database(*options.database_path);
50  PrintHeading1("Clearing database");
51  {
52  DatabaseTransaction transaction(&database);
53  if (type == "all") {
54  PrintHeading2("Clearing all tables");
55  database.ClearAllTables();
56  } else if (type == "images") {
57  PrintHeading2("Clearing Images and all dependent tables");
58  database.ClearImages();
59  database.ClearTwoViewGeometries();
60  database.ClearMatches();
61  } else if (type == "features") {
62  PrintHeading2("Clearing image features and matches");
63  database.ClearDescriptors();
64  database.ClearKeypoints();
65  database.ClearTwoViewGeometries();
66  database.ClearMatches();
67  } else if (type == "matches") {
68  PrintHeading2("Clearing image matches");
69  database.ClearTwoViewGeometries();
70  database.ClearMatches();
71  } else {
72  std::cout << "WARNING: Invalid cleanup type: " << type <<
73  "; no changes in database" << std::endl;
74  return EXIT_FAILURE;
75  }
76  }
77 
78  return EXIT_SUCCESS;
79 }
80 
81 int RunDatabaseCreator(int argc, char** argv) {
82  OptionManager options;
83  options.AddDatabaseOptions();
84  options.Parse(argc, argv);
85 
86  Database database(*options.database_path);
87 
88  return EXIT_SUCCESS;
89 }
90 
91 int RunDatabaseMerger(int argc, char** argv) {
92  std::string database_path1;
93  std::string database_path2;
94  std::string merged_database_path;
95 
96  OptionManager options;
97  options.AddRequiredOption("database_path1", &database_path1);
98  options.AddRequiredOption("database_path2", &database_path2);
99  options.AddRequiredOption("merged_database_path", &merged_database_path);
100  options.Parse(argc, argv);
101 
102  if (ExistsFile(merged_database_path)) {
103  std::cout << "WARNING: Merged database file must not exist." << std::endl;
104  return EXIT_FAILURE;
105  }
106 
107  Database database1(database_path1);
108  Database database2(database_path2);
109  Database merged_database(merged_database_path);
110  Database::Merge(database1, database2, &merged_database);
111 
112  return EXIT_SUCCESS;
113 }
114 
115 } // namespace colmap
char type
void ClearDescriptors() const
Definition: database.cc:846
static void Merge(const Database &database1, const Database &database2, Database *merged_database)
Definition: database.cc:866
void ClearImages() const
Definition: database.cc:841
void ClearAllTables() const
Definition: database.cc:827
void ClearKeypoints() const
Definition: database.cc:851
void ClearTwoViewGeometries() const
Definition: database.cc:861
void ClearMatches() const
Definition: database.cc:856
void AddRequiredOption(const std::string &name, T *option, const std::string &help_text="")
std::shared_ptr< std::string > database_path
void Parse(const int argc, char **argv)
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
void PrintHeading2(const std::string &heading)
Definition: misc.cc:231
void StringToLower(std::string *str)
Definition: string.cc:193
int RunDatabaseCleaner(int argc, char **argv)
Definition: database.cc:40
bool ExistsFile(const std::string &path)
Definition: misc.cc:100
int RunDatabaseMerger(int argc, char **argv)
Definition: database.cc:91
void PrintHeading1(const std::string &heading)
Definition: misc.cc:225
int RunDatabaseCreator(int argc, char **argv)
Definition: database.cc:81