-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentation.h
More file actions
184 lines (150 loc) · 4.6 KB
/
Segmentation.h
File metadata and controls
184 lines (150 loc) · 4.6 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* Created on: 26/03/2021
* Author: Ziniu Lu (luziniuoskar@outlook.com)
*/
#pragma once
#include <vector>
#include <list>
#include <map>
#include "project.h"
#include "cgalHeader.hpp"
#include "iglHeader.h"
#include "Skeletonization.h"
BEGIN_PROJECT_NAMESPACE
struct Constraint
{
private:
MAT_3d V;
MAT_2i E;
enum : char
{
UpperConstraint = 'U',
LowerConstraint = 'L',
LocalConstraint = 'M', // constraints in the middle
};
public:
inline void get_constraint(MAT_3d& V, MAT_2i& E)
{
V = this->V;
E = this->E;
}
};
/// <summary>
/// Segment is a subset of pmesh.
/// One segment represents the set of pmesh faces where the vertices corresponding to a skel_chain
/// are located.
/// </summary>
class Segment
{
private:
size_t id; // begins with 1
MAT_3d V;
MAT_3i F;
std::vector<size_t> node2v_map;
std::map<size_t, size_t> vID_map; // <old_id, new_id> of V;
std::map<size_t, size_t> nd_map; // <vID_skel_node, vID_seg>
std::vector<Constraint> constraints;
//void sort_F(const MAT_3i& F_old, MAT_3i& F_new);
public:
Segment();
Segment(const size_t id, const MAT_3d& V, const MAT_3i& F) :id(id), V(V), F(F){ }
Segment(
const std::vector<SkelNode>& skel_nodes,
const SkelChain& skel_chain,
const MAT_3d& V,
const MAT_3i& F,
MAT_3i& V_ID, // V_ID.row(old_id) = <new_id...0, seg_id...1, skel_nd_id...1> // ...1 means index starts from 1
MAT_4i& F_ID); // F_ID.row(old_id) = <ocupied 0/1, seg_id...1, seg_id...1, seg_id...1>
static void set_VF_ID(
const std::vector<SkelNode>& skel_nodes,
const std::vector<SkelChain>& skel_chains,
const MAT_3d& V,
const MAT_3i& F,
MAT_3i& V_ID, // V_ID.row(old_id) = <new_id...0, seg_id...1, skel_nd_id...1> // ...1 means index starts from 1
MAT_4i& F_ID); // F_ID.row(old_id) = <ocupied 0/1, seg_id...1, seg_id...1, seg_id...1>
static size_t count_V_ID(const size_t segment_id, MAT_3i& V_ID);
static size_t count_F_ID(const size_t segment_id, MAT_4i& F_ID);
void set_segment(
const std::vector<SkelNode>& skel_nodes,
const SkelChain& skel_chain,
const MAT_3d& V,
const MAT_3i& F,
MAT_3i& V_ID,
MAT_4i& F_ID);
inline size_t get_id() { return this->id; }
inline void get_segment(MAT_3d& V, MAT_3i& F)
{
V = this->V;
F = this->F;
}
inline const MAT_3d& get_V()
{
return this->V;
}
inline const MAT_3i& get_F()
{
return this->F;
}
const MAT_2i get_edges_around_vertex(RVec_3d& V);
const MAT_6i get_faces_around_edges(MAT_2i& E); // return (F11, F12, F13, F21, F22, F23)
};
class Segmentation
{
private:
std::vector<Segment> segments;
public:
Segmentation();
Segmentation(SkelGraph& skel_graph, Polyhedron& pmesh);
void set_segments(SkelGraph& skel_graph, Polyhedron& pmesh);
void set_constraints(Settings& settings);
inline std::vector<Segment>& get_segments()
{
return this->segments;
}
};
//
//
//class Segments
//{
//private:
// std::list<SkelChain> skel_segments;
//
// std::list<SkelChain>::iterator& select_next_chain(
// size_t source_node,
// std::vector<std::list<SkelChain>::iterator&> it_branches);
//
//public:
// Segments();
// Segments(SkelGraph& skel_graph, Polyhedron& pmesh);
//
// void set_id_breadth_first(SkelGraph& skel_graph);
//
//
// void breadth_first_traverse(SkelGraph& skel_graph);
// void depth_first_merge(SkelGraph& skel_graph);
// void insert(std::vector<SkelChain>& segment);
// void insert(SkelChain& skel_chain);
//
//};
//
//class Segmentation
//{
//private:
// Polyhedron pmesh;
// std::string out_path;
//
// size_t number_of_segments = 0;
//
//
//public:
// Segmentation();
// Segmentation(std::string path);
//
// void set_out_path(std::string path);
//
// bool extract_from_skeleton(Skeleton& skeleton, Polyhedron& pmesh);
// bool extract_from_map_length(SkelGraph& skel_graph, Polyhedron& pmesh);
// bool extract_from_mesh(Triangle_mesh& tmesh);
// bool output_segments_to_file();
//};
END_PROJECT_NAMESPACE
extern PROJECT_NAME::Segmentation* segmentation;