22#define PREBUNDLE_SIGNATURE "MVE_PREBUNDLE\n"
23#define PREBUNDLE_SIGNATURE_LEN 14
25#define SURVEY_SIGNATURE "MVE_SURVEY\n"
26#define SURVEY_SIGNATURE_LEN 11
35Track::invalidate (
void)
37 std::fill(this->pos.begin(), this->pos.end(),
38 std::numeric_limits<float>::quiet_NaN());
42Track::remove_view (
int view_id)
44 for (FeatureReferenceList::iterator iter = this->features.begin();
45 iter != this->features.end();)
47 if (iter->view_id == view_id)
48 iter = this->features.erase(iter);
64 int32_t num_viewports =
static_cast<int32_t
>(viewports.size());
65 out.write(
reinterpret_cast<char const*
>(&num_viewports),
sizeof(int32_t));
68 for (std::size_t i = 0; i < viewports.size(); ++i)
73 int32_t num_positions =
static_cast<int32_t
>(vpf.
positions.size());
74 out.write(
reinterpret_cast<char const*
>(&num_positions),
sizeof(int32_t));
75 for (std::size_t j = 0; j < vpf.
positions.size(); ++j)
79 int32_t num_colors =
static_cast<int32_t
>(vpf.
colors.size());
80 out.write(
reinterpret_cast<char const*
>(&num_colors),
sizeof(int32_t));
81 for (std::size_t j = 0; j < vpf.
colors.size(); ++j)
86 int32_t num_pairs =
static_cast<int32_t
>(matching.size());
87 out.write(
reinterpret_cast<char const*
>(&num_pairs),
sizeof(int32_t));
90 for (std::size_t i = 0; i < matching.size(); ++i)
93 int32_t id1 =
static_cast<int32_t
>(tvr.
view_1_id);
94 int32_t id2 =
static_cast<int32_t
>(tvr.
view_2_id);
95 int32_t num_matches =
static_cast<int32_t
>(tvr.
matches.size());
96 out.write(
reinterpret_cast<char const*
>(&id1),
sizeof(int32_t));
97 out.write(
reinterpret_cast<char const*
>(&id2),
sizeof(int32_t));
98 out.write(
reinterpret_cast<char const*
>(&num_matches),
sizeof(int32_t));
99 for (std::size_t j = 0; j < tvr.
matches.size(); ++j)
102 int32_t i1 =
static_cast<int32_t
>(c.first);
103 int32_t i2 =
static_cast<int32_t
>(c.second);
104 out.write(
reinterpret_cast<char const*
>(&i1),
sizeof(int32_t));
105 out.write(
reinterpret_cast<char const*
>(&i2),
sizeof(int32_t));
119 throw std::invalid_argument(
"Invalid prebundle file signature");
125 int32_t num_viewports;
126 in.read(
reinterpret_cast<char*
>(&num_viewports),
sizeof(int32_t));
127 viewports->resize(num_viewports);
130 for (
int i = 0; i < num_viewports; ++i)
135 int32_t num_positions;
136 in.read(
reinterpret_cast<char*
>(&num_positions),
sizeof(int32_t));
138 for (
int j = 0; j < num_positions; ++j)
143 in.read(
reinterpret_cast<char*
>(&num_colors),
sizeof(int32_t));
144 vpf.
colors.resize(num_colors);
145 for (
int j = 0; j < num_colors; ++j)
151 in.read(
reinterpret_cast<char*
>(&num_pairs),
sizeof(int32_t));
154 for (int32_t i = 0; i < num_pairs; ++i)
156 int32_t id1, id2, num_matches;
157 in.read(
reinterpret_cast<char*
>(&id1),
sizeof(int32_t));
158 in.read(
reinterpret_cast<char*
>(&id2),
sizeof(int32_t));
159 in.read(
reinterpret_cast<char*
>(&num_matches),
sizeof(int32_t));
164 tvr.
matches.reserve(num_matches);
165 for (int32_t j = 0; j < num_matches; ++j)
168 in.read(
reinterpret_cast<char*
>(&i1),
sizeof(int32_t));
169 in.read(
reinterpret_cast<char*
>(&i2),
sizeof(int32_t));
171 c.first =
static_cast<int>(i1);
172 c.second =
static_cast<int>(i2);
175 matching->push_back(tvr);
183 std::ofstream out(filename.c_str(), std::ios::binary);
194 std::ifstream in(filename.c_str(), std::ios::binary);
220 std::ifstream in(filename.c_str());
228 throw std::invalid_argument(
"Invalid survey file signature");
230 std::size_t num_points = 0;
231 std::size_t num_observations = 0;
232 in >> num_points >> num_observations;
239 survey_points->resize(num_points);
240 for (std::size_t i = 0; i < num_points; ++i)
243 for (
int j = 0; j < 3; ++j)
244 in >> survey_point.
pos[j];
247 for (std::size_t i = 0; i < num_observations; ++i)
249 int point_id, view_id;
251 in >> point_id >> view_id >> x >> y;
253 if (
static_cast<std::size_t
>(point_id) > num_points)
256 SurveyPoint& survey_point = survey_points->at(point_id);
272 double distort_squared_radius (
double const r2,
double const k1,
277 double coeff = 1.0 + r2 * k1 + r2 * r2 * k2;
278 return r2 * coeff * coeff;
281 double solve_undistorted_squared_radius (
double const r2,
282 double const k1,
double const k2)
285 double lbound = r2, ubound = r2;
286 while (distort_squared_radius(lbound, k1, k2) > r2)
291 while (distort_squared_radius(ubound, k1, k2) < r2)
301 double mid = 0.5 * (lbound + ubound);
302 while (mid != lbound && mid != ubound)
304 if (distort_squared_radius(mid, k1, k2) > r2)
308 mid = 0.5 * (lbound + ubound);
317 float const focal_length)
323 scale = std::sqrt(solve_undistorted_squared_radius(r2, k1, k2) / r2);
#define PREBUNDLE_SIGNATURE_LEN
#define PREBUNDLE_SIGNATURE
#define SURVEY_SIGNATURE_LEN
Vector class for arbitrary dimensions and types.
T square_norm(void) const
Computes the squared norm of the vector (much cheaper).
The FeatureSet holds per-feature information for a single view, and allows to transparently compute a...
std::vector< math::Vec3uc > colors
Per-feature image color.
std::vector< math::Vec2f > positions
Per-feature image position.
Universal, simple exception class.
Exception class for file exceptions with additional filename.
Vector< unsigned char, 3 > Vec3uc
void load_prebundle_from_file(std::string const &filename, ViewportList *viewports, PairwiseMatching *matching)
Loads the pre-bundle data from file, initializing viewports and matching.
std::vector< Viewport > ViewportList
The list of all viewports considered for bundling.
math::Vec2f undistort_feature(math::Vec2f const &f, double const k1, double const k2, float const focal_length)
void save_prebundle_to_file(ViewportList const &viewports, PairwiseMatching const &matching, std::string const &filename)
Saves the pre-bundle data to file, which records all viewport and matching data necessary for increme...
void load_prebundle_data(std::istream &in, ViewportList *viewports, PairwiseMatching *matching)
std::vector< SurveyPoint > SurveyPointList
The list of all survey poins.
std::vector< TwoViewMatching > PairwiseMatching
The matching result between several pairs of views.
void save_prebundle_data(ViewportList const &viewports, PairwiseMatching const &matching, std::ostream &out)
void load_survey_from_file(std::string const &filename, SurveyPointList *survey_points)
Loads survey points and their observations from file.
std::pair< int, int > CorrespondenceIndex
The IDs of a matching feature pair in two images.
#define SFM_BUNDLER_NAMESPACE_END
#define SFM_BUNDLER_NAMESPACE_BEGIN
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN
Representation of a survey point.
SurveyObservationList observations
The matching result between two views.
CorrespondenceIndices matches