def draw(self, painter, color):
		
		coord = self.rotate()
	
		x0 = round(self.robot.posX + coord[0] * self.relDist)
		y0 = round(self.robot.posY + coord[1] * self.relDist)
		
		dx = coord[0] * RangeSensor.MAX_DISTANCE
		dy = coord[1] * RangeSensor.MAX_DISTANCE
		
		x1 = round(x0 + dx)
		y1 = round(y0 + dy)
		
		#color = QtGui.QColor(0xFF0000)
		painter.fillRect(x0, y0, 1, 1, color)
		
		dx = abs(x1 - x0)
		dy = abs(y1 - y0)
		
		if x0 < x1:
			sx = 1
		else:
			sx = -1
		if y0 < y1:
			sy = 1
		else:
			sy = -1
		err = dx - dy
		
		while True:
			#print('range_sensor.RangeSensor.draw x0: ' + str(x0) + ' y0: ' + str(y0) + ' x1: ' + str(x1) + ' y1: ' + str(y1))
			if x0 < 0 or y0 < 0 or x0 >= ImageMap.width() or y0 >= ImageMap.height():
				return
			
			if ImageMap.pixel(x0, y0) != 0xFFFFFFFF:
				return
			
			painter.fillRect(x0, y0, 1, 1, color)
			
			if x0 == x1 and y0 == y1:
				return
		
			e2 = 2 * err
			if e2 > -dy: 
				err = err - dy
				x0 = x0 + sx
			
			if x0 == x1 and y0 == y1:
				painter.fillRect(x0, y0, 1, 1, color)
				self.distance = RangeSensor.MAX_DISTANCE
				return
			
			if e2 <  dx:
				err = err + dx
				y0 = y0 + sy 
Beispiel #2
0
def rendered_events(event_filter=None, ics_uri=None):
    start_time = time.time()

    event_filter = request.args.get('filter')
    ics_uri = request.args.get('input')
    image_map_path = request.args.get('images') or DEFAULT_IMAGE_MAP_PATH
    refresh = request.args.get('refresh')
    look_ahead_days = request.args.get('look_ahead_days') or MAX_LOOKAHEAD_DAYS
    if refresh is not None:
        try:
            refresh = int(refresh)
        except ValueError:
            pass

    template = Template(path=DEFAULT_TEMPLATE_PATH).get_template()

    if any([arg is None for arg in [event_filter, ics_uri]]):
        return template.render(error="Parameters missing")

    cal = Cal(ics_uri)

    today, today_events = cal.filter_events_today(event_filter)
    next_day, next_day_events = cal.filter_events_next_occurrence(
        event_filter, look_ahead_days)

    image_map = ImageMap(image_map_path)
    today_events = image_map.add_images(today_events)

    duration = time.time() - start_time
    return template.render(today_events=today_events,
                           today=today.strftime("%A, %-d %b %Y"),
                           next_day_events=next_day_events,
                           next_day=next_day.strftime("%A, %-d %b %Y"),
                           refresh=refresh,
                           filter_expr=event_filter,
                           last_updated=datetime.now().strftime("%A, %-d %b %Y %H:%M:%S"),
                           duration="{0:.3f}".format(duration))
Beispiel #3
0
    def save_map(self):
        name = self.Name.toPlainText()

        # Map prepared must have a name
        if not name:
            info_box = qt.QMessageBox(self)
            info_box.setIcon(qt.QMessageBox.Critical)
            info_box.setText("Name can't be empty!")
            return info_box.exec()

        # Computes keypoints and descriptors of the image map
        sift = cv2.xfeatures2d.SIFT_create()
        image_hist_eq = utils.histogram_equalization(self.img)
        kp, des = sift.detectAndCompute(image_hist_eq, None)

        # Because pickling cv2.KeyPoint causes PicklingError, we need to create a new abstraction for it
        keypoints = utils.keypoints_to_kpdict(kp)

        interestPoints = [
            a.getInterestPoint() for a in self.editor_scene.augments
        ]

        try:
            scale = int(self.Name_2.toPlainText())
            # TODO
        except:
            info_box = qt.QMessageBox(self)
            info_box.setIcon(qt.QMessageBox.Critical)
            info_box.setText("Please insert a valid number as scale!")
            return info_box.exec()

        # Creates a new ImageMap with the data from the manipulated image
        imageMap = ImageMap(name, scale, self.editor_scene.entry['img'],
                            keypoints, des, interestPoints)
        self._database.add_map(imageMap)

        info_box = qt.QMessageBox(self)
        info_box.setIcon(qt.QMessageBox.Information)
        info_box.setText("Saved successfully as '%s'" % imageMap.name)
        info_box.exec()
        self.entry_saved.emit(imageMap)
	def getDistance(self):
		coord = self.rotate()
	
		x0 = round(self.robot.posX + coord[0] * self.relDist)
		y0 = round(self.robot.posY + coord[1] * self.relDist)
		
		sX0 = x0
		sY0 = y0
		
		dx = coord[0] * RangeSensor.MAX_DISTANCE
		dy = coord[1] * RangeSensor.MAX_DISTANCE
		
		x1 = round(x0 + dx)
		y1 = round(y0 + dy)
		
		#color = QtGui.QColor(0xFF0000)
		
		dx = abs(x1 - x0)
		dy = abs(y1 - y0)
		
		if x0 < x1:
			sx = 1
		else:
			sx = -1
		if y0 < y1:
			sy = 1
		else:
			sy = -1
		err = dx - dy
		
		px = x0
		py = y0
		
		while True:
			#TODO cleanup
			#print('range_sensor.RangeSensor.draw x0: ' + str(x0) + ' y0: ' + str(y0) + ' x1: ' + str(x1) + ' y1: ' + str(y1))
			#print('%08X' % (ImageMap.image.pixel(x0, y0),))
			#print('%d - %d' % (x0, y0))
			
			if x0 < 0 or y0 < 0 or x0 >= ImageMap.width() or y0 >= ImageMap.height():
				
				d = math.sqrt(math.pow(sX0 - px, 2.0) + math.pow(sY0 - py, 2.0))
				
				if d < 0 or d > 1000:
					print('A: %d - %d # %f' % (px, py, d))
				return d
			
			if ImageMap.pixel(x0, y0) != 0xFFFFFFFF:
				
				d =  math.sqrt(math.pow(sX0 - x0, 2.0) + math.pow(sY0 - y0, 2.0))
				
				if d < 0 or d > 1000:
					print('B: %d - %d # %f' % (px, py, d))
				return d
			
			if x0 == x1 and y0 == y1:
				return RangeSensor.MAX_DISTANCE
			
			e2 = 2 * err
			if e2 > -dy: 
				err = err - dy
				px = x0
				x0 = x0 + sx
			
			if x0 == x1 and y0 == y1:
				return RangeSensor.MAX_DISTANCE
			
			if e2 <  dx:
				err = err + dx
				py = y0
				y0 = y0 + sy