MRPT  1.9.9
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-2019, 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>
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>
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
GLdouble s
Definition: glext.h:3682
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...
GLsizei const GLchar ** string
Definition: glext.h:4116
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...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
GLenum GLint GLint y
Definition: glext.h:3542
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 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019