Skip to content

Commit

Permalink
Complete use of rotscan obs
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 2, 2023
1 parent cac4567 commit 6dd5207
Show file tree
Hide file tree
Showing 26 changed files with 946 additions and 270 deletions.
24 changes: 24 additions & 0 deletions apps/RawLogViewer/main_show_selected_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
Notebook1->ChangeSelection(8);
auto obs = std::dynamic_pointer_cast<CObservation2DRangeScan>(sel_obj);

// Hide unused viewports:
bmp3Dobs_depth->setViewportVisibility(false);
bmp3Dobs_int->setViewportVisibility(false);

// Additional text description: This is not within
// getDescriptionAsTextValue() because mrpt-maps is not available within
// mrpt-obs:
Expand Down Expand Up @@ -348,6 +352,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
obs->load(); // Make sure the 3D point cloud, etc... are all
// loaded in memory.

// Hide unused viewports:
bmp3Dobs_depth->setViewportVisibility(false);
bmp3Dobs_int->setViewportVisibility(false);

// Render options
// --------------------------------
const auto& p = pnViewOptions->m_params;
Expand Down Expand Up @@ -407,6 +415,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
Notebook1->ChangeSelection(8);
auto obs = std::dynamic_pointer_cast<CObservationVelodyneScan>(sel_obj);

// Hide unused viewports:
bmp3Dobs_depth->setViewportVisibility(false);
bmp3Dobs_int->setViewportVisibility(false);

obs->generatePointCloud();
const auto& p = pnViewOptions->m_params;

Expand Down Expand Up @@ -434,6 +446,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
Notebook1->ChangeSelection(8);
auto obs = std::dynamic_pointer_cast<CObservationPointCloud>(sel_obj);

// Hide unused viewports:
bmp3Dobs_depth->setViewportVisibility(false);
bmp3Dobs_int->setViewportVisibility(false);

const auto& p = pnViewOptions->m_params;

auto glPts = mrpt::opengl::CSetOfObjects::Create();
Expand All @@ -459,6 +475,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
// ----------------------------------------------------------------------
Notebook1->ChangeSelection(8);

// Hide unused viewports:
bmp3Dobs_depth->setViewportVisibility(false);
bmp3Dobs_int->setViewportVisibility(false);

// Update 3D view ==========
#if RAWLOGVIEWER_HAS_3D
auto openGLSceneRef = m_gl3DRangeScan->getOpenGLSceneRef();
Expand All @@ -478,6 +498,10 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
Notebook1->ChangeSelection(8);
auto obs = std::dynamic_pointer_cast<CObservationRotatingScan>(sel_obj);

// Show viewports:
bmp3Dobs_depth->setViewportVisibility(true);
bmp3Dobs_int->setViewportVisibility(true);

// Get range image as bitmap:
// ---------------------------
int rangeHeight = 30;
Expand Down
4 changes: 4 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- mrpt::math::KDTreeCapable: Add optional argument maximumSearchDistanceSqr in many API methods to exploit the new nanoflann RKNN search method.
- \ref mrpt_opengl_grp
- mrpt::opengl::PLY_Importer: Add support for importing point clouds with the `timestamp` property per point.
- \ref mrpt_obs_grp
- mrpt::obs::CObservationRotatingScan:
- Moved from the library mrpt-maps to mrpt-obs, since it no longer requires any mrpt::maps class.
- Complete its implementation: insertion into point cloud, observation likelihood, visualization in RawLogViewer, etc.
- BUG FIXES:
- Fix missing Threads::Threads downstream due to missing `find_dependency(Threads)` in MRPT cmake config files.
- Fix broken import of PLY files in SceneViewer3D (empty scene even if correctly imported).
Expand Down
24 changes: 24 additions & 0 deletions libs/apps/src/rawlog-edit_externalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <mrpt/obs/CObservation3DRangeScan.h>
#include <mrpt/obs/CObservationImage.h>
#include <mrpt/obs/CObservationPointCloud.h>
#include <mrpt/obs/CObservationRotatingScan.h>
#include <mrpt/obs/CObservationStereoImages.h>

