Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 3, 2024
2 parents 001eb46 + 3bbe5b0 commit 7bb2cf4
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 20 deletions.
6 changes: 3 additions & 3 deletions apps/SceneViewer3D/_DSceneViewerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ void CMyGLCanvas::OnPostRenderSwapBuffers(double At, wxPaintDC& dc)
meanEstimatedFPS = 0.8 * meanEstimatedFPS + 0.2 * estimatedFPS;

string str = format(
"Center=(%.02f,%.02f,%.02f) Zoom:%.02f AZ=%.02f deg EL:%.02f deg", getCameraPointingX(),
getCameraPointingY(), getCameraPointingZ(), getZoomDistance(), getAzimuthDegrees(),
getElevationDegrees());
"Center=(%.02f,%.02f,%.02f) Zoom:%.02f AZ=%.02f deg EL:%.02f deg ROLL:%.02f",
getCameraPointingX(), getCameraPointingY(), getCameraPointingZ(), getZoomDistance(),
getAzimuthDegrees(), getElevationDegrees(), getRollDegrees());
theWindow->StatusBar1->SetStatusText(str.c_str(), 1);

str = format("%.02f FPS", meanEstimatedFPS);
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# version format
version: 2.14.5-{branch}-build{build}
version: 2.14.6-{branch}-build{build}

os: Visual Studio 2019

Expand Down
10 changes: 10 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
\page changelog Change Log

# Version 2.14.6: Released Dec 3rd, 2024
- Changes in libraries:
- \ref mrpt_gui_grp:
- Added a new mouse control to rotate OpenGL cameras by pressing the "Alt" key.
- \ref mrpt_opengl_grp:
- mrpt::opengl::Texture now supports rendering 16-bit images.
- mrpt::opengl::CCamera now has a "roll" angle when in orbit-view mode.
- BUG FIXES:
- mrpt::opengl::CMesh: There was a bug with texture scaling with non-square images.

# Version 2.14.5: Released Nov 4th, 2024
- Upgraded nanoflann to v1.6.2 (fixes a potential bug).
- Debian files:
Expand Down
2 changes: 2 additions & 0 deletions doc/source/tutorial-3d-navigation-cheatsheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ All MRPT applications use the following convention:

- **Look around** (pivot camera): CTRL+Left-button pressed + mouse move up/down.

- **Roll camera** (rotate around front-facing axis): ALT+Left-button pressed + mouse move up/down.

- **Pan** (XY plane): Right button or wheel pressed + mouse move.

- **Move camera along Z axis**: SHIFT+Left-button pressed + mouse move left/right,
Expand Down
11 changes: 11 additions & 0 deletions libs/gui/include/mrpt/gui/CGlCanvasBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CGlCanvasBase
float cameraElevationDeg = 45.f, cameraAzimuthDeg = 45.f;
bool cameraIsProjective = true;
float cameraFOV = 30.f;
float cameraRollDeg = .0f;
};

CGlCanvasBase() = default;
Expand All @@ -63,6 +64,7 @@ class CGlCanvasBase

/** Sets the last mouse position */
void updateLastPos(int x, int y);

/** Calls the glViewport function*/
void resizeViewport(int w, int h);

Expand All @@ -71,28 +73,35 @@ class CGlCanvasBase
* and updates the zoom of the CameraParams.
* See also updateZoom(CamaraParams &, float)*/
void updateZoom(CamaraParams& params, int x, int y) const;

/** This function for the wheel event
* It gets a reference to CamaraParams, delta
* and updates the zoom of the CameraParams.
* See also updateZoom(CamaraParams &, int, int)*/
void updateZoom(CamaraParams& params, float delta) const;

/** This function for the mouse event
* It gets a reference to CamaraParams, x, y
* and updates the elevation and azimuth.
* See also getElevationDegrees(), getAzimuthDegrees()*/
void updateRotate(CamaraParams& params, int x, int y) const;

/** This function for the mouse event
* It gets a reference to CamaraParams, x, y
* and updates the elevation and azimuth.
* See also getElevationDegrees(), getAzimuthDegrees()*/
void updateOrbitCamera(CamaraParams& params, int x, int y) const;

/** This function for the mouse event
* It gets a reference to CamaraParams, x, y
* and updates the pointing of the camera.
* See also getCameraPointingX(), getCameraPointingY(),
* getCameraPointingZ()*/
void updatePan(CamaraParams& params, int x, int y) const;

