def scan_complete(self): self._logger.debug("Scan complete writing pointcloud files with %i points." % (self.point_cloud.get_size(),)) self.point_cloud.saveAsFile(self._prefix) self.settings.saveAsFile(self._prefix) message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SAVING_POINT_CLOUD" message['data']['scan_id'] = self._prefix message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) FSUtil.delete_image_folders(self._prefix) self.reset_scanner_state() event = FSEvent() event.command = '_COMPLETE' #TODO: generate MESH Here if option is selected in scan settings! #self.create_mesh(self._prefix) self.eventManager.publish(FSEvents.COMMAND,event) message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCAN_COMPLETE" message['data']['scan_id'] = self._prefix message['data']['level'] = "success" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def scan_complete(self): self._logger.debug("Scan complete writing pointcloud files with %i points." % (self.point_cloud.get_size(),)) self.point_cloud.saveAsFile(self._prefix) self.settings.saveAsFile(self._prefix) message = { "message": "SAVING_POINT_CLOUD", "scan_id": self._prefix, "level": "info" } self.eventManager.broadcast_client_message(FSEvents.ON_INFO_MESSAGE, message) FSUtil.delete_image_folders(self._prefix) self.reset_scanner_state() event = FSEvent() event.command = 'COMPLETE' self.eventManager.publish(FSEvents.COMMAND,event) message = { "message": "SCAN_COMPLETE", "scan_id": self._prefix, "level": "success" } self.eventManager.broadcast_client_message(FSEvents.ON_INFO_MESSAGE, message) self.hardwareController.camera.device.stopStream()
def _on_client_connected(self,eventManager, event): message = FSUtil.new_message() message['type'] = FSEvents.ON_CLIENT_INIT message['data']['client'] = event['client'] message['data']['state'] = self._state message['data']['server_version'] = str(__version__) message['data']['firmware_version'] = str(self.hardwareController.get_firmware_version()) #message['data']['points'] = self.pointcloud message['data']['settings'] = self.settings.todict(self.settings) eventManager.publish(FSEvents.ON_SOCKET_SEND, message) message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE if not self.hardwareController.arduino_is_connected(): message['data']['message'] = "NO_SERIAL_CONNECTION" message['data']['level'] = "error" else: message['data']['message'] = "SERIAL_CONNECTION_READY" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) if not self.hardwareController.camera_is_connected(): message['data']['message'] = "NO_CAMERA_CONNECTION" message['data']['level'] = "error" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) else: message['data']['message'] = "CAMERA_READY" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def scan_complete(self): self._logger.debug( "Scan complete writing pointcloud files with %i points." % (self.point_cloud.get_size(), )) self.point_cloud.saveAsFile(self._prefix) self.settings.saveAsFile(self._prefix) message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SAVING_POINT_CLOUD" message['data']['scan_id'] = self._prefix message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message) FSUtil.delete_image_folders(self._prefix) self.reset_scanner_state() event = FSEvent() event.command = '_COMPLETE' #TODO: generate MESH Here if option is selected in scan settings! #self.create_mesh(self._prefix) self.eventManager.publish(FSEvents.COMMAND, event) message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCAN_COMPLETE" message['data']['scan_id'] = self._prefix message['data']['level'] = "success" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def set_state(self, state): self._state = state message = FSUtil.new_message() message = FSUtil.new_message() message['type'] = FSEvents.ON_STATE_CHANGED message['data']['state'] = state self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def stop_scan(self): self._stop_scan = True self._worker_pool.kill() time.sleep(1) FSUtil.delete_scan(self._prefix) self.reset_scanner_state() self._logger.info("Scan stoped")
def stop_scan(self): self._stop_scan = True self._worker_pool.kill() time.sleep(1) FSUtil.delete_scan(self._prefix) self.reset_scanner_state() self._logger.info("Scan stoped") self.hardwareController.camera.device.stopStream() message = { "message": "SCAN_CANCELED", "level": "info" } self.eventManager.broadcast_client_message(FSEvents.ON_INFO_MESSAGE, message)
def on_stop(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCAN_CANCELED" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def on_stop(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCAN_CANCELED" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def init_object_scan(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCANNING_OBJECT" self.current_position = 0 self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) self._laser_positions = self.settings.laser_positions self.hardwareController.led.on(self.settings.led.red,self.settings.led.green,self.settings.led.blue) self.hardwareController.laser.on() self.settings.camera.brightness = self._scan_brightness self.settings.camera.contrast = self._scan_contrast # TODO: solve this timing issue! # Workaround for Logitech webcam. We have to wait a loooong time until the logitech cam is ready... #time.sleep(3) self.hardwareController.camera.device.objectExposure() self._laser_angle = self.image_processor.calculate_laser_angle(self.hardwareController.camera.device.getStream()) self._logger.debug("Detected Laser Angle at: %f deg" %(self._laser_angle, )) self._worker_pool.create(self.config.process_number)
def message_event(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "MESHING_DONE" message['data']['scan_id'] = self.prefix message['data']['level'] = "success" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def set_state(self, state): self._state = state message = FSUtil.new_message() message['type'] = FSEvents.ON_STATE_CHANGED message['data']['state'] = state self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def message_event(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "MESHING_DONE" message['data']['scan_id'] = self.scan_id message['data']['level'] = "success" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def on_laser_detection_failed(self): self._logger.info("Send laser detection failed message to frontend") message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "NO_LASER_FOUND" message['data']['level'] = "warn" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def on_laser_detection_failed(self): self._logger.info("Send laser detection failed message to frontend") message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "NO_LASER_FOUND" message['data']['level'] = "warn" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def _on_client_connected(self,eventManager, event): message = FSUtil.new_message() message['type'] = FSEvents.ON_CLIENT_INIT message['data']['client'] = event['client'] message['data']['state'] = self._state #message['data']['points'] = self.pointcloud message['data']['settings'] = self.settings.todict(self.settings) #message['data']['settings'] = dict() eventManager.publish(FSEvents.ON_SOCKET_SEND, message)
def init_texture_scan(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCANNING_TEXTURE" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) self._worker_pool.create(self.config.process_number) self._scan_brightness = self.settings.camera.brightness self._scan_contrast = self.settings.camera.contrast self.settings.camera.brightness = 50 self.settings.camera.contrast = 0 self.hardwareController.led.on(50,50,50) time.sleep(2) self.hardwareController.camera.device.flushStream() time.sleep(1) self.hardwareController.camera.device.getStream()
def image_processed(self, eventManager, event): if event['image_type'] == 'laser': self.append_points(event['points']) self.semaphore.acquire() self._progress += 1 self.semaphore.release() message = FSUtil.new_message() message['type'] = FSEvents.ON_NEW_PROGRESS message['data']['points'] = event['points'] message['data']['progress'] = self._progress message['data']['resolution'] = self._total if self._progress == self._total: self.scan_complete() eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def init_object_scan(self): self._logger.debug("Started object scan initialisation") self.current_position = 0 self._laser_positions = self.settings.laser_positions self.hardwareController.led.on(self.settings.led.red, self.settings.led.green, self.settings.led.blue) self.hardwareController.laser.on() self.settings.camera.brightness = self._scan_brightness self.settings.camera.contrast = self._scan_contrast self.settings.camera.saturation = self._scan_saturation # TODO: solve this timing issue! # Workaround for Logitech webcam. We have to wait a loooong time until the logitech cam is ready... #time.sleep(3) self.hardwareController.camera.device.objectExposure() self.hardwareController.camera.device.flushStream() time.sleep(2) self._laser_angle = self.image_processor.calculate_laser_angle( self.hardwareController.camera.device.getFrame()) if self._laser_angle == None: event = FSEvent() event.command = '_LASER_DETECTION_FAILED' self.eventManager.publish(FSEvents.COMMAND, event) self.on_laser_detection_failed() self._logger.debug("Send laser detection failure event") else: message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCANNING_OBJECT" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message) self._logger.debug("Detected Laser Angle at: %f deg" % (self._laser_angle, )) self._worker_pool.create(self.config.process_numbers)
def image_processed(self, eventManager, event): if event['image_type'] == 'laser': self.append_points(event['points']) self.semaphore.acquire() self._progress +=1 self.semaphore.release() message = FSUtil.new_message() message['type'] = FSEvents.ON_NEW_PROGRESS message['data']['points'] = event['points'] message['data']['progress'] = self._progress message['data']['resolution'] = self._total if self._progress == self._total: self.scan_complete() eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message)
def init_texture_scan(self): message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCANNING_TEXTURE" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST, message) self._worker_pool.create(self.config.process_numbers) self._scan_brightness = self.settings.camera.brightness self._scan_contrast = self.settings.camera.contrast self._scan_saturation = self.settings.camera.saturation self.hardwareController.camera.device.textureExposure() self.settings.camera.brightness = 50 self.settings.camera.contrast = 0 self.settings.camera.saturation = 0 self.hardwareController.led.on(30, 30, 30) time.sleep(2) self.hardwareController.camera.device.flushStream() time.sleep(1)
def init_object_scan(self): self._logger.debug("Started object scan initialisation") self.current_position = 0 self._laser_positions = self.settings.laser_positions self.hardwareController.led.on(self.settings.led.red,self.settings.led.green,self.settings.led.blue) self.hardwareController.laser.on() self.settings.camera.brightness = self._scan_brightness self.settings.camera.contrast = self._scan_contrast self.settings.camera.saturation = self._scan_saturation # TODO: solve this timing issue! # Workaround for Logitech webcam. We have to wait a loooong time until the logitech cam is ready... #time.sleep(3) self.hardwareController.camera.device.objectExposure() self.hardwareController.camera.device.flushStream() time.sleep(2) self._laser_angle = self.image_processor.calculate_laser_angle(self.hardwareController.camera.device.getFrame()) if self._laser_angle == None: event = FSEvent() event.command = '_LASER_DETECTION_FAILED' self.eventManager.publish(FSEvents.COMMAND,event) self.on_laser_detection_failed() self._logger.debug("Send laser detection failure event") else: message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "SCANNING_OBJECT" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message) self._logger.debug("Detected Laser Angle at: %f deg" %(self._laser_angle, )) self._worker_pool.create(self.config.process_numbers)
def run(self): try: self._logger.info("Meshlab Process Started...") basedir = os.path.dirname(os.path.dirname(__file__)) script_name = "default_meshing.mlx" mlx = basedir+"/mlx/"+script_name input = self.config.folders.scans+str(self.prefix)+"/scan_"+str(self.prefix)+".ply" output = self.config.folders.scans+str(self.prefix)+"/mesh_"+str(self.prefix)+"_"+script_name.split(".")[0]+".ply" FSSystem.run_command("xvfb-run meshlabserver -i "+input+" -o "+output+" -s "+str(mlx)+" -om vc vn") self.message_event() self._logger.info("Meshlab Process finished.") except: self._logger.error("Meshing Task crashed.") message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "MESHING_FAILED" message['data']['level'] = "error" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def _on_command(self,mgr, event): command = event.command ## Start Scan and goto Settings Mode if command == FSCommand.SCAN: if self._state is FSState.IDLE: self.set_state(FSState.SETTINGS) self.hardwareController.settings_mode_on() ## Update Settings in Settings Mode elif command == FSCommand.UPDATE_SETTINGS: if self._state is FSState.SETTINGS: try: #self._logger.info(event.settings) self.settings.update(event.settings) self.hardwareController.led.on(self.settings.led.red,self.settings.led.green,self.settings.led.blue) except: pass ## Start Scan Process elif command == FSCommand.START: if self._state is FSState.SETTINGS: self._logger.debug("Start command received...") self.set_state(FSState.SCANNING) self.hardwareController.settings_mode_off() self.scanProcessor = FSScanProcessor.start() self.scanProcessor.tell({FSEvents.COMMAND:FSCommand.START}) ## Stop Scan Process or Stop Settings Mode elif command == FSCommand.STOP: if self._state is FSState.SCANNING: self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) self.scanProcessor.stop() if self._state is FSState.SETTINGS: self.hardwareController.settings_mode_off() #self.scanProcessor.stop() self.hardwareController.camera.device.stopStream() self.set_state(FSState.IDLE) elif command == FSCommand._COMPLETE: self.set_state(FSState.IDLE) self.hardwareController.camera.device.stopStream() #self.scanProcessor.stop() self._logger.info("Scan complete") elif command == FSCommand._LASER_DETECTION_FAILED: #self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) self._logger.info("No Laser detected, returning to settings dialog.") #self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) #self.scanProcessor.stop() self.set_state(FSState.SETTINGS) self.hardwareController.settings_mode_on() elif command == FSCommand.MESHING: _meshlabTask = FSMeshlabTask(event.scan_id, event.filter, event.format) _meshlabTask.start() message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "MESHING_STARTED" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)
def _on_command(self,mgr, event): command = event.command ## Start Scan and goto Settings Mode if command == FSCommand.SCAN: if self._state is FSState.IDLE: self.set_state(FSState.SETTINGS) self.hardwareController.settings_mode_on() ## Update Settings in Settings Mode elif command == FSCommand.UPDATE_SETTINGS: if self._state is FSState.SETTINGS: try: #self._logger.info(event.settings) self.settings.update(event.settings) self.hardwareController.led.on(self.settings.led.red,self.settings.led.green,self.settings.led.blue) except: pass ## Start Scan Process elif command == FSCommand.START: if self._state is FSState.SETTINGS: self._logger.debug("Start command received...") self.set_state(FSState.SCANNING) self.hardwareController.settings_mode_off() self.scanProcessor = FSScanProcessor.start() self.scanProcessor.tell({FSEvents.COMMAND:FSCommand.START}) ## Stop Scan Process or Stop Settings Mode elif command == FSCommand.STOP: if self._state is FSState.SCANNING: self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) self.scanProcessor.stop() if self._state is FSState.SETTINGS: self.hardwareController.settings_mode_off() #self.scanProcessor.stop() self.hardwareController.camera.device.stopStream() self.set_state(FSState.IDLE) elif command == FSCommand._COMPLETE: self.set_state(FSState.IDLE) self.hardwareController.camera.device.stopStream() #self.scanProcessor.stop() self._logger.info("Scan complete") elif command == FSCommand._LASER_DETECTION_FAILED: #self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) self._logger.info("No Laser detected, returning to settings dialog.") #self.scanProcessor.ask({FSEvents.COMMAND:FSCommand.STOP}) #self.scanProcessor.stop() self.set_state(FSState.SETTINGS) self.hardwareController.settings_mode_on() elif command == FSCommand.MESHING: _meshlabTask = FSMeshlabTask(event.scan_id) _meshlabTask.start() message = FSUtil.new_message() message['type'] = FSEvents.ON_INFO_MESSAGE message['data']['message'] = "MESHING_STARTED" message['data']['level'] = "info" self.eventManager.publish(FSEvents.ON_SOCKET_BROADCAST,message)