MRPT  2.0.3
CVectorField3D.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-2020, 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 "opengl-precomp.h" // Precompiled header
11 
13 #include <mrpt/opengl/opengl_api.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::opengl;
18 using namespace mrpt::math;
19 using namespace std;
20 
22 
23 /** Constructor */
25  : x_vf(0, 0), y_vf(0, 0), z_vf(0, 0), x_p(0, 0), y_p(0, 0), z_p(0, 0)
26 {
27  m_point_color = m_color;
28  m_field_color = m_color;
29  m_still_color = m_color;
30  m_maxspeed_color = m_color;
31  m_maxspeed = 1.f;
32 }
33 
34 /** Constructor with a initial set of lines. */
36  CMatrixFloat x_vf_ini, CMatrixFloat y_vf_ini, CMatrixFloat z_vf_ini,
37  CMatrixFloat x_p_ini, CMatrixFloat y_p_ini, CMatrixFloat z_p_ini)
38  : m_colorFromModule(false), m_showPoints(true)
39 {
40  x_vf = x_vf_ini;
41  y_vf = y_vf_ini;
42  z_vf = z_vf_ini;
43  x_p = x_p_ini;
44  y_p = y_p_ini;
45  z_p = z_p_ini;
50  m_maxspeed = 1.f;
51 }
52 
54 {
55  switch (rc.shader_id)
56  {
59  break;
62  break;
63  };
64 }
66 {
69 }
70 
72 {
75  vbd.clear();
76  cbd.clear();
77 
78  vbd.reserve(x_vf.size());
79  cbd.reserve(x_vf.size());
80 
81  for (int i = 0; i < x_vf.cols(); i++)
82  for (int j = 0; j < x_vf.rows(); j++)
83  {
84  vbd.emplace_back(x_p(j, i), y_p(j, i), z_p(j, i));
85  vbd.emplace_back(
86  x_p(j, i) + x_vf(j, i), y_p(j, i) + y_vf(j, i),
87  z_p(j, i) + z_vf(j, i));
88 
89  if (!m_colorFromModule)
90  {
91  cbd.emplace_back(m_field_color);
92  }
93  else
94  {
95  // Compute color
97  const float module = sqrt(
98  square(x_vf(j, i)) + square(y_vf(j, i)) +
99  square(z_vf(j, i)));
100  if (module > m_maxspeed)
101  col = m_maxspeed_color;
102  else
103  {
104  const float f = (m_maxspeed - module) / m_maxspeed;
105  const float f2 = module / m_maxspeed;
106  col = mrpt::img::TColorf(
107  f * m_still_color.R + f2 * m_maxspeed_color.R,
108  f * m_still_color.G + f2 * m_maxspeed_color.G,
109  f * m_still_color.B + f2 * m_maxspeed_color.B,
110  f * m_still_color.A + f2 * m_maxspeed_color.A)
111  .asTColor();
112  }
113  cbd.emplace_back(col);
114  }
115  }
116 
117  cbd.assign(vbd.size(), m_field_color);
118 }
119 
121 {
124 
125  vbd.clear();
126  vbd.reserve(x_p.size());
127 
128  for (int i = 0; i < x_p.cols(); i++)
129  for (int j = 0; j < x_p.rows(); j++)
130  vbd.emplace_back(x_p(j, i), y_p(j, i), z_p(j, i));
131 
132  cbd.assign(vbd.size(), m_point_color);
133 }
134 uint8_t CVectorField3D::serializeGetVersion() const { return 0; }
136 {
138 
139  out << x_vf << y_vf << z_vf;
140  out << x_p << y_p << z_p;
141  out << m_lineWidth;
142  out << m_pointSize;
143  out << m_antiAliasing;
144  out << m_point_color;
145  out << m_field_color;
146 }
148  mrpt::serialization::CArchive& in, uint8_t version)
149 {
150  switch (version)
151  {
152  case 0:
154 
155  in >> x_vf >> y_vf >> z_vf;
156  in >> x_p >> y_p >> z_p;
157  in >> m_lineWidth;
158  in >> m_pointSize;
159  in >> m_antiAliasing;
160  in >> m_point_color;
161  in >> m_field_color;
162  break;
163 
164  default:
166  break;
167  };
169 }
170 
173 {
174  bb_min.x = 10e10;
175  bb_min.y = 10e10;
176  bb_min.z = 10e10;
177  bb_max.x = -10e10;
178  bb_max.y = -10e10;
179  bb_max.z = -10e10;
180 
181  for (int i = 0; i < x_p.cols(); i++)
182  for (int j = 0; j < x_p.rows(); j++)
183  {
184  // Minimum values
185  if (x_p(j, i) < bb_min.x) bb_min.x = x_p(j, i);
186 
187  if (x_p(j, i) + x_vf(j, i) < bb_min.x)
188  bb_min.x = x_p(j, i) + x_vf(j, i);
189 
190  if (y_p(j, i) < bb_min.y) bb_min.y = y_p(j, i);
191 
192  if (y_p(j, i) + y_vf(j, i) < bb_min.y)
193  bb_min.y = y_p(j, i) + y_vf(j, i);
194 
195  if (z_p(j, i) < bb_min.z) bb_min.z = z_p(j, i);
196 
197  if (z_p(j, i) + z_vf(j, i) < bb_min.z)
198  bb_min.z = z_p(j, i) + z_vf(j, i);
199 
200  // Maximum values
201  if (x_p(j, i) > bb_max.x) bb_max.x = x_p(j, i);
202 
203  if (x_p(j, i) + x_vf(j, i) > bb_max.x)
204  bb_max.x = x_p(j, i) + x_vf(j, i);
205 
206  if (y_p(j, i) > bb_max.y) bb_max.y = y_p(j, i);
207 
208  if (y_p(j, i) + y_vf(j, i) > bb_max.y)
209  bb_max.y = y_p(j, i) + y_vf(j, i);
210 
211  if (z_p(j, i) > bb_max.z) bb_max.z = z_p(j, i);
212 
213  if (z_p(j, i) + z_vf(j, i) > bb_max.z)
214  bb_max.z = z_p(j, i) + z_vf(j, i);
215  }
216 
217  // Convert to coordinates of my parent:
220 }
opengl_api.h
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::math::TPoint3D_< double >
mrpt::opengl::CRenderizable::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizable.cpp:99
mrpt::opengl::CVectorField3D::x_p
mrpt::math::CMatrixF x_p
X coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:51
mrpt::opengl::CRenderizableShaderWireFrame::m_antiAliasing
bool m_antiAliasing
Definition: CRenderizableShaderWireFrame.h:66
CVectorField3D.h
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
mrpt::opengl::CVectorField3D::m_field_color
mrpt::img::TColor m_field_color
Definition: CVectorField3D.h:63
mrpt::opengl::CRenderizableShaderWireFrame::m_color_buffer_data
std::vector< mrpt::img::TColor > m_color_buffer_data
Definition: CRenderizableShaderWireFrame.h:68
mrpt::opengl::CVectorField3D
A 3D vector field representation, consisting of points and arrows drawn at any spatial position.
Definition: CVectorField3D.h:38
mrpt::img::TColorf::asTColor
TColor asTColor() const
Returns the 0-255 integer version of this color: RGBA_u8
Definition: TColor.h:101
mrpt::opengl::CVectorField3D::onUpdateBuffers_Wireframe
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CVectorField3D.cpp:71
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:51
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::opengl::CVectorField3D::m_colorFromModule
bool m_colorFromModule
By default it is false.
Definition: CVectorField3D.h:58
mrpt::opengl::CRenderizableShaderPoints::m_pointSize
float m_pointSize
Definition: CRenderizableShaderPoints.h:97
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::opengl::CVectorField3D::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CVectorField3D.cpp:147
mrpt::opengl::CVectorField3D::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CVectorField3D.cpp:134
mrpt::opengl::CVectorField3D::CVectorField3D
CVectorField3D()
Constructor.
Definition: CVectorField3D.cpp:24
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:51
mrpt::opengl::DefaultShaderID::WIREFRAME
static constexpr shader_id_t WIREFRAME
Definition: DefaultShaders.h:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::CRenderizable::m_pose
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:62
mrpt::opengl::CRenderizableShaderWireFrame::m_vertex_buffer_data
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
Definition: CRenderizableShaderWireFrame.h:67
mrpt::opengl::CRenderizable::m_color
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:59
mrpt::poses::CPose3D::composePoint
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::optional_ref< mrpt::math::CMatrixDouble33 > out_jacobian_df_dpoint=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dpose=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dse3=std::nullopt, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
mrpt::opengl::CRenderizableShaderPoints::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
mrpt::opengl::CVectorField3D::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CVectorField3D.cpp:53
mrpt::opengl::CVectorField3D::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CVectorField3D.cpp:135
mrpt::opengl::CVectorField3D::x_vf
mrpt::math::CMatrixF x_vf
X component of the vector field.
Definition: CVectorField3D.h:44
mrpt::img::TColorf
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
mrpt::opengl::CVectorField3D::m_showPoints
bool m_showPoints
By default it is true.
Definition: CVectorField3D.h:60
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::opengl::CRenderizableShaderWireFrame::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CRenderizableShaderWireFrame.cpp:52
mrpt::square
return_t square(const num_t x)
Inline function for the square of a number.
Definition: core/include/mrpt/core/bits_math.h:23
mrpt::opengl::CVectorField3D::y_p
mrpt::math::CMatrixF y_p
Y coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:53
mrpt::opengl::CVectorField3D::m_maxspeed
float m_maxspeed
Value of the module of the motion field which will correspond to 'm_maxspeed_color'.
Definition: CVectorField3D.h:72
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:51
mrpt::opengl::CVectorField3D::m_maxspeed_color
mrpt::img::TColor m_maxspeed_color
Color associated to fields whose module is equal or larger than 'm_maxspeed'.
Definition: CVectorField3D.h:69
mrpt::opengl::CRenderizable::RenderContext
Context for calls to render()
Definition: CRenderizable.h:266
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
Definition: CSerializable.h:166
mrpt::opengl::CRenderizableShaderWireFrame::m_lineWidth
float m_lineWidth
Definition: CRenderizableShaderWireFrame.h:65
mrpt::opengl::CRenderizable::RenderContext::shader_id
mrpt::opengl::shader_id_t shader_id
Definition: CRenderizable.h:272
opengl-precomp.h
mrpt::opengl::CVectorField3D::z_p
mrpt::math::CMatrixF z_p
Z coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:55
mrpt::opengl::CVectorField3D::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
Definition: CVectorField3D.cpp:65
mrpt::opengl::CVectorField3D::getBoundingBox
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...
Definition: CVectorField3D.cpp:171
mrpt::img::TColor::G
uint8_t G
Definition: TColor.h:51
mrpt::opengl::CVectorField3D::y_vf
mrpt::math::CMatrixF y_vf
Y component of the vector field.
Definition: CVectorField3D.h:46
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
mrpt::opengl::CVectorField3D::m_still_color
mrpt::img::TColor m_still_color
Color associated to fields with null module.
Definition: CVectorField3D.h:66
mrpt::math::CMatrixDynamic::cols
size_type cols() const
Number of columns in the matrix.
Definition: CMatrixDynamic.h:340
mrpt::opengl::CRenderizableShaderPoints::m_vertex_buffer_data
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
Definition: CRenderizableShaderPoints.h:94
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
mrpt::opengl::CRenderizable::writeToStreamRender
void writeToStreamRender(mrpt::serialization::CArchive &out) const
Definition: CRenderizable.cpp:44
mrpt::math::CMatrixDynamic::size
matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
Definition: CMatrixDynamic.h:343
mrpt::opengl::CRenderizableShaderWireFrame::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
mrpt::opengl::CRenderizableShaderPoints::m_color_buffer_data
std::vector< mrpt::img::TColor > m_color_buffer_data
Definition: CRenderizableShaderPoints.h:95
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::DefaultShaderID::POINTS
static constexpr shader_id_t POINTS
Definition: DefaultShaders.h:24
mrpt::math::CMatrixDynamic
This template class provides the basic functionality for a general 2D any-size, resizable container o...
Definition: CMatrixDynamic.h:39
mrpt::math::CMatrixDynamic::rows
size_type rows() const
Number of rows in the matrix.
Definition: CMatrixDynamic.h:337
mrpt::opengl::CVectorField3D::z_vf
mrpt::math::CMatrixF z_vf
Z component of the vector field.
Definition: CVectorField3D.h:48
mrpt::opengl::CVectorField3D::onUpdateBuffers_Points
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CVectorField3D.cpp:120
mrpt::opengl::CVectorField3D::m_point_color
mrpt::img::TColor m_point_color
Definition: CVectorField3D.h:62



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Thu May 21 21:53:32 UTC 2020