eos 1.4.0
|
Software rendering and texture extraction functionality. More...
Classes | |
class | ExtractionFragmentShader |
A fragment shader that is used to extract, or remap, texture from an image to a UV map (i.e. the reverse process of texturing). More... | |
class | Rasterizer |
Todo. More... | |
class | SoftwareRenderer |
X. More... | |
class | Texture |
Represents a texture for rendering. More... | |
class | TexturingFragmentShader |
A fragment shader that textures. More... | |
class | VertexColoringFragmentShader |
A simple fragment shader that does vertex-colouring. More... | |
class | VertexShader |
A simple vertex shader that projects the vertex and returns the vertex in clip-space coordinates. More... | |
Typedefs | |
template<typename T > | |
using | Triangle = std::array< detail::Vertex< T >, 3 > |
X. | |
Enumerations | |
enum class | ProjectionType { Orthographic , Perspective } |
Functions | |
void | draw_line (core::Image3u &image, float x0, float y0, float x1, float y1, Eigen::Vector3f color) |
void | draw_wireframe (core::Image3u &image, const core::Mesh &mesh, Eigen::Matrix4f modelview, Eigen::Matrix4f projection, Eigen::Vector4f viewport, Eigen::Vector3f color=Eigen::Vector3f(0, 255, 0)) |
template<typename T > | |
Eigen::Vector3< T > | compute_inverse_perspectively_correct_lambda (const Eigen::Vector3< T > &lambda_world, const T &one_over_w0, const T &one_over_w1, const T &one_over_w2) |
Computes inverse perspectively correct lambda. | |
template<typename T > | |
Eigen::Matrix4< T > | perspective (T fov_y, T aspect, T z_near, T z_far) |
template<typename T > | |
Eigen::Matrix4< T > | ortho (T left, T right, T bottom, T top) |
Creates a 2D orthographic projection matrix. | |
template<typename T > | |
Eigen::Matrix4< T > | ortho (T left, T right, T bottom, T top, T z_near, T z_far) |
Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates. | |
template<typename T > | |
Eigen::Vector3< T > | project (const Eigen::Vector3< T > &point_3d, const Eigen::Matrix4< T > &modelview_matrix, const Eigen::Matrix4< T > &projection_matrix, const Eigen::Vector4< T > &viewport) |
Eigen::Vector3f | compute_face_normal (const Eigen::Vector3f &v0, const Eigen::Vector3f &v1, const Eigen::Vector3f &v2) |
Eigen::Vector3f | compute_face_normal (const Eigen::Vector4f &v0, const Eigen::Vector4f &v1, const Eigen::Vector4f &v2) |
std::vector< Eigen::Vector3f > | compute_face_normals (const std::vector< Eigen::Vector3f > &vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices) |
std::vector< Eigen::Vector3f > | compute_vertex_normals (const std::vector< Eigen::Vector3f > &vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices, const std::vector< Eigen::Vector3f > &face_normals) |
void | draw_wireframe (cv::Mat image, const core::Mesh &mesh, Eigen::Matrix4f modelview, Eigen::Matrix4f projection, Eigen::Vector4f viewport, cv::Scalar color=cv::Scalar(0, 255, 0, 255)) |
cv::Mat | draw_texcoords (core::Mesh mesh, cv::Mat image=cv::Mat()) |
std::pair< bool, cpp17::optional< float > > | ray_triangle_intersect (const Eigen::Vector3f &ray_origin, const Eigen::Vector3f &ray_direction, const Eigen::Vector3f &v0, const Eigen::Vector3f &v1, const Eigen::Vector3f &v2, bool enable_backculling) |
Computes the intersection of the given ray with the given triangle. | |
core::Image4u | render (const core::Mesh &mesh, const Eigen::Matrix4f &model_view_matrix, const Eigen::Matrix4f &projection_matrix, int viewport_width, int viewport_height, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true) |
core::Image4u | render (const core::Mesh &mesh, const Eigen::Matrix4f &model_view_matrix, const Eigen::Matrix4f &projection_matrix, int viewport_width, int viewport_height, Texture texture, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true) |
unsigned int | get_max_possible_mipmaps_num (unsigned int width, unsigned int height) |
bool | is_power_of_two (int x) |
Texture | create_mipmapped_texture (const eos::core::Image4u &image, unsigned int mipmapsNum=0) |
eos::core::Image4u | extract_texture (const core::Mesh &mesh, Eigen::Matrix4f view_model_matrix, Eigen::Matrix4f projection_matrix, ProjectionType projection_type, const eos::core::Image4u &image, int texturemap_resolution=512) |
Extracts the texture from the given image and returns a texture map. | |
Eigen::Vector2f | clip_to_screen_space (const Eigen::Vector2f &clip_coordinates, int screen_width, int screen_height) |
template<typename T > | |
Eigen::Vector2< T > | clip_to_screen_space (const T clip_coord_x, const T clip_coord_y, int screen_width, int screen_height) |
bool | is_vertex_visible (const Eigen::Vector3f &probe_vertex, const std::vector< Eigen::Vector3f > &mesh_vertices, const std::vector< std::array< int, 3 > > &mesh_triangle_vertex_indices, detail::RayDirection ray_direction_type) |
std::vector< bool > | compute_per_vertex_self_occlusion (const std::vector< Eigen::Vector3f > &viewspace_vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices, detail::RayDirection ray_direction_type) |
std::vector< bool > | compute_per_vertex_self_occlusion (const std::vector< Eigen::Vector3f > &vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices, const Eigen::Matrix4f &modelview, detail::RayDirection ray_direction_type) |
Software rendering and texture extraction functionality.
using eos::render::Triangle = typedef std::array<detail::Vertex<T>, 3> |
X.
Can this go into the SoftwareRenderer class or something? No, I think FragShader needs it? Where to put it?
|
strong |
Specifies whether orthographic or perspective projection shall be used.
|
inline |
Transforms a point from clip space ([-1, 1] x [-1, 1]) to image (screen) coordinates, i.e. the window transform. Note that the y-coordinate is flipped because the image origin is top-left while in clip space top is +1 and bottom is -1. No z-division is performed. Note: It should rather be called from NDC to screen space?
Exactly conforming to the OpenGL viewport transform, except that we flip y at the end. Qt: Origin top-left. OpenGL: bottom-left. OCV: top-left.
[in] | clip_coordinates | A point in clip coordinates. |
[in] | screen_width | Width of the screen or window. |
[in] | screen_height | Height of the screen or window. |
|
inline |
Computes the normal of a face (triangle), i.e. the per-face normal. Returned normal will be unit length.
Assumes the triangle is given in CCW order, i.e. vertices in counterclockwise order on the screen are front-facing.
[in] | v0 | First vertex. |
[in] | v1 | Second vertex. |
[in] | v2 | Third vertex. |
|
inline |
Computes the normal of a face (triangle), i.e. the per-face normal. Returned normal will be unit length.
Assumes the triangle is given in CCW order, i.e. vertices in counterclockwise order on the screen are front-facing.
[in] | v0 | First vertex. |
[in] | v1 | Second vertex. |
[in] | v2 | Third vertex. |
|
inline |
Computes the per-face (per-triangle) normals of all triangles of the given mesh. Returned normals will be unit length.
Assumes triangles are given in CCW order, i.e. vertices in counterclockwise order on the screen are front-facing.
[in] | vertices | A list of vertices. |
[in] | triangle_vertex_indices | Triangle list for the given vertices. |
Eigen::Vector3< T > eos::render::compute_inverse_perspectively_correct_lambda | ( | const Eigen::Vector3< T > & | lambda_world, |
const T & | one_over_w0, | ||
const T & | one_over_w1, | ||
const T & | one_over_w2 | ||
) |
Computes inverse perspectively correct lambda.
X. Inverts the perspective texture mapping. Can be derived using some tedious algebra. Todo: Probably move to a texturing file, internal/detail one, where we will also put the tex2d, mipmapping etc stuff?
[in] | X | X. |
|
inline |
For each given vertex, compute whether it is visible or self-occluded by the mesh formed by the given vertices and triangle indices.
Transforms the vertices into view space first using the given modelview
matrix.
[in] | vertices | A set of vertices that form a mesh. |
[in] | triangle_vertex_indices | Triangle indices corresponding to the given mesh. |
[in] | modelview | Model-view matrix, to transform the given vertices from model space to view space. |
[in] | ray_direction_type | Whether the occlusion should be computed under orthographic or perspective projection. |
|
inline |
For each given vertex, compute whether it is visible or self-occluded by the mesh formed by the given vertices and triangle indices.
The function uses simple ray casting for each vertex, and checks whether each ray intersects any other triangle. Thus, the algorithm can become quite slow for larger meshes. Depending on ray_direction_type
, the rays are either casted from each vertex along the positive z axis, or towards the origin (0, 0, 0).
[in] | viewspace_vertices | A set of vertices that form a mesh, in view-space coordinates. |
[in] | triangle_vertex_indices | Triangle indices corresponding to the given mesh. |
[in] | ray_direction_type | Whether the occlusion should be computed under orthographic or perspective projection. |
|
inline |
Computes the per-vertex normals of all vertices of the given mesh. Returned normals will be unit length.
Assumes triangles are given in CCW order, i.e. vertices in counterclockwise order on the screen are front-facing.
[in] | vertices | A list of vertices. |
[in] | triangle_vertex_indices | Triangle list for the given vertices. |
[in] | face_normals | Per-face normals for all triangles. |
|
inline |
Draws a line using the Bresenham algorithm.
From: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm I also tried this: https://www.thecrazyprogrammer.com/2017/01/bresenhams-line-drawing-algorithm-c-c.html which looks awesome, but it drew weird lines.
[in] | image | An image to draw into. |
[in] | x0 | X coordinate of the start point. |
[in] | y0 | Y coordinate of the start point. |
[in] | x1 | X coordinate of the start point. |
[in] | y1 | Y coordinate of the end point. |
[in] | color | RGB colour of the line to be drawn. |
|
inline |
Draws the texture coordinates (uv-coords) of the given mesh into an image by looping over the triangles and drawing each triangle's texcoords.
Note/Todo: This function has a slight problems, the lines do not actually get drawn blue, if the image is 8UC4. Well if I save a PNG, it is blue. Not sure.
[in] | mesh | A mesh with texture coordinates. |
[in] | image | An optional image to draw onto. |
|
inline |
Draws the given mesh as wireframe into the image.
It does backface culling, i.e. draws only vertices in CCW order.
[in] | image | An image to draw into. |
[in] | mesh | The mesh to draw. |
[in] | modelview | Model-view matrix to draw the mesh. |
[in] | projection | Projection matrix to draw the mesh. |
[in] | viewport | Viewport to draw the mesh. |
[in] | color | Colour of the mesh to be drawn, in RGB. |
|
inline |
Draws the given mesh as wireframe into the image.
It does backface culling, i.e. draws only vertices in CCW order.
Note: This function might be deprecated in the future, in favour of draw_wireframe(...) in render/draw_utils.hpp, which doesn't depend on OpenCV anymore.
[in] | image | An image to draw into. |
[in] | mesh | The mesh to draw. |
[in] | modelview | Model-view matrix to draw the mesh. |
[in] | projection | Projection matrix to draw the mesh. |
[in] | viewport | Viewport to draw the mesh. |
[in] | color | Colour of the mesh to be drawn. |
|
inline |
Extracts the texture from the given image and returns a texture map.
Remaps the texture from the given image
, using the given mesh
, projection matrices, and the mesh's uv coordinates, to a texture map.
Notes & todo's:
We perhaps should add another parameter,
Eigen::Vector4 viewport. We could need to change
clip_to_screen_space()to make use of that.
Perhaps add an overload that takes a
vector<bool> visible vertices`, for the case when we already computed the visibility? (e.g. from the edge-fitting)[in] | mesh | A mesh with texture coordinates. |
[in] | view_model_matrix | Model-view matrix, to bring the mesh into view-space. |
[in] | projection_matrix | Projection matrix, to bring the mesh into clip-space. |
[in] | projection_type | Indicates whether the projection used is orthographic or perspective. |
[in] | image | The image to extract the texture from. |
[in] | texturemap_resolution | The resolution of the generated texture map. Defaults to 512x512. |
|
inline |
Computes whether the given probe_vertex
is visible or self-occluded by the mesh formed by the given vertices and triangle indices.
The function uses simple ray casting and checks whether the ray intersects any triangle of the given mesh. Thus, the algorithm can become quite slow for larger meshes. Depending on ray_direction_type
, the rays are either casted from each vertex along the positive z axis, or towards the origin (0, 0, 0).
[in] | probe_vertex | A single vertex to compute the visibility for. |
[in] | mesh_vertices | A set of vertices that form a mesh. |
[in] | mesh_triangle_vertex_indices | Triangle indices corresponding to the given mesh. |
[in] | ray_direction_type | Whether the occlusion should be computed under orthographic or perspective projection. |
Eigen::Matrix4< T > eos::render::ortho | ( | T | left, |
T | right, | ||
T | bottom, | ||
T | top | ||
) |
Creates a 2D orthographic projection matrix.
This function sets up a two-dimensional orthographic viewing region. This is equivalent to calling glOrtho with near=-1 and far=1. The function is equivalent to glm::orthoRH_NO(), but with near=-1 and far=1.
More details can be found on the gluOrtho2D man page: https://registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/gluOrtho2D.xml.
[in] | left | Specifies the coordinates for the left vertical clipping plane. |
[in] | right | Specifies the coordinates for the right vertical clipping plane. |
[in] | bottom | Specifies the coordinates for the bottom horizontal clipping plane. |
[in] | top | Specifies the coordinates for the top horizontal clipping plane. |
T | A floating-point scalar type, ceres::Jet, or similar compatible type. |
Eigen::Matrix4< T > eos::render::ortho | ( | T | left, |
T | right, | ||
T | bottom, | ||
T | top, | ||
T | z_near, | ||
T | z_far | ||
) |
Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates.
The function follows the OpenGL clip volume definition, which is also the GLM default. The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively.
The function is equivalent to glm::orthoRH_NO(...).
[in] | left | Specifies the coordinates for the left vertical clipping plane. |
[in] | right | Specifies the coordinates for the right vertical clipping plane. |
[in] | bottom | Specifies the coordinates for the bottom horizontal clipping plane. |
[in] | top | Specifies the coordinates for the top horizontal clipping plane. |
[in] | z_near | Specifies the distance from the viewer to the near clipping plane (always positive). |
[in] | z_far | Specifies the distance from the viewer to the far clipping plane (always positive). |
T | A floating-point scalar type, ceres::Jet, or similar compatible type. |
Eigen::Matrix4< T > eos::render::perspective | ( | T | fov_y, |
T | aspect, | ||
T | z_near, | ||
T | z_far | ||
) |
Creates a matrix for a right-handed, symmetric perspective-view frustum.
The function follows the OpenGL clip volume definition, which is also the GLM default. The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively.
This function is equivalent to glm::perspectiveRH_NO(...).
More details can be found on the gluPerspective man page: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml.
[in] | fov_y | Specifies the field of view angle in the y direction. Expressed in radians. |
[in] | aspect | Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). |
[in] | z_near | Specifies the distance from the viewer to the near clipping plane (always positive). |
[in] | z_far | Specifies the distance from the viewer to the far clipping plane (always positive). |
T | A floating-point scalar type, ceres::Jet, or similar compatible type. |
Eigen::Vector3< T > eos::render::project | ( | const Eigen::Vector3< T > & | point_3d, |
const Eigen::Matrix4< T > & | modelview_matrix, | ||
const Eigen::Matrix4< T > & | projection_matrix, | ||
const Eigen::Vector4< T > & | viewport | ||
) |
Project the given point_3d (from object coordinates) into window coordinates.
The function follows the OpenGL clip volume definition. The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. This function is equivalent to glm::projectNO(...).
More details can be found on the gluProject man page: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluProject.xml.
[in] | point_3d | A 3D point in object coordinates. |
[in] | modelview_matrix | A model-view matrix, transforming the point into view (camera) space. |
[in] | projection_matrix | The projection matrix to be used. |
[in] | viewport | The viewport transformation to be used. |
T | A floating-point scalar type, ceres::Jet, or similar compatible type. |
|
inline |
Computes the intersection of the given ray with the given triangle.
Uses the Möller-Trumbore algorithm "Fast Minimum Storage Ray/Triangle Intersection". Independent implementation, inspired by: http://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection The default eps (1e-6f) is from the paper. When culling is on, rays intersecting triangles from the back will be discarded - otherwise, the triangles normal direction w.r.t. the ray direction is just ignored.
Todo: We don't need the pair<> here, we could just return optional<float>. Also, I hope optional wouldn't be a performance problem here, as this function is called loads of times.
[in] | ray_origin | Ray origin. |
[in] | ray_direction | Ray direction. |
[in] | v0 | First vertex of a triangle. |
[in] | v1 | Second vertex of a triangle. |
[in] | v2 | Third vertex of a triangle. |
[in] | enable_backculling | When culling is on, rays intersecting triangles from the back will be discarded. |
core::Image4u eos::render::render | ( | const core::Mesh & | mesh, |
const Eigen::Matrix4f & | model_view_matrix, | ||
const Eigen::Matrix4f & | projection_matrix, | ||
int | viewport_width, | ||
int | viewport_height, | ||
bool | enable_backface_culling = false , |
||
bool | enable_near_clipping = true , |
||
bool | enable_far_clipping = true |
||
) |
Convenience function that renders the given mesh onto a 2D image using SoftwareRenderer
. Conforms to OpenGL conventions.
Renders using per-vertex colouring, without texturing.
[in] | mesh | A 3D mesh. |
[in] | model_view_matrix | A 4x4 OpenGL model-view matrix. |
[in] | projection_matrix | A 4x4 orthographic or perspective OpenGL projection matrix. |
[in] | viewport_width | Screen width. |
[in] | viewport_height | Screen height. |
[in] | enable_backface_culling | Whether the renderer should perform backface culling. If true, only draw triangles with vertices ordered CCW in screen-space. |
[in] | enable_near_clipping | Whether vertices should be clipped against the near plane. |
[in] | enable_far_clipping | Whether vertices should be clipped against the far plane. |
core::Image4u eos::render::render | ( | const core::Mesh & | mesh, |
const Eigen::Matrix4f & | model_view_matrix, | ||
const Eigen::Matrix4f & | projection_matrix, | ||
int | viewport_width, | ||
int | viewport_height, | ||
Texture | texture, | ||
bool | enable_backface_culling = false , |
||
bool | enable_near_clipping = true , |
||
bool | enable_far_clipping = true |
||
) |
Convenience function that renders the given mesh onto a 2D image using SoftwareRenderer
. Conforms to OpenGL conventions.
Performs texturing using the given texture
.
[in] | mesh | A 3D mesh. |
[in] | model_view_matrix | A 4x4 OpenGL model-view matrix. |
[in] | projection_matrix | A 4x4 orthographic or perspective OpenGL projection matrix. |
[in] | viewport_width | Screen width. |
[in] | viewport_height | Screen height. |
[in] | texture | A texture map to texture the model. |
[in] | enable_backface_culling | Whether the renderer should perform backface culling. If true, only draw triangles with vertices ordered CCW in screen-space. |
[in] | enable_near_clipping | Whether vertices should be clipped against the near plane. |
[in] | enable_far_clipping | Whether vertices should be clipped against the far plane. |