/** Updates the camera "roll" \note New in MRPT 2.14.6 */
void updateRoll(CamaraParams& params, int x, int y, float scale = 0.15f) const;

/** Returns a copy of CamaraParams
* See also getRefCameraParams(), setCameraParams(const CamaraParams &)*/
CamaraParams cameraParams() const;
Expand Down Expand Up @@ -160,6 +169,8 @@ class CGlCanvasBase
*/
float getAzimuthDegrees() const;

float getRollDegrees() const;

/** Saves the degrees of the elevation camera
* See also getElevationDegrees()
*/
Expand Down
11 changes: 11 additions & 0 deletions libs/gui/src/CGlCanvasBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "gui-precomp.h" // Precompiled headers
//
#include <mrpt/core/round.h>
#include <mrpt/gui/CGlCanvasBase.h>
#include <mrpt/opengl/opengl_api.h>

Expand Down Expand Up @@ -147,6 +148,12 @@ void CGlCanvasBase::updatePan(CamaraParams& params, int x, int y) const
D * (Ax * sin(DEG2RAD(params.cameraAzimuthDeg)) + Ay * cos(DEG2RAD(params.cameraAzimuthDeg)));
}

void CGlCanvasBase::updateRoll(CamaraParams& params, int x, int y, float scale) const
{
int Arot = mrpt::round(scale * (y - m_mouseClickY));
params.cameraRollDeg += Arot;
}

CGlCanvasBase::CamaraParams CGlCanvasBase::cameraParams() const { return m_cameraParams; }

const CGlCanvasBase::CamaraParams& CGlCanvasBase::getRefCameraParams() const
Expand All @@ -169,6 +176,7 @@ CCamera& CGlCanvasBase::updateCameraParams(CCamera& cam) const
cam.setPointingAt(_.cameraPointingX, _.cameraPointingY, _.cameraPointingZ);
cam.setZoomDistance(_.cameraZoomDistance);
cam.setAzimuthDegrees(_.cameraAzimuthDeg);
cam.setRollDegrees(_.cameraRollDeg);
cam.setElevationDegrees(_.cameraElevationDeg);
cam.setProjectiveModel(_.cameraIsProjective);
cam.setProjectiveFOVdeg(_.cameraFOV);
Expand All @@ -186,6 +194,8 @@ float CGlCanvasBase::getAzimuthDegrees() const { return m_cameraParams.cameraAzi

float CGlCanvasBase::getElevationDegrees() const { return m_cameraParams.cameraElevationDeg; }

float CGlCanvasBase::getRollDegrees() const { return m_cameraParams.cameraRollDeg; }

void CGlCanvasBase::setCameraProjective(bool is) { m_cameraParams.cameraIsProjective = is; }

bool CGlCanvasBase::isCameraProjective() const { return m_cameraParams.cameraIsProjective; }
Expand Down Expand Up @@ -327,6 +337,7 @@ CGlCanvasBase::CamaraParams CGlCanvasBase::CamaraParams::FromCamera(const mrpt::
p.cameraPointingY = c.getPointingAtY();
p.cameraPointingZ = c.getPointingAtZ();
p.cameraZoomDistance = c.getZoomDistance();
p.cameraRollDeg = c.getRollDegrees();

return p;
}
Expand Down
2 changes: 2 additions & 0 deletions libs/gui/src/CWxGLCanvasBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void CWxGLCanvasBase::OnMouseMove(wxMouseEvent& event)
updateZoom(params, X, Y);
else if (event.ControlDown())
updateRotate(params, X, Y);
else if (event.AltDown())
updateRoll(params, X, Y);
else
updateOrbitCamera(params, X, Y);
}
Expand Down
2 changes: 2 additions & 0 deletions libs/gui/src/NanoGUICanvasHeadless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void NanoGUICanvasHeadless::mouseMotionEvent(
updateZoom(params, X, Y);
else if (modifiers & GLFW_MOD_CONTROL)
updateRotate(params, X, Y);
else if (modifiers & GLFW_MOD_ALT)
updateRoll(params, X, Y, 0.30f);
else
updateOrbitCamera(params, X, Y);
}
Expand Down
6 changes: 5 additions & 1 deletion libs/opengl/include/mrpt/opengl/CCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ class CCamera : public CRenderizable

mrpt::math::TPoint3Df getPointingAt() const { return {m_pointingX, m_pointingY, m_pointingZ}; }