#include "rawlog-edit-declarations.h"
Expand Down Expand Up @@ -161,6 +162,29 @@ DECLARE_OP_FUNCTION(op_externalize)
else
entries_skipped++;
}
else if (IS_CLASS(*obs, CObservationRotatingScan))
{
auto o =
std::dynamic_pointer_cast<CObservationRotatingScan>(obs);

if (!o->organizedPoints.empty() && !o->isExternallyStored())
{
const string fileName = "scan_"s + label_time +
(m_external_txt ? ".txt"s : ".bin"s);
o->setAsExternalStorage(
fileName,
m_external_txt
? CObservationRotatingScan::ExternalStorageFormat::
PlainTextFile
: CObservationRotatingScan::ExternalStorageFormat::
MRPT_Serialization);

o->unload(); // this actually saves the data to disk
entries_converted++;
}
else
entries_skipped++;
}
else if (IS_CLASS(*obs, CObservation3DRangeScan))
{
CObservation3DRangeScan::Ptr obs3D =
Expand Down
72 changes: 72 additions & 0 deletions libs/maps/src/maps/CPointsMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <mrpt/obs/CObservation3DRangeScan.h>
#include <mrpt/obs/CObservationPointCloud.h>
#include <mrpt/obs/CObservationRange.h>
#include <mrpt/obs/CObservationRotatingScan.h>
#include <mrpt/obs/CObservationVelodyneScan.h>
#include <mrpt/opengl/CPointCloud.h>
#include <mrpt/opengl/CPointCloudColoured.h>
Expand Down Expand Up @@ -1443,6 +1444,22 @@ double CPointsMap::internal_computeObservationLikelihood(
return internal_computeObservationLikelihoodPointCloud3D(
sensorAbsPose, xs, ys, zs, N);
}
else if (IS_CLASS(obs, CObservationRotatingScan))
{
const auto& o = dynamic_cast<const CObservationRotatingScan&>(obs);

if (!o.rowCount || !this->size()) return -100;

mrpt::maps::CSimplePointsMap auxPts;
auxPts.insertObservation(o, takenFrom);

const auto& xs = auxPts.getPointsBufferRef_x();
const auto& ys = auxPts.getPointsBufferRef_y();
const auto& zs = auxPts.getPointsBufferRef_z();

return internal_computeObservationLikelihoodPointCloud3D(
takenFrom, xs.data(), ys.data(), zs.data(), xs.size());
}
else if (IS_CLASS(obs, CObservationPointCloud))
{
const auto& o = dynamic_cast<const CObservationPointCloud&>(obs);
Expand Down Expand Up @@ -1901,6 +1918,61 @@ bool CPointsMap::internal_insertObservation(
}
return true;
}
else if (IS_CLASS(obs, CObservationRotatingScan))
{
mark_as_modified();

const auto& o = static_cast<const CObservationRotatingScan&>(obs);
ASSERT_(o.rowCount > 0);
ASSERT_(o.columnCount > 0);

if (insertionOptions.fuseWithExisting)
{
THROW_EXCEPTION(
"Fuse point cloud not implemented yet for "
"CObservationRotatingScan");
}
else
{
// Don't fuse: Simply add

const auto sensorGlobalPose = robotPose3D + o.sensorPose;

const size_t N_this = size();
const size_t N_otherMax = o.rowCount * o.columnCount;

// Set the new size:
this->reserve(N_this + N_otherMax);

// Optimization: detect the case of no transformation needed and
// avoid the matrix multiplications:
const bool identity_tf = (sensorGlobalPose == CPose3D::Identity());

for (size_t r = 0; r < o.rowCount; r++)
{
for (size_t c = 0; c < o.columnCount; c++)
{
if (!o.rangeImage(r, c)) continue; // invalid range

// Translation:
const auto pt = o.organizedPoints(r, c);

mrpt::math::TPoint3Df g;
if (!identity_tf)
sensorGlobalPose.composePoint(
pt.x, pt.y, pt.z, g.x, g.y, g.z);
else
g = pt;

// Add to this map:
this->insertPointFast(g.x, g.y, g.z);
}
}

mark_as_modified();
}
return true;
}
else
{
/********************************************************************
Expand Down
74 changes: 37 additions & 37 deletions libs/maps/src/obs/CObservationPointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,49 +200,49 @@ void CObservationPointCloud::load() const
void CObservationPointCloud::unload() const
{
MRPT_START
if (isExternallyStored() && pointcloud)
{
// Free memory, saving to the file if it doesn't exist:
const auto abs_filename =
mrpt::io::lazy_load_absolute_path(m_external_file);
if (!isExternallyStored() || !pointcloud) return;

if (!mrpt::system::fileExists(abs_filename))
// Free memory, saving to the file if it doesn't exist:
const auto abs_filename =
mrpt::io::lazy_load_absolute_path(m_external_file);

if (!mrpt::system::fileExists(abs_filename))
{
switch (m_externally_stored)
{
switch (m_externally_stored)
case ExternalStorageFormat::None: break;
case ExternalStorageFormat::KittiBinFile:
{
case ExternalStorageFormat::None: break;
case ExternalStorageFormat::KittiBinFile:
{
THROW_EXCEPTION("Saving to kitti format not supported.");
}
case ExternalStorageFormat::PlainTextFile:
{
std::ofstream f(abs_filename);
ASSERT_(f.is_open());
std::vector<float> row;
for (size_t i = 0; i < pointcloud->size(); i++)
{
pointcloud->getPointAllFieldsFast(i, row);
for (const float v : row)
f << v << " ";
f << "\n";
}
}
break;
case ExternalStorageFormat::MRPT_Serialization:
THROW_EXCEPTION("Saving to kitti format not supported.");
}
case ExternalStorageFormat::PlainTextFile:
{
std::ofstream f(abs_filename);
ASSERT_(f.is_open());
std::vector<float> row;
for (size_t i = 0; i < pointcloud->size(); i++)
{
mrpt::io::CFileGZOutputStream f(abs_filename);
auto ar = mrpt::serialization::archiveFrom(f);
ar << *pointcloud;
pointcloud->getPointAllFieldsFast(i, row);
for (const float v : row)
f << v << " ";
f << "\n";
}
break;
};
}

// Now we can safely free the mem:
auto& me = const_cast<CObservationPointCloud&>(*this);
me.pointcloud.reset();
}
break;
case ExternalStorageFormat::MRPT_Serialization:
{
mrpt::io::CFileGZOutputStream f(abs_filename);
auto ar = mrpt::serialization::archiveFrom(f);
ar << *pointcloud;
}
break;
};
}

// Now we can safely free the mem:
auto& me = const_cast<CObservationPointCloud&>(*this);
me.pointcloud.reset();

MRPT_END
}

Expand Down
2 changes: 0 additions & 2 deletions libs/maps/src/registerAllClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <mrpt/maps.h>
#include <mrpt/maps/registerAllClasses.h>
#include <mrpt/obs/CObservationPointCloud.h>
#include <mrpt/obs/CObservationRotatingScan.h>
// deps:
#include <mrpt/graphs/registerAllClasses.h>
#include <mrpt/obs/registerAllClasses.h>
Expand Down Expand Up @@ -53,7 +52,6 @@ MRPT_INITIALIZER(registerAllClasses_mrpt_maps)
registerClass(CLASS_ID(CPlanarLaserScan));

registerClass(CLASS_ID(CObservationPointCloud));
registerClass(CLASS_ID(CObservationRotatingScan));

registerClass(CLASS_ID(CMultiMetricMap));

Expand Down
1 change: 1 addition & 0 deletions libs/obs/include/mrpt/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MRPT_WARNING(
#include <mrpt/obs/CObservationRawDAQ.h>
#include <mrpt/obs/CObservationReflectivity.h>
#include <mrpt/obs/CObservationRobotPose.h>
#include <mrpt/obs/CObservationRotatingScan.h>
#include <mrpt/obs/CObservationSkeleton.h>
#include <mrpt/obs/CObservationStereoImages.h>
#include <mrpt/obs/CObservationStereoImagesFeatures.h>
Expand Down
Loading

0 comments on commit 6dd5207

Please sign in to comment.