34 #if MRPT_HAS_OPENGL_GLUT
37 const size_t dim = m_cov.getColCount();
39 if(m_eigVal(0,0) != 0.0 && m_eigVal(1,1) != 0.0 && (dim==2 || m_eigVal(2,2) != 0.0) && m_quantiles!=0.0)
71 M.noalias() = double(m_quantiles) * m_eigVal * m_eigVec.adjoint();
76 for (i=0,ang=0;i<m_2D_segments;i++,ang+= (
M_2PI/m_2D_segments))
78 double ccos = cos(ang);
79 double ssin = sin(ang);
81 const float x = ccos * M.get_unsafe(0,0) + ssin * M.get_unsafe(1,0);
82 const float y = ccos * M.get_unsafe(0,1) + ssin * M.get_unsafe(1,1);
90 const double max_radius = m_quantiles * std::max( m_eigVal(0,0), m_eigVal(1,1) );
94 m_pose.composePoint(m_bb_min, m_bb_min);
95 m_pose.composePoint(m_bb_max, m_bb_max);
113 mat[3] = mat[7] = mat[11] = 0;
115 mat[12] = mat[13] = mat[14] = 0;
117 mat[0] = m_eigVec(0,0); mat[1] = m_eigVec(1,0); mat[2] = m_eigVec(2,0);
118 mat[4] = m_eigVec(0,1); mat[5] = m_eigVec(1,1); mat[6] = m_eigVec(2,1);
119 mat[8] = m_eigVec(0,2); mat[9] = m_eigVec(1,2); mat[10] = m_eigVec(2,2);
121 GLUquadricObj *
obj = gluNewQuadric();
126 gluQuadricDrawStyle(
obj, m_drawSolid3D ? GLU_FILL : GLU_LINE);
130 glScalef(m_eigVal(0,0)*m_quantiles,m_eigVal(1,1)*m_quantiles,m_eigVal(2,2)*m_quantiles);
132 gluSphere(
obj, 1,m_3D_segments,m_3D_segments);
137 gluDeleteQuadric(
obj);
141 const double max_radius = m_quantiles * std::max( m_eigVal(0,0), std::max(m_eigVal(1,1), m_eigVal(2,2) ) );
145 m_pose.composePoint(m_bb_min, m_bb_min);
146 m_pose.composePoint(m_bb_max, m_bb_max);
155 cout <<
"Covariance matrix leading to error is:" << endl << m_cov << endl; \
170 writeToStreamRender(out);
171 out << m_cov << m_drawSolid3D << m_quantiles << (
uint32_t)m_2D_segments << (
uint32_t)m_3D_segments << m_lineWidth;
187 readFromStreamRender(
in);
191 in >>
c; m_cov =
c.cast<
double>();
198 in >> m_drawSolid3D >> m_quantiles;
199 in >> i; m_2D_segments = i;
200 in >> i; m_3D_segments = i;
204 m_prevComputedCov = m_cov;
217 if (delta==0)
return (
t=-b_2/
a)>=0;
220 if ((
t=(-b_2-delta)/
a)>=0)
return true;
221 else return (
t=(-b_2+delta)/
a)>=0;
226 if (m_cov.getRowCount()!=3)
return false;
230 for (
size_t i=0;i<3;i++) {
233 for (
size_t j=0;j<3;j++) {
234 double vji=m_eigVec(j,i);
239 double a=0,b_2=0,
c=-
square(m_quantiles);
240 for (
size_t i=0;i<3;i++) {
241 double ev=m_eigVal(i,i);
253 ASSERT_( m.getColCount() == m.getRowCount() );
254 ASSERT_(
size(m,1)==2 ||
size(m,1)==3 || (resizeToSize>0 && (resizeToSize==2 || resizeToSize==3)));
257 if (resizeToSize>0 && resizeToSize<(
int)
size(m,1))
258 m_cov.setSize(resizeToSize,resizeToSize);
260 if (m_cov==m_prevComputedCov)
266 const double d=m_cov.det();
270 m_prevComputedCov = m_cov;
277 m_prevComputedCov = m_cov;
278 if (m_cov.eigenVectors(m_eigVec,m_eigVal)) {
279 m_eigVal = m_eigVal.array().sqrt().matrix();
bool quickSolveEqn(double a, double b_2, double c, double &t)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
This class is a "CSerializable" wrapper for "CMatrixFloat".
A 2D ellipse or 3D ellipsoid, depending on the size of the m_cov matrix (2x2 or 3x3).
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void setCovMatrix(const mrpt::math::CMatrixDouble &m, int resizeToSize=-1)
Set the 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid (if resizeToSize...
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Ray tracing.
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
GLAPI void GLAPIENTRY glPushMatrix(void)
GLAPI void GLAPIENTRY glMultMatrixf(const GLfloat *m)
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLAPI void GLAPIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glPopMatrix(void)
#define GL_ONE_MINUS_SRC_ALPHA
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLsizei GLsizei GLuint * obj
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLubyte GLubyte GLubyte a
void BASE_IMPEXP createFromPoseX(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the X axis in a given pose.
This file implements matrix/vector text and binary serialization.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define MRPT_END_WITH_CLEAN_UP(stuff)
This base provides a set of functions for maths stuff.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
T square(const T x)
Inline function for the square of a number.
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
The namespace for 3D scene representation and rendering.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t
3D line, represented by a base point and a director vector.
double director[3]
Director vector.
void unitarize()
Unitarize director vector.
TPoint3D pBase
Base point.