forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseam_leveling.cpp
executable file
·98 lines (75 loc) · 3.53 KB
/
seam_leveling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (C) 2015, Nils Moehrle
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/
#include <set>
#include "seam_leveling.h"
TEX_NAMESPACE_BEGIN
void
find_seam_edges(UniGraph const & graph,
core::TriangleMesh::ConstPtr mesh,
std::vector<MeshEdge> * seam_edges) {
// all the facets
core::TriangleMesh::FaceList const & faces = mesh->get_faces();
seam_edges->clear();
// Is it possible that a single edge is part of more than three faces whichs' label is non zero???
for (std::size_t node = 0; node < graph.num_nodes(); ++node) {
// all the adjacent nodes
std::vector<std::size_t> const & adj_nodes = graph.get_adj_nodes(node);
for (std::size_t adj_node : adj_nodes) {
/* Add each edge only once. */
if (node > adj_node) continue;
int label1 = graph.get_label(node);
int label2 = graph.get_label(adj_node);
/* Add only seam edges. */
if (label1 == label2) continue;
/* Find shared edge of the faces by finding the vertices contained by both two triangle. */
std::vector<std::size_t> shared_edge;
for (int i = 0; i < 3; ++i){
std::size_t v1 = faces[3 * node + i];
for (int j = 0; j < 3; j++){
std::size_t v2 = faces[3 * adj_node + j];
if (v1 == v2) shared_edge.push_back(v1);
}
}
assert(shared_edge.size() == 2);
std::size_t v1 = shared_edge[0];
std::size_t v2 = shared_edge[1];
assert(v1 != v2);
if (v1 > v2) std::swap(v1, v2);
MeshEdge seam_edge = {v1, v2};
seam_edges->push_back(seam_edge);
}
}
}
void
find_mesh_edge_projections(
std::vector<std::vector<VertexProjectionInfo> > const & vertex_projection_infos,
MeshEdge mesh_edge, std::vector<ProjectedEdgeInfo> * projected_edge_infos) {
std::vector<VertexProjectionInfo> const & v1_projection_infos = vertex_projection_infos[mesh_edge.v1];
std::vector<VertexProjectionInfo> const & v2_projection_infos = vertex_projection_infos[mesh_edge.v2];
/* Use a set to eliminate duplicates which may occur if the mesh is degenerated. */
std::set<ProjectedEdgeInfo> projected_edge_infos_set;
for (VertexProjectionInfo v1_projection_info : v1_projection_infos) {
for (VertexProjectionInfo v2_projection_info : v2_projection_infos) {
if (v1_projection_info.texture_patch_id != v2_projection_info.texture_patch_id) continue;
//// any use????
for (std::size_t face_id1 : v1_projection_info.faces) {
for (std::size_t face_id2 : v2_projection_info.faces) {
if(face_id1 != face_id2) continue;
std::size_t texture_patch_id = v1_projection_info.texture_patch_id;
math::Vec2f p1 = v1_projection_info.projection;
math::Vec2f p2 = v2_projection_info.projection;
ProjectedEdgeInfo projected_edge_info = {texture_patch_id, p1, p2};
projected_edge_infos_set.insert(projected_edge_info);
}
}
}
}
projected_edge_infos->insert(projected_edge_infos->end(), projected_edge_infos_set.begin(), projected_edge_infos_set.end());
}
TEX_NAMESPACE_END