39 out << i << j << m_locationMC << m_locationGauss << m_locationSOG;
49 in >> i >> j >> m_locationMC >> m_locationGauss >> m_locationSOG;
51 m_typePDF =
static_cast<TTypePDF>(j);
68 m_locationMC.getMean(
p);
71 m_locationGauss.getMean(
p);
74 m_locationSOG.getMean(
p);
91 m_locationMC.getCovarianceAndMean(COV,
p);
94 m_locationGauss.getCovarianceAndMean(COV,
p);
97 m_locationSOG.getCovarianceAndMean(COV,
p);
110 const double minMahalanobisDistToDrop)
116 m_locationMC.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
119 m_locationGauss.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
122 m_locationSOG.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
139 m_locationMC.drawSingleSample(outSample);
142 m_locationGauss.drawSingleSample(outSample);
145 m_locationSOG.drawSingleSample(outSample);
162 m_locationMC.copyFrom(o);
165 m_locationGauss.copyFrom(o);
168 m_locationSOG.copyFrom(o);
185 return m_locationMC.saveToTextFile(file);
188 return m_locationGauss.saveToTextFile(file);
191 return m_locationSOG.saveToTextFile(file);
208 m_locationMC.changeCoordinatesReference(newReferenceBase);
211 m_locationGauss.changeCoordinatesReference(newReferenceBase);
214 m_locationSOG.changeCoordinatesReference(newReferenceBase);
234 mrpt::make_aligned_shared<opengl::CPointCloud>();
235 obj->setColor(1, 0, 0);
237 obj->setPointSize(2.5);
239 const size_t N = m_locationMC.m_particles.size();
242 for (
size_t i = 0; i < N; i++)
244 i, m_locationMC.m_particles[i].d->x,
245 m_locationMC.m_particles[i].d->y,
246 m_locationMC.m_particles[i].d->z);
254 mrpt::make_aligned_shared<opengl::CEllipsoid>();
256 obj->setPose(m_locationGauss.mean);
257 obj->setLineWidth(3);
260 if (C(2, 2) == 0) C.setSize(2, 2);
261 obj->setCovMatrix(C);
263 obj->setQuantiles(3);
264 obj->enableDrawSolid3D(
false);
266 obj->setColor(1, 0, 0, 0.85);
272 m_locationSOG.getAs3DObject(outObj);
280 obj2->setString(
format(
"#%d", static_cast<int>(m_ID)));
283 this->getMean(meanP);
284 obj2->setLocation(meanP.
x() + 0.10, meanP.
y() + 0.10, meanP.z());
285 outObj->insert(obj2);
307 size_t i, N = m_locationMC.m_particles.size();
312 for (i = 0; i < N; i++)
315 auxStr,
sizeof(auxStr),
"%.3f%c",
316 m_locationMC.m_particles[i].d->x, (i == N - 1) ?
' ' :
',');
319 auxStr,
sizeof(auxStr),
"%.3f%c",
320 m_locationMC.m_particles[i].d->y, (i == N - 1) ?
' ' :
',');
325 out_Str.emplace_back(sx);
326 out_Str.emplace_back(sy);
327 out_Str.emplace_back(
"plot(xs,ys,'k.','MarkerSize',4);");
337 auxStr,
sizeof(auxStr),
"m=[%.3f %.3f];",
338 m_locationGauss.mean.x(), m_locationGauss.mean.y());
339 out_Str.emplace_back(auxStr);
341 auxStr,
sizeof(auxStr),
"C=[%e %e;%e %e];",
342 m_locationGauss.cov(0, 0), m_locationGauss.cov(0, 1),
343 m_locationGauss.cov(1, 0), m_locationGauss.cov(1, 1));
344 out_Str.emplace_back(auxStr);
346 out_Str.emplace_back(
347 "error_ellipse(C,m,'conf',0.997,'style','k');");
353 it != m_locationSOG.end(); ++it)
356 auxStr,
sizeof(auxStr),
"m=[%.3f %.3f];",
357 (it)->
val.mean.x(), (it)->
val.mean.y());
358 out_Str.emplace_back(auxStr);
360 auxStr,
sizeof(auxStr),
"C=[%e %e;%e %e];",
361 (it)->
val.cov(0, 0), (it)->
val.cov(0, 1),
362 (it)->
val.cov(1, 0), (it)->
val.cov(1, 1));
363 out_Str.emplace_back(auxStr);
364 out_Str.emplace_back(
365 "error_ellipse(C,m,'conf',0.997,'style','k');");
378 auxStr,
sizeof(auxStr),
"text(%f,%f,'#%i');", meanP.
x(), meanP.
y(),
379 static_cast<int>(m_ID));
380 out_Str.emplace_back(auxStr);
405 const CPoint3D& centerPoint,
const float& maxDistanceFromCenter)
const 411 if (m_typePDF == pdfGauss)
417 new_beaconPos->
get(0).
val = m_locationGauss;
418 beaconPos = new_beaconPos;
423 beaconPos =
static_cast<const CPointPDFSOG*
>(&m_locationSOG);
429 it != beaconPos->end(); ++it)
433 (it)->
val.mean.x() - sensorPntOnRobot.
x(),
434 (it)->
val.mean.y() - sensorPntOnRobot.
y(),
435 (it)->
val.mean.z() - sensorPntOnRobot.z());
437 size_t startIdx = outPDF.
size();
448 maxDistanceFromCenter
452 for (
size_t k = startIdx; k < outPDF.
size(); k++)
456 if (m_typePDF == pdfGauss)
delete beaconPos;
468 bool clearPreviousContentsOutPDF,
const CPoint3D& centerPoint,
469 const float& maxDistanceFromCenter)
482 double el, th, A_ang;
483 const float maxDistBetweenGaussians =
487 size_t B = (size_t)(
M_2PIf *
R / maxDistBetweenGaussians) + 1;
490 B = max(B, (
size_t)30);
502 S(1, 1) = S(2, 2) =
square(
511 if (clearPreviousContentsOutPDF)
520 modeIdx = outPDF.
size();
526 for (idxEl = 0; idxEl <= (1 + B / 2); idxEl++)
528 el = minEl + idxEl * A_ang;
529 if (el > (maxEl + 0.5 * A_ang))
continue;
533 if (fabs(cos(el)) < 1e-4)
538 for (idxTh = 0; idxTh < nThSteps; idxTh++)
543 dir.x((sensorPnt.
x() +
R * cos(th) * cos(el)));
544 dir.y((sensorPnt.
y() +
R * sin(th) * cos(el)));
545 dir.z((sensorPnt.z() +
R * sin(el)));
549 bool reallyCreateIt =
true;
550 if (maxDistanceFromCenter > 0)
552 dir.distanceTo(centerPoint) < maxDistanceFromCenter;
576 C33.get_unsafe(0, 2) = C33.get_unsafe(2, 0) =
577 C33.get_unsafe(1, 2) = C33.get_unsafe(2, 1) =
578 C33.get_unsafe(2, 2) = 0;
582 if (covarianceCompositionToAdd)
583 outPDF.
get(modeIdx).
val.
cov += *covarianceCompositionToAdd;
double x() const
Common members of all points & poses classes.
#define THROW_EXCEPTION(msg)
void copyFrom(const mrpt::poses::CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void getAsMatlabDrawCommands(std::vector< std::string > &out_Str) const
Gets a set of MATLAB commands which draw the current state of the beacon:
CPoint3D mean
The mean value.
double DEG2RAD(const double x)
Degrees to radians.
void resize(const size_t N)
Resize the number of SOG modes.
void changeCoordinatesReference(const mrpt::poses::CPose3D &newReferenceBase) override
this = p (+) this.
Declares a class that represents a Probability Density function (PDF) of a 3D point ...
The struct for each mode:
void clear()
Clear all the gaussian modes.
GLsizei GLsizei GLuint * obj
double maxElevation_deg
Minimum and maximum elevation angles (in degrees) for inserting new beacons at the first observation:...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
float SOG_maxDistBetweenGaussians
A parameter for initializing 2D/3D SOGs.
This namespace contains representation of robot actions and observations.
A class for storing a map of 3D probabilistic beacons, using a Montecarlo, Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM).
float SOG_separationConstant
Constant used to compute the std.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, mrpt::poses::CPoint3D &mean_point) const override
Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once...
const TGaussianMode & get(size_t i) const
Access to individual beacons.
GLsizei const GLchar ** string
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CMatrixTemplateNumeric< T > generateAxisBaseFromDirection(T dx, T dy, T dz)
Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of the...
Virtual base class for "archives": classes abstracting I/O streams.
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
OPENGL_SETOFOBJECTSPTR getAs3DObject() const
Returns a 3D representation of this PDF.
double rangeStd
The standard deviation used for Beacon ranges likelihood (default=0.08m).
std::deque< TGaussianMode >::const_iterator const_iterator
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
size_t size() const
Return the number of Gaussian modes.
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
mrpt::maps::CBeaconMap::TLikelihoodOptions likelihoodOptions
double log_w
The log-weight.
void drawSingleSample(mrpt::poses::CPoint3D &outSample) const override
Draw a sample from the pdf.
static void generateRingSOG(const float &sensedRange, mrpt::poses::CPointPDFSOG &outPDF, const CBeaconMap *myBeaconMap, const mrpt::poses::CPoint3D &sensorPnt, const mrpt::math::CMatrixDouble33 *covarianceCompositionToAdd=nullptr, bool clearPreviousContentsOutPDF=true, const mrpt::poses::CPoint3D ¢erPoint=mrpt::poses::CPoint3D(0, 0, 0), const float &maxDistanceFromCenter=0)
This static method returns a SOG with ring-shape (or as a 3D sphere) that can be used to initialize a...
mrpt::maps::CBeaconMap::TInsertionOptions insertionOptions
unsigned __int32 uint32_t
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions...
void generateObservationModelDistribution(const float &sensedRange, mrpt::poses::CPointPDFSOG &outPDF, const CBeaconMap *myBeaconMap, const mrpt::poses::CPoint3D &sensorPntOnRobot, const mrpt::poses::CPoint3D ¢erPoint=mrpt::poses::CPoint3D(0, 0, 0), const float &maxDistanceFromCenter=0) const
Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an a...
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
void getMean(mrpt::poses::CPoint3D &mean_point) const override
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF).