Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpPanda3DRenderParameters.cpp
1
2/*
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 */
31
32#include <visp3/ar/vpPanda3DRenderParameters.h>
33#if defined(VISP_HAVE_PANDA3D)
34
35#include <matrixLens.h>
36#include <camera.h>
37
40{
41 // Adapted from Megapose code (https://github.com/megapose6d/megapose6d/blob/master/src/megapose/panda3d_renderer/types.py#L59),
42 // which was itself inspired by https://discourse.panda3d.org/t/lens-camera-for-opencv-style-camera-parameterisation/15413
43 // And http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl
44
45 if (m_width == 0 || m_height == 0) {
46 throw vpException(vpException::dimensionError, "Cannot create a projection matrix when the image width or height is 0");
47 }
48
49 PT(MatrixLens) lens = new MatrixLens();
50 const double A = (m_clipFar + m_clipNear) / (m_clipFar - m_clipNear);
51 const double B = -2.0 * (m_clipFar * m_clipNear) / (m_clipFar - m_clipNear);
52
53 const double cx = m_cam.get_u0();
54 const double cy = m_height - m_cam.get_v0();
55
56 lens->set_near_far(m_clipNear, m_clipFar);
57 lens->set_user_mat(LMatrix4(
58 m_cam.get_px(), 0, 0, 0,
59 0, 0, A, 1,
60 0, m_cam.get_py(), 0, 0,
61 0, 0, B, 0
62 ));
63 lens->set_film_size(m_width, m_height);
64 lens->set_film_offset(m_width * 0.5 - cx, m_height * 0.5 - cy);
65 camera->set_lens(lens);
66}
67
68END_VISP_NAMESPACE
69
70#elif !defined(VISP_BUILD_SHARED_LIBS)
71// Work around to avoid warning: libvisp_ar.a(vpPanda3DRenderParameters.cpp.o) has no symbols
72void dummy_vpPanda3DRenderParameters() { }
73
74#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
void setupPandaCamera(Camera *camera)
Update a Panda3D camera object to use this objects's parameters.