22#ifndef EOS_RENDER_DRAW_UTILS_HPP
23#define EOS_RENDER_DRAW_UTILS_HPP
25#include "eos/core/Mesh.hpp"
26#include "eos/render/matrix_projection.hpp"
27#include "eos/render/detail/utils.hpp"
51 auto plot_line_low = [&image, &color](
float x0,
float y0,
float x1,
float y1) {
61 float D = 2 * dy - dx;
64 for (
int x = x0; x <= x1; ++x)
66 image(y, x) = {color[0], color[1], color[2]};
76 auto plot_line_high = [&image, &color](
float x0,
float y0,
float x1,
float y1) {
86 float D = 2 * dx - dy;
89 for (
int y = y0; y <= y1; ++y)
91 image(y, x) = {color[0], color[1], color[2]};
101 if (abs(y1 - y0) < abs(x1 - x0))
105 plot_line_low(x1, y1, x0, y0);
108 plot_line_low(x0, y0, x1, y1);
114 plot_line_high(x1, y1, x0, y0);
117 plot_line_high(x0, y0, x1, y1);
135 Eigen::Matrix4f projection, Eigen::Vector4f viewport,
136 Eigen::Vector3f color = Eigen::Vector3f(0, 255, 0))
138 for (
const auto& triangle : mesh.
tvi)
140 const auto p1 =
project(mesh.
vertices[triangle[0]], modelview, projection, viewport);
141 const auto p2 =
project(mesh.
vertices[triangle[1]], modelview, projection, viewport);
142 const auto p3 =
project(mesh.
vertices[triangle[2]], modelview, projection, viewport);
143 if (render::detail::are_vertices_ccw_in_screen_space<float>(p1.head<2>(), p2.head<2>(), p3.head<2>()))
145 draw_line(image, p1.x(), p1.y(), p2.x(), p2.y(), color);
146 draw_line(image, p2.x(), p2.y(), p3.x(), p3.y(), color);
147 draw_line(image, p3.x(), p3.y(), p1.x(), p1.y(), color);
Class to represent images.
Definition: Image.hpp:44
void draw_line(core::Image3u &image, float x0, float y0, float x1, float y1, Eigen::Vector3f color)
Definition: draw_utils.hpp:49
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)
Definition: matrix_projection.hpp:148
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))
Definition: draw_utils.hpp:134
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)
Definition: render.hpp:52
Namespace containing all of eos's 3D model fitting functionality.
This class represents a 3D mesh consisting of vertices, vertex colour information and texture coordin...
Definition: Mesh.hpp:45
std::vector< Eigen::Vector3f > vertices
3D vertex positions.
Definition: Mesh.hpp:46
std::vector< std::array< int, 3 > > tvi
Triangle vertex indices.
Definition: Mesh.hpp:50