MRPT  1.9.9
mrpt::opengl::COpenGLViewport Class Reference

Detailed Description

A viewport within a COpenGLScene, containing a set of OpenGL objects to render.

This class has protected constuctor, thus it cannot be created by users. Use COpenGLScene::createViewport instead. A viewport has these "operation modes":

  • Normal (default): It renders the contained objects.
  • Cloned: It clones the objects from another viewport. See setCloneView()
  • Image mode: It renders an image (e.g. from a video stream) efficiently using a textued quad. See setImageView().

In any case, the viewport can be resized to only fit a part of the entire parent viewport. There will be always at least one viewport in a COpenGLScene named "main".

This class can be observed (see mrpt::system::CObserver) for the following events (see mrpt::system::mrptEvent):

Two directional light sources at infinity are created by default, with directions (-1,-1,-1) and (1,2,1), respectively. All OpenGL properties of light sources are accesible via the methods: setNumberOfLights(), lightsClearAll(), addLight(), and getLight(). Please, refer to mrpt::opengl::CLight and the standard OpenGL documentation for the meaning of all light properties.

Refer to mrpt::opengl::COpenGLScene for further details.

Definition at line 59 of file COpenGLViewport.h.

#include <mrpt/opengl/COpenGLViewport.h>

Inheritance diagram for mrpt::opengl::COpenGLViewport:

Classes

struct  TLastProjectiveMatrixInfo
 

Public Member Functions

 ~COpenGLViewport () override
 Destructor: clears all objects. More...
 
 COpenGLViewport (COpenGLScene *parent=nullptr, const std::string &name=std::string(""))
 Constructor, invoked from COpenGLScene only. More...
 
virtual mxArraywriteToMatlab () const
 Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class. More...
 
Set the viewport "modes"
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. More...
 
void setImageView (const mrpt::img::CImage &img)
 Set this viewport into "image view"-mode, where an image is efficiently drawn (fitting the viewport area) using an OpenGL textured quad. More...
 
void setImageView (mrpt::img::CImage &&img)
 Just like setImageView but moves the internal image memory instead of making a copy, so it's faster but empties the input image. More...
 
void resetCloneView ()
 Reset the viewport to normal mode: rendering its own objects. More...
 
void setCloneCamera (bool enable)
 If set to true, and setCloneView() has been called, this viewport will be rendered using the camera of the cloned viewport. More...
 
void setNormalMode ()
 Resets the viewport to a normal 3D viewport. More...
 
OpenGL global settings that affect rendering all objects in the

scene/viewport

void enablePolygonNicest (bool enable=true)
 Sets glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) is enabled, or GL_FASTEST otherwise. More...
 
bool isPolygonNicestEnabled () const
 
void lightsClearAll ()
 Removes all lights (and disables the global "GL_LIGHTING") More...
 
void addLight (const CLight &l)
 Append a new light to the scene. More...
 
void setNumberOfLights (const size_t N)
 Allocates a number of lights, which must be correctly defined via getLight(i), etc. More...
 
CLightgetLight (const size_t i)
 
const CLightgetLight (const size_t i) const
 
Change or read viewport properties (except "viewport modes")
std::string getName ()
 Returns the name of the viewport. More...
 
void setViewportPosition (const double x, const double y, const double width, const double height)
 Change the viewport position and dimension on the rendering window. More...
 
void getViewportPosition (double &x, double &y, double &width, double &height)
 Get the current viewport position and dimension on the rendering window. More...
 
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) More...
 
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) More...
 
void setBorderSize (unsigned int lineWidth)
 Set the border size ("frame") of the viewport (default=0). More...
 
bool isTransparent ()
 Return whether the viewport will be rendered transparent over previous viewports. More...
 
void setTransparent (bool trans)
 Set the transparency, that is, whether the viewport will be rendered transparent over previous viewports (default=false). More...
 
void setCustomBackgroundColor (const mrpt::img::TColorf &color)
 Set a background color different from that of the parent GUI window. More...
 
mrpt::img::TColorf getCustomBackgroundColor () const
 
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 select 3D objects by clicking onto the 2D image. More...
 
RTTI classes and functions for polymorphic hierarchies
mrpt::rtti::CObject::Ptr duplicateGetSmartPtr () const
 Makes a deep copy of the object and returns a smart pointer to it. More...
 

Protected Member Functions

void initializeAllTextures ()
 Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) More...
 
void dumpListOfObjects (std::vector< std::string > &lst)
 Retrieves a list of all objects in text form. More...
 
void render (const int render_width, const int render_height) const
 Render the objects in this viewport (called from COpenGLScene only) More...
 
void internal_enableImageView ()
 
void publishEvent (const mrptEvent &e) const
 Called when you want this object to emit an event to all the observers currently subscribed to this object. More...
 
bool hasSubscribers () const
 Can be called by a derived class before preparing an event for publishing with publishEvent to determine if there is no one subscribed, so it can save the wasted time preparing an event that will be not read. More...
 
CSerializable virtual methods
uint8_t serializeGetVersion () const override
 Must return the current versioning number of the object. More...
 
void serializeTo (mrpt::serialization::CArchive &out) const override
 Pure virtual method for writing (serializing) to an abstract archive. More...
 
