Commit 54a7e4af authored by Patrik Huber's avatar Patrik Huber

Added a few comments

parent 9e9cddab
...@@ -49,7 +49,7 @@ namespace eos { ...@@ -49,7 +49,7 @@ namespace eos {
struct Mesh struct Mesh
{ {
std::vector<cv::Vec4f> vertices; ///< 3D vertex positions. std::vector<cv::Vec4f> vertices; ///< 3D vertex positions.
std::vector<cv::Vec3f> colors; ///< Color information for each vertex. Expected to be in RGB order. std::vector<cv::Vec3f> colors; ///< Colour information for each vertex. Expected to be in RGB order.
std::vector<cv::Vec2f> texcoords; ///< Texture coordinates for each vertex. std::vector<cv::Vec2f> texcoords; ///< Texture coordinates for each vertex.
std::vector<std::array<int, 3>> tvi; ///< Triangle vertex indices std::vector<std::array<int, 3>> tvi; ///< Triangle vertex indices
...@@ -145,7 +145,7 @@ inline void write_textured_obj(Mesh mesh, std::string filename) ...@@ -145,7 +145,7 @@ inline void write_textured_obj(Mesh mesh, std::string filename)
mtl_file << "map_Kd " << texture_filename.string() << std::endl; mtl_file << "map_Kd " << texture_filename.string() << std::endl;
return; return;
} };
} /* namespace render */ } /* namespace render */
} /* namespace eos */ } /* namespace eos */
......
...@@ -166,11 +166,17 @@ struct TriangleToRasterize ...@@ -166,11 +166,17 @@ struct TriangleToRasterize
*/ */
cv::Rect calculate_clipped_bounding_box(cv::Vec4f v0, cv::Vec4f v1, cv::Vec4f v2, int viewport_width, int viewport_height) cv::Rect calculate_clipped_bounding_box(cv::Vec4f v0, cv::Vec4f v1, cv::Vec4f v2, int viewport_width, int viewport_height)
{ {
/* Old, producing artifacts:
t.minX = max(min(t.v0.position[0], min(t.v1.position[0], t.v2.position[0])), 0.0f);
t.maxX = min(max(t.v0.position[0], max(t.v1.position[0], t.v2.position[0])), (float)(viewportWidth - 1));
t.minY = max(min(t.v0.position[1], min(t.v1.position[1], t.v2.position[1])), 0.0f);
t.maxY = min(max(t.v0.position[1], max(t.v1.position[1], t.v2.position[1])), (float)(viewportHeight - 1));*/
using std::min; using std::min;
using std::max; using std::max;
using std::floor; using std::floor;
using std::ceil; using std::ceil;
int minX = max(min(floor(v0[0]), min(floor(v1[0]), floor(v2[0]))), 0.0f); int minX = max(min(floor(v0[0]), min(floor(v1[0]), floor(v2[0]))), 0.0f); // Readded this comment after merge: What about rounding, or rather the conversion from double to int?
int maxX = min(max(ceil(v0[0]), max(ceil(v1[0]), ceil(v2[0]))), static_cast<float>(viewport_width - 1)); int maxX = min(max(ceil(v0[0]), max(ceil(v1[0]), ceil(v2[0]))), static_cast<float>(viewport_width - 1));
int minY = max(min(floor(v0[1]), min(floor(v1[1]), floor(v2[1]))), 0.0f); int minY = max(min(floor(v0[1]), min(floor(v1[1]), floor(v2[1]))), 0.0f);
int maxY = min(max(ceil(v0[1]), max(ceil(v1[1]), ceil(v2[1]))), static_cast<float>(viewport_height - 1)); int maxY = min(max(ceil(v0[1]), max(ceil(v1[1]), ceil(v2[1]))), static_cast<float>(viewport_height - 1));
......
...@@ -73,6 +73,12 @@ inline bool is_point_in_triangle(cv::Point2f point, cv::Point2f triV0, cv::Point ...@@ -73,6 +73,12 @@ inline bool is_point_in_triangle(cv::Point2f point, cv::Point2f triV0, cv::Point
* The vertices should be given in screen coordinates, but with their * The vertices should be given in screen coordinates, but with their
* z-values preserved, so they can be compared against the depthbuffer. * z-values preserved, so they can be compared against the depthbuffer.
* *
* Obviously the depthbuffer given should have been created with the same projection
* matrix than the texture extraction is called with.
*
* Also, we don't do perspective-correct interpolation here I think, so only
* use it with affine and orthographic projection matrices.
*
* @param[in] v0 First vertex, in screen coordinates (but still with their z-value). * @param[in] v0 First vertex, in screen coordinates (but still with their z-value).
* @param[in] v1 Second vertex. * @param[in] v1 Second vertex.
* @param[in] v2 Third vertex. * @param[in] v2 Third vertex.
......
...@@ -53,6 +53,8 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat ...@@ -53,6 +53,8 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat
* Extracts the texture of the face from the given image * Extracts the texture of the face from the given image
* and stores it as isomap (a rectangular texture map). * and stores it as isomap (a rectangular texture map).
* *
* Todo: These should be renamed to extract_texture_affine? Can we combine both cases somehow?
*
* @param[in] mesh A mesh with texture coordinates. * @param[in] mesh A mesh with texture coordinates.
* @param[in] affine_camera_matrix An estimated 3x4 affine camera matrix. * @param[in] affine_camera_matrix An estimated 3x4 affine camera matrix.
* @param[in] image The image to extract the texture from. * @param[in] image The image to extract the texture from.
...@@ -78,6 +80,10 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat ...@@ -78,6 +80,10 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat
* To just run the texture extraction, see the overload * To just run the texture extraction, see the overload
* extract_texture(Mesh, cv::Mat, cv::Mat, TextureInterpolation, int). * extract_texture(Mesh, cv::Mat, cv::Mat, TextureInterpolation, int).
* *
* It might be wise to remove this overload as it can get quite confusing
* with the zbuffer. Obviously the depthbuffer given should have been created
* with the same (affine or ortho) projection matrix than the texture extraction is called with.
*
* @param[in] mesh A mesh with texture coordinates. * @param[in] mesh A mesh with texture coordinates.
* @param[in] affine_camera_matrix An estimated 3x4 affine camera matrix. * @param[in] affine_camera_matrix An estimated 3x4 affine camera matrix.
* @param[in] image The image to extract the texture from. * @param[in] image The image to extract the texture from.
......
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