forked from Kallu-A/Tri-2-Quad-Mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathborderOrientation.cpp
139 lines (109 loc) · 4.73 KB
/
borderOrientation.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <ultimaille/all.h>
#include <set>
#include <string>
#include <map>
#include "intersectData.cpp"
using namespace UM;
class borderOrientation {
private:
std::unordered_map<std::string, std::set<int>> mapBorder;
std::unordered_map<std::string, int> intersectMapBorder;
// Function to generate a key name for the map of border
// The advantage of this function is that it will always generate the same key for the same pair of vertices
static std::string generateKeyName(int v0, int v1) {
if (v0 > v1)
std::swap(v0, v1);
return std::to_string(v0) + "-" + std::to_string(v1);
}
// Helper function to generate a key name for the intersection map
static std::string generatorKeyNameList(std::vector<int> list) {
std::string key = "";
std::sort(list.begin(), list.end());
for (int i = 0; i < list.size(); i++) {
key += std::to_string(list[i]);
if (i != list.size() - 1) {
key += "-";
}
}
return key;
}
public:
borderOrientation() {}
// Return all the key of the map that contain the group in parameter
// Allow to easily retrieve all border of a region
std::vector<std::string> getAllKeyFromGroup(int group) const {
std::vector<std::string> keys;
for (auto key : mapBorder) {
if (getAllKeyContainNumbers(key.first, group)) {
keys.push_back(key.first);
}
}
return keys;
}
std::vector<std::string> getAllKeyIntersectFromGroup(int group) const {
std::vector<std::string> keys;
for (auto key : intersectMapBorder) {
if (isElementInString(key.first, group)) {
keys.push_back(key.first);
}
}
return keys;
}
// Fill the map with the vertices intersection of the border
void calculateIntersectionBorder(Triangles &triangle, Quads &quad, FacetAttribute<int> &fa, PointAttribute<int> &pa, CornerAttribute<int> &ca, std::vector<Region> ®ions, bool gifmode = false) {
for (auto ®ion : regions) {
std::vector<int> borderVertices = region.getBorderVertice(ca);
for (int i = 0; i < borderVertices.size(); i++) {
std::set<int> regionMeet = std::set<int>();
regionMeet.insert(region.getIdGroup());
auto v = Surface::Vertex(triangle, borderVertices[i]);
for (auto h : v.iter_halfedges()) {
auto f = Surface::Halfedge(triangle, h);
regionMeet.insert(fa[f.facet()]);
if (f.opposite() == -1) {
regionMeet.insert(borderOut);
}
}
if (regionMeet.size() > 2) {
std::vector<int> listRegionMeet = std::vector<int>();
listRegionMeet = std::vector<int>(regionMeet.begin(), regionMeet.end());
std::string key = generatorKeyNameList(listRegionMeet);
intersectMapBorder[key] = borderVertices[i];
fillIntersect(key, borderVertices[i], triangle, fa);
}
}
}
//iter on all key of the inter map to display it
for (auto key : intersectMapBorder) {
pa[key.second] = 100;
}
}
// Function to classify border in region
void calculateBorder(Triangles &triangle, Quads &quad, FacetAttribute<int> &fa, PointAttribute<int> &pa, CornerAttribute<int> &ca, std::vector<Region> ®ions, bool gifmode = false) {
for (auto ®ion : regions) {
int idGroup = region.getIdGroup();
std::vector<int> borderHalfEdge = region.getBorderHalfEdge(ca);
for (auto fId : borderHalfEdge) {
auto f = Surface::Halfedge(triangle, fId);
std::string key;
if (f.opposite() == -1)
key = generateKeyName(idGroup, borderOut);
else
key = generateKeyName(idGroup, fa[f.opposite().facet()]);
auto key_it = mapBorder.emplace(key, std::set<int>()).first;
key_it->second.insert(f.from());
key_it->second.insert(f.to());
//pa[f.from()] = idGroup + fa[f.opposite().facet()];
//pa[f.to()] = idGroup + fa[f.opposite().facet()];
}
}
}
// Return the map of the intersection border
std::unordered_map<std::string, int> getMapIntersectBorder() {
return intersectMapBorder;
}
// Return the map of the border
std::unordered_map<std::string, std::set<int>> getMapBorder() {
return mapBorder;
}
};