void serializeFrom (mrpt::serialization::CArchive &in, uint8_t serial_version) override
 Pure virtual method for reading (deserializing) from an abstract archive. More...
 
CSerializable virtual methods
virtual void serializeTo (CSchemeArchiveBase &out) const
 Virtual method for writing (serializing) to an abstract schema based archive. More...
 
virtual void serializeFrom (CSchemeArchiveBase &in)
 Virtual method for reading (deserializing) from an abstract schema based archive. More...
 

Protected Attributes

opengl::CCamera m_camera
 The camera associated to the viewport. More...
 
mrpt::safe_ptr< COpenGLScenem_parent
 The scene that contains this viewport. More...
 
bool m_isCloned {false}
 Set by setCloneView. More...
 
bool m_isClonedCamera {false}
 Set by setCloneCamera. More...
 
std::string m_clonedViewport
 Only if m_isCloned=true. More...
 
std::string m_name
 The viewport's name. More...
 
bool m_isTransparent {false}
 Whether to clear color buffer. More...
 
uint32_t m_borderWidth {0}
 Default=0, the border around the viewport. More...
 
double m_view_x {0}
 The viewport position [0,1]. More...
 
double m_view_y {0}
 
double m_view_width {1}
 
double m_view_height {1}
 
double m_clip_min {0.1}
 The min/max clip depth distances (default: 0.1 - 10000) More...
 
double m_clip_max {10000}
 
bool m_custom_backgb_color {false}
 
mrpt::img::TColorf m_background_color
 used only if m_custom_backgb_color More...
 
bool m_isImageView {false}
 Set by setImageView. More...
 
mrpt::img::CImage::Ptr m_imageview_img
 The image to display, after calling setImageView() More...
 
TLastProjectiveMatrixInfo m_lastProjMat
 Info updated with each "render()" and used in "get3DRayForPixelCoord". More...
 
opengl::CListOpenGLObjects m_objects
 The list of objects that comprise the 3D scene. More...
 
bool m_OpenGL_enablePolygonNicest {true}
 
std::vector< CLightm_lights
 

Friends

class COpenGLScene
 

RTTI stuff

using Ptr = std::shared_ptr< COpenGLViewport >
 
using ConstPtr = std::shared_ptr< const COpenGLViewport >
 
using UniquePtr = std::unique_ptr< COpenGLViewport >
 
using ConstUniquePtr = std::unique_ptr< const COpenGLViewport >
 
static mrpt::rtti::CLASSINIT _init_COpenGLViewport
 
static const mrpt::rtti::TRuntimeClassId runtimeClassId
 
static constexpr const char * className = "COpenGLViewport"
 
static const mrpt::rtti::TRuntimeClassId_GetBaseClass ()
 
static constexpr auto getClassName ()
 
static const mrpt::rtti::TRuntimeClassIdGetRuntimeClassIdStatic ()
 
static std::shared_ptr< CObjectCreateObject ()
 
template<typename... Args>
static Ptr Create (Args &&... args)
 
template<typename Alloc , typename... Args>
static Ptr CreateAlloc (const Alloc &alloc, Args &&... args)
 
template<typename... Args>
static UniquePtr CreateUnique (Args &&... args)
 
virtual const mrpt::rtti::TRuntimeClassIdGetRuntimeClass () const override
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::rtti::CObjectclone () const override
 Returns a deep copy (clone) of the object, indepently of its class. More...
 

Contained objects set/get/search

using const_iterator = CListOpenGLObjects::const_iterator
 
using iterator = CListOpenGLObjects::iterator
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
void clear ()
 Delete all internal obejcts. More...
 
void insert (const CRenderizable::Ptr &newObject)
 Insert a new object into the list. More...
 
void getCurrentCameraPose (mrpt::poses::CPose3D &out_cameraPose) const
 Compute the current 3D camera pose. More...
 
CRenderizable::Ptr getByName (const std::string &str)
 Returns the first object with a given name, or nullptr if not found. More...
 
template<typename T >
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 pointer) if not found. More...
 
void removeObject (const CRenderizable::Ptr &obj)
 Removes the given object from the scene (it also deletes the object to free its memory). More...
 
size_t size () const
 Number of objects contained. More...
 
bool empty () const
 
opengl::CCameragetCamera ()
 Get a reference to the camera associated with this viewport. More...
 
const opengl::CCameragetCamera () const
 Get a reference to the camera associated with this viewport. More...
 
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 the object parent. More...
 

Member Typedef Documentation

◆ const_iterator

using mrpt::opengl::COpenGLViewport::const_iterator = CListOpenGLObjects::const_iterator

Definition at line 253 of file COpenGLViewport.h.

◆ ConstPtr

◆ ConstUniquePtr

Definition at line 62 of file COpenGLViewport.h.

◆ iterator

using mrpt::opengl::COpenGLViewport::iterator = CListOpenGLObjects::iterator

Definition at line 254 of file COpenGLViewport.h.

◆ Ptr

A type for the associated smart pointer

Definition at line 62 of file COpenGLViewport.h.

◆ UniquePtr

Definition at line 62 of file COpenGLViewport.h.

Constructor & Destructor Documentation

◆ ~COpenGLViewport()

COpenGLViewport::~COpenGLViewport ( )
override

