mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-08 11:07:46 +08:00
fixed double compression of user_data
This commit is contained in:
@@ -3167,11 +3167,11 @@ TEST(MemoryTest, UpdateKeepsUserDataThatArrivesCompressed)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MemoryTest, UpdateReusesTheGivenCompressedScanUnlessItFiltersIt)
|
||||
TEST(MemoryTest, UpdateReusesTheGivenCompressedData)
|
||||
{
|
||||
// A scan given both raw and compressed is not compressed again: the compressed copy
|
||||
// given is stored as is, sharing its buffer -- but only while Memory has not filtered
|
||||
// the scan, since a filtered scan no longer matches the compressed one given.
|
||||
// Data given both raw and compressed is not compressed again: the compressed copy
|
||||
// given is stored as is, sharing its buffer. For the scan, only while Memory has not
|
||||
// filtered it, since a filtered scan no longer matches the compressed one given.
|
||||
cv::Mat points(1, 10, CV_32FC3);
|
||||
for(int i = 0; i < points.cols; ++i)
|
||||
{
|
||||
@@ -3196,6 +3196,8 @@ TEST(MemoryTest, UpdateReusesTheGivenCompressedScanUnlessItFiltersIt)
|
||||
const LaserScan compressedScan(compressData2(points), points.cols, 10.0f, LaserScan::kXYZ);
|
||||
data.setLaserScan(compressedScan);
|
||||
data.setLaserScan(LaserScan(points, points.cols, 10.0f, LaserScan::kXYZ), false);
|
||||
data.setUserData(points.t()); // raw, several rows: compressed by setUserData()
|
||||
ASSERT_FALSE(data.userDataCompressed().empty());
|
||||
ASSERT_FALSE(data.laserScanRaw().isEmpty());
|
||||
ASSERT_FALSE(data.laserScanCompressed().isEmpty());
|
||||
|
||||
@@ -3203,6 +3205,8 @@ TEST(MemoryTest, UpdateReusesTheGivenCompressedScanUnlessItFiltersIt)
|
||||
const Signature * s = memory.getSignature(memory.getLastSignatureId());
|
||||
ASSERT_NE(s, nullptr);
|
||||
|
||||
EXPECT_EQ(s->sensorData().userDataCompressed().data, data.userDataCompressed().data);
|
||||
|
||||
const LaserScan & stored = s->sensorData().laserScanCompressed();
|
||||
ASSERT_FALSE(stored.isEmpty());
|
||||
if(std::string(downsample) == "1")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <rtabmap/core/Compression.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <rtabmap/core/SensorData.h>
|
||||
#include <rtabmap/core/CameraModel.h>
|
||||
@@ -595,6 +596,43 @@ TEST(SensorDataTest, SetUserData)
|
||||
EXPECT_EQ(data.userDataRaw().cols, 100);
|
||||
}
|
||||
|
||||
TEST(SensorDataTest, SetUserDataCompressesRawData)
|
||||
{
|
||||
SensorData data;
|
||||
const cv::Mat userData = (cv::Mat_<float>(1, 4) << 1.0f, 2.0f, 3.0f, 4.0f);
|
||||
|
||||
data.setUserData(userData);
|
||||
|
||||
ASSERT_FALSE(data.userDataCompressed().empty());
|
||||
EXPECT_EQ(0.0, cv::norm(uncompressData(data.userDataCompressed()), userData, cv::NORM_INF));
|
||||
}
|
||||
|
||||
// Without clearing, the raw data of compressed user data already set is added to it:
|
||||
// the compressed copy is kept rather than compressed again, as setLaserScan() and
|
||||
// setRGBDImage() do. With nothing compressed yet, the raw data is still compressed.
|
||||
TEST(SensorDataTest, SetUserDataWithoutClearingKeepsTheCompressedCopy)
|
||||
{
|
||||
const cv::Mat userData = (cv::Mat_<float>(1, 4) << 1.0f, 2.0f, 3.0f, 4.0f);
|
||||
const cv::Mat compressed = compressData2(userData);
|
||||
|
||||
SensorData data;
|
||||
data.setUserData(compressed);
|
||||
ASSERT_TRUE(data.userDataRaw().empty());
|
||||
data.setUserData(userData, false);
|
||||
EXPECT_EQ(data.userDataRaw().data, userData.data);
|
||||
EXPECT_EQ(data.userDataCompressed().data, compressed.data);
|
||||
|
||||
SensorData fresh;
|
||||
fresh.setUserData(userData, false);
|
||||
ASSERT_FALSE(fresh.userDataCompressed().empty());
|
||||
EXPECT_EQ(0.0, cv::norm(uncompressData(fresh.userDataCompressed()), userData, cv::NORM_INF));
|
||||
|
||||
// Clearing, the default, compresses the new data again.
|
||||
data.setUserData(userData);
|
||||
EXPECT_NE(data.userDataCompressed().data, compressed.data);
|
||||
EXPECT_EQ(0.0, cv::norm(uncompressData(data.userDataCompressed()), userData, cv::NORM_INF));
|
||||
}
|
||||
|
||||
// Occupancy Grid Tests
|
||||
|
||||
TEST(SensorDataTest, SetOccupancyGrid)
|
||||
|
||||
Reference in New Issue
Block a user