36 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING) 56 m_background_color(0.6f, 0.6f, 0.6f),
68 m_lights[0].setDirection(-1, -1, -1);
71 m_lights[1].setPosition(1, 2, -1, 0);
101 const double x,
const double y,
const double width,
const double height)
143 const int render_width,
const int render_height)
const 145 #if MRPT_HAS_OPENGL_GLUT 220 old_colors[0], old_colors[1], old_colors[2], old_colors[3]);
232 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING) 233 glv_timlog.enter(
"COpenGLViewport::render imageview");
246 const int img_w =
img->getWidth();
247 const int img_h =
img->getHeight();
249 if (img_w != 0 && img_h != 0)
256 const double ratio = vw * img_h / double(vh * img_w);
257 double ortho_w = img_w;
258 double ortho_h = img_h;
264 glOrtho(-0.5, ortho_h - 0.5, ortho_w - 0.5, -0.5, -1, 1);
268 glPixelZoom(vw /
float(ortho_w), -vh /
float(ortho_h));
272 const int nBytesPerPixel =
img->isColor() ? 3 : 1;
274 const bool is_RGB_order =
284 img_w, img_h, img_format, img_type,
291 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING) 292 glv_timlog.leave(
"COpenGLViewport::render imageview");
315 "Cloned viewport '%s' not found in parent COpenGLScene",
318 objectsToRender = &view->m_objects;
337 myCamera =
dynamic_cast<CCamera*
>(cam_ptr.get());
341 if (!myCamera) myCamera = &viewForGetCamera->
m_camera;
348 const float dis = max(0.01f, myCamera->m_distanceZoom);
350 myCamera->m_pointingX +
353 myCamera->m_pointingY +
358 if (fabs(fabs(myCamera->m_elevationDeg) - 90) > 1e-6)
366 float sgn = myCamera->m_elevationDeg > 0 ? 1 : -1;
368 -cos(
DEG2RAD(myCamera->m_azimuthDeg)) * sgn;
370 -sin(
DEG2RAD(myCamera->m_azimuthDeg)) * sgn;
381 if (myCamera->m_projectiveModel)
384 myCamera->m_projectiveFOVdeg, vw /
double(vh),
m_clip_min,
390 const double ratio = vw / double(vh);
391 double Ax = myCamera->m_distanceZoom * 0.5;
392 double Ay = myCamera->m_distanceZoom * 0.5;
398 if (ratio != 0) Ay /= ratio;
405 if (myCamera->is6DOFMode())
413 at = pose + viewDirection;
415 pose.
x(), pose.
y(), pose.z(), at.
x(), at.
y(), at.z(),
462 for (
const auto& m_light :
m_lights) m_light.sendToOpenGL();
507 "Exception while rendering a class '%s'\n%s",
510 msg =
format(
"Exception while rendering:\n%s", e.what());
522 "The MRPT has been compiled with MRPT_HAS_OPENGL_GLUT=0! OpenGL " 523 "functions are not implemented");
543 for (
const auto& m_object :
m_objects) out << *m_object;
622 if (m_object->m_name == str)
625 m_object->GetRuntimeClass() ==
642 #if MRPT_HAS_OPENGL_GLUT 647 ->loadTextureInOpenGL();
660 string s(m_object->GetRuntimeClass()->className);
661 if (m_object->m_name.size())
662 s +=
string(
" (") + m_object->m_name +
string(
")");
665 if (m_object->GetRuntimeClass() ==
668 std::vector<std::string> auxLst;
673 for (
const auto& i : auxLst) lst.emplace_back(
string(
" ") + i);
690 (*it)->GetRuntimeClass() ==
699 const double clip_min,
const double clip_max)
711 double& clip_min,
double& clip_max)
const 727 const double ASPECT =
759 if (ASPECT != 0) Ay /= ASPECT;
762 const double point_lx =
764 const double point_ly =
769 point_ly * cam_up_3d.
x,
771 point_ly * cam_up_3d.
y,
773 point_ly * cam_up_3d.
z);
775 out_ray.
pBase = ray_origin;
791 const double FOVx = 2.0 * atan(ASPECT * tan(FOVy * 0.5));
793 const double ang_horz =
795 const double ang_vert =
799 tan(ang_horz), tan(ang_vert),
803 l.
x * cam_x_3d.
x + l.
y * cam_up_3d.
x + l.
z * pointing_dir.
x,
804 l.
x * cam_x_3d.
y + l.
y * cam_up_3d.
y + l.
z * pointing_dir.
y,
805 l.
x * cam_x_3d.
z + l.
y * cam_up_3d.
z + l.
z * pointing_dir.
z);
819 M(0, 0) = cam_x_3d.
x;
820 M(1, 0) = cam_x_3d.
y;
821 M(2, 0) = cam_x_3d.
z;
824 M(0, 1) = cam_up_3d.
x;
825 M(1, 1) = cam_up_3d.
y;
826 M(2, 1) = cam_up_3d.
z;
829 M(0, 2) = pointing_dir.
x;
830 M(1, 2) = pointing_dir.
y;
831 M(2, 2) = pointing_dir.
z;
843 MRPT_TODO(
"Implement a setCurrentCameraFromPose() method")
849 get3DRayForPixelCoord(0, 0, dum, &out_cameraPose);
889 std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
890 std::numeric_limits<double>::max());
892 -std::numeric_limits<double>::max(),
893 -std::numeric_limits<double>::max(),
894 -std::numeric_limits<double>::max());
899 std::numeric_limits<double>::max(),
900 std::numeric_limits<double>::max(),
901 std::numeric_limits<double>::max());
903 -std::numeric_limits<double>::max(),
904 -std::numeric_limits<double>::max(),
905 -std::numeric_limits<double>::max());
906 m_object->getBoundingBox(child_bbmin, child_bbmax);
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
size_t viewport_width
In pixels.
opengl::CListOpenGLObjects m_objects
The list of objects that comprise the 3D scene.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
A compile-time fixed-size numeric matrix container.
CRenderizable::Ptr getByName(const std::string &str)
Returns the first object with a given name, or nullptr if not found.
void get3DRayForPixelCoord(const double x_coord, const double y_coord, mrpt::math::TLine3D &out_ray, mrpt::poses::CPose3D *out_cameraPose=nullptr) const
Compute the 3D ray corresponding to a given pixel; this can be used to allow the user to pick and sel...
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
A base class for all OpenGL objects with loadable textures.
bool m_isTransparent
Whether to clear color buffer.
A set of object, which are referenced to the coordinates framework established in this object...
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define THROW_EXCEPTION(msg)
uint32_t m_borderWidth
Default=0, the border around the viewport.
void setCloneView(const std::string &clonedViewport)
Set this viewport as a clone of some other viewport, given its name - as a side effect, current list of internal OpenGL objects is cleared.
static Ptr Create(Args &&... args)
#define GL_STENCIL_BUFFER_BIT
float azimuth
Camera elev & azimuth, in radians.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
#define GL_FRONT_AND_BACK
double DEG2RAD(const double x)
Degrees to radians.
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
std::vector< CLight > m_lights
void getViewportClipDistances(double &clip_min, double &clip_max) const
Get the current min/max clip depth distances of the rendering frustum (default: 0.1 - 10000)
The base class of 3D objects that can be directly rendered through OpenGL.
void setImageView(const mrpt::img::CImage &img)
Set this viewport into "image view"-mode, where an image is efficiently drawn (fitting the viewport a...
bool m_custom_backgb_color
std::shared_ptr< CRenderizable > Ptr
void setViewportClipDistances(const double clip_min, const double clip_max)
Set the min/max clip depth distances of the rendering frustum (default: 0.1 - 10000) ...
TPoint3D pBase
Base point.
mrpt::img::CImage::Ptr m_imageview_img
The image to display, after calling setImageView()
#define GL_PERSPECTIVE_CORRECTION_HINT
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
#define GL_COLOR_MATERIAL
mrpt::math::TPoint3D eye
The camera is here.
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
GLsizei GLsizei GLuint * obj
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
A viewport within a COpenGLScene, containing a set of OpenGL objects to render.
GLAPI void GLAPIENTRY glLoadIdentity(void)
mrpt::safe_ptr< COpenGLScene > m_parent
The scene that contains this viewport.
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
bool m_isClonedCamera
Set by setCloneCamera.
double m_clip_min
The min/max clip depth distances (default: 0.1 - 10000)
GLAPI void GLAPIENTRY glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
#define ASSERT_(f)
Defines an assertion mechanism.
GLAPI void GLAPIENTRY glGetDoublev(GLenum pname, GLdouble *params)
#define GL_DEPTH_BUFFER_BIT
void internal_enableImageView()
#define GL_COLOR_BUFFER_BIT
This base provides a set of functions for maths stuff.
bool m_isImageView
Set by setImageView.
#define GL_COLOR_CLEAR_VALUE
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
GLAPI void GLAPIENTRY glDepthFunc(GLenum func)
std::array< double, 3 > director
Director vector.
void render(const int render_width, const int render_height) const
Render the objects in this viewport (called from COpenGLScene only)
~COpenGLViewport() override
Destructor: clears all objects.
#define IS_DERIVED(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is an instance of the given ...
GLAPI void GLAPIENTRY glColorMaterial(GLenum face, GLenum mode)
GLAPI void GLAPIENTRY glPixelZoom(GLfloat xfactor, GLfloat yfactor)
void removeObject(const CRenderizable::Ptr &obj)
Removes the given object from the scene (it also deletes the object to free its memory).
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
mrpt::math::TPoint3D up
Up vector of the camera.
double x() const
Common members of all points & poses classes.
TLastProjectiveMatrixInfo m_lastProjMat
Info updated with each "render()" and used in "get3DRayForPixelCoord".
void setNormalMode()
Resets the viewport to a normal 3D viewport.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
bool m_OpenGL_enablePolygonNicest
GLsizei const GLchar ** string
GLAPI void GLAPIENTRY glHint(GLenum target, GLenum mode)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const override
Returns information about the class of an object in runtime.
mrpt::math::TPoint3D pointing
The camera points to here.
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) ...
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
GLAPI void GLAPIENTRY glLightModeli(GLenum pname, GLint param)
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLAPI void GLAPIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_UNPACK_ROW_LENGTH
Virtual base class for "archives": classes abstracting I/O streams.
void clear()
Delete all internal obejcts.
#define GL_UNPACK_ALIGNMENT
An event sent by an mrpt::opengl::COpenGLViewport just after clearing the viewport and setting the GL...
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
An event sent by an mrpt::opengl::COpenGLViewport after calling the scene OpenGL drawing primitives a...
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
void publishEvent(const mrptEvent &e) const
Called when you want this object to emit an event to all the observers currently subscribed to this o...
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
The namespace for 3D scene representation and rendering.
GLuint const GLchar * name
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
GLAPI void GLAPIENTRY glEnd(void)
std::string m_clonedViewport
Only if m_isCloned=true.
#define GL_POLYGON_SMOOTH_HINT
mrpt::img::TColorf m_background_color
used only if m_custom_backgb_color
#define GL_LIGHT_MODEL_TWO_SIDE
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
T::Ptr getByClass(const size_t &ith=0) const
Returns the i'th object of a given class (or of a descendant class), or nullptr (an empty smart point...
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
GLenum GLsizei GLsizei height
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned __int32 uint32_t
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
void setViewportPosition(const double x, const double y, const double width, const double height)
Change the viewport position and dimension on the rendering window.
void dumpListOfObjects(std::vector< std::string > &lst)
Retrieves a list of all objects in text form.
#define GL_AMBIENT_AND_DIFFUSE
#define GL_ACCUM_BUFFER_BIT
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
void getViewportPosition(double &x, double &y, double &width, double &height)
Get the current viewport position and dimension on the rendering window.
void insert(const CRenderizable::Ptr &newObject)
Insert a new object into the list.
double m_view_x
The viewport position [0,1].
GLAPI void GLAPIENTRY glRasterPos2f(GLfloat x, GLfloat y)
opengl::CCamera m_camera
The camera associated to the viewport.
std::string m_name
The viewport's name.
A class for storing images as grayscale or RGB bitmaps.
bool m_isCloned
Set by setCloneView.
3D line, represented by a base point and a director vector.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.