Skip to content

Commit

Permalink
Added const and simplified landmark mappings loop
Browse files Browse the repository at this point in the history
Changed all occurences of this code.
* Added const wherever possible
* Simplified code with .homogeneous(), to avoid creating a temporary object.
  • Loading branch information
patrikhuber committed Mar 26, 2023
1 parent 4baa106 commit fb6d6a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
8 changes: 4 additions & 4 deletions examples/fit-model-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ int main(int argc, char* argv[])
// Sub-select all the landmarks which we have a mapping for (i.e. that are defined in the 3DMM):
for (int i = 0; i < landmarks.size(); ++i)
{
auto converted_name = landmark_mapper.convert(landmarks[i].name);
const auto converted_name = landmark_mapper.convert(landmarks[i].name);
if (!converted_name)
{ // no mapping defined for the current landmark
continue;
}
int vertex_idx = std::stoi(converted_name.value());
auto vertex = morphable_model.get_shape_model().get_mean_at_point(vertex_idx);
model_points.emplace_back(Vector4f(vertex.x(), vertex.y(), vertex.z(), 1.0f));
const int vertex_idx = std::stoi(converted_name.value());
const auto vertex = morphable_model.get_shape_model().get_mean_at_point(vertex_idx);
model_points.emplace_back(vertex.homogeneous());
vertex_indices.emplace_back(vertex_idx);
image_points.emplace_back(landmarks[i].coordinates);
}
Expand Down
14 changes: 6 additions & 8 deletions include/eos/fitting/fitting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ inline auto get_corresponding_pointset(const T& landmarks, const core::LandmarkM
// Sub-select all the landmarks which we have a mapping for (i.e. that are defined in the 3DMM):
for (int i = 0; i < landmarks.size(); ++i)
{
auto converted_name = landmark_mapper.convert(landmarks[i].name);
const auto converted_name = landmark_mapper.convert(landmarks[i].name);
if (!converted_name)
{ // no mapping defined for the current landmark
continue;
}
int vertex_idx = std::stoi(converted_name.get());
auto vertex = morphable_model.get_shape_model().get_mean_at_point(vertex_idx);
model_points.emplace_back(Vector4f(vertex.x(), vertex.y(), vertex.z(), 1.0f));
const int vertex_idx = std::stoi(converted_name.get());
const auto vertex = morphable_model.get_shape_model().get_mean_at_point(vertex_idx);
model_points.emplace_back(vertex.homogeneous());
vertex_indices.emplace_back(vertex_idx);
image_points.emplace_back(landmarks[i].coordinates);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ inline std::pair<core::Mesh, fitting::RenderingParameters> fit_shape_and_pose(
// and get the corresponding model points (mean if given no initial coeffs, from the computed shape otherwise):
for (int i = 0; i < landmarks.size(); ++i)
{
auto converted_name = landmark_mapper.convert(landmarks[i].name);
const auto converted_name = landmark_mapper.convert(landmarks[i].name);
if (!converted_name)
{ // no mapping defined for the current landmark
continue;
Expand All @@ -398,9 +398,7 @@ inline std::pair<core::Mesh, fitting::RenderingParameters> fit_shape_and_pose(
{
vertex_idx = std::stoi(converted_name.value());
}
Vector4f vertex(current_mesh.vertices[vertex_idx][0], current_mesh.vertices[vertex_idx][1],
current_mesh.vertices[vertex_idx][2], 1.0f);
model_points.emplace_back(vertex);
model_points.emplace_back(current_mesh.vertices[vertex_idx].homogeneous());
vertex_indices.emplace_back(vertex_idx);
image_points.emplace_back(landmarks[i].coordinates);
}
Expand Down
9 changes: 3 additions & 6 deletions include/eos/fitting/multi_image_fitting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,13 @@ inline std::pair<std::vector<core::Mesh>, std::vector<fitting::RenderingParamete
// otherwise):
for (int i = 0; i < landmarks[j].size(); ++i)
{
auto converted_name = landmark_mapper.convert(landmarks[j][i].name);
const auto converted_name = landmark_mapper.convert(landmarks[j][i].name);
if (!converted_name)
{ // no mapping defined for the current landmark
continue;
}
int vertex_idx = std::stoi(converted_name.value());
Vector4f vertex(current_meshes[j].vertices[vertex_idx][0],
current_meshes[j].vertices[vertex_idx][1],
current_meshes[j].vertices[vertex_idx][2], 1.0f);
current_model_points.emplace_back(vertex);
const int vertex_idx = std::stoi(converted_name.value());
current_model_points.emplace_back(current_meshes[j].vertices[vertex_idx].homogeneous());
current_vertex_indices.emplace_back(vertex_idx);
current_image_points.emplace_back(landmarks[j][i].coordinates);
}
Expand Down

0 comments on commit fb6d6a4

Please sign in to comment.