Skip to content

Commit

Permalink
Fix flipped range images in rawlogviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 5, 2023
1 parent f2b39bd commit 23ed5e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/RawLogViewer/main_show_selected_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
img_range.setFromMatrix(
obs->rangeImage.asEigen().cast<float>() *
(1.0f / maxActualRange),
true /*already in [0,1]*/);
true /*already in [0,1]*/, true /*flip_vertical*/);

showImageInGLView(*bmp3Dobs_depth, img_range);

Expand All @@ -535,7 +535,7 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
img_intensity.setFromMatrix(
obs->intensityImage.asEigen().cast<float>() *
(1.0f / maxActualInt),
true /*already in [0,1]*/);
true /*already in [0,1]*/, true /*flip_vertical*/);

showImageInGLView(*bmp3Dobs_int, img_intensity);

Expand Down
10 changes: 7 additions & 3 deletions libs/img/include/mrpt/img/CImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ class CImage : public mrpt::serialization::CSerializable, public CCanvas
* \sa getAsMatrix
*/
template <typename MAT>
void setFromMatrix(const MAT& m, bool matrix_is_normalized = true)
void setFromMatrix(
const MAT& m, bool matrix_is_normalized = true,
bool flip_vertically = false)
{
MRPT_START
const unsigned int lx = m.cols();
Expand All @@ -840,7 +842,8 @@ class CImage : public mrpt::serialization::CSerializable, public CCanvas
{ // Matrix: [0,1]
for (unsigned int y = 0; y < ly; y++)
{
auto* pixels = ptrLine<uint8_t>(y);
auto* pixels =
ptrLine<uint8_t>(flip_vertically ? (ly - 1 - y) : y);
for (unsigned int x = 0; x < lx; x++)
(*pixels++) = static_cast<uint8_t>(m.coeff(y, x) * 255);
}
Expand All @@ -849,7 +852,8 @@ class CImage : public mrpt::serialization::CSerializable, public CCanvas
{ // Matrix: [0,255]
for (unsigned int y = 0; y < ly; y++)
{
auto* pixels = ptrLine<uint8_t>(y);
auto* pixels =
ptrLine<uint8_t>(flip_vertically ? (ly - 1 - y) : y);
for (unsigned int x = 0; x < lx; x++)
(*pixels++) = static_cast<uint8_t>(m.coeff(y, x));
}
Expand Down

0 comments on commit 23ed5e4

Please sign in to comment.