37 "%u %u %f %f %f %f %f %f %f\n", it->this_idx, it->other_idx,
38 it->this_x, it->this_y, it->this_z, it->other_x, it->other_y,
39 it->other_z, it->errorSquareAfterTransformation);
48 FILE* f =
os::fopen(filName.c_str(),
"wt");
50 fprintf(f,
"%% ----------------------------------------------------\n");
51 fprintf(f,
"%% File generated automatically by the MRPT method:\n");
52 fprintf(f,
"%% saveAsMATLABScript \n");
54 f,
"%% Before calling this script, define the color of lines, eg:\n");
55 fprintf(f,
"%% colorLines=[1 1 1]");
56 fprintf(f,
"%% J.L. Blanco (C) 2005-2012 \n");
57 fprintf(f,
"%% ----------------------------------------------------\n\n");
59 fprintf(f,
"axis equal; hold on;\n");
63 f,
"line([%f %f],[%f %f],'Color',colorLines);\n", it->this_x,
64 it->other_x, it->this_y, it->other_y);
67 "set(plot([%f %f],[%f " 68 "%f],'.'),'Color',colorLines,'MarkerSize',15);\n",
69 it->this_x, it->other_x, it->this_y, it->other_y);
81 if (it->other_idx == idx)
return true;
88 if (
a.this_idx ==
b.this_idx)
89 return (
a.this_idx <
b.this_idx);
91 return (
a.other_idx <
b.other_idx);
96 return (
a.this_idx ==
b.this_idx) && (
a.other_idx ==
b.other_idx);
102 if (
a.size() !=
b.size())
return false;
104 it1 !=
a.end(); ++it1, ++it2)
105 if (!((*it1) == (*it2)))
return false;
114 vector<float> errs(
size());
115 squareErrorVector(
q, errs);
123 const CPose2D&
q, vector<float>& xs, vector<float>& ys)
const 125 vector<float> errs(
size());
126 squareErrorVector(
q, errs, xs, ys);
136 if (*corresp ==
p)
return true;
144 const CPose2D&
q, vector<float>& out_sqErrs)
const 146 out_sqErrs.resize(
size());
149 const float ccos = cos(
q.phi());
150 const float csin = sin(
q.phi());
151 const float qx =
q.x();
152 const float qy =
q.y();
156 for (corresp =
begin(), e_i = out_sqErrs.begin(); corresp !=
end();
159 float xx = qx + ccos * corresp->other_x - csin * corresp->other_y;
160 float yy = qy + csin * corresp->other_x + ccos * corresp->other_y;
161 *e_i =
square(corresp->this_x - xx) +
square(corresp->this_y - yy);
169 const CPose2D&
q, vector<float>& out_sqErrs, vector<float>& xs,
170 vector<float>& ys)
const 172 out_sqErrs.resize(
size());
178 const float ccos = cos(
q.phi());
179 const float csin = sin(
q.phi());
180 const float qx =
q.x();
181 const float qy =
q.y();
185 for (corresp =
begin(), e_i = out_sqErrs.begin(), xx = xs.begin(),
187 corresp !=
end(); ++corresp, ++e_i, ++xx, ++yy)
189 *xx = qx + ccos * corresp->other_x - csin * corresp->other_y;
190 *yy = qy + csin * corresp->other_x + ccos * corresp->other_y;
191 *e_i =
square(corresp->this_x - *xx) +
square(corresp->this_y - *yy);
196 const size_t num_elements_this_map,
199 std::vector<TMatchingPairConstPtr> bestMatchForThisMap(
201 out_filtered_list.clear();
205 for (
auto&
c : *
this)
207 if (bestMatchForThisMap[
c.this_idx] ==
nullptr ||
208 c.errorSquareAfterTransformation <
209 bestMatchForThisMap[
c.this_idx]
210 ->errorSquareAfterTransformation
213 bestMatchForThisMap[
c.this_idx] = &
c;
219 for (
auto&
c : *
this)
221 if (bestMatchForThisMap[
c.this_idx] == &
c)
222 out_filtered_list.push_back(
c);
bool fileOpenCorrectly()
Returns true if the file was open without errors.
const_iterator end() const
float overallSquareError(const mrpt::poses::CPose2D &q) const
Computes the overall square error between the 2D points in the list of correspondences, given the 2D transformation "q" Where are the elements of the square error vector as computed by computeSquareErrorVector.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
float overallSquareErrorAndPoints(const mrpt::poses::CPose2D &q, std::vector< float > &xs, std::vector< float > &ys) const
Computes the overall square error between the 2D points in the list of correspondences, given the 2D transformation "q", and return the transformed points as well.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
int void fclose(FILE *f)
An OS-independent version of fclose.
GLdouble GLdouble GLdouble GLdouble q
const_iterator begin() const
This file implements several operations that operate element-wise on individual or pairs of container...
bool contains(const TMatchingPair &p) const
Test whether the given pair "p" is within the pairings.
const Scalar * const_iterator
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
This CStream derived class allow using a file as a write-only, binary stream.
void dumpToFile(const std::string &fileName) const
Saves the correspondences to a text file.
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
void saveAsMATLABScript(const std::string &filName) const
Saves the correspondences as a MATLAB script which draws them.
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
TMatchingPair const * TMatchingPairConstPtr
void squareErrorVector(const mrpt::poses::CPose2D &q, std::vector< float > &out_sqErrs) const
Returns a vector with the square error between each pair of correspondences in the list...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
void filterUniqueRobustPairs(const size_t num_elements_this_map, TMatchingPairList &out_filtered_list) const
Creates a filtered list of pairings with those ones which have a single correspondence which coincide...
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.
GLubyte GLubyte GLubyte a
bool indexOtherMapHasCorrespondence(size_t idx) const
Checks if the given index from the "other" map appears in the list.
A structure for holding correspondences between two sets of points or points-like entities in 2D or 3...
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.