Skip to content

Commit

Permalink
Done port mrpt-maps to mrpt-viz
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Feb 5, 2025
1 parent 137c837 commit b4ae01f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 305 deletions.
4 changes: 2 additions & 2 deletions libs/maps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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")
list(APPEND maps_EXTRA_SRCS_NAME "maps" "maps" "back-compat-hdrs")

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

list(APPEND maps_EXTRA_SRCS "${MRPT_SOURCE_DIR}/libs/maps/src/obs/*.cpp" "${MRPT_SOURCE_DIR}/libs/maps/include/mrpt/obs/*.h")
list(APPEND maps_EXTRA_SRCS_NAME "obs" "obs")
Expand Down
7 changes: 0 additions & 7 deletions libs/maps/include/mrpt/maps/CColouredPointsMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ class CColouredPointsMap : public CPointsMap
/** The options employed when inserting laser scans in the map. */
TColourOptions colorScheme;

/** Reset the minimum-observed-distance buffer for all the points to a
* predefined value */
void resetPointsMinDist(float defValue = 2000.0f);

// clang-format off
auto getPointsBufferRef_color_R() const -> const mrpt::aligned_std_vector<float>* override { return &m_color_R;}
auto getPointsBufferRef_color_G() const -> const mrpt::aligned_std_vector<float>* override { return &m_color_G; }
Expand Down Expand Up @@ -317,9 +313,6 @@ class CColouredPointsMap : public CPointsMap
/** The color data */
mrpt::aligned_std_vector<float> m_color_R, m_color_G, m_color_B;

/** Minimum distance from where the points have been seen */
// std::vector<float> m_min_dist;

/** Clear the map, erasing all the points */
void internal_clear() override;

Expand Down
58 changes: 19 additions & 39 deletions libs/maps/include/mrpt/viz/CAngularObservationMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#include <mrpt/math/CMatrixDynamic.h>
#include <mrpt/math/geometry.h>
#include <mrpt/obs/CObservation2DRangeScan.h>
#include <mrpt/viz/CRenderizableShaderTriangles.h>
#include <mrpt/viz/CRenderizableShaderWireFrame.h>
#include <mrpt/viz/CSetOfLines.h>
#include <mrpt/viz/CSetOfTriangles.h>
#include <mrpt/viz/CVisualObject.h>

