Easy3D 2.6.1
Loading...
Searching...
No Matches
OffScreen Class Reference

Offscreen rendering. More...

#include <easy3d/viewer/offscreen.h>

Inheritance diagram for OffScreen:
Viewer

Public Member Functions

 OffScreen (int width=800, int height=600)
 Constructor.
 
Camera manipulation.
Cameracamera ()
 Returns the camera used by the offscreen renderer. See Camera.
 
const Cameracamera () const
 Returns the camera used by the offscreen renderer. See Camera.
 
bool render (const std::string &file_name, float scaling=1.0f, int samples=4, int back_ground=1, bool expand=true) const
 Render the current scene into an image file. Supported image format: png, jpg, bmp, and tga.
 
Other properties
void resize (int w, int h)
 Set/Change the size of the offscreen renderer.
 
int width () const
 Returns the width of the offscreen renderer.
 
int height () const
 Returns the height of the offscreen renderer.
 
void set_background_color (const easy3d::vec4 &color)
 Set the background color of the offscreen renderer.
 
const easy3d::vec4background_color () const
 Query the background color of the offscreen renderer.
 
Drawable management
Drawableadd_drawable (std::shared_ptr< Drawable > drawable)
 Add a drawable to the offscreen renderer. On success, the offscreen renderer will be in charge of its memory management.
 
bool delete_drawable (Drawable *drawable)
 
const std::vector< std::shared_ptr< Drawable > > & drawables () const
 Query the drawables managed by this offscreen renderer.
 
void clear_scene ()
 Delete all visual contents of the offscreen renderer (all models and drawables).
 

Model management

bool delete_model (Model *model)
 Delete a model. The memory of the model will be released and its existing drawables also be deleted.
 
const std::vector< std::shared_ptr< Model > > & models () const
 Query the models managed by this offscreen renderer.
 
Modelcurrent_model () const
 Query the active model.
 
virtual Modeladd_model (const std::string &file_name, bool create_default_drawables=true)
 Add a model from a file to the offscreen renderer. On success, the offscreen renderer will be in charge of the memory management of the model. The loaded model can be accessed by the 'current_model()' method.
 
Modeladd_model (std::shared_ptr< Model > model, bool create_default_drawables=true)
 Add an existing model to the offscreen renderer. On success, the offscreen renderer will be in charge of its memory management.
 

Additional Inherited Members

Modeladd_model (std::shared_ptr< Model > model, bool create_default_drawables=true)
 Add an existing model to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model.
 

Detailed Description

Offscreen rendering.

To use offscreen rendering, simply create an instance of OffScreen and call the render() method, e.g.,

if (!os.add_model("bunny.ply")) {
LOG(ERROR) << "failed to load model";
return EXIT_FAILURE;
}
... when necessary, access the camera and modify the view here.
bool success = os.render("image.png");
bool render(const std::string &file_name, float scaling=1.0f, int samples=4, int back_ground=1, bool expand=true) const
Render the current scene into an image file. Supported image format: png, jpg, bmp,...
Definition offscreen.cpp:50
OffScreen(int width=800, int height=600)
Constructor.
Definition offscreen.cpp:32
virtual Model * add_model(const std::string &file_name, bool create_default_drawables=true)
Add a model from a file to the offscreen renderer. On success, the offscreen renderer will be in char...
Definition offscreen.cpp:80
Camera * camera()
Returns the camera used by the offscreen renderer. See Camera.
Definition offscreen.cpp:40

Constructor & Destructor Documentation

◆ OffScreen()

OffScreen ( int width = 800,
int height = 600 )
explicit

Constructor.

Parameters
widthThe width of the offscreen renderer, which can be changed by calling resize() after construction.
heightThe height of the offscreen renderer, which can be changed by calling resize() after construction.

Member Function Documentation

◆ add_drawable()

Drawable * add_drawable ( std::shared_ptr< Drawable > drawable)

Add a drawable to the offscreen renderer. On success, the offscreen renderer will be in charge of its memory management.

The use of drawables for visualization is quite flexible. Drawables are typically created for rendering 3D models (e.g., point clouds, meshes, graphs) and a 3D model is usually loaded from a file or generated by an algorithm. This method allows the user to visualize drawables without defining a 3D model.

Parameters
drawableThe pointer to the drawable.
Returns
The pointer of the drawable added to the viewer.

◆ background_color()

const easy3d::vec4 & background_color ( ) const

Query the background color of the offscreen renderer.

Returns
The background color of the offscreen renderer

◆ current_model()

Model * current_model ( ) const