void setZoomDistance(float z) { m_eyeDistance = z; }
float getZoomDistance() const { return m_eyeDistance; }
float getAzimuthDegrees() const { return m_azimuthDeg; }
float getElevationDegrees() const { return m_elevationDeg; }
float getRollDegrees() const { return m_eyeRollDeg; }

void setZoomDistance(float z) { m_eyeDistance = z; }
void setAzimuthDegrees(float ang) { m_azimuthDeg = ang; }
void setElevationDegrees(float ang) { m_elevationDeg = ang; }
void setRollDegrees(float ang) { m_eyeRollDeg = ang; }

/** Set 6DOFMode, if enabled camera is set according to its pose, set via
*CRenderizable::setPose(). (default=false).
Expand Down Expand Up @@ -168,6 +171,7 @@ class CCamera : public CRenderizable
float m_pointingX{0}, m_pointingY{0}, m_pointingZ{0};
float m_eyeDistance{10};
float m_azimuthDeg{45}, m_elevationDeg{45};
float m_eyeRollDeg{0};

/** If set to true (default), camera model is projective, otherwise, it's
* orthogonal. */
Expand Down
2 changes: 1 addition & 1 deletion libs/opengl/include/mrpt/opengl/TRenderMatrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct TRenderMatrices
double FOV = 30.0f;

/** Camera elev & azimuth, in radians. */
double azimuth = .0, elev = .0;
double azimuth = .0, elev = .0, roll = .0;
double eyeDistance = 1.0f;

/** In pixels. This may be smaller than the total render window. */
Expand Down
5 changes: 5 additions & 0 deletions libs/opengl/include/mrpt/opengl/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class Texture

/** How to repeat texture coordinate "T" */
Wrapping wrappingModeT = Wrapping::Repeat;

/** If enabled, 16-bit images will be automatically bright-adjusted so they are visible
* as 8-bit image textures. Set to false to disable adjustment.
*/
bool autoScale16to8bitConversion = true;
};

