ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
reconstruction_manager.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 
33 
34 #include "util/misc.h"
35 #include "util/option_manager.h"
36 
37 namespace colmap {
38 
40 
43  reconstructions_ = std::move(other.reconstructions_);
44 }
45 
47  ReconstructionManager&& other) {
48  if (this != &other) {
49  reconstructions_ = std::move(other.reconstructions_);
50  }
51  return *this;
52 }
53 
54 size_t ReconstructionManager::Size() const { return reconstructions_.size(); }
55 
56 const Reconstruction& ReconstructionManager::Get(const size_t idx) const {
57  return *reconstructions_.at(idx);
58 }
59 
61  return *reconstructions_.at(idx);
62 }
63 
65  const size_t idx = Size();
66  reconstructions_.emplace_back(new Reconstruction());
67  return idx;
68 }
69 
70 void ReconstructionManager::Delete(const size_t idx) {
71  CHECK_LT(idx, reconstructions_.size());
72  reconstructions_.erase(reconstructions_.begin() + idx);
73 }
74 
75 void ReconstructionManager::Clear() { reconstructions_.clear(); }
76 
77 size_t ReconstructionManager::Read(const std::string& path) {
78  const size_t idx = Add();
79  reconstructions_[idx]->Read(path);
80  return idx;
81 }
82 
83 void ReconstructionManager::Write(const std::string& path,
84  const OptionManager* options) const {
85  std::vector<std::pair<size_t, size_t>> recon_sizes(reconstructions_.size());
86  for (size_t i = 0; i < reconstructions_.size(); ++i) {
87  recon_sizes[i] = std::make_pair(i, reconstructions_[i]->NumPoints3D());
88  }
89  std::sort(recon_sizes.begin(), recon_sizes.end(),
90  [](const std::pair<size_t, size_t>& first,
91  const std::pair<size_t, size_t>& second) {
92  return first.second > second.second;
93  });
94 
95  for (size_t i = 0; i < reconstructions_.size(); ++i) {
96  const std::string reconstruction_path = JoinPaths(path, std::to_string(i));
97  CreateDirIfNotExists(reconstruction_path);
98  reconstructions_[recon_sizes[i].first]->Write(reconstruction_path);
99  if (options != nullptr) {
100  options->Write(JoinPaths(reconstruction_path, "project.ini"));
101  }
102  }
103 }
104 
105 } // namespace colmap
void Write(const std::string &path) const
ReconstructionManager & operator=(ReconstructionManager &&other)
const Reconstruction & Get(const size_t idx) const
size_t Read(const std::string &path)
void Write(const std::string &path, const OptionManager *options) const
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
static const std::string path
Definition: PointCloud.cpp:59
void CreateDirIfNotExists(const std::string &path)
Definition: misc.cc:112
std::string JoinPaths(T const &... paths)
Definition: misc.h:128
std::string to_string(const T &n)
Definition: Common.h:20