26 m_point_color = m_color;
27 m_field_color = m_color;
33 float ymin,
float ymax)
41 m_point_color = m_color;
42 m_field_color = m_color;
73 vbd.reserve(xcomp.size() * 2);
75 const float x_cell_size = (xMax - xMin) / (xcomp.cols() - 1);
76 const float y_cell_size = (yMax - yMin) / (ycomp.rows() - 1);
78 for (
int i = 0; i < xcomp.cols(); i++)
79 for (
int j = 0; j < xcomp.rows(); j++)
81 vbd.emplace_back(xMin + i * x_cell_size, yMin + j * y_cell_size, 0);
83 xMin + i * x_cell_size + xcomp(j, i),
84 yMin + j * y_cell_size + ycomp(j, i), 0);
87 cbd.assign(vbd.size(), m_field_color);
96 tris.reserve(xcomp.size());
98 const float x_cell_size = (xMax - xMin) / (xcomp.cols() - 1);
99 const float y_cell_size = (yMax - yMin) / (ycomp.rows() - 1);
101 for (
int i = 0; i < xcomp.cols(); i++)
102 for (
int j = 0; j < xcomp.rows(); j++)
104 const float tri_side =
106 sqrt(xcomp(j, i) * xcomp(j, i) + ycomp(j, i) * ycomp(j, i));
107 const float ang = ::atan2f(ycomp(j, i), xcomp(j, i)) - 1.5708f;
109 P3f(-sin(ang) * 0.866f * tri_side + xMin + i * x_cell_size +
111 cos(ang) * 0.866f * tri_side + yMin + j * y_cell_size +
114 P3f(cos(ang) * 0.5f * tri_side + xMin + i * x_cell_size +
116 sin(ang) * 0.5f * tri_side + yMin + j * y_cell_size +
119 P3f(-cos(ang) * 0.5f * tri_side + xMin + i * x_cell_size +
121 -sin(ang) * 0.5f * tri_side + yMin + j * y_cell_size +
129 t.setColor(m_field_color);
138 vbd.reserve(xcomp.size());
140 const float x_cell_size = (xMax - xMin) / (xcomp.cols() - 1);
141 const float y_cell_size = (yMax - yMin) / (ycomp.rows() - 1);
143 for (
int i = 0; i < xcomp.cols(); i++)
144 for (
int j = 0; j < xcomp.rows(); j++)
146 xMin + i * x_cell_size, yMin + j * y_cell_size, .0f);
148 cbd.assign(vbd.size(), m_point_color);
158 writeToStreamRender(
out);
160 out << xcomp << ycomp;
161 out << xMin << xMax << yMin << yMax;
164 out << m_antiAliasing;
165 out << m_point_color;
166 out << m_field_color;
175 readFromStreamRender(in);
177 in >> xcomp >> ycomp;
178 in >> xMin >> xMax >> yMin >> yMax;
181 in >> m_antiAliasing;
204 const float x_cell_size = (xMax - xMin) / (xcomp.cols() - 1);
205 const float y_cell_size = (yMax - yMin) / (ycomp.rows() - 1);
207 for (
int i = 0; i < xcomp.cols(); i++)
208 for (
int j = 0; j < xcomp.rows(); j++)
210 const float tri_side =
212 sqrt(xcomp(j, i) * xcomp(j, i) + ycomp(j, i) * ycomp(j, i));
213 const float ang = ::atan2f(ycomp(j, i), xcomp(j, i)) - 1.5708f;
215 if (-sin(ang) * 0.866f * tri_side + xMin + i * x_cell_size +
218 bb_min.x = -sin(ang) * 0.866f * tri_side + xMin +
219 i * x_cell_size + xcomp(j, i);
221 if (cos(ang) * 0.866f * tri_side + yMin + j * y_cell_size +
224 bb_min.y = cos(ang) * 0.866f * tri_side + yMin +
225 j * y_cell_size + ycomp(j, i);
227 if (-sin(ang) * 0.866f * tri_side + xMin + i * x_cell_size +
230 bb_max.x = -sin(ang) * 0.866f * tri_side + xMin +
231 i * x_cell_size + xcomp(j, i);
233 if (cos(ang) * 0.866f * tri_side + yMin + j * y_cell_size +
236 bb_max.y = cos(ang) * 0.866f * tri_side + yMin +
237 j * y_cell_size + ycomp(j, i);
249 const float ratio_xp =
250 xcomp.maxCoeff() * (xcomp.cols() - 1) / (xMax - xMin);
251 const float ratio_xn =
252 xcomp.minCoeff() * (xcomp.cols() - 1) / (xMax - xMin);
253 const float ratio_yp =
254 ycomp.maxCoeff() * (ycomp.rows() - 1) / (yMax - yMin);
255 const float ratio_yn =
256 ycomp.minCoeff() * (ycomp.rows() - 1) / (yMax - yMin);
257 const float norm_factor = 0.85f / max(max(ratio_xp, std::abs(ratio_xn)),
258 max(ratio_yp, std::abs(ratio_yn)));
260 xcomp *= norm_factor;
261 ycomp *= norm_factor;
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.
mrpt::opengl::shader_id_t shader_id
The base class of 3D objects that can be directly rendered through OpenGL.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
#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.
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
This base provides a set of functions for maths stuff.
static constexpr shader_id_t WIREFRAME
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
A 2D vector field representation, consisting of points and arrows drawn on a plane (invisible grid)...
static constexpr shader_id_t TRIANGLES
CVectorField2D()
Constructor.
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 serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
std::vector< mrpt::img::TColor > m_color_buffer_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Virtual base class for "archives": classes abstracting I/O streams.
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
mrpt::vision::TStereoCalibResults out
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
The namespace for 3D scene representation and rendering.
void adjustVectorFieldToGrid()
Adjust the vector field in the scene (vectors magnitude) according to the grid size.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
TPoint3D_< float > TPoint3Df
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
static constexpr shader_id_t POINTS
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.