Commit 41f0818a authored by Patrik Huber's avatar Patrik Huber

Added inline to all non-template functions

This fixes ODR violations of the headers are used in multiple translation units.

Also removed a few unnecessary eos:: namespace qualifiers to have consistent style
parent 6d33d6b7
...@@ -192,7 +192,7 @@ private: ...@@ -192,7 +192,7 @@ private:
* @param[in] filename The file to write. * @param[in] filename The file to write.
* @throws std::runtime_error if unable to open the given file for writing. * @throws std::runtime_error if unable to open the given file for writing.
*/ */
void save_rendering_parameters(RenderingParameters rendering_parameters, std::string filename) inline void save_rendering_parameters(RenderingParameters rendering_parameters, std::string filename)
{ {
std::ofstream file(filename); std::ofstream file(filename);
if (file.fail()) { if (file.fail()) {
...@@ -206,7 +206,7 @@ void save_rendering_parameters(RenderingParameters rendering_parameters, std::st ...@@ -206,7 +206,7 @@ void save_rendering_parameters(RenderingParameters rendering_parameters, std::st
* @brief Returns a glm/OpenGL compatible viewport vector that flips y and * @brief Returns a glm/OpenGL compatible viewport vector that flips y and
* has the origin on the top-left, like in OpenCV. * has the origin on the top-left, like in OpenCV.
*/ */
glm::vec4 get_opencv_viewport(int width, int height) inline glm::vec4 get_opencv_viewport(int width, int height)
{ {
return glm::vec4(0, height, width, -height); return glm::vec4(0, height, width, -height);
}; };
...@@ -217,7 +217,7 @@ glm::vec4 get_opencv_viewport(int width, int height) ...@@ -217,7 +217,7 @@ glm::vec4 get_opencv_viewport(int width, int height)
* Note: I think the last use of this function is below in * Note: I think the last use of this function is below in
* get_3x4_affine_camera_matrix(). * get_3x4_affine_camera_matrix().
*/ */
cv::Mat to_mat(const glm::mat4x4& glm_matrix) inline cv::Mat to_mat(const glm::mat4x4& glm_matrix)
{ {
// glm stores its matrices in col-major order in memory, OpenCV in row-major order. // glm stores its matrices in col-major order in memory, OpenCV in row-major order.
// Hence we transpose the glm matrix to flip the memory layout, and then point OpenCV // Hence we transpose the glm matrix to flip the memory layout, and then point OpenCV
...@@ -235,7 +235,7 @@ cv::Mat to_mat(const glm::mat4x4& glm_matrix) ...@@ -235,7 +235,7 @@ cv::Mat to_mat(const glm::mat4x4& glm_matrix)
* This function is mainly used since the linear shape fitting fitting::fit_shape_to_landmarks_linear * This function is mainly used since the linear shape fitting fitting::fit_shape_to_landmarks_linear
* expects one of these 3x4 affine camera matrices, as well as render::extract_texture. * expects one of these 3x4 affine camera matrices, as well as render::extract_texture.
*/ */
cv::Mat get_3x4_affine_camera_matrix(fitting::RenderingParameters params, int width, int height) inline cv::Mat get_3x4_affine_camera_matrix(RenderingParameters params, int width, int height)
{ {
auto view_model = to_mat(params.get_modelview()); auto view_model = to_mat(params.get_modelview());
auto ortho_projection = to_mat(params.get_projection()); auto ortho_projection = to_mat(params.get_projection());
......
...@@ -50,7 +50,7 @@ namespace eos { ...@@ -50,7 +50,7 @@ namespace eos {
* @param[in] model_points Corresponding points of a 3D model. * @param[in] model_points Corresponding points of a 3D model.
* @return A 3x4 affine camera matrix (the third row is [0, 0, 0, 1]). * @return A 3x4 affine camera matrix (the third row is [0, 0, 0, 1]).
*/ */
cv::Mat estimate_affine_camera(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points) inline cv::Mat estimate_affine_camera(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points)
{ {
using cv::Mat; using cv::Mat;
assert(image_points.size() == model_points.size()); assert(image_points.size() == model_points.size());
......
...@@ -46,8 +46,7 @@ namespace eos { ...@@ -46,8 +46,7 @@ namespace eos {
struct ModelContour; struct ModelContour;
struct ContourLandmarks; struct ContourLandmarks;
std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_angle, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour); std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_angle, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour);
std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_nearest_contour_correspondences(const eos::core::LandmarkCollection<cv::Vec2f>& landmarks, const std::vector<std::string>& landmark_contour_identifiers, const std::vector<int>& model_contour_indices, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport); std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_nearest_contour_correspondences(const core::LandmarkCollection<cv::Vec2f>& landmarks, const std::vector<std::string>& landmark_contour_identifiers, const std::vector<int>& model_contour_indices, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport);
/** /**
* @brief Definition of the vertex indices that define the right and left model contour. * @brief Definition of the vertex indices that define the right and left model contour.
...@@ -199,7 +198,7 @@ struct ContourLandmarks ...@@ -199,7 +198,7 @@ struct ContourLandmarks
* @param[in] viewport Current viewport to use. * @param[in] viewport Current viewport to use.
* @return A tuple with the 2D contour landmark points, the corresponding points in the 3D shape model and their vertex indices. * @return A tuple with the 2D contour landmark points, the corresponding points in the 3D shape model and their vertex indices.
*/ */
std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_contour_correspondences(const eos::core::LandmarkCollection<cv::Vec2f>& landmarks, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour, float yaw_angle, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport) inline std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_contour_correspondences(const core::LandmarkCollection<cv::Vec2f>& landmarks, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour, float yaw_angle, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport)
{ {
// Select which side of the contour we'll use: // Select which side of the contour we'll use:
std::vector<int> model_contour_indices; std::vector<int> model_contour_indices;
...@@ -231,7 +230,7 @@ std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get ...@@ -231,7 +230,7 @@ std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get
* @param[in] model_contour The model contour indices that should be used/considered to find the closest corresponding 3D vertex. * @param[in] model_contour The model contour indices that should be used/considered to find the closest corresponding 3D vertex.
* @return A pair with two vectors containing the selected 2D image contour landmark ids and the 3D model contour indices. * @return A pair with two vectors containing the selected 2D image contour landmark ids and the 3D model contour indices.
*/ */
std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_angle, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour) inline std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_angle, const ContourLandmarks& contour_landmarks, const ModelContour& model_contour)
{ {
std::vector<int> model_contour_indices; std::vector<int> model_contour_indices;
std::vector<std::string> contour_landmark_identifiers; std::vector<std::string> contour_landmark_identifiers;
...@@ -270,7 +269,7 @@ std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_a ...@@ -270,7 +269,7 @@ std::pair<std::vector<std::string>, std::vector<int>> select_contour(float yaw_a
* @param[in] viewport Current viewport to use. * @param[in] viewport Current viewport to use.
* @return A tuple with the 2D contour landmark points, the corresponding points in the 3D shape model and their vertex indices. * @return A tuple with the 2D contour landmark points, the corresponding points in the 3D shape model and their vertex indices.
*/ */
std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_nearest_contour_correspondences(const eos::core::LandmarkCollection<cv::Vec2f>& landmarks, const std::vector<std::string>& landmark_contour_identifiers, const std::vector<int>& model_contour_indices, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport) inline std::tuple<std::vector<cv::Vec2f>, std::vector<cv::Vec4f>, std::vector<int>> get_nearest_contour_correspondences(const core::LandmarkCollection<cv::Vec2f>& landmarks, const std::vector<std::string>& landmark_contour_identifiers, const std::vector<int>& model_contour_indices, const morphablemodel::MorphableModel& morphable_model, const glm::mat4x4& view_model, const glm::mat4x4& ortho_projection, const glm::vec4& viewport)
{ {
// These are the additional contour-correspondences we're going to find and then use! // These are the additional contour-correspondences we're going to find and then use!
std::vector<cv::Vec4f> model_points_cnt; // the points in the 3D shape model std::vector<cv::Vec4f> model_points_cnt; // the points in the 3D shape model
......
...@@ -38,7 +38,7 @@ namespace eos { ...@@ -38,7 +38,7 @@ namespace eos {
// ret: 3rd entry is the z // ret: 3rd entry is the z
// radians // radians
// expects the landmark points to be in opencv convention, i.e. origin TL // expects the landmark points to be in opencv convention, i.e. origin TL
glm::vec3 project_ortho(glm::vec3 point, float rot_x_pitch, float rot_y_yaw, float rot_z_roll, float tx, float ty, float frustum_scale, /* fixed params now: */ int width, int height) inline glm::vec3 project_ortho(glm::vec3 point, float rot_x_pitch, float rot_y_yaw, float rot_z_roll, float tx, float ty, float frustum_scale, /* fixed params now: */ int width, int height)
{ {
// We could use quaternions in here, to be independent of the RPY... etc convention. // We could use quaternions in here, to be independent of the RPY... etc convention.
// Then, the user can decompose the quaternion as he wishes to. But then we'd have to estimate 4 parameters? // Then, the user can decompose the quaternion as he wishes to. But then we'd have to estimate 4 parameters?
......
...@@ -55,7 +55,7 @@ namespace eos { ...@@ -55,7 +55,7 @@ namespace eos {
* @param[out] blendshape_coefficients Output parameter that will contain the resulting blendshape coefficients. * @param[out] blendshape_coefficients Output parameter that will contain the resulting blendshape coefficients.
* @return The fitted model shape instance. * @return The fitted model shape instance.
*/ */
cv::Mat fit_shape(cv::Mat affine_camera_matrix, eos::morphablemodel::MorphableModel morphable_model, std::vector<eos::morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices, float lambda, boost::optional<int> num_coefficients_to_fit, std::vector<float>& pca_shape_coefficients, std::vector<float>& blendshape_coefficients) inline cv::Mat fit_shape(cv::Mat affine_camera_matrix, morphablemodel::MorphableModel morphable_model, std::vector<morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices, float lambda, boost::optional<int> num_coefficients_to_fit, std::vector<float>& pca_shape_coefficients, std::vector<float>& blendshape_coefficients)
{ {
using cv::Mat; using cv::Mat;
...@@ -105,7 +105,7 @@ cv::Mat fit_shape(cv::Mat affine_camera_matrix, eos::morphablemodel::MorphableMo ...@@ -105,7 +105,7 @@ cv::Mat fit_shape(cv::Mat affine_camera_matrix, eos::morphablemodel::MorphableMo
* @param[in] num_coefficients_to_fit How many shape-coefficients to fit (all others will stay 0). Should be bigger than zero, or boost::none to fit all coefficients. * @param[in] num_coefficients_to_fit How many shape-coefficients to fit (all others will stay 0). Should be bigger than zero, or boost::none to fit all coefficients.
* @return The fitted model shape instance. * @return The fitted model shape instance.
*/ */
cv::Mat fit_shape(cv::Mat affine_camera_matrix, eos::morphablemodel::MorphableModel morphable_model, std::vector<eos::morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices, float lambda = 3.0f, boost::optional<int> num_coefficients_to_fit = boost::optional<int>()) inline cv::Mat fit_shape(cv::Mat affine_camera_matrix, morphablemodel::MorphableModel morphable_model, std::vector<morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices, float lambda = 3.0f, boost::optional<int> num_coefficients_to_fit = boost::optional<int>())
{ {
std::vector<float> unused; std::vector<float> unused;
return fit_shape(affine_camera_matrix, morphable_model, blendshapes, image_points, vertex_indices, lambda, num_coefficients_to_fit, unused, unused); return fit_shape(affine_camera_matrix, morphable_model, blendshapes, image_points, vertex_indices, lambda, num_coefficients_to_fit, unused, unused);
......
...@@ -62,7 +62,7 @@ namespace eos { ...@@ -62,7 +62,7 @@ namespace eos {
* @param[in] height Height of the image (or viewport). * @param[in] height Height of the image (or viewport).
* @return The estimated model and camera parameters. * @return The estimated model and camera parameters.
*/ */
RenderingParameters estimate_orthographic_camera(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points, int width, int height) inline RenderingParameters estimate_orthographic_camera(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points, int width, int height)
{ {
using cv::Mat; using cv::Mat;
assert(image_points.size() == model_points.size()); assert(image_points.size() == model_points.size());
......
...@@ -67,7 +67,7 @@ struct ScaledOrthoProjectionParameters { ...@@ -67,7 +67,7 @@ struct ScaledOrthoProjectionParameters {
* @param[in] viewport_height Height of the viewport of the image points (needs to be given if is_viewport_upsidedown == true). * @param[in] viewport_height Height of the viewport of the image points (needs to be given if is_viewport_upsidedown == true).
* @return Rotation, translation and scaling of the estimated scaled orthographic projection. * @return Rotation, translation and scaling of the estimated scaled orthographic projection.
*/ */
ScaledOrthoProjectionParameters estimate_orthographic_projection_linear(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points, bool is_viewport_upsidedown, boost::optional<int> viewport_height = boost::none) inline ScaledOrthoProjectionParameters estimate_orthographic_projection_linear(std::vector<cv::Vec2f> image_points, std::vector<cv::Vec4f> model_points, bool is_viewport_upsidedown, boost::optional<int> viewport_height = boost::none)
{ {
using cv::Mat; using cv::Mat;
assert(image_points.size() == model_points.size()); assert(image_points.size() == model_points.size());
......
...@@ -69,7 +69,7 @@ struct Blendshape ...@@ -69,7 +69,7 @@ struct Blendshape
* @return The loaded blendshapes. * @return The loaded blendshapes.
* @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist). * @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist).
*/ */
std::vector<Blendshape> load_blendshapes(std::string filename) inline std::vector<Blendshape> load_blendshapes(std::string filename)
{ {
std::vector<Blendshape> blendshapes; std::vector<Blendshape> blendshapes;
...@@ -89,7 +89,7 @@ std::vector<Blendshape> load_blendshapes(std::string filename) ...@@ -89,7 +89,7 @@ std::vector<Blendshape> load_blendshapes(std::string filename)
* @param[in] blendshapes Vector of blendshapes. * @param[in] blendshapes Vector of blendshapes.
* @return The resulting matrix. * @return The resulting matrix.
*/ */
cv::Mat to_matrix(const std::vector<Blendshape>& blendshapes) inline cv::Mat to_matrix(const std::vector<Blendshape>& blendshapes)
{ {
// assert: all blendshapes have to have the same number of rows, and one col // assert: all blendshapes have to have the same number of rows, and one col
assert(blendshapes.size() > 0); assert(blendshapes.size() > 0);
......
...@@ -268,7 +268,7 @@ private: ...@@ -268,7 +268,7 @@ private:
* @return The loaded Morphable Model. * @return The loaded Morphable Model.
* @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist). * @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist).
*/ */
MorphableModel load_model(std::string filename) inline MorphableModel load_model(std::string filename)
{ {
MorphableModel model; MorphableModel model;
...@@ -289,7 +289,7 @@ MorphableModel load_model(std::string filename) ...@@ -289,7 +289,7 @@ MorphableModel load_model(std::string filename)
* @param[in] model The model to be saved. * @param[in] model The model to be saved.
* @param[in] filename Filename for the model. * @param[in] filename Filename for the model.
*/ */
void save_model(MorphableModel model, std::string filename) inline void save_model(MorphableModel model, std::string filename)
{ {
std::ofstream file(filename, std::ios::binary); std::ofstream file(filename, std::ios::binary);
cereal::BinaryOutputArchive output_archive(file); cereal::BinaryOutputArchive output_archive(file);
...@@ -312,13 +312,13 @@ namespace detail { /* eos::morphablemodel::detail */ ...@@ -312,13 +312,13 @@ namespace detail { /* eos::morphablemodel::detail */
* @param[in] texture_coordinates Optional texture coordinates for each vertex. * @param[in] texture_coordinates Optional texture coordinates for each vertex.
* @return A mesh created from given parameters. * @return A mesh created from given parameters.
*/ */
eos::render::Mesh sample_to_mesh(cv::Mat shape, cv::Mat color, std::vector<std::array<int, 3>> tvi, std::vector<std::array<int, 3>> tci, std::vector<cv::Vec2f> texture_coordinates /* = std::vector<cv::Vec2f>() */) inline render::Mesh sample_to_mesh(cv::Mat shape, cv::Mat color, std::vector<std::array<int, 3>> tvi, std::vector<std::array<int, 3>> tci, std::vector<cv::Vec2f> texture_coordinates /* = std::vector<cv::Vec2f>() */)
{ {
assert(shape.rows == color.rows || color.empty()); // The number of vertices (= model.getDataDimension() / 3) has to be equal for both models, or, alternatively, it has to be a shape-only model. assert(shape.rows == color.rows || color.empty()); // The number of vertices (= model.getDataDimension() / 3) has to be equal for both models, or, alternatively, it has to be a shape-only model.
auto num_vertices = shape.rows / 3; auto num_vertices = shape.rows / 3;
eos::render::Mesh mesh; render::Mesh mesh;
// Construct the mesh vertices: // Construct the mesh vertices:
mesh.vertices.resize(num_vertices); mesh.vertices.resize(num_vertices);
......
...@@ -38,7 +38,7 @@ namespace eos { ...@@ -38,7 +38,7 @@ namespace eos {
* @param[in] filename The file to write. * @param[in] filename The file to write.
* @throws std::runtime_error if unable to open the given file for writing. * @throws std::runtime_error if unable to open the given file for writing.
*/ */
void save_coefficients(std::vector<float> coefficients, std::string filename) inline void save_coefficients(std::vector<float> coefficients, std::string filename)
{ {
std::ofstream file(filename); std::ofstream file(filename);
if (file.fail()) { if (file.fail()) {
......
...@@ -56,7 +56,7 @@ std::vector<cv::Vec2f> load_isomap(boost::filesystem::path isomap_file); ...@@ -56,7 +56,7 @@ std::vector<cv::Vec2f> load_isomap(boost::filesystem::path isomap_file);
* @return The Morphable Model loaded from the file. * @return The Morphable Model loaded from the file.
* @throws ... * @throws ...
*/ */
MorphableModel load_scm_model(boost::filesystem::path model_filename, boost::filesystem::path isomap_file = boost::filesystem::path()) inline MorphableModel load_scm_model(boost::filesystem::path model_filename, boost::filesystem::path isomap_file = boost::filesystem::path())
{ {
using cv::Mat; using cv::Mat;
if (sizeof(unsigned int) != 4) { // note/todo: maybe use uint32 or similar instead? Yep, but still we could encounter endianness-trouble. if (sizeof(unsigned int) != 4) { // note/todo: maybe use uint32 or similar instead? Yep, but still we could encounter endianness-trouble.
...@@ -228,7 +228,7 @@ MorphableModel load_scm_model(boost::filesystem::path model_filename, boost::fil ...@@ -228,7 +228,7 @@ MorphableModel load_scm_model(boost::filesystem::path model_filename, boost::fil
* @return The 2D texture coordinates for every vertex. * @return The 2D texture coordinates for every vertex.
* @throws ... * @throws ...
*/ */
std::vector<cv::Vec2f> load_isomap(boost::filesystem::path isomapFile) inline std::vector<cv::Vec2f> load_isomap(boost::filesystem::path isomapFile)
{ {
using std::string; using std::string;
std::vector<float> xCoords, yCoords; std::vector<float> xCoords, yCoords;
......
...@@ -48,7 +48,7 @@ namespace eos { ...@@ -48,7 +48,7 @@ namespace eos {
* @param[in] affine_camera_matrix A 3x4 affine camera matrix. * @param[in] affine_camera_matrix A 3x4 affine camera matrix.
* @return The matrix with a third row inserted. * @return The matrix with a third row inserted.
*/ */
cv::Mat calculate_affine_z_direction(cv::Mat affine_camera_matrix) inline cv::Mat calculate_affine_z_direction(cv::Mat affine_camera_matrix)
{ {
using cv::Mat; using cv::Mat;
// Take the cross product of row 0 with row 1 to get the direction perpendicular to the viewing plane (= the viewing direction). // Take the cross product of row 0 with row 1 to get the direction perpendicular to the viewing plane (= the viewing direction).
...@@ -93,7 +93,7 @@ cv::Mat calculate_affine_z_direction(cv::Mat affine_camera_matrix) ...@@ -93,7 +93,7 @@ cv::Mat calculate_affine_z_direction(cv::Mat affine_camera_matrix)
* @param[in] colourbuffer The colour buffer to draw into. * @param[in] colourbuffer The colour buffer to draw into.
* @param[in] depthbuffer The depth buffer to draw into and use for the depth test. * @param[in] depthbuffer The depth buffer to draw into and use for the depth test.
*/ */
void raster_triangle_affine(TriangleToRasterize triangle, cv::Mat colourbuffer, cv::Mat depthbuffer) inline void raster_triangle_affine(TriangleToRasterize triangle, cv::Mat colourbuffer, cv::Mat depthbuffer)
{ {
for (int yi = triangle.min_y; yi <= triangle.max_y; ++yi) for (int yi = triangle.min_y; yi <= triangle.max_y; ++yi)
{ {
......
...@@ -231,7 +231,7 @@ double implicit_line(float x, float y, const glm::tvec4<T, P>& v1, const glm::tv ...@@ -231,7 +231,7 @@ double implicit_line(float x, float y, const glm::tvec4<T, P>& v1, const glm::tv
return ((double)v1[1] - (double)v2[1])*(double)x + ((double)v2[0] - (double)v1[0])*(double)y + (double)v1[0] * (double)v2[1] - (double)v2[0] * (double)v1[1]; return ((double)v1[1] - (double)v2[1])*(double)x + ((double)v2[0] - (double)v1[0])*(double)y + (double)v1[0] * (double)v2[1] - (double)v2[0] * (double)v1[1];
}; };
std::vector<Vertex> clip_polygon_to_plane_in_4d(const std::vector<Vertex>& vertices, const glm::tvec4<float>& plane_normal) inline std::vector<Vertex> clip_polygon_to_plane_in_4d(const std::vector<Vertex>& vertices, const glm::tvec4<float>& plane_normal)
{ {
std::vector<Vertex> clippedVertices; std::vector<Vertex> clippedVertices;
...@@ -281,12 +281,12 @@ std::vector<Vertex> clip_polygon_to_plane_in_4d(const std::vector<Vertex>& verti ...@@ -281,12 +281,12 @@ std::vector<Vertex> clip_polygon_to_plane_in_4d(const std::vector<Vertex>& verti
// used only in tex2D_linear_mipmap_linear // used only in tex2D_linear_mipmap_linear
// template? // template?
float clamp(float x, float a, float b) inline float clamp(float x, float a, float b)
{ {
return std::max(std::min(x, b), a); return std::max(std::min(x, b), a);
}; };
cv::Vec2f texcoord_wrap(const cv::Vec2f& texcoords) inline cv::Vec2f texcoord_wrap(const cv::Vec2f& texcoords)
{ {
return cv::Vec2f(texcoords[0] - (int)texcoords[0], texcoords[1] - (int)texcoords[1]); return cv::Vec2f(texcoords[0] - (int)texcoords[0], texcoords[1] - (int)texcoords[1]);
}; };
...@@ -295,7 +295,7 @@ cv::Vec2f texcoord_wrap(const cv::Vec2f& texcoords) ...@@ -295,7 +295,7 @@ cv::Vec2f texcoord_wrap(const cv::Vec2f& texcoords)
cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy); cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy);
cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmapIndex, const Texture& texture); cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmapIndex, const Texture& texture);
cv::Vec3f tex2d(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy) inline cv::Vec3f tex2d(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy)
{ {
return (1.0f / 255.0f) * tex2d_linear_mipmap_linear(texcoords, texture, dudx, dudy, dvdx, dvdy); return (1.0f / 255.0f) * tex2d_linear_mipmap_linear(texcoords, texture, dudx, dudy, dvdx, dvdy);
}; };
...@@ -308,7 +308,7 @@ glm::tvec3<T, P> tex2d(const glm::tvec2<T, P>& texcoords, const Texture& texture ...@@ -308,7 +308,7 @@ glm::tvec3<T, P> tex2d(const glm::tvec2<T, P>& texcoords, const Texture& texture
return glm::tvec3<T, P>(ret[0], ret[1], ret[2]); return glm::tvec3<T, P>(ret[0], ret[1], ret[2]);
}; };
cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy) inline cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture& texture, float dudx, float dudy, float dvdx, float dvdy)
{ {
using cv::Vec2f; using cv::Vec2f;
float px = std::sqrt(std::pow(dudx, 2) + std::pow(dvdx, 2)); float px = std::sqrt(std::pow(dudx, 2) + std::pow(dvdx, 2));
...@@ -335,7 +335,7 @@ cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture& ...@@ -335,7 +335,7 @@ cv::Vec3f tex2d_linear_mipmap_linear(const cv::Vec2f& texcoords, const Texture&
return color; return color;
}; };
cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmap_index, const Texture& texture) inline cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmap_index, const Texture& texture)
{ {
int x = (int)imageTexCoord[0]; int x = (int)imageTexCoord[0];
int y = (int)imageTexCoord[1]; int y = (int)imageTexCoord[1];
...@@ -387,7 +387,7 @@ cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmap_inde ...@@ -387,7 +387,7 @@ cv::Vec3f tex2d_linear(const cv::Vec2f& imageTexCoord, unsigned char mipmap_inde
// Todo: Split this function into the general (core-part) and the texturing part. // Todo: Split this function into the general (core-part) and the texturing part.
// Then, utils::extractTexture can re-use the core-part. // Then, utils::extractTexture can re-use the core-part.
// Note: Maybe a bit outdated "todo" above. // Note: Maybe a bit outdated "todo" above.
boost::optional<TriangleToRasterize> process_prospective_tri(Vertex v0, Vertex v1, Vertex v2, int viewport_width, int viewport_height, bool enable_backface_culling) inline boost::optional<TriangleToRasterize> process_prospective_tri(Vertex v0, Vertex v1, Vertex v2, int viewport_width, int viewport_height, bool enable_backface_culling)
{ {
using cv::Vec2f; using cv::Vec2f;
using cv::Vec3f; using cv::Vec3f;
...@@ -464,7 +464,7 @@ boost::optional<TriangleToRasterize> process_prospective_tri(Vertex v0, Vertex v ...@@ -464,7 +464,7 @@ boost::optional<TriangleToRasterize> process_prospective_tri(Vertex v0, Vertex v
return boost::optional<TriangleToRasterize>(t); return boost::optional<TriangleToRasterize>(t);
}; };
void raster_triangle(TriangleToRasterize triangle, cv::Mat colourbuffer, cv::Mat depthbuffer, boost::optional<Texture> texture, bool enable_far_clipping) inline void raster_triangle(TriangleToRasterize triangle, cv::Mat colourbuffer, cv::Mat depthbuffer, boost::optional<Texture> texture, bool enable_far_clipping)
{ {
using cv::Vec2f; using cv::Vec2f;
using cv::Vec3f; using cv::Vec3f;
......
...@@ -88,7 +88,7 @@ inline bool is_point_in_triangle(cv::Point2f point, cv::Point2f triV0, cv::Point ...@@ -88,7 +88,7 @@ inline bool is_point_in_triangle(cv::Point2f point, cv::Point2f triV0, cv::Point
* @param[in] depthbuffer Pre-calculated depthbuffer. * @param[in] depthbuffer Pre-calculated depthbuffer.
* @return True if the whole triangle is visible in the image. * @return True if the whole triangle is visible in the image.
*/ */
bool is_triangle_visible(const glm::tvec4<float>& v0, const glm::tvec4<float>& v1, const glm::tvec4<float>& v2, cv::Mat depthbuffer) inline bool is_triangle_visible(const glm::tvec4<float>& v0, const glm::tvec4<float>& v1, const glm::tvec4<float>& v2, cv::Mat depthbuffer)
{ {
// #Todo: Actually, only check the 3 vertex points, don't loop over the pixels - this should be enough. // #Todo: Actually, only check the 3 vertex points, don't loop over the pixels - this should be enough.
......
...@@ -122,7 +122,7 @@ namespace eos { ...@@ -122,7 +122,7 @@ namespace eos {
* @param[in] enable_far_clipping Whether vertices should be clipped against the far plane. * @param[in] enable_far_clipping Whether vertices should be clipped against the far plane.
* @return A pair with the colourbuffer as its first element and the depthbuffer as the second element. * @return A pair with the colourbuffer as its first element and the depthbuffer as the second element.
*/ */
std::pair<cv::Mat, cv::Mat> render(Mesh mesh, glm::tmat4x4<float> model_view_matrix, glm::tmat4x4<float> projection_matrix, int viewport_width, int viewport_height, const boost::optional<Texture>& texture = boost::none, bool enable_backface_culling = false, bool enable_near_clipping = true, bool enable_far_clipping = true) inline std::pair<cv::Mat, cv::Mat> render(Mesh mesh, glm::tmat4x4<float> model_view_matrix, glm::tmat4x4<float> projection_matrix, int viewport_width, int viewport_height, const boost::optional<Texture>& texture = boost::none, bool enable_backface_culling = false, bool enable_near_clipping = true, bool enable_far_clipping = true)
{ {
// Some internal documentation / old todos or notes: // Some internal documentation / old todos or notes:
// maybe change and pass depthBuffer as an optional arg (&?), because usually we never need it outside the renderer. Or maybe even a getDepthBuffer(). // maybe change and pass depthBuffer as an optional arg (&?), because usually we never need it outside the renderer. Or maybe even a getDepthBuffer().
......
...@@ -53,7 +53,7 @@ namespace eos { ...@@ -53,7 +53,7 @@ namespace eos {
* @param[in] do_backface_culling Whether the renderer should perform backface culling. * @param[in] do_backface_culling Whether the renderer should perform backface culling.
* @return A pair with the colourbuffer as its first element and the depthbuffer as the second element. * @return A pair with the colourbuffer as its first element and the depthbuffer as the second element.
*/ */
std::pair<cv::Mat, cv::Mat> render_affine(Mesh mesh, cv::Mat affine_camera_matrix, int viewport_width, int viewport_height, bool do_backface_culling = true) inline std::pair<cv::Mat, cv::Mat> render_affine(Mesh mesh, cv::Mat affine_camera_matrix, int viewport_width, int viewport_height, bool do_backface_culling = true)
{ {
assert(mesh.vertices.size() == mesh.colors.size() || mesh.colors.empty()); // The number of vertices has to be equal for both shape and colour, or, alternatively, it has to be a shape-only model. assert(mesh.vertices.size() == mesh.colors.size() || mesh.colors.empty()); // The number of vertices has to be equal for both shape and colour, or, alternatively, it has to be a shape-only model.
//assert(mesh.vertices.size() == mesh.texcoords.size() || mesh.texcoords.empty()); // same for the texcoords //assert(mesh.vertices.size() == mesh.texcoords.size() || mesh.texcoords.empty()); // same for the texcoords
......
...@@ -50,7 +50,7 @@ enum class TextureInterpolation { ...@@ -50,7 +50,7 @@ enum class TextureInterpolation {
}; };
// Forward declarations: // Forward declarations:
inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat image, cv::Mat depthbuffer, bool compute_view_angle, TextureInterpolation mapping_type, int isomap_resolution); cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat image, cv::Mat depthbuffer, bool compute_view_angle, TextureInterpolation mapping_type, int isomap_resolution);
namespace detail { cv::Mat interpolate_black_line(cv::Mat isomap); } namespace detail { cv::Mat interpolate_black_line(cv::Mat isomap); }
/** /**
...@@ -353,7 +353,7 @@ namespace detail { ...@@ -353,7 +353,7 @@ namespace detail {
// manifest themselves as black lines in the final isomap. This function // manifest themselves as black lines in the final isomap. This function
// just fills these missing values by interpolating between two neighbouring // just fills these missing values by interpolating between two neighbouring
// pixels. See GitHub issue #4. // pixels. See GitHub issue #4.
cv::Mat interpolate_black_line(cv::Mat isomap) inline cv::Mat interpolate_black_line(cv::Mat isomap)
{ {
assert(isomap.type() == CV_8UC4); assert(isomap.type() == CV_8UC4);
// Replace the vertical black line ("missing data"): // Replace the vertical black line ("missing data"):
......
...@@ -92,7 +92,7 @@ inline cv::Vec2f screen_to_clip_space(const cv::Vec2f& screen_coordinates, int s ...@@ -92,7 +92,7 @@ inline cv::Vec2f screen_to_clip_space(const cv::Vec2f& screen_coordinates, int s
* @param[in] v2 Third vertex. * @param[in] v2 Third vertex.
* @return The unit-length normal of the given triangle. * @return The unit-length normal of the given triangle.
*/ */
cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const cv::Vec3f& v2) inline cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const cv::Vec3f& v2)
{ {
cv::Vec3f n = (v1 - v0).cross(v2 - v0); // v0-to-v1 x v0-to-v2 cv::Vec3f n = (v1 - v0).cross(v2 - v0); // v0-to-v1 x v0-to-v2
n /= cv::norm(n); n /= cv::norm(n);
...@@ -108,7 +108,7 @@ cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const ...@@ -108,7 +108,7 @@ cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const
* @param[in] image An optional image to draw onto. * @param[in] image An optional image to draw onto.
* @return An image with the texture coordinate triangles drawn in it, 512x512 if no image is given. * @return An image with the texture coordinate triangles drawn in it, 512x512 if no image is given.
*/ */
cv::Mat draw_texcoords(Mesh mesh, cv::Mat image = cv::Mat()) inline cv::Mat draw_texcoords(Mesh mesh, cv::Mat image = cv::Mat())
{ {
using cv::Point2f; using cv::Point2f;
using cv::Scalar; using cv::Scalar;
...@@ -126,7 +126,7 @@ cv::Mat draw_texcoords(Mesh mesh, cv::Mat image = cv::Mat()) ...@@ -126,7 +126,7 @@ cv::Mat draw_texcoords(Mesh mesh, cv::Mat image = cv::Mat())
}; };
// TODO: Should go to detail:: namespace, or texturing/utils or whatever. // TODO: Should go to detail:: namespace, or texturing/utils or whatever.
unsigned int get_max_possible_mipmaps_num(unsigned int width, unsigned int height) inline unsigned int get_max_possible_mipmaps_num(unsigned int width, unsigned int height)
{ {
unsigned int mipmapsNum = 1; unsigned int mipmapsNum = 1;
unsigned int size = std::max(width, height); unsigned int size = std::max(width, height);
...@@ -165,7 +165,8 @@ public: ...@@ -165,7 +165,8 @@ public:
}; };
// throws: ocv exc, runtime_ex // throws: ocv exc, runtime_ex
Texture create_mipmapped_texture(cv::Mat image, unsigned int mipmapsNum = 0) { inline Texture create_mipmapped_texture(cv::Mat image, unsigned int mipmapsNum = 0)
{
assert(image.type() == CV_8UC3 || image.type() == CV_8UC4); assert(image.type() == CV_8UC3 || image.type() == CV_8UC4);
Texture texture; Texture texture;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment