-
Notifications
You must be signed in to change notification settings - Fork 45
/
analyzer.py
163 lines (126 loc) · 5.28 KB
/
analyzer.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from PyQt4.QtCore import QObject
from PyQt4.QtCore import QThread
from PyQt4.QtCore import pyqtSignal
__author__ = 'Tibor Vavra'
class Analyzer(object):
def __init__(self, controller):
self.controller = controller
self.analyzer_runner = AnalyzerRunner(controller)
self.analyzer_runner_thread = QThread()
self.finish_function = None
self.send_result_function = None
def make_analyze(self, finish_function, result_function):
self.finish_function = finish_function
self.send_result_function = result_function
if self.analyzer_runner.is_running:
print("cancel old analyze")
self.cancel_analyz()
print("start new analyze")
#self.analyzer_runner.whole_scene = whole_scene
self.analyzer_runner.moveToThread(self.analyzer_runner_thread)
self.analyzer_runner_thread.started.connect(self.analyzer_runner.start_analyze)
self.analyzer_runner.finished.connect(self.set_finished_read)
self.analyzer_runner.send_result.connect(self.set_result)
self.analyzer_runner.is_running = True
self.analyzer_runner_thread.start()
def cancel_analyz(self):
self.analyzer_runner.is_running = False
self.analyzer_runner_thread.quit()
self.analyzer_runner_thread.wait()
self.analyzer_runner_thread = QThread()
self.analyzer_runner = AnalyzerRunner(self.controller)
def set_finished_read(self):
print("analyze done")
if self.finish_function:
self.finish_function()
def set_result(self, result):
print(result)
if self.send_result_function:
self.send_result_function(result)
'''
def make_analyze(self, whole_scene):
#Some initialization
result = []
support = {
'name': 'Support',
'result': False,
'message': '',
'gui_name': 'supportCheckBox'
}
if self.is_support_needed(whole_scene):
support['result'] = True
support['message'] = "Some places in scene is hard to print without support. We are recommending to turn Support material parameter on"
result.append(support)
brim = {
'name': 'Brim',
'result': False,
'message': '',
'gui_name': 'brimCheckBox'
}
if self.is_brim_needed(whole_scene):
brim['result'] = True
brim['message'] = "Contact area between printed object and printing surface is too small, it is possible that object will be detach during printing. We are recommending to turn Brim parametr on"
result.append(brim)
return result
def is_support_needed(self, scene):
#detect angles between normal vector of face and normal of printing surface
#angel bigger than something is problem
data = self.controller.scene.get_faces_by_smaller_angel_normal_and_vector(np.array([0.,0.,-1.]), 35., scene)
#something returned? problematic printing without support, recommended to turn it on
if len(data) == 0:
return False
else:
return True
return True
def is_brim_needed(self, scene):
#detect small area on printing surface, it is need to generate brim
#something returned? problematic printing without brim, recommended to turn it on
return self.controller.scene.get_contact_faces_with_area_smaller_than(2., scene)
'''
class AnalyzerRunner(QObject):
finished = pyqtSignal()
send_result = pyqtSignal(dict)
def __init__(self, controller):
super(AnalyzerRunner, self).__init__()
self.is_running = False
self.controller = controller
self.whole_scene = None
def start_analyze(self):
print("get whole scene")
self.whole_scene = self.controller.scene.get_whole_scene_in_one_mesh()
print("analyze started")
result = {}
if self.is_running:
if self.is_support_needed(self.whole_scene):
result['support'] = True
else:
result['support'] = False
else:
result = {}
if self.is_running:
if self.is_brim_needed(self.whole_scene):
result['brim'] = True
else:
result['brim'] = False
else:
result = {}
self.is_running = False
self.send_result.emit(result)
self.finished.emit()
def is_support_needed(self, scene):
# detect angles between normal vector of face and normal of printing surface
# angel bigger than something is problem
data = self.controller.scene.get_faces_by_smaller_angel_normal_and_vector(np.array([0., 0., -1.]), 35., scene)
# something returned? problematic printing without support, recommended to turn it on
if len(data) == 0:
return False
else:
return True
return True
def is_brim_needed(self, scene):
# detect small area on printing surface, it is need to generate brim
# something returned? problematic printing without brim, recommended to turn it on
return self.controller.scene.get_contact_faces_with_area_smaller_than(2., scene)