Go to the documentation of this file.
37 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING)
54 m_isClonedCamera(false),
57 m_isTransparent(false),
65 m_custom_backgb_color(false),
66 m_background_color(0.6f, 0.6f, 0.6f),
71 m_OpenGL_enablePolygonNicest(true),
79 m_lights[0].setDirection(-1, -1, -1);
82 m_lights[1].setPosition(1, 2, -1, 0);
112 const double x,
const double y,
const double width,
const double height)
154 const int render_width,
const int render_height)
const
156 #if MRPT_HAS_OPENGL_GLUT
231 old_colors[0], old_colors[1], old_colors[2], old_colors[3]);
243 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING)
244 glv_timlog.enter(
"COpenGLViewport::render imageview");
257 const int img_w =
img->getWidth();
258 const int img_h =
img->getHeight();
260 if (img_w != 0 && img_h != 0)
267 const double ratio = vw * img_h / double(vh * img_w);
268 double ortho_w = img_w;
269 double ortho_h = img_h;
275 glOrtho(-0.5, ortho_h - 0.5, ortho_w - 0.5, -0.5, -1, 1);
279 glPixelZoom(vw /
float(ortho_w), -vh /
float(ortho_h));
283 const int nBytesPerPixel =
img->isColor() ? 3 : 1;
284 const bool is_RGB_order =
286 img->getChannelsOrder(),
295 img->getRowStride() / nBytesPerPixel);
297 img_w, img_h, img_format, img_type,
298 img->get_unsafe(0, 0));
304 #if defined(OPENGLVIEWPORT_ENABLE_TIMEPROFILING)
305 glv_timlog.leave(
"COpenGLViewport::render imageview");
328 "Cloned viewport '%s' not found in parent COpenGLScene",
331 objectsToRender = &view->m_objects;
350 myCamera =
dynamic_cast<CCamera*
>(cam_ptr.get());
354 if (!myCamera) myCamera = &viewForGetCamera->
m_camera;
361 const float dis = max(0.01f, myCamera->m_distanceZoom);
363 myCamera->m_pointingX +
366 myCamera->m_pointingY +
371 if (fabs(fabs(myCamera->m_elevationDeg) - 90) > 1e-6)
379 float sgn = myCamera->m_elevationDeg > 0 ? 1 : -1;
381 -cos(
DEG2RAD(myCamera->m_azimuthDeg)) * sgn;
383 -sin(
DEG2RAD(myCamera->m_azimuthDeg)) * sgn;
394 if (myCamera->m_projectiveModel)
397 myCamera->m_projectiveFOVdeg, vw /
double(vh),
m_clip_min,
403 const double ratio = vw / double(vh);
404 double Ax = myCamera->m_distanceZoom * 0.5;
405 double Ay = myCamera->m_distanceZoom * 0.5;
411 if (ratio != 0) Ay /= ratio;
418 if (myCamera->is6DOFMode())
426 at = pose + viewDirection;
428 pose.
x(), pose.
y(), pose.z(), at.
x(), at.
y(), at.z(),
475 for (
size_t i = 0; i <
m_lights.size(); i++)
521 "Exception while rendering a class '%s'\n%s",
524 msg =
format(
"Exception while rendering:\n%s", e.what());
536 "The MRPT has been compiled with MRPT_HAS_OPENGL_GLUT=0! OpenGL "
537 "functions are not implemented");
639 if ((*it)->m_name == str)
642 (*it)->GetRuntimeClass() ==
646 std::dynamic_pointer_cast<CSetOfObjects>(*it)->getByName(str);
658 #if MRPT_HAS_OPENGL_GLUT
663 std::dynamic_pointer_cast<CTexturedObject>(*it)
664 ->loadTextureInOpenGL();
666 std::dynamic_pointer_cast<CSetOfObjects>(*it)
667 ->initializeAllTextures();
678 string s((*it)->GetRuntimeClass()->className);
679 if ((*it)->m_name.size())
683 if ((*it)->GetRuntimeClass() ==
686 std::vector<std::string> auxLst;
690 for (
size_t i = 0; i < auxLst.size(); i++)
691 lst.emplace_back(
string(
" ") + auxLst[i]);
709 (*it)->GetRuntimeClass() ==
718 const double clip_min,
const double clip_max)
730 double& clip_min,
double& clip_max)
const
746 const double ASPECT =
778 if (ASPECT != 0) Ay /= ASPECT;
781 const double point_lx =
783 const double point_ly =
788 point_ly * cam_up_3d.
x,
790 point_ly * cam_up_3d.
y,
792 point_ly * cam_up_3d.
z);
794 out_ray.
pBase = ray_origin;
810 const double FOVx = 2.0 * atan(ASPECT * tan(FOVy * 0.5));
812 const double ang_horz =
814 const double ang_vert =
818 tan(ang_horz), tan(ang_vert),
822 l.
x * cam_x_3d.
x + l.
y * cam_up_3d.
x + l.
z * pointing_dir.
x,
823 l.
x * cam_x_3d.
y + l.
y * cam_up_3d.
y + l.
z * pointing_dir.
y,
824 l.
x * cam_x_3d.
z + l.
y * cam_up_3d.
z + l.
z * pointing_dir.
z);
838 M.get_unsafe(0, 0) = cam_x_3d.
x;
839 M.get_unsafe(1, 0) = cam_x_3d.
y;
840 M.get_unsafe(2, 0) = cam_x_3d.
z;
841 M.get_unsafe(3, 0) = 0;
843 M.get_unsafe(0, 1) = cam_up_3d.
x;
844 M.get_unsafe(1, 1) = cam_up_3d.
y;
845 M.get_unsafe(2, 1) = cam_up_3d.
z;
846 M.get_unsafe(3, 1) = 0;
848 M.get_unsafe(0, 2) = pointing_dir.
x;
849 M.get_unsafe(1, 2) = pointing_dir.
y;
850 M.get_unsafe(2, 2) = pointing_dir.
z;
851 M.get_unsafe(3, 2) = 0;
856 M.get_unsafe(3, 3) = 1;
862 MRPT_TODO(
"Implement a setCurrentCameraFromPose() method")
868 get3DRayForPixelCoord(0, 0, dum, &out_cameraPose);
915 std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
916 std::numeric_limits<double>::max());
918 -std::numeric_limits<double>::max(),
919 -std::numeric_limits<double>::max(),
920 -std::numeric_limits<double>::max());
926 std::numeric_limits<double>::max(),
927 std::numeric_limits<double>::max(),
928 std::numeric_limits<double>::max());
930 -std::numeric_limits<double>::max(),
931 -std::numeric_limits<double>::max(),
932 -std::numeric_limits<double>::max());
933 (*it)->getBoundingBox(child_bbmin, child_bbmax);
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_CLEAR_VALUE
#define GL_COLOR_MATERIAL
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
bool m_isImageView
Set by setImageView.
mrpt::math::TPoint3D eye
The camera is here.
GLAPI void GLAPIENTRY glDepthFunc(GLenum func)
void setImageView(const mrpt::img::CImage &img)
Set this viewport into "image view"-mode, where an image is efficiently drawn (fitting the viewport a...
const Scalar * const_iterator
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
std::vector< CLight > m_lights
mrpt::safe_ptr< COpenGLScene > m_parent
The scene that contains this viewport.
std::string m_name
The viewport's name.
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_POLYGON_SMOOTH_HINT
#define IS_DERIVED(ptrObj, class_name)
Evaluates to true if a pointer to an object (derived from mrpt::rtti::CObject) is an instance of the ...
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...
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X),...
TPoint3D pBase
Base point.
The base class of 3D objects that can be directly rendered through OpenGL.
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives.
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
void setNormalMode()
Resets the viewport to a normal 3D viewport.
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...
An event sent by an mrpt::opengl::COpenGLViewport after calling the scene OpenGL drawing primitives a...
opengl::CCamera m_camera
The camera associated to the viewport.
uint32_t m_borderWidth
Default=0, the border around the viewport.
bool m_custom_backgb_color
mrpt::img::TColorf m_background_color
used only if m_custom_backgb_color
GLsizei GLsizei GLuint * obj
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLAPI void GLAPIENTRY glLightModeli(GLenum pname, GLint param)
double m_view_x
The viewport position [0,1].
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
void setImageView_fast(mrpt::img::CImage &img)
Just like setImageView but moves the internal image memory instead of making a copy,...
double m_clip_min
The min/max clip depth distances (default: 0.1 - 10000)
void getViewportClipDistances(double &clip_min, double &clip_max) const
Get the current min/max clip depth distances of the rendering frustum (default: 0....
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
std::shared_ptr< CRenderizable > Ptr
Each of the possible lights of a 3D scene.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void insert(const CRenderizable::Ptr &newObject)
Insert a new object into the list.
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
void clear()
Delete all internal obejcts.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process (this is much faster than...
#define GL_FRONT_AND_BACK
void render(const int render_width, const int render_height) const
Render the objects in this viewport (called from COpenGLScene only)
void dumpListOfObjects(std::vector< std::string > &lst)
Retrieves a list of all objects in text form.
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
Virtual base class for "archives": classes abstracting I/O streams.
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
GLuint const GLchar * name
void internal_setImageView_fast(const mrpt::img::CImage &img, bool is_fast)
bool m_isCloned
Set by setCloneView.
#define GL_PERSPECTIVE_CORRECTION_HINT
#define GL_AMBIENT_AND_DIFFUSE
GLAPI void GLAPIENTRY glEnd(void)
void getViewportPosition(double &x, double &y, double &width, double &height)
Get the current viewport position and dimension on the rendering window.
GLAPI void GLAPIENTRY glGetDoublev(GLenum pname, GLdouble *params)
mrpt::math::TPoint3D pointing
The camera points to here.
TLastProjectiveMatrixInfo m_lastProjMat
Info updated with each "render()" and used in "get3DRayForPixelCoord".
#define GL_LIGHT_MODEL_TWO_SIDE
A set of object, which are referenced to the coordinates framework established in this object.
An event sent by an mrpt::opengl::COpenGLViewport just after clearing the viewport and setting the GL...
size_t viewport_width
In pixels.
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const override
Returns information about the class of an object in runtime.
opengl::CListOpenGLObjects m_objects
The list of objects that comprise the 3D scene.
mrpt::math::TPoint3D up
Up vector of the camera.
#define GL_STENCIL_BUFFER_BIT
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
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)
#define GL_ACCUM_BUFFER_BIT
CRenderizable::Ptr getByName(const std::string &str)
Returns the first object with a given name, or nullptr if not found.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
double x() const
Common members of all points & poses classes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
GLAPI void GLAPIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
A base class for all OpenGL objects with loadable textures.
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
A numeric matrix of compile-time fixed size.
GLenum GLsizei GLsizei height
mrpt::img::CImage::Ptr m_imageview_img
The image to display, after calling setImageView()
#define GL_DEPTH_BUFFER_BIT
void setViewportPosition(const double x, const double y, const double width, const double height)
Change the viewport position and dimension on the rendering window.
A class for storing images as grayscale or RGB bitmaps.
virtual ~COpenGLViewport()
Destructor: clears all objects.
GLAPI void GLAPIENTRY glPixelZoom(GLfloat xfactor, GLfloat yfactor)
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
std::string m_clonedViewport
Only if m_isCloned=true.
bool m_isClonedCamera
Set by setCloneCamera.
GLAPI void GLAPIENTRY glLoadIdentity(void)
bool m_isTransparent
Whether to clear color buffer.
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
float azimuth
Camera elev & azimuth, in radians.
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
bool m_OpenGL_enablePolygonNicest
A viewport within a COpenGLScene, containing a set of OpenGL objects to render.
This base provides a set of functions for maths stuff.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
3D line, represented by a base point and a director vector.
GLsizei const GLchar ** string
void setCloneView(const std::string &clonedViewport)
Set this viewport as a clone of some other viewport, given its name - as a side effect,...
GLAPI void GLAPIENTRY glHint(GLenum target, GLenum mode)
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...
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
The namespace for 3D scene representation and rendering.
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 director[3]
Director vector.
#define GL_UNPACK_ROW_LENGTH
std::shared_ptr< COpenGLViewport > Ptr
unsigned __int32 uint32_t
GLAPI void GLAPIENTRY glColorMaterial(GLenum face, GLenum mode)
void removeObject(const CRenderizable::Ptr &obj)
Removes the given object from the scene (it also deletes the object to free its memory).
#define GL_COLOR_BUFFER_BIT
GLAPI void GLAPIENTRY glRasterPos2f(GLfloat x, GLfloat y)
double DEG2RAD(const double x)
Degrees to radians.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |