Commit 444518427c1db1bcee39506092b8473c0fe6e56a

Authored by Renan Matsuda
1 parent 1f66bbca
Exists in master

FIX: performance improved

-search in locals causes frezzing
invesalius/constants.py
... ... @@ -795,7 +795,7 @@ SEED_OFFSET = 15
795 795 SEED_RADIUS = 1.5
796 796  
797 797 # Increased the default sleep parameter from 0.1 to 0.15 to decrease CPU load during navigation.
798   -SLEEP_NAVIGATION = 0.1
  798 +SLEEP_NAVIGATION = 0.15
799 799 SLEEP_COORDINATES = 0.05
800 800  
801 801 BRAIN_OPACITY = 0.5
... ...
invesalius/data/coordinates.py
... ... @@ -39,9 +39,9 @@ class TrackerCoordinates():
39 39 def SetCoordinates(self, coord, markers_flag):
40 40 self.coord = coord
41 41 self.markers_flag = markers_flag
42   - wx.CallAfter(Publisher.sendMessage, 'Sensors ID', markers_flag=self.markers_flag)
43 42  
44 43 def GetCoordinates(self):
  44 + wx.CallAfter(Publisher.sendMessage, 'Sensors ID', markers_flag=self.markers_flag)
45 45 return self.coord, self.markers_flag
46 46  
47 47  
... ... @@ -87,8 +87,7 @@ def PolarisP4Coord(trck_init, trck_id, ref_mode):
87 87 obj = obj[2:]
88 88  
89 89 if probe[:7] == "MISSING":
90   - if not "coord1" in locals():
91   - coord1 = np.hstack(([0, 0, 0], [0, 0, 0]))
  90 + coord1 = np.hstack(([0, 0, 0], [0, 0, 0]))
92 91 else:
93 92 q = [int(probe[i:i + 6]) * 0.0001 for i in range(0, 24, 6)]
94 93 t = [int(probe[i:i + 7]) * 0.01 for i in range(24, 45, 7)]
... ... @@ -97,8 +96,7 @@ def PolarisP4Coord(trck_init, trck_id, ref_mode):
97 96 coord1 = np.hstack((trans_probe, angles_probe))
98 97  
99 98 if ref[:7] == "MISSING":
100   - if not "coord2" in locals():
101   - coord2 = np.hstack(([0, 0, 0], [0, 0, 0]))
  99 + coord2 = np.hstack(([0, 0, 0], [0, 0, 0]))
102 100 else:
103 101 q = [int(ref[i:i + 6]) * 0.0001 for i in range(0, 24, 6)]
104 102 t = [int(ref[i:i + 7]) * 0.01 for i in range(24, 45, 7)]
... ... @@ -107,8 +105,7 @@ def PolarisP4Coord(trck_init, trck_id, ref_mode):
107 105 coord2 = np.hstack((trans_ref, angles_ref))
108 106  
109 107 if obj[:7] == "MISSING":
110   - if not "coord3" in locals():
111   - coord3 = np.hstack(([0, 0, 0], [0, 0, 0]))
  108 + coord3 = np.hstack(([0, 0, 0], [0, 0, 0]))
112 109 else:
113 110 q = [int(obj[i:i + 6]) * 0.0001 for i in range(0, 24, 6)]
114 111 t = [int(obj[i:i + 7]) * 0.01 for i in range(24, 45, 7)]
... ...
invesalius/data/elfin_robot.py
... ... @@ -269,62 +269,62 @@ class ControlRobot(threading.Thread):
269 269 if self.process_tracker.head_move_threshold(current_ref_filtered):
270 270 coord_inv = self.process_tracker.head_move_compensation(current_ref_filtered,
271 271 self.m_change_robot2ref)
272   - #if self.coord_inv_old is None:
273   - # self.coord_inv_old = coord_inv
274   -
275   - # if np.allclose(np.array(coord_inv), np.array(coord_robot_raw), 0, 0.01):
276   - # # print("At target within range 5")
277   - # pass
278   - # elif not np.allclose(np.array(coord_inv), np.array(self.coord_inv_old), 0, 5):
279   - # # print("stop")
280   - # self.trck_init_robot.StopRobot()
281   - # self.coord_inv_old = coord_inv
282   - # else:
283   - self.trck_init_robot.SendCoordinates(coord_inv, const.MOTIONS["normal"])
284   - # if self.process_tracker.correction_distance_calculation_target(coord_inv, coord_robot_raw) < 100 and not self.arcmotion_flag:
285   - # self.trck_init_robot.SendCoordinates(coord_inv, const.MOTIONS["normal"])
286   - #
287   - # elif self.process_tracker.correction_distance_calculation_target(coord_inv, coord_robot_raw) >= 100 or self.arcmotion_flag:
288   - # actual_point = coord_robot_raw
289   - # if not self.arcmotion_flag:
290   - # coord_head = self.process_tracker.estimate_head_center(self.tracker,
291   - # current_ref_filtered).tolist()
292   - # pc = coord_head[0], coord_head[1], coord_head[2], coord_inv[3], coord_inv[4], coord_inv[
293   - # 5]
294   - # self.target_linearout, self.target_arc = self.process_tracker.arcmotion(coord_robot_raw, pc,
295   - # coord_inv)
296   - # self.arcmotion_flag = True
297   - # self.arcmotion_step_flag = const.MOTIONS["linear out"]
298   - #
299   - # if self.arcmotion_flag and self.arcmotion_step_flag == const.MOTIONS["linear out"]:
300   - # coord = self.target_linearout
301   - # if np.allclose(np.array(actual_point), np.array(self.target_linearout), 0, 1):
302   - # self.arcmotion_step_flag = const.MOTIONS["arc"]
303   - # coord = self.target_arc
304   - #
305   - # elif self.arcmotion_flag and self.arcmotion_step_flag == const.MOTIONS["arc"]:
306   - # coord_head = self.process_tracker.estimate_head_center(self.tracker,
307   - # current_ref_filtered).tolist()
308   - # pc = coord_head[0], coord_head[1], coord_head[2], coord_inv[3], coord_inv[4], coord_inv[
309   - # 5]
310   - # _, new_target_arc = self.process_tracker.arcmotion(coord_robot_raw, pc,
311   - # coord_inv)
312   - # if np.allclose(np.array(new_target_arc[3:-1]), np.array(self.target_arc[3:-1]), 0, 1):
313   - # None
314   - # else:
315   - # if self.process_tracker.correction_distance_calculation_target(coord_inv,
316   - # coord_robot_raw) >= 80:
317   - # self.target_arc = new_target_arc
318   - #
319   - # coord = self.target_arc
320   - #
321   - # if np.allclose(np.array(actual_point), np.array(self.target_arc[3:-1]), 0, 10):
322   - # self.arcmotion_flag = False
323   - # self.arcmotion_step_flag = const.MOTIONS["normal"]
324   - # coord = coord_inv
325   - #
326   - # self.trck_init_robot.SendCoordinates(coord, self.arcmotion_step_flag)
327   - #self.coord_inv_old = coord_inv
  272 + if self.coord_inv_old is None:
  273 + self.coord_inv_old = coord_inv
  274 +
  275 + if np.allclose(np.array(coord_inv), np.array(coord_robot_raw), 0, 0.01):
  276 + # print("At target within range 5")
  277 + pass
  278 + elif not np.allclose(np.array(coord_inv), np.array(self.coord_inv_old), 0, 5):
  279 + # print("stop")
  280 + self.trck_init_robot.StopRobot()
  281 + self.coord_inv_old = coord_inv
  282 + else:
  283 + #self.trck_init_robot.SendCoordinates(coord_inv, const.MOTIONS["normal"])
  284 + if self.process_tracker.correction_distance_calculation_target(coord_inv, coord_robot_raw) < 100 and not self.arcmotion_flag:
  285 + self.trck_init_robot.SendCoordinates(coord_inv, const.MOTIONS["normal"])
  286 +
  287 + elif self.process_tracker.correction_distance_calculation_target(coord_inv, coord_robot_raw) >= 100 or self.arcmotion_flag:
  288 + actual_point = coord_robot_raw
  289 + if not self.arcmotion_flag:
  290 + coord_head = self.process_tracker.estimate_head_center(self.tracker,
  291 + current_ref_filtered).tolist()
  292 + pc = coord_head[0], coord_head[1], coord_head[2], coord_inv[3], coord_inv[4], coord_inv[
  293 + 5]
  294 + self.target_linearout, self.target_arc = self.process_tracker.arcmotion(coord_robot_raw, pc,
  295 + coord_inv)
  296 + self.arcmotion_flag = True
  297 + self.arcmotion_step_flag = const.MOTIONS["linear out"]
  298 +
  299 + if self.arcmotion_flag and self.arcmotion_step_flag == const.MOTIONS["linear out"]:
  300 + coord = self.target_linearout
  301 + if np.allclose(np.array(actual_point), np.array(self.target_linearout), 0, 1):
  302 + self.arcmotion_step_flag = const.MOTIONS["arc"]
  303 + coord = self.target_arc
  304 +
  305 + elif self.arcmotion_flag and self.arcmotion_step_flag == const.MOTIONS["arc"]:
  306 + coord_head = self.process_tracker.estimate_head_center(self.tracker,
  307 + current_ref_filtered).tolist()
  308 + pc = coord_head[0], coord_head[1], coord_head[2], coord_inv[3], coord_inv[4], coord_inv[
  309 + 5]
  310 + _, new_target_arc = self.process_tracker.arcmotion(coord_robot_raw, pc,
  311 + coord_inv)
  312 + if np.allclose(np.array(new_target_arc[3:-1]), np.array(self.target_arc[3:-1]), 0, 1):
  313 + None
  314 + else:
  315 + if self.process_tracker.correction_distance_calculation_target(coord_inv,
  316 + coord_robot_raw) >= 80:
  317 + self.target_arc = new_target_arc
  318 +
  319 + coord = self.target_arc
  320 +
  321 + if np.allclose(np.array(actual_point), np.array(self.target_arc[3:-1]), 0, 10):
  322 + self.arcmotion_flag = False
  323 + self.arcmotion_step_flag = const.MOTIONS["normal"]
  324 + coord = coord_inv
  325 +
  326 + self.trck_init_robot.SendCoordinates(coord, self.arcmotion_step_flag)
  327 + self.coord_inv_old = coord_inv
328 328 else:
329 329 self.trck_init_robot.StopRobot()
330 330  
... ... @@ -339,11 +339,11 @@ class ControlRobot(threading.Thread):
339 339 self.robot_tracker_flag, self.m_change_robot2ref = self.robottarget_queue.get_nowait()
340 340 self.robottarget_queue.task_done()
341 341  
342   - # if self.objattarget_queue.empty():
343   - # None
344   - # else:
345   - # self.target_flag = self.objattarget_queue.get_nowait()
346   - # self.objattarget_queue.task_done()
  342 + if self.objattarget_queue.empty():
  343 + None
  344 + else:
  345 + self.target_flag = self.objattarget_queue.get_nowait()
  346 + self.objattarget_queue.task_done()
347 347  
348 348 self.control(coords_tracker_in_robot, coord_robot_raw, markers_flag)
349 349  
... ... @@ -376,5 +376,4 @@ class ControlRobot(threading.Thread):
376 376  
377 377 csv_writer.writerow(info)
378 378  
379   -#sem sleep roda melhor
380   - #sleep(0.01)
381 379 \ No newline at end of file
  380 + sleep(0.02)
382 381 \ No newline at end of file
... ...