Easy3D 2.6.1
|
Offscreen rendering. More...
#include <easy3d/viewer/offscreen.h>
Public Member Functions | |
OffScreen (int width=800, int height=600) | |
Constructor. | |
Camera manipulation. | |
Camera * | camera () |
Returns the camera used by the offscreen renderer. See Camera . | |
const Camera * | camera () 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::vec4 & | background_color () const |
Query the background color of the offscreen renderer. | |
Drawable management | |
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. | |
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. | |
Model * | current_model () const |
Query the active model. | |
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 charge of the memory management of the model. The loaded model can be accessed by the 'current_model()' method. | |
Model * | add_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 | |
Model * | add_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. | |
Offscreen rendering.
To use offscreen rendering, simply create an instance of OffScreen and call the render() method, e.g.,
|
explicit |
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.
drawable | The pointer to the drawable. |
const easy3d::vec4 & background_color | ( | ) | const |
Query the background color of the offscreen renderer.
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.
bool delete_drawable | ( | Drawable * | drawable | ) |
Delete the drawable from the offscreen renderer. The related drawables will also be deleted.
drawable | The pointer to the drawable. |
|
virtual |
Delete a model. The memory of the model will be released and its existing drawables also be deleted.
model | The pointer to the model. |
Reimplemented from Viewer.
const std::vector< std::shared_ptr< Drawable > > & drawables | ( | ) | const |
Query the drawables managed by this offscreen renderer.
const std::vector< std::shared_ptr< Model > > & models | ( | ) | const |
Query the models managed by this offscreen renderer.
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).
file_name | The image file name. |
scaling | The 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; |
samples | The required number of samples for antialiased rendering (which can be different from that of the default framebuffer). The default value is 4. |
back_ground | Determines the background color. 0: current color; 1: white; 2: transparent. |
expand | Expand the frustum to ensure the image aspect ratio. |
void resize | ( | int | w, |
int | h ) |
Set/Change the size of the offscreen renderer.
w/h | The requested width/height (in pixels) of the offscreen renderer. |
void set_background_color | ( | const easy3d::vec4 & | color | ) |
Set the background color of the offscreen renderer.
color | The background color. |
|
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
file_name | The string of the file name. |
create_default_drawables | If true, the default drawables will be created. |
Reimplemented from Viewer.
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
model | The pointer to the model. |
create_default_drawables | If true, the default drawables will be created. |