MRPT  2.0.0
CPoint.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "poses-precomp.h" // Precompiled headers
11 
12 #include <mrpt/poses/CPoint.h>
13 #include <mrpt/poses/CPoint2D.h>
14 #include <mrpt/poses/CPoint3D.h>
15 #include <iostream>
16 
17 using namespace mrpt::poses;
18 
19 template <class DERIVEDCLASS, std::size_t DIM>
20 void CPoint<DERIVEDCLASS, DIM>::fromString(const std::string& s)
21 {
23  if (!m.fromMatlabStringFormat(s))
24  THROW_EXCEPTION("Malformed expression in ::fromString");
25  ASSERT_EQUAL_(m.rows(), 1);
26  ASSERT_EQUAL_(m.cols(), DERIVEDCLASS::static_size);
27  for (int i = 0; i < DERIVEDCLASS::static_size; i++)
28  derived().m_coords[i] = m(0, i);
29 }
30 
31 template <class DERIVEDCLASS, std::size_t DIM>
32 void CPoint<DERIVEDCLASS, DIM>::asString(std::string& s) const
33 {
34  s = (!DERIVEDCLASS::is3DPoseOrPoint())
35  ? mrpt::format(
36  "[%f %f]", static_cast<const DERIVEDCLASS*>(this)->x(),
37  static_cast<const DERIVEDCLASS*>(this)->y())
38  : mrpt::format(
39  "[%f %f %f]", static_cast<const DERIVEDCLASS*>(this)->x(),
40  static_cast<const DERIVEDCLASS*>(this)->y(),
41  static_cast<const DERIVEDCLASS*>(this)->m_coords[2]);
42 }
43 
44 namespace mrpt::poses
45 {
46 // Explicit instantiations:
47 template class CPoint<CPoint2D, 2>;
48 template class CPoint<CPoint3D, 3>;
49 
50 } // namespace mrpt::poses
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
std::string asString() const
Definition: CPoint.h:77
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
bool fromMatlabStringFormat(const std::string &s, mrpt::optional_ref< std::ostream > dump_errors_here=std::nullopt)
Reads a matrix from a string in Matlab-like format, for example: "[1 0 2; 0 4 -1]" The string must st...
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void fromString(const std::string &s)
Set the current object value from a string generated by &#39;asString&#39; (eg: "[0.02 1.04]" ) ...
Definition: CPoint.cpp:20



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020