18 #include <Eigen/Dense> 34 const auto cols = Z.cols();
35 const auto rows = Z.rows();
37 if ((m_colorFromZ) || (m_isImage)) updateColorsMatrix();
39 ASSERT_((cols > 0) && (rows > 0));
40 ASSERT_((xMax > xMin) && (yMax > yMin));
41 X.setSize(rows, cols);
42 Y.setSize(rows, cols);
43 const float sCellX = (xMax - xMin) / (rows - 1);
44 const float sCellY = (yMax - yMin) / (cols - 1);
46 for (
int iX = 0; iX < rows; iX++)
47 for (
int iY = 0; iY < cols; iY++)
49 X(iX, iY) = xMin + iX * sCellX;
50 Y(iX, iY) = yMin + iY * sCellY;
53 pointsUpToDate =
true;
61 #if MRPT_HAS_OPENGL_GLUT 63 if (!pointsUpToDate) updatePoints();
85 for (
int i = 0; i < X.rows(); i++)
86 for (
int j = 0; j < X.cols(); j++)
88 if (m_isImage && m_textureImage.isColor())
89 glColor4f(C_r(i, j), C_g(i, j), C_b(i, j), m_color.A / 255.f);
92 glColor4f(C(i, j), C(i, j), C(i, j), m_color.A / 255.f);
94 else if (m_colorFromZ)
103 m_color.R / 255.f, m_color.G / 255.f, m_color.B / 255.f,
127 m_textureImage =
img;
130 Z.setZero(
img.getHeight(),
img.getWidth());
133 m_modified_Image =
true;
134 m_enableTransparency =
false;
135 m_colorFromZ =
false;
137 pointsUpToDate =
false;
150 (
img.getWidth() ==
static_cast<size_t>(in_Z.
cols())) &&
151 (
img.getHeight() ==
static_cast<size_t>(in_Z.
rows())));
156 m_textureImage =
img;
159 m_modified_Image =
true;
160 m_enableTransparency =
false;
161 m_colorFromZ =
false;
163 pointsUpToDate =
false;
173 writeToStreamRender(out);
175 out << m_textureImage;
177 out << xMin << xMax << yMin << yMax;
179 out << m_enableTransparency;
183 out << m_pointSmooth;
193 readFromStreamRender(
in);
195 in >> m_textureImage;
204 in >> m_enableTransparency;
215 pointsUpToDate =
false;
226 if ((!m_modified_Z) && (!m_modified_Image))
return;
232 const int cols = m_textureImage.getWidth();
233 const int rows = m_textureImage.getHeight();
235 if ((cols != Z.cols()) || (rows != Z.rows()))
237 printf(
"\nTexture Image and Z sizes have to be equal");
239 else if (m_textureImage.isColor())
241 C_r.setSize(rows, cols);
242 C_g.setSize(rows, cols);
243 C_b.setSize(rows, cols);
244 m_textureImage.getAsRGBMatrices(C_r, C_g, C_b);
248 C.setSize(rows, cols);
249 m_textureImage.getAsMatrix(C);
254 const size_t cols = Z.cols();
255 const size_t rows = Z.rows();
257 C.setSize(rows, cols);
266 m_modified_Image =
false;
267 m_modified_Z =
false;
268 pointsUpToDate =
false;
275 pointsUpToDate =
false;
void updateColorsMatrix() const
Called internally to assure C is updated.
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void colormap(const TColormap &color_map, const float color_index, float &r, float &g, float &b)
Transform a float number in the range [0,1] into RGB components.
TColormap
Different colormaps for use in mrpt::img::colormap()
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
This file implements several operations that operate element-wise on individual or pairs of container...
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
void assignImageAndZ(const mrpt::img::CImage &img, const mrpt::math::CMatrixDynamic< float > &in_Z)
Assigns a texture image and Z simultaneously, and disable transparency.
void render_dl() const override
Render.
#define GL_ONE_MINUS_SRC_ALPHA
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL's display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
void normalize(CONTAINER &c, Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void setZ(const mrpt::math::CMatrixDynamic< float > &in_Z)
This method sets the matrix of heights for each position (cell) in the mesh grid. ...
GLAPI void GLAPIENTRY glBegin(GLenum mode)
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...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
The namespace for 3D scene representation and rendering.
GLAPI void GLAPIENTRY glEnd(void)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image, and disable transparency.
A class for storing images as grayscale or RGB bitmaps.