MRPT  1.9.9
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-2019, 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 #include "opengl_internals.h"
17 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 
21 using namespace mrpt::math;
22 using namespace std;
23 
25 
26 /** Constructor */
27 CSetOfLines::CSetOfLines() : mSegments() {}
28 /** Constructor with a initial set of lines. */
29 CSetOfLines::CSetOfLines(const std::vector<TSegment3D>& sgms, bool antiAliasing)
30  : mSegments(sgms),
31  mLineWidth(1.0),
32  m_antiAliasing(antiAliasing),
33  m_verticesPointSize(.0f)
34 {
35 }
36 
37 /*---------------------------------------------------------------
38  setLineByIndex
39  ---------------------------------------------------------------*/
41  size_t index, const mrpt::math::TSegment3D& segm)
42 {
44  if (index >= mSegments.size()) THROW_EXCEPTION("Index out of bounds");
46  mSegments[index] = segm;
47  MRPT_END
48 }
49 
51 void CSetOfLines::setVerticesPointSize(const float size_points)
52 {
53  m_verticesPointSize = size_points;
55 }
56 
57 /*---------------------------------------------------------------
58  render
59  ---------------------------------------------------------------*/
61 {
62 #if MRPT_HAS_OPENGL_GLUT
63 
64  // Enable antialiasing:
66  if (m_antiAliasing || m_color.A != 255)
67  {
70  }
74 
75  glDisable(GL_LIGHTING); // Disable lights when drawing lines
78  for (const auto& mSegment : mSegments)
79  {
80  glVertex3d(mSegment.point1.x, mSegment.point1.y, mSegment.point1.z);
81  glVertex3d(mSegment.point2.x, mSegment.point2.y, mSegment.point2.z);
82  }
83  glEnd();
85 
86  // Draw vertices?
87  if (m_verticesPointSize > 0)
88  {
90  if (m_antiAliasing)
92  else
94 
97  bool first = true;
98  for (const auto& seg : mSegments)
99  {
100  if (first)
101  {
102  glVertex3d(seg.point1.x, seg.point1.y, seg.point1.z);
103  first = false;
104  }
105  glVertex3d(seg.point2.x, seg.point2.y, seg.point2.z);
106  }
107 
108  glEnd();
109  }
110 
111  glEnable(GL_LIGHTING); // Disable lights when drawing lines
112 
113  // End of antialiasing:
114  glPopAttrib();
115 
116 #endif
117 }
118 
121 {
122  writeToStreamRender(out);
123  out << mSegments << mLineWidth;
124  out << m_antiAliasing; // Added in v3
125  out << m_verticesPointSize; // v4
126 }
127 
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 >> mLineWidth;
141  else
142  mLineWidth = 1;
143  size_t N = x0.size();
144  mSegments.resize(N);
145  for (size_t i = 0; i < N; i++)
146  {
147  mSegments[i][0][0] = x0[i];
148  mSegments[i][0][1] = y0[i];
149  mSegments[i][0][2] = z0[i];
150  mSegments[i][1][0] = x1[i];
151  mSegments[i][1][1] = y1[i];
152  mSegments[i][1][2] = z1[i];
153  }
154  }
155  break;
156  case 2:
157  case 3:
158  case 4:
159  {
161  in >> mSegments;
162  in >> mLineWidth;
163  if (version >= 3)
164  in >> m_antiAliasing;
165  else
166  m_antiAliasing = true;
167  if (version >= 4)
169  else
170  m_verticesPointSize = .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 : mSegments)
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 < mSegments.size());
213  const mrpt::math::TPoint3D& p0 = mSegments[index].point1;
214  const mrpt::math::TPoint3D& p1 = mSegments[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 }
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:35
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
#define MRPT_START
Definition: exceptions.h:241
double x
X,Y,Z coordinates.
Definition: TPoint3D.h:83
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr, 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...
Definition: CPose3D.cpp:368
GLAPI void GLAPIENTRY glEnable(GLenum cap)
Template for column vectors of dynamic size, compatible with Eigen.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
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.
GLint * first
Definition: glext.h:3833
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
STL namespace.
uint8_t B
Definition: TColor.h:46
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:39
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
uint8_t G
Definition: TColor.h:46
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...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
GLAPI void GLAPIENTRY glPopAttrib(void)
GLdouble s
Definition: glext.h:3682
#define GL_LIGHTING
Definition: glew.h:386
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:54
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
unsigned char uint8_t
Definition: rptypes.h:44
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:266
This base provides a set of functions for maths stuff.
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...
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:50
3D segment, consisting of two points.
Definition: TSegment3D.h:21
void writeToStreamRender(mrpt::serialization::CArchive &out) const
#define GL_LINE_SMOOTH
Definition: glew.h:368
GLuint index
Definition: glext.h:4068
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 setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:51
#define GL_POINT_SMOOTH
Definition: glew.h:364
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:433
#define GL_POINTS
Definition: glew.h:273
uint8_t R
Definition: TColor.h:46
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:60
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:51
#define GL_SRC_ALPHA
Definition: glew.h:287
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:27
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
#define MRPT_END
Definition: exceptions.h:245
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
GLAPI void GLAPIENTRY glEnd(void)
const auto bb_min
#define GL_LINES
Definition: glew.h:274
Lightweight 3D point.
Definition: TPoint3D.h:90
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:31
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat GLfloat p
Definition: glext.h:6398
void readFromStreamRender(mrpt::serialization::CArchive &in)
#define GL_LINE_BIT
Definition: glew.h:254
uint8_t A
Definition: TColor.h:46
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:40



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019