29 void TMatchingPairList::dumpToFile(
const std::string& fileName)
const 31 std::ofstream f(fileName);
33 for (
const auto& it : *
this)
36 "%u %u %f %f %f %f %f %f %f\n", it.this_idx, it.other_idx,
37 it.this_x, it.this_y, it.this_z, it.other_x, it.other_y, it.other_z,
38 it.errorSquareAfterTransformation);
42 void TMatchingPairList::saveAsMATLABScript(
const std::string& filName)
const 44 FILE* f =
os::fopen(filName.c_str(),
"wt");
46 fprintf(f,
"%% ----------------------------------------------------\n");
47 fprintf(f,
"%% File generated automatically by the MRPT method:\n");
48 fprintf(f,
"%% saveAsMATLABScript \n");
50 f,
"%% Before calling this script, define the color of lines, eg:\n");
51 fprintf(f,
"%% colorLines=[1 1 1]");
52 fprintf(f,
"%% J.L. Blanco (C) 2005-2012 \n");
53 fprintf(f,
"%% ----------------------------------------------------\n\n");
55 fprintf(f,
"axis equal; hold on;\n");
56 for (
const auto& it : *
this)
59 f,
"line([%f %f],[%f %f],'Color',colorLines);\n", it.this_x,
60 it.other_x, it.this_y, it.other_y);
63 "set(plot([%f %f],[%f " 64 "%f],'.'),'Color',colorLines,'MarkerSize',15);\n",
65 it.this_x, it.other_x, it.this_y, it.other_y);
73 bool TMatchingPairList::indexOtherMapHasCorrespondence(
size_t idx)
const 75 for (
const auto& it : *
this)
77 if (it.other_idx == idx)
return true;
98 if (a.size() != b.size())
return false;
99 for (
auto it1 = a.begin(), it2 = b.begin(); it1 != a.end(); ++it1, ++it2)
100 if (!((*it1) == (*it2)))
return false;
104 float TMatchingPairList::overallSquareError(
const CPose2D& q)
const 106 vector<float> errs(
size());
107 squareErrorVector(q, errs);
108 return std::accumulate(errs.begin(), errs.end(), .0f);
111 float TMatchingPairList::overallSquareErrorAndPoints(
112 const CPose2D& q, vector<float>& xs, vector<float>& ys)
const 114 vector<float> errs(
size());
115 squareErrorVector(q, errs, xs, ys);
116 return std::accumulate(errs.begin(), errs.end(), .0f);
124 for (
const auto& corresp : *
this)
125 if (corresp == p)
return true;
132 void TMatchingPairList::squareErrorVector(
133 const CPose2D& q, vector<float>& out_sqErrs)
const 135 out_sqErrs.resize(
size());
138 const float ccos =
d2f(std::cos(q.
phi()));
139 const float csin =
d2f(std::sin(q.
phi()));
140 const float qx =
d2f(q.
x());
141 const float qy =
d2f(q.
y());
143 const_iterator corresp;
144 vector<float>::iterator e_i;
145 for (corresp =
begin(), e_i = out_sqErrs.begin(); corresp !=
end();
148 float xx = qx + ccos * corresp->other_x - csin * corresp->other_y;
149 float yy = qy + csin * corresp->other_x + ccos * corresp->other_y;
150 *e_i =
square(corresp->this_x - xx) +
square(corresp->this_y - yy);
157 void TMatchingPairList::squareErrorVector(
158 const CPose2D& q, vector<float>& out_sqErrs, vector<float>& xs,
159 vector<float>& ys)
const 161 out_sqErrs.resize(
size());
167 const float ccos =
d2f(cos(q.
phi()));
168 const float csin =
d2f(sin(q.
phi()));
169 const float qx =
d2f(q.
x());
170 const float qy =
d2f(q.
y());
172 const_iterator corresp;
173 vector<float>::iterator e_i, xx, yy;
174 for (corresp =
begin(), e_i = out_sqErrs.begin(), xx = xs.begin(),
176 corresp !=
end(); ++corresp, ++e_i, ++xx, ++yy)
178 *xx = qx + ccos * corresp->other_x - csin * corresp->other_y;
179 *yy = qy + csin * corresp->other_x + ccos * corresp->other_y;
180 *e_i =
square(corresp->this_x - *xx) +
square(corresp->this_y - *yy);
184 void TMatchingPairList::filterUniqueRobustPairs(
185 const size_t num_elements_this_map,
188 std::vector<TMatchingPairConstPtr> bestMatchForThisMap(
190 out_filtered_list.clear();
194 for (
auto& c : *
this)
196 if (bestMatchForThisMap[c.this_idx] ==
nullptr ||
197 c.errorSquareAfterTransformation <
198 bestMatchForThisMap[c.this_idx]
199 ->errorSquareAfterTransformation
202 bestMatchForThisMap[c.this_idx] = &c;
208 for (
auto& c : *
this)
210 if (bestMatchForThisMap[c.this_idx] == &c)
211 out_filtered_list.push_back(c);
TMatchingPair const * TMatchingPairConstPtr
std::ostream & operator<<(std::ostream &o, const mrpt::tfest::TMatchingPair &pair)
std::string std::string format(std::string_view fmt, ARGS &&... args)
size_t size(const MATRIXLIKE &m, const int dim)
int void fclose(FILE *f)
An OS-independent version of fclose.
#define ASSERT_(f)
Defines an assertion mechanism.
float d2f(const double d)
shortcut for static_cast<float>(double)
This base provides a set of functions for maths stuff.
double phi() const
Get the phi angle of the 2D pose (in radians)
double x() const
Common members of all points & poses classes.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
A structure for holding correspondences between two sets of points or points-like entities in 2D or 3...
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
return_t square(const num_t x)
Inline function for the square of a number.
const_iterator end() const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const_iterator begin() const
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
bool operator==(const TMatchingPair &a, const TMatchingPair &b)
A comparison operator.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
bool operator<(const TMatchingPair &a, const TMatchingPair &b)
A comparison operator, for sorting lists of TMatchingPair's, first order by this_idx, if equals, by other_idx.
Functions for estimating the optimal transformation between two frames of references given measuremen...