Destructor: clears all objects.

Definition at line 86 of file COpenGLViewport.cpp.

References clear().

Here is the call graph for this function:

◆ COpenGLViewport()

COpenGLViewport::COpenGLViewport ( COpenGLScene parent = nullptr,
const std::string name = std::string("") 
)

Constructor, invoked from COpenGLScene only.

Definition at line 49 of file COpenGLViewport.cpp.

References m_lights.

Member Function Documentation

◆ _GetBaseClass()

static const mrpt::rtti::TRuntimeClassId* mrpt::opengl::COpenGLViewport::_GetBaseClass ( )
staticprotected

◆ addLight()

void mrpt::opengl::COpenGLViewport::addLight ( const CLight l)
inline

Append a new light to the scene.

By default there are two lights. "GL_LIGHTING" is disabled if all lights are removed

Definition at line 124 of file COpenGLViewport.h.

References m_lights.

◆ begin() [1/2]

const_iterator mrpt::opengl::COpenGLViewport::begin ( ) const
inline

Definition at line 256 of file COpenGLViewport.h.

References m_objects.

◆ begin() [2/2]

iterator mrpt::opengl::COpenGLViewport::begin ( )
inline

Definition at line 258 of file COpenGLViewport.h.

References m_objects.

◆ clear()

void COpenGLViewport::clear ( )

Delete all internal obejcts.

See also
insert

Definition at line 130 of file COpenGLViewport.cpp.

References m_objects.

Referenced by serializeFrom(), setCloneView(), and ~COpenGLViewport().

Here is the caller graph for this function:

◆ clone()

virtual mrpt::rtti::CObject* mrpt::opengl::COpenGLViewport::clone ( ) const
overridevirtual

Returns a deep copy (clone) of the object, indepently of its class.

Implements mrpt::rtti::CObject.

◆ Create()

template<typename... Args>
static Ptr mrpt::opengl::COpenGLViewport::Create ( Args &&...  args)
inlinestatic

Definition at line 62 of file COpenGLViewport.h.

◆ CreateAlloc()

template<typename Alloc , typename... Args>
static Ptr mrpt::opengl::COpenGLViewport::CreateAlloc ( const Alloc &  alloc,
Args &&...  args 
)
inlinestatic

Definition at line 62 of file COpenGLViewport.h.

◆ CreateObject()

static std::shared_ptr<CObject> mrpt::opengl::COpenGLViewport::CreateObject ( )
static

◆ CreateUnique()

template<typename... Args>
static UniquePtr mrpt::opengl::COpenGLViewport::CreateUnique ( Args &&...  args)
inlinestatic

Definition at line 62 of file COpenGLViewport.h.

◆ dumpListOfObjects()

void COpenGLViewport::dumpListOfObjects ( std::vector< std::string > &  lst)
protected

Retrieves a list of all objects in text form.

Definition at line 655 of file COpenGLViewport.cpp.

References CLASS_ID_NAMESPACE, and m_objects.

◆ duplicateGetSmartPtr()

mrpt::rtti::CObject::Ptr CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Makes a deep copy of the object and returns a smart pointer to it.

Definition at line 200 of file CObject.h.

References mrpt::rtti::CObject::clone().

Referenced by mrpt::obs::CRawlog::addActions(), and mrpt::obs::CRawlog::addObservations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool mrpt::opengl::COpenGLViewport::empty ( ) const
inline

Definition at line 320 of file COpenGLViewport.h.

References m_objects.

◆ enablePolygonNicest()

void mrpt::opengl::COpenGLViewport::enablePolygonNicest ( bool  enable = true)
inline

Sets glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) is enabled, or GL_FASTEST otherwise.

Definition at line 115 of file COpenGLViewport.h.

References m_OpenGL_enablePolygonNicest.

◆ end() [1/2]

const_iterator mrpt::opengl::COpenGLViewport::end ( ) const
inline

Definition at line 257 of file COpenGLViewport.h.

References m_objects.

◆ end() [2/2]

iterator mrpt::opengl::COpenGLViewport::end ( )
inline

Definition at line 259 of file COpenGLViewport.h.

References m_objects.

◆ get3DRayForPixelCoord()

void COpenGLViewport::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 select 3D objects by clicking onto the 2D image.

Parameters
x_coordHorizontal coordinate with the usual meaning (0:left of the viewport, W-1: right border).
y_coordHorizontal coordinate with the usual meaning (0:top of the viewport, H-1: right border).
out_cameraPoseIf not nullptr, will have the camera 3D pose as a mrpt::poses::CPose3D. See also
Note
(x,y) refer to VIEWPORT coordinates. Take into account this when viewports do not extend to the whole window size.
x and y are double instead of integers to allow sub-pixel precision.
See also
getCurrentCameraPose

Definition at line 720 of file COpenGLViewport.cpp.

References ASSERTDEB_, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::azimuth, mrpt::math::crossProduct3D(), mrpt::DEG2RAD(), mrpt::math::TLine3D::director, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::elev, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::eye, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::FOV, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::is_projective, m_lastProjMat, mrpt::math::TLine3D::pBase, mrpt::math::UNINITIALIZED_MATRIX, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::viewport_height, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::viewport_width, mrpt::math::TPoint3D_data::x, mrpt::math::TPoint3D_data::y, mrpt::math::TPoint3D_data::z, and mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::zoom.