/** This is how an 2D texture image is loaded into this object, and a
Expand Down
10 changes: 9 additions & 1 deletion libs/opengl/src/CCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ using namespace std;

IMPLEMENTS_SERIALIZABLE(CCamera, CRenderizable, mrpt::opengl)

uint8_t CCamera::serializeGetVersion() const { return 3; }
uint8_t CCamera::serializeGetVersion() const { return 4; }
void CCamera::serializeTo(mrpt::serialization::CArchive& out) const
{
// Save data:
out << m_pointingX << m_pointingY << m_pointingZ << m_eyeDistance << m_azimuthDeg
<< m_elevationDeg << m_projectiveModel << m_projectiveFOVdeg;
out << m_pinholeModel; // v2
out << m_useNoProjection; // v3
out << m_eyeRollDeg; // v4
}

void CCamera::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
Expand All @@ -39,6 +40,7 @@ void CCamera::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
case 1:
case 2:
case 3:
case 4:
{
// Load data:
in >> m_pointingX >> m_pointingY >> m_pointingZ >> m_eyeDistance >> m_azimuthDeg >>
Expand All @@ -52,6 +54,11 @@ void CCamera::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
in >> m_useNoProjection;
else
m_useNoProjection = false;

if (version >= 4)
in >> m_eyeRollDeg;
else
m_eyeRollDeg = 0;
}
break;
case 0:
Expand Down Expand Up @@ -81,6 +88,7 @@ void CCamera::toYAMLMap(mrpt::containers::yaml& p) const
MCP_SAVE(p, m_projectiveModel);
MCP_SAVE(p, m_projectiveFOVdeg);
MCP_SAVE(p, m_useNoProjection);
MCP_SAVE(p, m_eyeRollDeg);

if (m_pinholeModel) p["pinholeModel"] = m_pinholeModel->asYAML();
}
2 changes: 1 addition & 1 deletion libs/opengl/src/CMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void CMesh::onUpdateBuffers_TexturedTriangles()

// Default: texture over the whole extension.
const float textureSizeX = (m_textureSize_x != 0) ? m_textureSize_x : (m_xMax - m_xMin);
const float textureSizeY = (m_textureSize_y != 0) ? m_textureSize_y : (m_xMax - m_xMin);
const float textureSizeY = (m_textureSize_y != 0) ? m_textureSize_y : (m_yMax - m_yMin);

for (auto& i : actualMesh)
{
Expand Down
43 changes: 40 additions & 3 deletions libs/opengl/src/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <mrpt/opengl/Texture.h>
#include <mrpt/opengl/opengl_api.h>

// Universal include for all versions of OpenCV
#include <mrpt/3rdparty/do_opencv_includes.h>

#include <iostream>
#include <mutex>
#include <set>
Expand Down Expand Up @@ -244,11 +247,45 @@ void Texture::internalAssignImage_2D(
in_rgb->forceLoad(); // just in case they are lazy-load imgs
if (in_alpha) in_alpha->forceLoad();

ASSERT_(in_rgb->getPixelDepth() == mrpt::img::PixelDepth::D8U);
mrpt::img::CImage rgb;

switch (in_rgb->getPixelDepth())
{
// Ideal case, nothing to do:
case mrpt::img::PixelDepth::D8U:
rgb = mrpt::img::CImage(*in_rgb, mrpt::img::SHALLOW_COPY);
break;

case mrpt::img::PixelDepth::D16U:
{
#if MRPT_HAS_OPENCV
double ratio;
if (o.autoScale16to8bitConversion)
{
// enhance brigthness:

cv::Scalar meanColor = cv::mean(in_rgb->asCvMatRef());
const double avrVal = meanColor.val[0];
ratio = std::max<double>(1.0, 2 * avrVal);
}
else
{
ratio = 65536.0;
}

rgb.resize(in_rgb->getWidth(), in_rgb->getHeight(), mrpt::img::CH_RGB);
cv::convertScaleAbs(in_rgb->asCvMatRef(), rgb.asCvMatRef(), 255.0 / ratio);
#endif
}
break;

default:
THROW_EXCEPTION_FMT(
"Unhandled pixel depth: PixelDepth=#%i", static_cast<int>(in_rgb->getPixelDepth()));
};

// Shallow copy of the images, for the case we need to downsample them
// below:
mrpt::img::CImage rgb(*in_rgb, mrpt::img::SHALLOW_COPY);
mrpt::img::CImage alpha;
if (in_alpha) alpha = mrpt::img::CImage(*in_alpha, mrpt::img::SHALLOW_COPY);

Expand Down Expand Up @@ -299,7 +336,7 @@ void Texture::internalAssignImage_2D(
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, lmbdWrapMap(o.wrappingModeT));
CHECK_OPENGL_ERROR_IN_DEBUG();

// Assure that the images do not overpass the maximum dimensions allowed
// Ensure that the images do not overpass the maximum dimensions allowed
// by OpenGL:
// ------------------------------------------------------------------------------------
GLint texSize;
Expand Down
19 changes: 16 additions & 3 deletions libs/opengl/src/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ void Viewport::updateMatricesFromCamera(const CCamera& myCamera) const
_.eyeDistance = myCamera.getZoomDistance();
_.azimuth = DEG2RAD(myCamera.getAzimuthDegrees());
_.elev = DEG2RAD(myCamera.getElevationDegrees());
_.roll = DEG2RAD(myCamera.getRollDegrees());

if (myCamera.is6DOFMode())
{
Expand All @@ -1255,14 +1256,26 @@ void Viewport::updateMatricesFromCamera(const CCamera& myCamera) const
// point:
_.pointing = myCamera.getPointingAt();

const auto c2m_u = mrpt::math::TVector3D(
cos(_.azimuth) * cos(_.elev), //
sin(_.azimuth) * cos(_.elev), //
sin(_.elev) //
);

const double dis = std::max<double>(0.001, myCamera.getZoomDistance());
_.eye.x = _.pointing.x + dis * cos(_.azimuth) * cos(_.elev);
_.eye.y = _.pointing.y + dis * sin(_.azimuth) * cos(_.elev);
_.eye.z = _.pointing.z + dis * sin(_.elev);
_.eye = _.pointing + c2m_u * dis;

_.up.x = -cos(_.azimuth) * sin(_.elev);
_.up.y = -sin(_.azimuth) * sin(_.elev);
_.up.z = cos(_.elev);

// roll?
if (_.roll != .0)
{
// _.up & c2m_u are both unit vectors and orthogonal to each other.
const auto w = mrpt::math::crossProduct3D(c2m_u, _.up);
_.up = _.up * cos(_.roll) + w * sin(_.roll);
}
}

// Compute the projection matrix (p_matrix):
Expand Down
Loading

0 comments on commit 7bb2cf4

Please sign in to comment.