-
Notifications
You must be signed in to change notification settings - Fork 1
/
chooseconnectedcomponent.py
137 lines (91 loc) · 3.63 KB
/
chooseconnectedcomponent.py
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
import faulthandler; faulthandler.enable()
import numpy as np
import pymeshlab
import polyscope as ps
import polyscope.imgui as psim
import Polymeshlabfusion
import os
class ChooseCC(Polymeshlabfusion.Mesh):
'''This is the class responsible for choosing the connected components'''
is_active = False
connectedcomp = []
ms = None
current_cc = 1
numberofcc = 0
def __init__(self, Mesh, color=(0.3, 0.5, 1), mode = 'quad'):
'''Slightly changed constructor method '''
self.ms = pymeshlab.MeshSet()
self.ms.add_mesh(Mesh)
self.id = self.ms.current_mesh().id()
self.Mesh = Mesh
self.name = f"CC number {ChooseCC.numberofcc}"
self.color = color
self.VisibleMesh = self.register_mesh(mode)
ChooseCC.connectedcomp.append(self)
ChooseCC.numberofcc += 1
def set_current_mesh(self):
self.ms.set_current_mesh(self.id)
def __del__(self):
self.VisibleMesh.remove()
self.ms.set_current_mesh(self.id)
self.ms.delete_current_mesh()
@classmethod
def callback(cls, PolyGUI):
if not psim.TreeNode('Choose connected component'):
cls.remove_all()
if PolyGUI.current_step>1:
PolyGUI.layers[PolyGUI.current_step-1].set_enabled(True)
return
if psim.Button('Split up'):
if not PolyGUI.ms.current_mesh().is_point_cloud():
#ps.remove_all_structures()
cls.is_active = True
cls.ms = pymeshlab.MeshSet()
m = PolyGUI.ms.current_mesh()
cls.ms.add_mesh(m)
cls.ms.generate_splitting_by_connected_components(delete_source_mesh=True)
for cc in cls.ms:
ChooseCC(cc)
else:
ps.error("The current mesh is not a point cloud!")
if cls.connectedcomp !=[]:
cls.connectedcomp[cls.current_cc-1].set_current_mesh()
current_step_clicked, cls.current_cc = psim.SliderInt('Connected component no', cls.current_cc, v_min=1, v_max=np.max([len(cls.connectedcomp), 1]))
if psim.Button('This one'):
Chosen_one = cls.connectedcomp[cls.current_cc-1]
while len(cls.connectedcomp)>0:
del cls.connectedcomp[0]
cls.connectedcomp.append(Chosen_one)
cls.current_cc = 1
PolyGUI.ms.add_mesh(cls.connectedcomp[cls.current_cc-1].Mesh)
PolyGUI.layers.append(Polymeshlabfusion.Mesh(PolyGUI.ms, f"Reconstructed component", (.2,.3,.4)))
PolyGUI.current_step = len(PolyGUI.layers)
cls.is_active = False
cls.mainloop()
if cls.is_active:
cls.set_everything_disabled(PolyGUI.layers)
@classmethod
def set_everything_disabled(cls,structurelist):
for structure in structurelist:
structure.set_enabled(False)
@classmethod
def mainloop(cls):
for i in range(len(cls.connectedcomp)):
enabled = True if (i==cls.current_cc-1) else False
cls.connectedcomp[i].set_enabled(enabled)
@classmethod
def remove_all(cls):
while len(cls.connectedcomp)>0:
del cls.connectedcomp[0]
MS = pymeshlab.MeshSet()
def callback():
ChooseCC.callback(MS)
def main():
MS.load_new_mesh(os.getcwd()+'/Experiment-78/Experiment-78+pointcloud.ply')
#MS.load_new_mesh(os.getcwd()+'/step3.ply')
ps.init()
Original = Polymeshlabfusion.Mesh(MS, 'Super cool mesh', (0.5, 1, 0.5))
ps.set_user_callback(lambda Mesh = MS : ChooseCC.callback(Mesh))
ps.show()
if __name__ == '__main__':
main()