18 #include <Eigen/Dense> 33 const auto cols = Z.cols();
34 const auto rows = Z.rows();
36 if ((m_colorFromZ) || (m_isImage)) updateColorsMatrix();
38 ASSERT_((cols > 0) && (rows > 0));
39 ASSERT_((xMax > xMin) && (yMax > yMin));
40 X.setSize(rows, cols);
41 Y.setSize(rows, cols);
42 const float sCellX = (xMax - xMin) / (rows - 1);
43 const float sCellY = (yMax - yMin) / (cols - 1);
45 for (
int iX = 0; iX < rows; iX++)
46 for (
int iY = 0; iY < cols; iY++)
48 X(iX, iY) = xMin + iX * sCellX;
49 Y(iX, iY) = yMin + iY * sCellY;
52 pointsUpToDate =
true;
60 if (!pointsUpToDate) updatePoints();
70 for (
int i = 0; i < X.rows(); i++)
72 for (
int j = 0; j < X.cols(); j++)
76 if (m_isImage && m_textureImage.isColor())
77 col =
TColor(C_r(i, j), C_g(i, j), C_b(i, j), m_color.A);
79 col =
TColor(C(i, j), C(i, j), C(i, j), m_color.A);
80 else if (m_colorFromZ)
83 colormap(m_colorMap, C(i, j) / 255.0f, rz, gz, bz);
89 cbd.emplace_back(col);
90 vbd.emplace_back(X(i, j), Y(i, j), Z(i, j));
100 m_textureImage = img;
106 m_modified_Image =
true;
107 m_enableTransparency =
false;
108 m_colorFromZ =
false;
110 pointsUpToDate =
false;
129 m_textureImage = img;
132 m_modified_Image =
true;
133 m_enableTransparency =
false;
134 m_colorFromZ =
false;
136 pointsUpToDate =
false;
146 writeToStreamRender(
out);
148 out << m_textureImage;
150 out << xMin << xMax << yMin << yMax;
152 out << m_enableTransparency;
154 out << int16_t(m_colorMap);
165 readFromStreamRender(in);
167 in >> m_textureImage;
176 in >> m_enableTransparency;
186 pointsUpToDate =
false;
197 if (!m_modified_Z && !m_modified_Image)
return;
203 const int cols = m_textureImage.getWidth();
204 const int rows = m_textureImage.getHeight();
209 if (m_textureImage.isColor())
211 C_r.setSize(rows, cols);
212 C_g.setSize(rows, cols);
213 C_b.setSize(rows, cols);
214 m_textureImage.getAsRGBMatrices(C_r, C_g, C_b);
218 C.setSize(rows, cols);
219 m_textureImage.getAsMatrix(C);
224 const size_t cols = Z.cols();
225 const size_t rows = Z.rows();
227 C.setSize(rows, cols);
231 Eigen::MatrixXf Zf = Z.asEigen().cast<
float>();
236 C = Zf.cast<uint8_t>();
239 m_modified_Image =
false;
240 m_modified_Z =
false;
241 pointsUpToDate =
false;
248 pointsUpToDate =
false;
void updateColorsMatrix() const
Called internally to assure C is 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.
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
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.
The base class of 3D objects that can be directly rendered through OpenGL.
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.
size_t getHeight() const override
Returns the height of the image in pixels.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
std::vector< mrpt::img::TColor > m_color_buffer_data
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
void normalize(CONTAINER &c, Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
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. ...
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
mrpt::vision::TStereoCalibResults out
An RGBA color - floats in the range [0,1].
The namespace for 3D scene representation and rendering.
TColor asTColor() const
Returns the 0-255 integer version of this color: RGBA_u8.
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.