eos 1.4.0
Loading...
Searching...
No Matches
transforms.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/render/transforms.hpp
5 *
6 * Copyright 2014, 2015, 2023 Patrik Huber
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#pragma once
21
22#ifndef EOS_RENDER_TRANSFORMS_HPP
23#define EOS_RENDER_TRANSFORMS_HPP
24
25#include "Eigen/Core"
26
27namespace eos {
28namespace render {
29
47inline Eigen::Vector2f clip_to_screen_space(const Eigen::Vector2f& clip_coordinates, int screen_width,
48 int screen_height)
49{
50 // Window transform:
51 const float x_ss = (clip_coordinates[0] + 1.0f) * (screen_width / 2.0f);
52 const float y_ss =
53 screen_height - (clip_coordinates[1] + 1.0f) *
54 (screen_height / 2.0f); // also flip y; Qt: Origin top-left. OpenGL: bottom-left.
55 return Eigen::Vector2f(x_ss, y_ss);
56 /* Note: What we do here is equivalent to
57 x_w = (x * vW/2) + vW/2;
58 However, Shirley says we should do:
59 x_w = (x * vW/2) + (vW-1)/2;
60 (analogous for y)
61 Todo: Check the consequences.
62 */
63};
64
65// Equivalent to the above, but templated, and taking clip_coord_x and _y separately.
66// Todo: Can merge this back into one function I think?
67template <typename T>
68Eigen::Vector2<T> clip_to_screen_space(const T clip_coord_x, const T clip_coord_y, int screen_width,
69 int screen_height)
70{
71 // Window transform:
72 const T x_ss = (clip_coord_x + T(1)) * (screen_width / 2.0);
73 const T y_ss =
74 screen_height - (clip_coord_y + T(1)) *
75 (screen_height / 2.0); // also flip y; Qt: Origin top-left. OpenGL: bottom-left.
76 return Eigen::Vector2<T>(x_ss, y_ss);
77};
78
90/*inline cv::Vec2f screen_to_clip_space(const cv::Vec2f& screen_coordinates, int screen_width, int screen_height)
91{
92 const float x_cs = screen_coordinates[0] / (screen_width / 2.0f) - 1.0f;
93 float y_cs = screen_coordinates[1] / (screen_height / 2.0f) - 1.0f;
94 y_cs *= -1.0f;
95 return cv::Vec2f(x_cs, y_cs);
96};*/
97
98} /* namespace render */
99} /* namespace eos */
100
101#endif /* EOS_RENDER_TRANSFORMS_HPP */
Eigen::Vector2f clip_to_screen_space(const Eigen::Vector2f &clip_coordinates, int screen_width, int screen_height)
Definition: transforms.hpp:47
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.