Here is the call graph for this function:

◆ getBoundingBox()

void COpenGLViewport::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 the object parent.

Definition at line 885 of file COpenGLViewport.cpp.

References bb_max, bb_min, mrpt::keep_max(), mrpt::keep_min(), m_objects, mrpt::math::TPoint3D_data::x, mrpt::math::TPoint3D_data::y, and mrpt::math::TPoint3D_data::z.

Here is the call graph for this function:

◆ getByClass()

template<typename T >
T::Ptr mrpt::opengl::COpenGLViewport::getByClass ( const size_t &  ith = 0) const
inline

Returns the i'th object of a given class (or of a descendant class), or nullptr (an empty smart pointer) if not found.

Example:

CSphere::Ptr obs = view.getByClass<CSphere>();

By default (ith=0), the first observation is returned.

Definition at line 288 of file COpenGLViewport.h.

References CLASS_ID_NAMESPACE, m_objects, MRPT_END, and MRPT_START.

Referenced by render().

Here is the caller graph for this function:

◆ getByName()

CRenderizable::Ptr COpenGLViewport::getByName ( const std::string str)

Returns the first object with a given name, or nullptr if not found.

Definition at line 618 of file COpenGLViewport.cpp.

References CLASS_ID_NAMESPACE, and m_objects.

◆ getCamera() [1/2]

opengl::CCamera& mrpt::opengl::COpenGLViewport::getCamera ( )
inline

Get a reference to the camera associated with this viewport.

Definition at line 322 of file COpenGLViewport.h.

References m_camera.

◆ getCamera() [2/2]

const opengl::CCamera& mrpt::opengl::COpenGLViewport::getCamera ( ) const
inline

Get a reference to the camera associated with this viewport.

Definition at line 324 of file COpenGLViewport.h.

References m_camera.

◆ getClassName()

static constexpr auto mrpt::opengl::COpenGLViewport::getClassName ( )
inlinestatic

Definition at line 62 of file COpenGLViewport.h.

◆ getCurrentCameraPose()

void COpenGLViewport::getCurrentCameraPose ( mrpt::poses::CPose3D out_cameraPose) const

Compute the current 3D camera pose.

See also
get3DRayForPixelCoord

Definition at line 845 of file COpenGLViewport.cpp.

◆ getCustomBackgroundColor()

mrpt::img::TColorf mrpt::opengl::COpenGLViewport::getCustomBackgroundColor ( ) const
inline

Definition at line 221 of file COpenGLViewport.h.

References m_background_color.

◆ getLight() [1/2]

CLight& mrpt::opengl::COpenGLViewport::getLight ( const size_t  i)
inline

Definition at line 128 of file COpenGLViewport.h.

References ASSERT_BELOW_, and m_lights.

◆ getLight() [2/2]

const CLight& mrpt::opengl::COpenGLViewport::getLight ( const size_t  i) const
inline

Definition at line 133 of file COpenGLViewport.h.

References ASSERT_BELOW_, and m_lights.

◆ getName()

std::string mrpt::opengl::COpenGLViewport::getName ( )
inline

Returns the name of the viewport.

Definition at line 146 of file COpenGLViewport.h.

References m_name.

◆ GetRuntimeClass()

virtual const mrpt::rtti::TRuntimeClassId* mrpt::opengl::COpenGLViewport::GetRuntimeClass ( ) const
overridevirtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::serialization::CSerializable.

◆ GetRuntimeClassIdStatic()

static const mrpt::rtti::TRuntimeClassId& mrpt::opengl::COpenGLViewport::GetRuntimeClassIdStatic ( )
static

◆ getViewportClipDistances()

void COpenGLViewport::getViewportClipDistances ( double &  clip_min,
double &  clip_max 
) const

Get the current min/max clip depth distances of the rendering frustum (default: 0.1 - 10000)

See also
setViewportClipDistances

Definition at line 710 of file COpenGLViewport.cpp.

References m_clip_max, and m_clip_min.

◆ getViewportPosition()

void COpenGLViewport::getViewportPosition ( double &  x,
double &  y,
double &  width,
double &  height 
)

Get the current viewport position and dimension on the rendering window.

X & Y coordinates here can have two interpretations:

  • If in the range [0,1], they are factors with respect to the actual window sizes (i.e. width=1 means the entire width of the rendering window).
  • If >1, they are interpreted as pixels.
    Note
    (x,y) specify the lower left corner of the viewport rectangle.
    See also
    setViewportPosition

Definition at line 118 of file COpenGLViewport.cpp.

References m_view_height, m_view_width, m_view_x, and m_view_y.

◆ hasSubscribers()

bool mrpt::system::CObservable::hasSubscribers ( ) const
inlineprotectedinherited

Can be called by a derived class before preparing an event for publishing with publishEvent to determine if there is no one subscribed, so it can save the wasted time preparing an event that will be not read.

Definition at line 53 of file CObservable.h.

References mrpt::system::CObservable::m_subscribers.

Referenced by mrpt::gui::CWindowDialog::OnMouseDown(), mrpt::gui::CWindowDialog::OnMouseMove(), mrpt::gui::CWindowDialog::OnResize(), and render().

