Blender V4.3
packed_intrinsics.h
Go to the documentation of this file.
1// Copyright (c) 2020 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
21#ifndef LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
22#define LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
23
24#include "libmv/base/array.h"
25
26namespace libmv {
27
28// Intrinsics parameters packed into a single continuous block of memory.
29// Used in cases like minimization problems which involves camera intrinsics
30// as a minimizing parameters.
31//
32// It keeps track of which parameters has been specified explicitly, which
33// allows to mark parameters which are not used by distortion model as constant,
34// which improves minimization quality.
36 public:
37 // Offsets of corresponding parameters in the array of all parameters.
38 enum {
39 // Camera calibration values.
43
44 // Distortion model coefficients.
51
52 // Number of parameters which are to be stored in the block.
54 };
55
57
58 void SetFocalLength(double focal_length);
59 double GetFocalLength() const;
60
61 void SetPrincipalPoint(double x, double y);
62 double GetPrincipalPointX() const;
63 double GetPrincipalPointY() const;
64
65 // TODO(sergey): Consider adding vectorized (Vec2) accessors for the principal
66 // point.
67
68#define DEFINE_PARAMETER(parameter_name) \
69 void Set##parameter_name(double value) { \
70 SetParameter(OFFSET_##parameter_name, value); \
71 } \
72 double Get##parameter_name() const { \
73 return GetParameter(OFFSET_##parameter_name); \
74 }
75
80
83
84#undef DEFINE_PARAMETER
85
86 double* GetParametersBlock() { return parameters_.data(); }
87 const double* GetParametersBlock() const { return parameters_.data(); }
88
89 bool IsParameterDefined(int offset);
90
91 private:
92 void SetParameter(int index, double value);
93 double GetParameter(int index) const;
94
95 // All intrinsics parameters packed into a single block.
96 // Use OFFSET_FOO indexes to access corresponding values.
97 array<double, NUM_PARAMETERS> parameters_;
98
99 // Indexed by parameter offset, set to truth if the value of the parameter is
100 // explicitly specified.
101 array<bool, NUM_PARAMETERS> known_parameters_;
102};
103
104} // namespace libmv
105
106#endif // LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
double GetPrincipalPointY() const
void SetFocalLength(double focal_length)
const double * GetParametersBlock() const
double GetPrincipalPointX() const
void SetPrincipalPoint(double x, double y)
bool IsParameterDefined(int offset)
#define DEFINE_PARAMETER(parameter_name)