ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
match_matrix_widget.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 "ui/match_matrix_widget.h"
33 
34 namespace colmap {
35 
37  : ImageViewerWidget(parent), options_(options) {
38  setWindowTitle("Match matrix");
39 }
40 
42  Database database(*options_->database_path);
43 
44  if (database.NumImages() == 0) {
45  return;
46  }
47 
48  // Sort the images according to their name.
49  std::vector<Image> images = database.ReadAllImages();
50  std::sort(images.begin(), images.end(),
51  [](const Image& image1, const Image& image2) {
52  return image1.Name() < image2.Name();
53  });
54 
55  // Allocate the match matrix image.
56  Bitmap match_matrix;
57  match_matrix.Allocate(images.size(), images.size(), true);
58  match_matrix.Fill(BitmapColor<uint8_t>(255));
59 
60  // Map image identifiers to match matrix locations.
61  std::unordered_map<image_t, size_t> image_id_to_idx;
62  for (size_t idx = 0; idx < images.size(); ++idx) {
63  image_id_to_idx.emplace(images[idx].ImageId(), idx);
64  }
65 
66  std::vector<std::pair<image_t, image_t>> image_pairs;
67  std::vector<int> num_inliers;
68  database.ReadTwoViewGeometryNumInliers(&image_pairs, &num_inliers);
69 
70  // Fill the match matrix.
71  if (!num_inliers.empty()) {
72  const double max_value =
73  std::log1p(*std::max_element(num_inliers.begin(), num_inliers.end()));
74  for (size_t i = 0; i < image_pairs.size(); ++i) {
75  const double value = std::log1p(num_inliers[i]) / max_value;
76  const size_t idx1 = image_id_to_idx.at(image_pairs[i].first);
77  const size_t idx2 = image_id_to_idx.at(image_pairs[i].second);
78  const BitmapColor<float> color(255 * JetColormap::Red(value),
79  255 * JetColormap::Green(value),
80  255 * JetColormap::Blue(value));
81  match_matrix.SetPixel(idx1, idx2, color.Cast<uint8_t>());
82  match_matrix.SetPixel(idx2, idx1, color.Cast<uint8_t>());
83  }
84  }
85 
86  ShowBitmap(match_matrix);
87 }
88 
89 } // namespace colmap
math::float4 color
bool SetPixel(const int x, const int y, const BitmapColor< uint8_t > &color)
Definition: bitmap.cc:199
void Fill(const BitmapColor< uint8_t > &color)
Definition: bitmap.cc:226
bool Allocate(const int width, const int height, const bool as_rgb)
Definition: bitmap.cc:104
void ReadTwoViewGeometryNumInliers(std::vector< std::pair< image_t, image_t >> *image_pairs, std::vector< int > *num_inliers) const
Definition: database.cc:579
size_t NumImages() const
Definition: database.cc:329
std::vector< Image > ReadAllImages() const
Definition: database.cc:423
void ShowBitmap(const Bitmap &bitmap)
static float Red(const float gray)
Definition: bitmap.cc:655
static float Blue(const float gray)
Definition: bitmap.cc:659
static float Green(const float gray)
Definition: bitmap.cc:657
MatchMatrixWidget(QWidget *parent, OptionManager *options)
std::shared_ptr< std::string > database_path