Here is the caller graph for this function:

◆ initializeAllTextures()

void COpenGLViewport::initializeAllTextures ( )
protected

Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)

Definition at line 640 of file COpenGLViewport.cpp.

References IS_CLASS, IS_DERIVED, and m_objects.

◆ insert()

void COpenGLViewport::insert ( const CRenderizable::Ptr newObject)

Insert a new object into the list.

The object MUST NOT be deleted, it will be deleted automatically by this object when not required anymore.

Definition at line 134 of file COpenGLViewport.cpp.

References m_objects.

◆ internal_enableImageView()

void COpenGLViewport::internal_enableImageView ( )
protected

Definition at line 875 of file COpenGLViewport.cpp.

References mrpt::img::CImage::Create(), m_imageview_img, and m_isImageView.

Referenced by setImageView().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPolygonNicestEnabled()

bool mrpt::opengl::COpenGLViewport::isPolygonNicestEnabled ( ) const
inline

Definition at line 119 of file COpenGLViewport.h.

References m_OpenGL_enablePolygonNicest.

◆ isTransparent()

bool mrpt::opengl::COpenGLViewport::isTransparent ( )
inline

Return whether the viewport will be rendered transparent over previous viewports.

Definition at line 209 of file COpenGLViewport.h.

References m_isTransparent.

◆ lightsClearAll()

void mrpt::opengl::COpenGLViewport::lightsClearAll ( )
inline

Removes all lights (and disables the global "GL_LIGHTING")

Definition at line 121 of file COpenGLViewport.h.

References m_lights.

◆ publishEvent()

void CObservable::publishEvent ( const mrptEvent e) const
protectedinherited

Called when you want this object to emit an event to all the observers currently subscribed to this object.

Definition at line 48 of file CObservable.cpp.

References MRPT_END, and MRPT_START.

Referenced by mrpt::gui::CDisplayWindow3D::internal_emitGrabImageEvent(), mrpt::gui::CWindowDialog::OnChar(), mrpt::gui::CWindowDialog::OnClose(), mrpt::gui::C3DWindowDialog::OnClose(), mrpt::gui::CWindowDialog::OnMouseDown(), mrpt::gui::CWindowDialog::OnMouseMove(), mrpt::gui::CWindowDialog::OnResize(), mrpt::gui::C3DWindowDialog::OnResize(), and render().

Here is the caller graph for this function:

◆ removeObject()

void COpenGLViewport::removeObject ( const CRenderizable::Ptr obj)

Removes the given object from the scene (it also deletes the object to free its memory).

Definition at line 681 of file COpenGLViewport.cpp.

References CLASS_ID_NAMESPACE, and m_objects.

◆ render()

void COpenGLViewport::render ( const int  render_width,
const int  render_height 
) const
protected

Render the objects in this viewport (called from COpenGLScene only)

Definition at line 142 of file COpenGLViewport.cpp.

References mrpt::img::TColorf::A, ASSERT_, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::azimuth, mrpt::img::TColorf::B, mrpt::opengl::CRenderizable::checkOpenGLError(), mrpt::rtti::TRuntimeClassId::className, mrpt::DEG2RAD(), mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::elev, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::eye, mrpt::format(), mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::FOV, mrpt::img::TColorf::G, getByClass(), mrpt::poses::CPose3D::getRotationMatrix(), mrpt::opengl::CRenderizable::GetRuntimeClass(), GL_ACCUM_BUFFER_BIT, GL_AMBIENT_AND_DIFFUSE, GL_BGR, GL_COLOR_BUFFER_BIT, GL_COLOR_CLEAR_VALUE, GL_COLOR_MATERIAL, GL_DEPTH_BUFFER_BIT, GL_DEPTH_TEST, GL_FASTEST, GL_FRONT_AND_BACK, GL_LEQUAL, GL_LIGHT_MODEL_TWO_SIDE, GL_LIGHTING, GL_LINE_LOOP, GL_LUMINANCE, GL_MODELVIEW, GL_NICEST, GL_PERSPECTIVE_CORRECTION_HINT, GL_POLYGON_SMOOTH_HINT, GL_PROJECTION, GL_RGB, GL_SCISSOR_TEST, GL_SMOOTH, GL_STENCIL_BUFFER_BIT, GL_TRUE, GL_UNPACK_ALIGNMENT, GL_UNPACK_ROW_LENGTH, GL_UNSIGNED_BYTE, glBegin(), glClear(), glClearColor(), glColor4f(), glColorMaterial(), glDepthFunc(), glDisable(), glDrawPixels(), glEnable(), glEnd(), glGetDoublev(), glHint(), glLightModeli(), glLineWidth(), glLoadIdentity(), glMatrixMode(), glOrtho(), glPixelStorei(), glPixelZoom(), glRasterPos2f(), glScissor(), glShadeModel(), glVertex2f(), glViewport(), mrpt::system::CObservable::hasSubscribers(), mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::is_projective, m_background_color, m_borderWidth, m_camera, m_clip_max, m_clip_min, m_clonedViewport, m_custom_backgb_color, mrpt::opengl::CCamera::m_distanceZoom, m_imageview_img, m_isCloned, m_isClonedCamera, m_isImageView, m_isTransparent, m_lastProjMat, m_lights, m_objects, m_OpenGL_enablePolygonNicest, m_parent, m_view_height, m_view_width, m_view_x, m_view_y, MRPT_UNUSED_PARAM, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::pointing, mrpt::system::CObservable::publishEvent(), mrpt::img::TColorf::R, mrpt::opengl::gl_utils::renderSetOfObjects(), THROW_EXCEPTION, THROW_EXCEPTION_FMT, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::up, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::viewport_height, mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::viewport_width, mrpt::math::TPoint3D_data::x, mrpt::poses::CPoseOrPoint< DERIVEDCLASS, DIM >::x(), mrpt::math::TPoint3D_data::y, mrpt::poses::CPoseOrPoint< DERIVEDCLASS, DIM >::y(), mrpt::math::TPoint3D_data::z, and mrpt::opengl::COpenGLViewport::TLastProjectiveMatrixInfo::zoom.

