Skip to content

Commit b4ae01f

Browse files
committed
Done port mrpt-maps to mrpt-viz
1 parent 137c837 commit b4ae01f

File tree

8 files changed

+58
-305
lines changed

8 files changed

+58
-305
lines changed

libs/maps/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
list(APPEND maps_EXTRA_SRCS "${MRPT_SOURCE_DIR}/libs/maps/src/maps/*.cpp" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/maps/*.h" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/slam/*.h")
55
list(APPEND maps_EXTRA_SRCS_NAME "maps" "maps" "back-compat-hdrs")
66

7-
list(APPEND maps_EXTRA_SRCS "${MRPT_SOURCE_DIR}/libs/maps/src/opengl/*.cpp" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/viz/*.h")
8-
list(APPEND maps_EXTRA_SRCS_NAME "opengl" "opengl")
7+
list(APPEND maps_EXTRA_SRCS "${MRPT_SOURCE_DIR}/libs/maps/src/viz/*.cpp" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/viz/*.h")
8+
list(APPEND maps_EXTRA_SRCS_NAME "viz" "viz")
99

1010
list(APPEND maps_EXTRA_SRCS "${MRPT_SOURCE_DIR}/libs/maps/src/obs/*.cpp" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/obs/*.h")
1111
list(APPEND maps_EXTRA_SRCS_NAME "obs" "obs")

libs/maps/include/mrpt/maps/CColouredPointsMap.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ class CColouredPointsMap : public CPointsMap
208208
/** The options employed when inserting laser scans in the map. */
209209
TColourOptions colorScheme;
210210

211-
/** Reset the minimum-observed-distance buffer for all the points to a
212-
* predefined value */
213-
void resetPointsMinDist(float defValue = 2000.0f);
214-
215211
// clang-format off
216212
auto getPointsBufferRef_color_R() const -> const mrpt::aligned_std_vector<float>* override { return &m_color_R;}
217213
auto getPointsBufferRef_color_G() const -> const mrpt::aligned_std_vector<float>* override { return &m_color_G; }
@@ -317,9 +313,6 @@ class CColouredPointsMap : public CPointsMap
317313
/** The color data */
318314
mrpt::aligned_std_vector<float> m_color_R, m_color_G, m_color_B;
319315

320-
/** Minimum distance from where the points have been seen */
321-
// std::vector<float> m_min_dist;
322-
323316
/** Clear the map, erasing all the points */
324317
void internal_clear() override;
325318

libs/maps/include/mrpt/viz/CAngularObservationMesh.h

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
#include <mrpt/math/CMatrixDynamic.h>
1414
#include <mrpt/math/geometry.h>
1515
#include <mrpt/obs/CObservation2DRangeScan.h>
16-
#include <mrpt/viz/CRenderizableShaderTriangles.h>
17-
#include <mrpt/viz/CRenderizableShaderWireFrame.h>
1816
#include <mrpt/viz/CSetOfLines.h>
1917
#include <mrpt/viz/CSetOfTriangles.h>
18+
#include <mrpt/viz/CVisualObject.h>
2019

2120
namespace mrpt::viz
2221
{
@@ -39,8 +38,9 @@ namespace mrpt::viz
3938
* \ingroup mrpt_maps_grp
4039
*/
4140
class CAngularObservationMesh :
42-
public CRenderizableShaderTriangles,
43-
public CRenderizableShaderWireFrame
41+
virtual public CVisualObject,
42+
public VisualObjectParams_Triangles,
43+
public VisualObjectParams_Lines
4444
{
4545
DEFINE_SERIALIZABLE(CAngularObservationMesh, mrpt::viz)
4646
public:
@@ -120,7 +120,7 @@ class CAngularObservationMesh :
120120
* and the increment.
121121
* \throw std::logic_error if the increment is zero.
122122
*/
123-
inline static TDoubleRange CreateFromIncrement(double initial, double final, double increment)
123+
static TDoubleRange CreateFromIncrement(double initial, double final, double increment)
124124
{
125125
if (increment == 0) throw std::logic_error("Invalid increment value.");
126126
return TDoubleRange(initial, final, increment);
@@ -129,24 +129,23 @@ class CAngularObservationMesh :
129129
* Creates a range of values from the initial value, the final value
130130
* and a desired amount of samples.
131131
*/
132-
inline static TDoubleRange CreateFromAmount(double initial, double final, size_t amount)
132+
static TDoubleRange CreateFromAmount(double initial, double final, size_t amount)
133133
{
134134
return TDoubleRange(initial, final, amount);
135135
}
136136
/**
137137
* Creates a zero-centered range of values from an aperture, an amount
138138
* of samples and a direction.
139139
*/
140-
inline static TDoubleRange CreateFromAperture(
141-
double aperture, size_t amount, bool negToPos = true)
140+
static TDoubleRange CreateFromAperture(double aperture, size_t amount, bool negToPos = true)
142141
{
143142
return TDoubleRange(aperture, amount, negToPos);
144143
}
145144
/**
146145
* Returns the total aperture of the range.
147146
* \throw std::logic_error on invalid range type.
148147
*/
149-
inline double aperture() const
148+
double aperture() const
150149
{
151150
switch (rangeType)
152151
{
@@ -167,7 +166,7 @@ class CAngularObservationMesh :
167166
* Returns the first value of the range.
168167
* \throw std::logic_error on invalid range type.
169168
*/
170-
inline double initialValue() const
169+
double initialValue() const
171170
{
172171
switch (rangeType)
173172
{
@@ -185,7 +184,7 @@ class CAngularObservationMesh :
185184
* Returns the last value of the range.
186185
* \throw std::logic_error on invalid range type.
187186
*/
188-
inline double finalValue() const
187+
double finalValue() const
189188
{
190189
switch (rangeType)
191190
{
@@ -207,7 +206,7 @@ class CAngularObservationMesh :
207206
* Returns the increment between two consecutive values of the range.
208207
* \throw std::logic_error on invalid range type.
209208
*/
210-
inline double increment() const
209+
double increment() const
211210
{
212211
switch (rangeType)
213212
{
@@ -228,7 +227,7 @@ class CAngularObservationMesh :
228227
* Returns the total amount of values in this range.
229228
* \throw std::logic_error on invalid range type.
230229
*/
231-
inline size_t amount() const
230+
size_t amount() const
232231
{
233232
switch (rangeType)
234233
{
@@ -257,7 +256,7 @@ class CAngularObservationMesh :
257256
* positive, false otherwise.
258257
* \throw std::logic_error on invalid range type.
259258
*/
260-
inline bool negToPos() const
259+
bool negToPos() const
261260
{
262261
switch (rangeType)
263262
{
@@ -315,47 +314,28 @@ class CAngularObservationMesh :
315314
/**
316315
* Returns whether the object is configured as wireframe or solid.
317316
*/
318-
inline bool isWireframe() const { return m_Wireframe; }
317+
bool isWireframe() const { return m_Wireframe; }
319318
/**
320319
* Sets the display mode for the object. True=wireframe, False=solid.
321320
*/
322-
inline void setWireframe(bool enabled = true)
321+
void setWireframe(bool enabled = true)
323322
{
324323
m_Wireframe = enabled;
325-
CRenderizable::notifyChange();
324+
CVisualObject::notifyChange();
326325
}
327326
/**
328327
* Returns whether the object may be transparent or not.
329328
*/
330-
inline bool isTransparencyEnabled() const { return mEnableTransparency; }
329+
bool isTransparencyEnabled() const { return mEnableTransparency; }
331330
/**
332331
* Enables or disables transparencies.
333332
*/
334-
inline void enableTransparency(bool enabled = true)
333+
void enableTransparency(bool enabled = true)
335334
{
336335
mEnableTransparency = enabled;
337-
CRenderizable::notifyChange();
336+
CVisualObject::notifyChange();
338337
}
339338

340-
/** @name Renderizable shader API virtual methods
341-
* @{ */
342-
void freeOpenGLResources() override
343-
{
344-
CRenderizableShaderTriangles::freeOpenGLResources();
345-
CRenderizableShaderWireFrame::freeOpenGLResources();
346-
}
347-
void render(const RenderContext& rc) const override;
348-
void renderUpdateBuffers() const override;
349-
350-
virtual shader_list_t requiredShaders() const override
351-
{
352-
// May use up to two shaders (triangles and lines):
353-
return {DefaultShaderID::WIREFRAME, DefaultShaderID::TRIANGLES_LIGHT};
354-
}
355-
void onUpdateBuffers_Wireframe() override;
356-
void onUpdateBuffers_Triangles() override;
357-
/** @} */
358-
359339
/**
360340
* Traces a ray to the object, returning the distance to a given pose
361341
* through its X axis.

libs/maps/include/mrpt/viz/CPlanarLaserScan.h

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
#include <mrpt/maps/CSimplePointsMap.h>
1515
#include <mrpt/obs/CObservation.h>
1616
#include <mrpt/obs/CObservation2DRangeScan.h>
17-
#include <mrpt/viz/CRenderizableShaderPoints.h>
18-
#include <mrpt/viz/CRenderizableShaderTriangles.h>
19-
#include <mrpt/viz/CRenderizableShaderWireFrame.h>
17+
#include <mrpt/viz/CVisualObject.h>
2018

21-
namespace mrpt
22-
{
23-
/** \ingroup mrpt_maps_grp */
24-
namespace viz
19+
namespace mrpt::viz
2520
{
2621
/** This object renders a 2D laser scan by means of three elements: the points,
2722
* the line along end-points and the 2D scanned surface.
@@ -53,61 +48,40 @@ namespace viz
5348
* \ingroup mrpt_maps_grp
5449
*/
5550
class CPlanarLaserScan :
56-
public CRenderizableShaderPoints,
57-
public CRenderizableShaderTriangles,
58-
public CRenderizableShaderWireFrame
51+
virtual public CVisualObject,
52+
public VisualObjectParams_Triangles,
53+
public VisualObjectParams_Lines,
54+
public VisualObjectParams_Points
5955
{
6056
DEFINE_SERIALIZABLE(CPlanarLaserScan, mrpt::viz)
6157

6258
public:
63-
/** @name Renderizable shader API virtual methods
64-
* @{ */
65-
void render(const RenderContext& rc) const override;
66-
void renderUpdateBuffers() const override;
67-
void freeOpenGLResources() override
68-
{
69-
CRenderizableShaderTriangles::freeOpenGLResources();
70-
CRenderizableShaderWireFrame::freeOpenGLResources();
71-
CRenderizableShaderPoints::freeOpenGLResources();
72-
}
73-
74-
virtual shader_list_t requiredShaders() const override
75-
{
76-
return {
77-
DefaultShaderID::WIREFRAME, DefaultShaderID::TRIANGLES_NO_LIGHT, DefaultShaderID::POINTS};
78-
}
79-
void onUpdateBuffers_Wireframe() override;
80-
void onUpdateBuffers_Triangles() override;
81-
void onUpdateBuffers_Points() override;
82-
mrpt::math::TPoint3Df getLocalRepresentativePoint() const override;
83-
/** @} */
84-
8559
CPlanarLaserScan() = default;
8660
~CPlanarLaserScan() override = default;
8761

8862
/** Clear the scan */
8963
void clear();
9064

9165
/** Show or hides the scanned points \sa sePointsWidth, setPointsColor*/
92-
inline void enablePoints(bool enable = true)
66+
void enablePoints(bool enable = true)
9367
{
9468
m_enable_points = enable;
95-
CRenderizable::notifyChange();
69+
CVisualObject::notifyChange();
9670
}
9771

9872
/** Show or hides lines along all scanned points \sa setLineWidth,
9973
* setLineColor*/
100-
inline void enableLine(bool enable = true)
74+
void enableLine(bool enable = true)
10175
{
10276
m_enable_line = enable;
103-
CRenderizable::notifyChange();
77+
CVisualObject::notifyChange();
10478
}
10579

10680
/** Show or hides the scanned area as a 2D surface \sa setSurfaceColor */
107-
inline void enableSurface(bool enable = true)
81+
void enableSurface(bool enable = true)
10882
{
10983
m_enable_surface = enable;
110-
CRenderizable::notifyChange();
84+
CVisualObject::notifyChange();
11185
}
11286

11387
void setLineColor(float R, float G, float B, float A = 1.0f)
@@ -134,12 +108,13 @@ class CPlanarLaserScan :
134108

135109
void setScan(const mrpt::obs::CObservation2DRangeScan& scan)
136110
{
137-
CRenderizable::notifyChange();
111+
CVisualObject::notifyChange();
138112
m_cache_valid = false;
139113
m_scan = scan;
140114
}
141115

142116
auto internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf override;
117+
auto getLocalRepresentativePoint() const -> mrpt::math::TPoint3Df override;
143118

144119
protected:
145120
mrpt::obs::CObservation2DRangeScan m_scan;
@@ -157,5 +132,4 @@ class CPlanarLaserScan :
157132
bool m_enable_surface{true};
158133
};
159134

160-
} // namespace viz
161-
} // namespace mrpt
135+
} // namespace mrpt::viz

libs/maps/src/maps/CColouredPointsMap.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <mrpt/serialization/aligned_serialization.h>
1818
#include <mrpt/system/os.h>
1919
#include <mrpt/viz/CPointCloudColoured.h>
20+
#include <mrpt/viz/CSetOfObjects.h>
2021

2122
#include "CPointsMap_crtp_common.h"
2223

@@ -492,9 +493,6 @@ bool CColouredPointsMap::colourFromObservation(
492493
chB = 2;
493494
}
494495

495-
unsigned int n_proj = 0;
496-
const float factor = 1.0f / 255; // Normalize pixels:
497-
498496
// Get the colour of the projected points
499497
size_t k;
500498
for (itProPoints = projectedPoints.begin(), k = 0; itProPoints != projectedPoints.end();
@@ -506,21 +504,13 @@ bool CColouredPointsMap::colourFromObservation(
506504
unsigned int ii = p_idx[p_proj[k]];
507505
uint8_t* p = obs.image((unsigned int)itProPoints->x, (unsigned int)itProPoints->y);
508506

509-
m_color_R[ii] = p[chR] * factor; // R
510-
m_color_G[ii] = p[chG] * factor; // G
511-
m_color_B[ii] = p[chB] * factor; // B
512-
// m_min_dist[ii] = p_dist[p_proj[k]];
513-
514-
n_proj++;
507+
m_color_R[ii] = mrpt::u8tof(p[chR]);
508+
m_color_G[ii] = mrpt::u8tof(p[chG]);
509+
m_color_B[ii] = mrpt::u8tof(p[chB]);
515510
}
516-
} // end for
511+
}
517512

518513
return true;
519-
} // end colourFromObservation
520-
521-
void CColouredPointsMap::resetPointsMinDist([[maybe_unused]] float defValue)
522-
{
523-
// m_min_dist.assign(x.size(),defValue);
524514
}
525515

526516
bool CColouredPointsMap::save3D_and_colour_to_text_file(const std::string& file) const

libs/maps/src/maps/CPointsMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <mrpt/system/os.h>
2929
#include <mrpt/viz/CPointCloud.h>
3030
#include <mrpt/viz/CPointCloudColoured.h>
31+
#include <mrpt/viz/CSetOfObjects.h>
3132

3233
#include <fstream>
3334
#include <sstream>

0 commit comments

Comments
 (0)