Query the active model.

The offscreen renderer can manage multiple models, and only one model is actively being processed. This method is used to identify this active model.

Returns
The active model.

◆ delete_drawable()

bool delete_drawable ( Drawable * drawable)

Delete the drawable from the offscreen renderer. The related drawables will also be deleted.

Parameters
drawableThe pointer to the drawable.
Returns
True if the drawable has been deleted.

◆ delete_model()

bool delete_model ( Model * model)
virtual

Delete a model. The memory of the model will be released and its existing drawables also be deleted.

Parameters
modelThe pointer to the model.
Returns
True if the model has been deleted.

Reimplemented from Viewer.

◆ drawables()

const std::vector< std::shared_ptr< Drawable > > & drawables ( ) const

Query the drawables managed by this offscreen renderer.

Returns
The drawables managed by this offscreen renderer.

◆ models()

const std::vector< std::shared_ptr< Model > > & models ( ) const

Query the models managed by this offscreen renderer.

Returns
The models managed by this offscreen renderer.

◆ render()

bool render ( const std::string & file_name,
float scaling = 1.0f,
int samples = 4,
int back_ground = 1,
bool expand = true ) const

Render the current scene into an image file. Supported image format: png, jpg, bmp, and tga.

This function renders the scene into a framebuffer and takes a snapshot of the framebuffer. It allows the snapshot image to have a dimension different from the offscreen renderer, and it has no limit on the image size (if memory allows).

Parameters
file_nameThe image file name.
scalingThe scaling factor that determines the size of the image (default to 1.0, same size as the offscreen renderer), i.e., image_width = width() * scaling; image_height = height() * scaling;
samplesThe required number of samples for antialiased rendering (which can be different from that of the default framebuffer). The default value is 4.
back_groundDetermines the background color. 0: current color; 1: white; 2: transparent.
expandExpand the frustum to ensure the image aspect ratio.
Returns
true on success and false otherwise.

◆ resize()

void resize ( int w,
int h )

Set/Change the size of the offscreen renderer.

Parameters
w/hThe requested width/height (in pixels) of the offscreen renderer.

◆ set_background_color()

void set_background_color ( const easy3d::vec4 & color)

Set the background color of the offscreen renderer.

Parameters
colorThe background color.

Friends And Related Symbol Documentation

◆ add_model() [1/2]

Model * add_model ( const std::string & file_name,
bool create_default_drawables = true )
related

Add a model from a file to the offscreen renderer. On success, the offscreen renderer will be in charge of the memory management of the model. The loaded model can be accessed by the 'current_model()' method.

This method loads a model into the offscreen renderer. It allows the user to control if default drawables will be created. The default drawables are

  • for point clouds: "vertices".
  • for surface meshes: "faces", "vertices", "edges", "borders", and "locks".
  • for graphs: "vertices" and "edges".
  • polyhedral meshes: "faces:border", "faces:interior", "vertices", and "edges". These drawables are usually sufficient for basic rendering of the model. In case the default drawables don't meet the particular visualization purpose, you can set 'create_default_drawables' to false and create your needed drawables by calling model->renderer()->add_[type]_drawable(). Here the [type] must be one of "points", "lines", and "triangles'.
    Parameters
    file_nameThe string of the file name.
    create_default_drawablesIf true, the default drawables will be created.
    Returns
    The pointer to the model added to the offscreen renderer (nullptr if failed). (Model*, bool).

Reimplemented from Viewer.

◆ add_model() [2/2]

Model * add_model ( std::shared_ptr< Model > model,
bool create_default_drawables = true )
related

Add an existing model to the offscreen renderer. On success, the offscreen renderer will be in charge of its memory management.

This method adds a model into the offscreen renderer. It allows the user to control if default drawables will be created. The default drawables are

  • for point clouds: "vertices".
  • for surface meshes: "faces", "vertices", "edges", "borders", and "locks".
  • for graphs: "vertices" and "edges".
  • polyhedral meshes: "faces:border", "faces:interior", "vertices", and "edges". These drawables are usually sufficient for basic rendering of the model. In case the default drawables don't meet the particular visualization purpose, you can set 'create_default_drawables' to false and create your needed drawables by calling model->renderer()->add_[type]_drawable(). Here the [type] must be one of "points", "lines", and "triangles'.
    Parameters
    modelThe pointer to the model.
    create_default_drawablesIf true, the default drawables will be created.
    Returns
    The pointer to the model added to the offscreen renderer (nullptr if failed). (const std::string&, bool).

The documentation for this class was generated from the following files: