Commit 94aaf7a9 authored by Patrik Huber's avatar Patrik Huber

Added Matlab bindings for render() function

The diff looks really weird because I clang-formatted the whole document. But there should be no changes in extract_texture, except for tabs->spaces.
parent 60eae2ea
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "eos/core/Mesh.hpp" #include "eos/core/Mesh.hpp"
#include "eos/fitting/RenderingParameters.hpp" #include "eos/fitting/RenderingParameters.hpp"
#include "eos/render/texture_extraction.hpp" #include "eos/render/texture_extraction.hpp"
#include "eos/render/render.hpp"
#include "mexplus_opencv.hpp" #include "mexplus_opencv.hpp"
#include "mexplus_eos_types.hpp" #include "mexplus_eos_types.hpp"
...@@ -34,35 +35,71 @@ ...@@ -34,35 +35,71 @@
using namespace eos; using namespace eos;
using namespace mexplus; using namespace mexplus;
MEX_DEFINE(extract_texture) (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) MEX_DEFINE(extract_texture)(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
// Check for proper number of input and output arguments:
if (nrhs != 5)
{
mexErrMsgIdAndTxt("eos:render:nargin", "extract_texture requires 5 input arguments.");
}
if (nlhs != 1)
{
mexErrMsgIdAndTxt("eos:render:nargout", "extract_texture returns one output argument.");
}
InputArguments input(nrhs, prhs, 5);
const auto mesh = input.get<core::Mesh>(0);
const auto rendering_params = input.get<fitting::RenderingParameters>(1);
const auto image = input.get<cv::Mat>(2);
const auto compute_view_angle = input.get<bool>(3); // default: false
const auto isomap_resolution = input.get<int>(4); // default: 512
// We expect to be given a RGB image. Let's convert it to BGR for OpenCV.
// Actually, it doesn't matter at all for the texture extraction - just keep it!
// cv::Mat image_as_bgr;// = image.clone();
// cv::cvtColor(image, image_as_bgr, cv::COLOR_RGB2BGR);
// Now do the actual extraction:
const cv::Mat affine_from_ortho =
fitting::get_3x4_affine_camera_matrix(rendering_params, image.cols, image.rows);
const cv::Mat isomap =
render::extract_texture(mesh, affine_from_ortho, image, compute_view_angle,
render::TextureInterpolation::NearestNeighbour, isomap_resolution);
// Return the extracted texturemap:
OutputArguments output(nlhs, plhs, 1);
output.set(0, isomap);
};
MEX_DEFINE(render)(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{ {
// Check for proper number of input and output arguments: // Check for proper number of input and output arguments:
if (nrhs != 5) { if (nrhs != 6)
mexErrMsgIdAndTxt("eos:render:nargin", "extract_texture requires 5 input arguments."); {
mexErrMsgIdAndTxt("eos:render:nargin", "render requires 6 input arguments.");
} }
if (nlhs != 1) { if (nlhs != 2)
mexErrMsgIdAndTxt("eos:render:nargout", "extract_texture returns one output argument."); {
mexErrMsgIdAndTxt("eos:render:nargout", "render returns two output arguments.");
} }
InputArguments input(nrhs, prhs, 5); InputArguments input(nrhs, prhs, 6);
const auto mesh = input.get<core::Mesh>(0); const auto mesh = input.get<core::Mesh>(0);
const auto rendering_params = input.get<fitting::RenderingParameters>(1); const auto modelview_matrix = input.get<glm::mat4x4>(1);
const auto image = input.get<cv::Mat>(2); const auto projection_matrix = input.get<glm::mat4x4>(2);
const auto compute_view_angle = input.get<bool>(3); // default: false const auto image_width = input.get<int>(3);
const auto isomap_resolution = input.get<int>(4); // default: 512 const auto image_height = input.get<int>(4);
const auto texture = input.get<cv::Mat>(5);
// We expect to be given a RGB image. Let's convert it to BGR for OpenCV. cv::Mat colorbuffer, depthbuffer;
// Actually, it doesn't matter at all for the texture extraction - just keep it! std::tie(colorbuffer, depthbuffer) =
//cv::Mat image_as_bgr;// = image.clone(); render::render(mesh, modelview_matrix, projection_matrix, image_width, image_height,
//cv::cvtColor(image, image_as_bgr, cv::COLOR_RGB2BGR); render::create_mipmapped_texture(texture), true, false,
false); // backface culling = true, near & far plane clipping = false
// Now do the actual extraction: OutputArguments output(nlhs, plhs, 2);
const cv::Mat affine_from_ortho = fitting::get_3x4_affine_camera_matrix(rendering_params, image.cols, image.rows); output.set(0, colorbuffer);
const cv::Mat isomap = render::extract_texture(mesh, affine_from_ortho, image, compute_view_angle, render::TextureInterpolation::NearestNeighbour, isomap_resolution); output.set(1, depthbuffer);
// Return the extracted texture-map:
OutputArguments output(nlhs, plhs, 1);
output.set(0, isomap);
}; };
MEX_DISPATCH; MEX_DISPATCH;
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