Here is the call graph for this function:

◆ resetCloneView()

void mrpt::opengl::COpenGLViewport::resetCloneView ( )
inline

Reset the viewport to normal mode: rendering its own objects.

See also
setCloneView, setNormalMode

Definition at line 97 of file COpenGLViewport.h.

References setNormalMode().

Here is the call graph for this function:

◆ serializeFrom() [1/2]

void COpenGLViewport::serializeFrom ( mrpt::serialization::CArchive in,
uint8_t  serial_version 
)
overrideprotectedvirtual

Pure virtual method for reading (deserializing) from an abstract archive.

Users don't call this method directly. Instead, use stream >> object;.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any I/O error

Implements mrpt::serialization::CSerializable.

Definition at line 552 of file COpenGLViewport.cpp.

References mrpt::img::TColorf::A, mrpt::img::TColorf::B, clear(), mrpt::img::TColorf::G, m_background_color, m_borderWidth, m_camera, m_clonedViewport, m_custom_backgb_color, m_isCloned, m_isClonedCamera, m_isTransparent, m_lights, m_name, m_objects, m_OpenGL_enablePolygonNicest, m_view_height, m_view_width, m_view_x, m_view_y, MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION, and mrpt::img::TColorf::R.

Here is the call graph for this function:

◆ serializeFrom() [2/2]

virtual void mrpt::serialization::CSerializable::serializeFrom ( CSchemeArchiveBase in)
inlineprotectedvirtualinherited

Virtual method for reading (deserializing) from an abstract schema based archive.

Definition at line 74 of file CSerializable.h.

References mrpt::serialization::CSerializable::GetRuntimeClass(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ serializeGetVersion()

uint8_t COpenGLViewport::serializeGetVersion ( ) const
overrideprotectedvirtual

Must return the current versioning number of the object.

Start in zero for new classes, and increments each time there is a change in the stored format.

Implements mrpt::serialization::CSerializable.

Definition at line 527 of file COpenGLViewport.cpp.

◆ serializeTo() [1/2]

void COpenGLViewport::serializeTo ( mrpt::serialization::CArchive out) const
overrideprotectedvirtual

Pure virtual method for writing (serializing) to an abstract archive.

Users don't call this method directly. Instead, use stream << object;.

Exceptions
std::exceptionOn any I/O error

Implements mrpt::serialization::CSerializable.

Definition at line 528 of file COpenGLViewport.cpp.

References mrpt::img::TColorf::A, mrpt::img::TColorf::B, mrpt::img::TColorf::G, m_background_color, m_borderWidth, m_camera, m_clonedViewport, m_custom_backgb_color, m_isCloned, m_isClonedCamera, m_isTransparent, m_lights, m_name, m_objects, m_OpenGL_enablePolygonNicest, m_view_height, m_view_width, m_view_x, m_view_y, and mrpt::img::TColorf::R.

◆ serializeTo() [2/2]

virtual void mrpt::serialization::CSerializable::serializeTo ( CSchemeArchiveBase out) const
inlineprotectedvirtualinherited

Virtual method for writing (serializing) to an abstract schema based archive.

Definition at line 64 of file CSerializable.h.

References mrpt::serialization::CSerializable::GetRuntimeClass(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ setBorderSize()

void mrpt::opengl::COpenGLViewport::setBorderSize ( unsigned int  lineWidth)
inline

Set the border size ("frame") of the viewport (default=0).

Definition at line 201 of file COpenGLViewport.h.

References m_borderWidth.

◆ setCloneCamera()

void mrpt::opengl::COpenGLViewport::setCloneCamera ( bool  enable)
inline

If set to true, and setCloneView() has been called, this viewport will be rendered using the camera of the cloned viewport.

Definition at line 101 of file COpenGLViewport.h.

References m_isClonedCamera.

◆ setCloneView()

void COpenGLViewport::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.

By default, only the objects are cloned, not the camera. See

See also
resetCloneView

Definition at line 90 of file COpenGLViewport.cpp.

References clear(), m_clonedViewport, and m_isCloned.

Here is the call graph for this function:

◆ setCustomBackgroundColor()

void mrpt::opengl::COpenGLViewport::setCustomBackgroundColor ( const mrpt::img::TColorf color)
inline

Set a background color different from that of the parent GUI window.

Definition at line 215 of file COpenGLViewport.h.

References m_background_color, and m_custom_backgb_color.

◆ setImageView() [1/2]

void COpenGLViewport::setImageView ( const mrpt::img::CImage img)

Set this viewport into "image view"-mode, where an image is efficiently drawn (fitting the viewport area) using an OpenGL textured quad.

Call this method with the new image to update the displayed image (but recall to first lock the parent openglscene's critical section, then do the update, then release the lock, and then issue a window repaint). Internally, the texture is drawn using a mrpt::opengl::CTexturedPlane The viewport can be reverted to behave like a normal viewport by calling setNormalMode()

Definition at line 864 of file COpenGLViewport.cpp.

References internal_enableImageView(), and m_imageview_img.

Here is the call graph for this function:

◆ setImageView() [2/2]

void COpenGLViewport::setImageView ( mrpt::img::CImage &&  img)

Just like setImageView but moves the internal image memory instead of making a copy, so it's faster but empties the input image.

See also
setImageView

Definition at line 869 of file COpenGLViewport.cpp.

References internal_enableImageView(), and m_imageview_img.

Here is the call graph for this function:

◆ setNormalMode()

void COpenGLViewport::setNormalMode ( )

Resets the viewport to a normal 3D viewport.

See also
setCloneView, setImageView

Definition at line 854 of file COpenGLViewport.cpp.

References m_imageview_img, m_isCloned, m_isClonedCamera, and m_isImageView.

Referenced by resetCloneView().

Here is the caller graph for this function:

◆ setNumberOfLights()

void mrpt::opengl::COpenGLViewport::setNumberOfLights ( const size_t  N)
inline

Allocates a number of lights, which must be correctly defined via getLight(i), etc.

Definition at line 127 of file COpenGLViewport.h.

References m_lights.

◆ setTransparent()

void mrpt::opengl::COpenGLViewport::setTransparent ( bool  trans)
inline

Set the transparency, that is, whether the viewport will be rendered transparent over previous viewports (default=false).

Definition at line 213 of file COpenGLViewport.h.

References m_isTransparent.

◆ setViewportClipDistances()

void COpenGLViewport::setViewportClipDistances ( const double  clip_min,
const double  clip_max 
)

Set the min/max clip depth distances of the rendering frustum (default: 0.1 - 10000)

See also
getViewportClipDistances

Definition at line 698 of file COpenGLViewport.cpp.

References ASSERT_, m_clip_max, and m_clip_min.

◆ setViewportPosition()

void COpenGLViewport::setViewportPosition ( const double  x,
const double  y,
const double  width,
const double  height 
)

Change the viewport position and dimension on the rendering window.

X & Y coordinates here can have two interpretations:

  • If in the range [0,1], they are factors with respect to the actual window sizes (i.e. width=1 means the entire width of the rendering window).
  • If >1, they are interpreted as pixels.

width & height can be interpreted as:

  • If >1, they are the size of the viewport in that dimension, in pixels.
  • If in [0,1], they are the size of the viewport in that dimension, in a factor of the width/height.
  • If in [-1,0[, the size is computed such as the right/top border ends up in the given coordinate, interpreted as a factor (e.g. -1: up to the end of the viewport, -0.5: up to the middle of it).
  • If <-1 the size is computed such as the right/top border ends up in the given absolute coordinate (e.g. -200: up to the row/column 200px).
Note
(x,y) specify the lower left corner of the viewport rectangle.
See also
getViewportPosition

Definition at line 100 of file COpenGLViewport.cpp.

References ASSERT_, m_view_height, m_view_width, m_view_x, m_view_y, MRPT_END, and MRPT_START.

◆ size()

size_t mrpt::opengl::COpenGLViewport::size ( ) const
inline

Number of objects contained.

Definition at line 319 of file COpenGLViewport.h.

References m_objects.

◆ writeToMatlab()

virtual mxArray* mrpt::serialization::CSerializable::writeToMatlab ( ) const
inlinevirtualinherited

Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.

Returns
A new mxArray (caller is responsible of memory freeing) or nullptr is class does not support conversion to MATLAB.

Definition at line 90 of file CSerializable.h.

Friends And Related Function Documentation

◆ COpenGLScene

friend class COpenGLScene
friend

Definition at line 63 of file COpenGLViewport.h.

Member Data Documentation

◆ _init_COpenGLViewport

mrpt::rtti::CLASSINIT mrpt::opengl::COpenGLViewport::_init_COpenGLViewport
staticprotected

Definition at line 62 of file COpenGLViewport.h.

◆ className

constexpr const char* mrpt::opengl::COpenGLViewport::className = "COpenGLViewport"
static

Definition at line 62 of file COpenGLViewport.h.

◆ m_background_color

mrpt::img::TColorf mrpt::opengl::COpenGLViewport::m_background_color
protected

used only if m_custom_backgb_color

Definition at line 377 of file COpenGLViewport.h.

Referenced by getCustomBackgroundColor(), render(), serializeFrom(), serializeTo(), and setCustomBackgroundColor().

◆ m_borderWidth

uint32_t mrpt::opengl::COpenGLViewport::m_borderWidth {0}
protected

Default=0, the border around the viewport.

Definition at line 370 of file COpenGLViewport.h.

Referenced by render(), serializeFrom(), serializeTo(), and setBorderSize().

◆ m_camera

opengl::CCamera mrpt::opengl::COpenGLViewport::m_camera
protected

The camera associated to the viewport.

Definition at line 356 of file COpenGLViewport.h.

Referenced by getCamera(), render(), serializeFrom(), and serializeTo().

◆ m_clip_max

double mrpt::opengl::COpenGLViewport::m_clip_max {10000}
protected

Definition at line 374 of file COpenGLViewport.h.

Referenced by getViewportClipDistances(), render(), and setViewportClipDistances().

◆ m_clip_min

double mrpt::opengl::COpenGLViewport::m_clip_min {0.1}
protected

The min/max clip depth distances (default: 0.1 - 10000)

Definition at line 374 of file COpenGLViewport.h.

Referenced by getViewportClipDistances(), render(), and setViewportClipDistances().

◆ m_clonedViewport

std::string mrpt::opengl::COpenGLViewport::m_clonedViewport
protected

Only if m_isCloned=true.

Definition at line 364 of file COpenGLViewport.h.

Referenced by render(), serializeFrom(), serializeTo(), and setCloneView().

◆ m_custom_backgb_color

bool mrpt::opengl::COpenGLViewport::m_custom_backgb_color {false}
protected

Definition at line 375 of file COpenGLViewport.h.

Referenced by render(), serializeFrom(), serializeTo(), and setCustomBackgroundColor().

◆ m_imageview_img

mrpt::img::CImage::Ptr mrpt::opengl::COpenGLViewport::m_imageview_img
protected

The image to display, after calling setImageView()

Definition at line 383 of file COpenGLViewport.h.

Referenced by internal_enableImageView(), render(), setImageView(), and setNormalMode().

◆ m_isCloned

bool mrpt::opengl::COpenGLViewport::m_isCloned {false}
protected

Set by setCloneView.

Definition at line 360 of file COpenGLViewport.h.

Referenced by render(), serializeFrom(), serializeTo(), setCloneView(), and setNormalMode().

◆ m_isClonedCamera

bool mrpt::opengl::COpenGLViewport::m_isClonedCamera {false}
protected

Set by setCloneCamera.

Definition at line 362 of file COpenGLViewport.h.

Referenced by render(), serializeFrom(), serializeTo(), setCloneCamera(), and setNormalMode().

◆ m_isImageView

bool mrpt::opengl::COpenGLViewport::m_isImageView {false}
protected

Set by setImageView.

Definition at line 379 of file COpenGLViewport.h.

Referenced by internal_enableImageView(), render(), and setNormalMode().

◆ m_isTransparent

bool mrpt::opengl::COpenGLViewport::m_isTransparent {false}
protected

Whether to clear color buffer.

Definition at line 368 of file COpenGLViewport.h.

Referenced by isTransparent(), render(), serializeFrom(), serializeTo(), and setTransparent().

◆ m_lastProjMat

TLastProjectiveMatrixInfo mrpt::opengl::COpenGLViewport::m_lastProjMat
mutableprotected

Info updated with each "render()" and used in "get3DRayForPixelCoord".

Definition at line 408 of file COpenGLViewport.h.

Referenced by get3DRayForPixelCoord(), and render().

◆ m_lights

std::vector<CLight> mrpt::opengl::COpenGLViewport::m_lights
protected

◆ m_name

std::string mrpt::opengl::COpenGLViewport::m_name
protected

The viewport's name.

Definition at line 366 of file COpenGLViewport.h.

Referenced by getName(), serializeFrom(), and serializeTo().

◆ m_objects

opengl::CListOpenGLObjects mrpt::opengl::COpenGLViewport::m_objects
protected

The list of objects that comprise the 3D scene.

Objects are automatically deleted when calling "clear" or in the destructor.

Definition at line 414 of file COpenGLViewport.h.

Referenced by begin(), clear(), dumpListOfObjects(), empty(), end(), getBoundingBox(), getByClass(), getByName(), initializeAllTextures(), insert(), removeObject(), render(), serializeFrom(), serializeTo(), and size().

◆ m_OpenGL_enablePolygonNicest

bool mrpt::opengl::COpenGLViewport::m_OpenGL_enablePolygonNicest {true}
protected

◆ m_parent

mrpt::safe_ptr<COpenGLScene> mrpt::opengl::COpenGLViewport::m_parent
protected

The scene that contains this viewport.

Definition at line 358 of file COpenGLViewport.h.

Referenced by render().

◆ m_view_height

double mrpt::opengl::COpenGLViewport::m_view_height {1}
protected

◆ m_view_width

double mrpt::opengl::COpenGLViewport::m_view_width {1}
protected

◆ m_view_x

double mrpt::opengl::COpenGLViewport::m_view_x {0}
protected

The viewport position [0,1].

Definition at line 372 of file COpenGLViewport.h.

Referenced by getViewportPosition(), render(), serializeFrom(), serializeTo(), and setViewportPosition().

◆ m_view_y

double mrpt::opengl::COpenGLViewport::m_view_y {0}
protected

◆ runtimeClassId

const mrpt::rtti::TRuntimeClassId mrpt::opengl::COpenGLViewport::runtimeClassId
staticprotected

Definition at line 62 of file COpenGLViewport.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019