namespace mrpt::viz
{
Expand All @@ -39,8 +38,9 @@ namespace mrpt::viz
* \ingroup mrpt_maps_grp
*/
class CAngularObservationMesh :
public CRenderizableShaderTriangles,
public CRenderizableShaderWireFrame
virtual public CVisualObject,
public VisualObjectParams_Triangles,
public VisualObjectParams_Lines
{
DEFINE_SERIALIZABLE(CAngularObservationMesh, mrpt::viz)
public:
Expand Down Expand Up @@ -120,7 +120,7 @@ class CAngularObservationMesh :
* and the increment.
* \throw std::logic_error if the increment is zero.
*/
inline static TDoubleRange CreateFromIncrement(double initial, double final, double increment)
static TDoubleRange CreateFromIncrement(double initial, double final, double increment)
{
if (increment == 0) throw std::logic_error("Invalid increment value.");
return TDoubleRange(initial, final, increment);
Expand All @@ -129,24 +129,23 @@ class CAngularObservationMesh :
* Creates a range of values from the initial value, the final value
* and a desired amount of samples.
*/
inline static TDoubleRange CreateFromAmount(double initial, double final, size_t amount)
static TDoubleRange CreateFromAmount(double initial, double final, size_t amount)
{
return TDoubleRange(initial, final, amount);
}
/**
* Creates a zero-centered range of values from an aperture, an amount
* of samples and a direction.
*/
inline static TDoubleRange CreateFromAperture(
double aperture, size_t amount, bool negToPos = true)
static TDoubleRange CreateFromAperture(double aperture, size_t amount, bool negToPos = true)
{
return TDoubleRange(aperture, amount, negToPos);
}
/**
* Returns the total aperture of the range.
* \throw std::logic_error on invalid range type.
*/
inline double aperture() const
double aperture() const
{
switch (rangeType)
{
Expand All @@ -167,7 +166,7 @@ class CAngularObservationMesh :
* Returns the first value of the range.
* \throw std::logic_error on invalid range type.
*/
inline double initialValue() const
double initialValue() const
{
switch (rangeType)
{
Expand All @@ -185,7 +184,7 @@ class CAngularObservationMesh :
* Returns the last value of the range.
* \throw std::logic_error on invalid range type.
*/
inline double finalValue() const
double finalValue() const
{
switch (rangeType)
{
Expand All @@ -207,7 +206,7 @@ class CAngularObservationMesh :
* Returns the increment between two consecutive values of the range.
* \throw std::logic_error on invalid range type.
*/
inline double increment() const
double increment() const
{
switch (rangeType)
{
Expand All @@ -228,7 +227,7 @@ class CAngularObservationMesh :
* Returns the total amount of values in this range.
* \throw std::logic_error on invalid range type.
*/
inline size_t amount() const
size_t amount() const
{
switch (rangeType)
{
Expand Down Expand Up @@ -257,7 +256,7 @@ class CAngularObservationMesh :
* positive, false otherwise.
* \throw std::logic_error on invalid range type.
*/
inline bool negToPos() const
bool negToPos() const
{
switch (rangeType)
{
Expand Down Expand Up @@ -315,47 +314,28 @@ class CAngularObservationMesh :
/**
* Returns whether the object is configured as wireframe or solid.
*/
inline bool isWireframe() const { return m_Wireframe; }
bool isWireframe() const { return m_Wireframe; }
/**
* Sets the display mode for the object. True=wireframe, False=solid.
*/
inline void setWireframe(bool enabled = true)
void setWireframe(bool enabled = true)
{
m_Wireframe = enabled;
CRenderizable::notifyChange();
CVisualObject::notifyChange();
}
/**
* Returns whether the object may be transparent or not.
*/
inline bool isTransparencyEnabled() const { return mEnableTransparency; }
bool isTransparencyEnabled() const { return mEnableTransparency; }
/**
* Enables or disables transparencies.
*/
inline void enableTransparency(bool enabled = true)
void enableTransparency(bool enabled = true)
{
mEnableTransparency = enabled;
CRenderizable::notifyChange();
CVisualObject::notifyChange();
}

/** @name Renderizable shader API virtual methods
* @{ */
void freeOpenGLResources() override
{
CRenderizableShaderTriangles::freeOpenGLResources();
CRenderizableShaderWireFrame::freeOpenGLResources();
}
void render(const RenderContext& rc) const override;
void renderUpdateBuffers() const override;

virtual shader_list_t requiredShaders() const override
{
// May use up to two shaders (triangles and lines):
return {DefaultShaderID::WIREFRAME, DefaultShaderID::TRIANGLES_LIGHT};
}
void onUpdateBuffers_Wireframe() override;
void onUpdateBuffers_Triangles() override;
/** @} */

/**
* Traces a ray to the object, returning the distance to a given pose
* through its X axis.
Expand Down
56 changes: 15 additions & 41 deletions libs/maps/include/mrpt/viz/CPlanarLaserScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
#include <mrpt/maps/CSimplePointsMap.h>
#include <mrpt/obs/CObservation.h>
#include <mrpt/obs/CObservation2DRangeScan.h>
#include <mrpt/viz/CRenderizableShaderPoints.h>
#include <mrpt/viz/CRenderizableShaderTriangles.h>
#include <mrpt/viz/CRenderizableShaderWireFrame.h>
#include <mrpt/viz/CVisualObject.h>

namespace mrpt
{
/** \ingroup mrpt_maps_grp */
namespace viz
namespace mrpt::viz
{
/** This object renders a 2D laser scan by means of three elements: the points,
* the line along end-points and the 2D scanned surface.
Expand Down Expand Up @@ -53,61 +48,40 @@ namespace viz
* \ingroup mrpt_maps_grp
*/
class CPlanarLaserScan :
public CRenderizableShaderPoints,
public CRenderizableShaderTriangles,
public CRenderizableShaderWireFrame
virtual public CVisualObject,
public VisualObjectParams_Triangles,
public VisualObjectParams_Lines,
public VisualObjectParams_Points
{
DEFINE_SERIALIZABLE(CPlanarLaserScan, mrpt::viz)

public:
/** @name Renderizable shader API virtual methods
* @{ */
void render(const RenderContext& rc) const override;
void renderUpdateBuffers() const override;
void freeOpenGLResources() override
{
CRenderizableShaderTriangles::freeOpenGLResources();
CRenderizableShaderWireFrame::freeOpenGLResources();
CRenderizableShaderPoints::freeOpenGLResources();
}

virtual shader_list_t requiredShaders() const override
{
return {
DefaultShaderID::WIREFRAME, DefaultShaderID::TRIANGLES_NO_LIGHT, DefaultShaderID::POINTS};
}
void onUpdateBuffers_Wireframe() override;
void onUpdateBuffers_Triangles() override;
void onUpdateBuffers_Points() override;
mrpt::math::TPoint3Df getLocalRepresentativePoint() const override;
/** @} */

CPlanarLaserScan() = default;
~CPlanarLaserScan() override = default;

/** Clear the scan */
void clear();

/** Show or hides the scanned points \sa sePointsWidth, setPointsColor*/
inline void enablePoints(bool enable = true)
void enablePoints(bool enable = true)
{
m_enable_points = enable;
CRenderizable::notifyChange();
CVisualObject::notifyChange();
}

/** Show or hides lines along all scanned points \sa setLineWidth,
* setLineColor*/
inline void enableLine(bool enable = true)
void enableLine(bool enable = true)
{
m_enable_line = enable;
CRenderizable::notifyChange();
CVisualObject::notifyChange();
}

/** Show or hides the scanned area as a 2D surface \sa setSurfaceColor */
inline void enableSurface(bool enable = true)
void enableSurface(bool enable = true)
{
m_enable_surface = enable;
CRenderizable::notifyChange();
CVisualObject::notifyChange();
}

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

void setScan(const mrpt::obs::CObservation2DRangeScan& scan)
{
CRenderizable::notifyChange();
CVisualObject::notifyChange();
m_cache_valid = false;
m_scan = scan;
}

auto internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf override;
auto getLocalRepresentativePoint() const -> mrpt::math::TPoint3Df override;

protected:
mrpt::obs::CObservation2DRangeScan m_scan;
Expand All @@ -157,5 +132,4 @@ class CPlanarLaserScan :
bool m_enable_surface{true};
};

} // namespace viz
} // namespace mrpt
} // namespace mrpt::viz
20 changes: 5 additions & 15 deletions libs/maps/src/maps/CColouredPointsMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <mrpt/serialization/aligned_serialization.h>
#include <mrpt/system/os.h>
#include <mrpt/viz/CPointCloudColoured.h>
#include <mrpt/viz/CSetOfObjects.h>

#include "CPointsMap_crtp_common.h"

Expand Down Expand Up @@ -492,9 +493,6 @@ bool CColouredPointsMap::colourFromObservation(
chB = 2;
}

unsigned int n_proj = 0;
const float factor = 1.0f / 255; // Normalize pixels:

// Get the colour of the projected points
size_t k;
for (itProPoints = projectedPoints.begin(), k = 0; itProPoints != projectedPoints.end();
Expand All @@ -506,21 +504,13 @@ bool CColouredPointsMap::colourFromObservation(
unsigned int ii = p_idx[p_proj[k]];
uint8_t* p = obs.image((unsigned int)itProPoints->x, (unsigned int)itProPoints->y);

m_color_R[ii] = p[chR] * factor; // R
m_color_G[ii] = p[chG] * factor; // G
m_color_B[ii] = p[chB] * factor; // B
// m_min_dist[ii] = p_dist[p_proj[k]];

n_proj++;
m_color_R[ii] = mrpt::u8tof(p[chR]);
m_color_G[ii] = mrpt::u8tof(p[chG]);
m_color_B[ii] = mrpt::u8tof(p[chB]);
}
} // end for
}

return true;
} // end colourFromObservation

void CColouredPointsMap::resetPointsMinDist([[maybe_unused]] float defValue)
{
// m_min_dist.assign(x.size(),defValue);
}

bool CColouredPointsMap::save3D_and_colour_to_text_file(const std::string& file) const
Expand Down
1 change: 1 addition & 0 deletions libs/maps/src/maps/CPointsMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <mrpt/system/os.h>
#include <mrpt/viz/CPointCloud.h>
#include <mrpt/viz/CPointCloudColoured.h>
#include <mrpt/viz/CSetOfObjects.h>

#include <fstream>
#include <sstream>
Expand Down
Loading

0 comments on commit b4ae01f

Please sign in to comment.