forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_adjacency_graph.cpp
executable file
·59 lines (47 loc) · 1.84 KB
/
build_adjacency_graph.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
/*
* 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 "texturing.h"
#include "progress_counter.h"
TEX_NAMESPACE_BEGIN
void
build_adjacency_graph(core::TriangleMesh::ConstPtr mesh,
core::VertexInfoList::ConstPtr vertex_infos, UniGraph * graph) {
// vertex indices of facets
core::TriangleMesh::FaceList const & faces = mesh->get_faces();
// number of facets
std::size_t const num_faces = faces.size() / 3;
ProgressCounter face_counter("\tAdding edges", num_faces);
for (std::size_t i = 0; i < faces.size(); i += 3) {
face_counter.progress<SIMPLE>();
//vertex index of facets
std::size_t v1 = faces[i];
std::size_t v2 = faces[i + 1];
std::size_t v3 = faces[i + 2];
// get adjacent faces by finding faces containing edges v1v2 v2v3 v3v1
std::vector<std::size_t> adj_faces;
vertex_infos->get_faces_for_edge(v1, v2, &adj_faces);
vertex_infos->get_faces_for_edge(v2, v3, &adj_faces);
vertex_infos->get_faces_for_edge(v3, v1, &adj_faces);
for (std::size_t j = 0; j < adj_faces.size(); ++j) {
/* Face id vs. face position. */
std::size_t face = i / 3;
std::size_t adj_face = adj_faces[j];
/* Avoid self referencing. */
if (face != adj_face) {
/* Edge not already in graph? */
if (!graph->has_edge(face, adj_face)){
graph->add_edge(face, adj_face);
}
}
}
face_counter.inc();
}
std::cout << "\t" << graph->num_edges() << " total edges." << std::endl;
}
TEX_NAMESPACE_END