MRPT  2.0.4
CSetOfLines.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 
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::math;
20 using namespace std;
21 
23 
24 /** Constructor */
26 {
27  // Override default pointsize=1 in points shader:
29 }
30 
31 /** Constructor with a initial set of lines. */
32 CSetOfLines::CSetOfLines(const std::vector<TSegment3D>& sgms, bool antiAliasing)
33  : m_Segments(sgms)
34 {
35  // Override default pointsize=1 in points shader:
37 
38  m_lineWidth = 1;
39  m_antiAliasing = antiAliasing;
40 }
41 
42 void CSetOfLines::render(const RenderContext& rc) const
43 {
44  switch (rc.shader_id)
45  {
48  break;
51  break;
52  };
53 }
55 {
58 }
59 
60 /*---------------------------------------------------------------
61  setLineByIndex
62  ---------------------------------------------------------------*/
64  size_t index, const mrpt::math::TSegment3D& segm)
65 {
67  if (index >= m_Segments.size()) THROW_EXCEPTION("Index out of bounds");
69  m_Segments[index] = segm;
70  MRPT_END
71 }
72 
74 void CSetOfLines::setVerticesPointSize(const float size_points)
75 {
76  m_pointSize = size_points;
78 }
79 
81 {
84  vbd.clear();
85  vbd.reserve(m_Segments.size() * 2);
86 
87  for (const auto& segment : m_Segments)
88  {
89  vbd.emplace_back(segment.point1);
90  vbd.emplace_back(segment.point2);
91  }
92 
93  // The same color to all vertices:
94  cbd.assign(vbd.size(), m_color);
95 }
96 
98 {
101  vbd.clear();
102  cbd.clear();
103 
104  // Only draw points if they are enabled:
105  if (m_pointSize <= .0f) return;
106 
107  vbd.reserve(m_Segments.size() * 2);
108 
109  for (const auto& segment : m_Segments)
110  {
111  vbd.emplace_back(segment.point1);
112  vbd.emplace_back(segment.point2);
113  }
114 
115  // The same color to all vertices:
116  cbd.assign(vbd.size(), m_color);
117 }
118 
119 uint8_t CSetOfLines::serializeGetVersion() const { return 4; }
121 {
123  out << m_Segments << m_lineWidth;
124  out << m_antiAliasing; // Added in v3
126 }
127 
129  mrpt::serialization::CArchive& in, uint8_t version)
130 {
131  switch (version)
132  {
133  case 0:
134  case 1:
135  {
137  CVectorFloat x0, y0, z0, x1, y1, z1;
138  in >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
139  if (version >= 1)
140  in >> m_lineWidth;
141  else
142  m_lineWidth = 1;
143  size_t N = x0.size();
144  m_Segments.resize(N);
145  for (size_t i = 0; i < N; i++)
146  {
147  m_Segments[i][0][0] = x0[i];
148  m_Segments[i][0][1] = y0[i];
149  m_Segments[i][0][2] = z0[i];
150  m_Segments[i][1][0] = x1[i];
151  m_Segments[i][1][1] = y1[i];
152  m_Segments[i][1][2] = z1[i];
153  }
154  }
155  break;
156  case 2:
157  case 3:
158  case 4:
159  {
161  in >> m_Segments;
162  in >> m_lineWidth;
163  if (version >= 3)
164  in >> m_antiAliasing;
165  else
166  m_antiAliasing = true;
167  if (version >= 4)
169  else
170  m_pointSize = .0f;
171  }
172  break;
173  default:
175  };
177 }
178 
181 {
183  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
184  std::numeric_limits<double>::max());
186  -std::numeric_limits<double>::max(),
187  -std::numeric_limits<double>::max(),
188  -std::numeric_limits<double>::max());
189 
190  for (const auto& s : m_Segments)
191  {
192  for (size_t p = 0; p < 2; p++)
193  {
194  const TPoint3D& pt = s[p];
195  for (size_t j = 0; j < 3; j++)
196  {
197  keep_min(bb_min[j], pt[j]);
198  keep_max(bb_max[j], pt[j]);
199  }
200  }
201  }
202 
203  // Convert to coordinates of my parent:
206 }
207 
209  size_t index, double& x0, double& y0, double& z0, double& x1, double& y1,
210  double& z1) const
211 {
212  ASSERT_(index < m_Segments.size());
213  const mrpt::math::TPoint3D& p0 = m_Segments[index].point1;
214  const mrpt::math::TPoint3D& p1 = m_Segments[index].point2;
215  x0 = p0.x;
216  y0 = p0.y;
217  z0 = p0.z;
218  x1 = p1.x;
219  y1 = p1.y;
220  z1 = p1.z;
221 }
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CSetOfLines.cpp:42
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
#define MRPT_START
Definition: exceptions.h:241
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Template for column vectors of dynamic size, compatible with Eigen.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
void getLineByIndex(size_t index, double &x0, double &y0, double &z0, double &x1, double &y1, double &z1) const
Gets a specific line in the set, given its index.
#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.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CSetOfLines.cpp:54
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
STL namespace.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:62
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
std::vector< mrpt::img::TColor > m_color_buffer_data
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
void params_deserialize(mrpt::serialization::CArchive &in)
This base provides a set of functions for maths stuff.
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CSetOfLines.cpp:80
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:73
3D segment, consisting of two points.
Definition: TSegment3D.h:20
void writeToStreamRender(mrpt::serialization::CArchive &out) const
static constexpr shader_id_t WIREFRAME
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...
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:74
void params_serialize(mrpt::serialization::CArchive &out) const
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
std::vector< mrpt::math::TSegment3D > m_Segments
Definition: CSetOfLines.h:37
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:59
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CSetOfLines.cpp:97
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
std::vector< mrpt::img::TColor > m_color_buffer_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:25
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
Renderizable generic renderer for objects using the wireframe shader.
#define MRPT_END
Definition: exceptions.h:245
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void readFromStreamRender(mrpt::serialization::CArchive &in)
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...
const auto bb_min
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:32
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
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:63
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 7b5ddf9de Fri May 29 14:02:56 2020 +0200 at vie may 29 14:15:09 CEST 2020