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 #ifndef COLMAP_SRC_UTIL_TYPES_H_
33 #define COLMAP_SRC_UTIL_TYPES_H_
34 
35 #include "util/alignment.h"
36 
37 #ifdef _MSC_VER
38 #if _MSC_VER >= 1600
39 #include <cstdint>
40 #else
41 typedef __int8 int8_t;
42 typedef __int16 int16_t;
43 typedef __int32 int32_t;
44 typedef __int64 int64_t;
45 typedef unsigned __int8 uint8_t;
46 typedef unsigned __int16 uint16_t;
47 typedef unsigned __int32 uint32_t;
48 typedef unsigned __int64 uint64_t;
49 #endif
50 #elif __GNUC__ >= 3
51 #include <cstdint>
52 #endif
53 
54 // Define non-copyable or non-movable classes.
55 #define NON_COPYABLE(class_name)          \
56   class_name(class_name const&) = delete; \
57   void operator=(class_name const& obj) = delete;
58 #define NON_MOVABLE(class_name) class_name(class_name&&) = delete;
59 
60 #include <Eigen/Core>
61 
62 namespace Eigen {
63 
64 typedef Eigen::Matrix<float, 3, 4> Matrix3x4f;
65 typedef Eigen::Matrix<double, 3, 4> Matrix3x4d;
66 typedef Eigen::Matrix<uint8_t, 3, 1> Vector3ub;
67 typedef Eigen::Matrix<uint8_t, 4, 1> Vector4ub;
68 typedef Eigen::Matrix<double, 6, 1> Vector6d;
69 
70 }  // namespace Eigen
71 
72 namespace colmap {
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 // Index types, determines the maximum number of objects.
76 ////////////////////////////////////////////////////////////////////////////////
77 
78 // Unique identifier for cameras.
79 typedef uint32_t camera_t;
80 
81 // Unique identifier for images.
82 typedef uint32_t image_t;
83 
84 // Each image pair gets a unique ID, see `Database::ImagePairToPairId`.
85 typedef uint64_t image_pair_t;
86 
87 // Index per image, i.e. determines maximum number of 2D points per image.
88 typedef uint32_t point2D_t;
89 
90 // Unique identifier per added 3D point. Since we add many 3D points,
91 // delete them, and possibly re-add them again, the maximum number of allowed
92 // unique indices should be large.
93 typedef uint64_t point3D_t;
94 
95 // Values for invalid identifiers or indices.
96 const camera_t kInvalidCameraId = std::numeric_limits<camera_t>::max();
97 const image_t kInvalidImageId = std::numeric_limits<image_t>::max();
98 const image_pair_t kInvalidImagePairId =
99     std::numeric_limits<image_pair_t>::max();
100 const point2D_t kInvalidPoint2DIdx = std::numeric_limits<point2D_t>::max();
101 const point3D_t kInvalidPoint3DId = std::numeric_limits<point3D_t>::max();
102 
103 }  // namespace colmap
104 
105 // This file provides specializations of the templated hash function for
106 // custom types. These are used for comparison in unordered sets/maps.
107 namespace std {
108 
109 // Hash function specialization for uint32_t pairs, e.g., image_t or camera_t.
110 template <>
111 struct hash<std::pair<uint32_t, uint32_t>> {
112   std::size_t operator()(const std::pair<uint32_t, uint32_t>& p) const {
113     const uint64_t s = (static_cast<uint64_t>(p.first) << 32) +
114                        static_cast<uint64_t>(p.second);
115     return std::hash<uint64_t>()(s);
116   }
117 };
118 
119 }  // namespace std
120 
121 #endif  // COLMAP_SRC_UTIL_TYPES_H_
122