ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
database_cache_test.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 #define TEST_NAME "base/database_cache"
33 #include "util/testing.h"
34 
35 #include "base/database_cache.h"
36 
37 using namespace colmap;
38 
40  DatabaseCache cache;
41  BOOST_CHECK_EQUAL(cache.NumCameras(), 0);
42  BOOST_CHECK_EQUAL(cache.NumImages(), 0);
43 }
44 
45 BOOST_AUTO_TEST_CASE(TestAddCamera) {
46  DatabaseCache cache;
47  Camera camera;
48  camera.SetCameraId(1);
50  cache.AddCamera(camera);
51  BOOST_CHECK_EQUAL(cache.NumCameras(), 1);
52  BOOST_CHECK_EQUAL(cache.NumImages(), 0);
53  BOOST_CHECK(cache.ExistsCamera(camera.CameraId()));
54  BOOST_CHECK_EQUAL(cache.Camera(camera.CameraId()).ModelId(),
55  camera.ModelId());
56 }
57 
58 BOOST_AUTO_TEST_CASE(TestDegenerateCamera) {
59  DatabaseCache cache;
60  Camera camera;
62  cache.AddCamera(camera);
63  BOOST_CHECK_EQUAL(cache.NumCameras(), 1);
64  BOOST_CHECK_EQUAL(cache.NumImages(), 0);
65  BOOST_CHECK(cache.ExistsCamera(camera.CameraId()));
66  BOOST_CHECK_EQUAL(cache.Camera(camera.CameraId()).MeanFocalLength(), 1);
67 }
68 
69 BOOST_AUTO_TEST_CASE(TestAddImage) {
70  DatabaseCache cache;
71  Image image;
72  image.SetImageId(1);
73  image.SetPoints2D(std::vector<Eigen::Vector2d>(10));
74  cache.AddImage(image);
75  BOOST_CHECK_EQUAL(cache.NumCameras(), 0);
76  BOOST_CHECK_EQUAL(cache.NumImages(), 1);
77  BOOST_CHECK(cache.ExistsImage(image.ImageId()));
78  BOOST_CHECK_EQUAL(cache.Image(image.ImageId()).NumPoints2D(),
79  image.NumPoints2D());
80  BOOST_CHECK(cache.CorrespondenceGraph().ExistsImage(image.ImageId()));
81  BOOST_CHECK_EQUAL(
83  0);
84  BOOST_CHECK_EQUAL(
85  cache.CorrespondenceGraph().NumObservationsForImage(image.ImageId()), 0);
86 }
std::shared_ptr< core::Tensor > image
void InitializeWithId(const int model_id, const double focal_length, const size_t width, const size_t height)
Definition: camera.cc:203
double MeanFocalLength() const
Definition: camera.cc:100
camera_t CameraId() const
Definition: camera.h:154
int ModelId() const
Definition: camera.h:158
void SetCameraId(const camera_t camera_id)
Definition: camera.h:156
bool ExistsImage(const image_t image_id) const
point2D_t NumCorrespondencesForImage(const image_t image_id) const
point2D_t NumObservationsForImage(const image_t image_id) const
size_t NumImages() const
bool ExistsCamera(const camera_t camera_id) const
void AddImage(const class Image &image)
class Camera & Camera(const camera_t camera_id)
class Image & Image(const image_t image_id)
size_t NumCameras() const
const class CorrespondenceGraph & CorrespondenceGraph() const
void AddCamera(const class Camera &camera)
bool ExistsImage(const image_t image_id) const
point2D_t NumPoints2D() const
Definition: image.h:261
BOOST_AUTO_TEST_CASE(TestEmpty)