Exemplo n.º 1
0
	def registerCursors(self, *args,**kwargs):
		self.id = kwargs.get('id', 0)
		cursors = args[0]
		
		# set the center for tangible creation, if not provdided otherwise
		calibrationCenter = pointVector(settings.get('calibrationCenter')[0],settings.get('calibrationCenter')[1])
		
		# add points to dictionary
		for c in cursors:
				self.tangibleCursors[c.id] = tangibleCursor(x=c.x,y=c.y)
				self.tangibleCursors[c.id].calcOffset(calibrationCenter)
		# create triangles from points	
		self.tangibleTriangles = createTrianglesFromCursors(cursors)
Exemplo n.º 2
0
    def registerCursors(self, *args, **kwargs):
        self.id = kwargs.get('id', 0)
        cursors = args[0]

        # set the center for tangible creation, if not provdided otherwise
        calibrationCenter = pointVector(
            settings.get('calibrationCenter')[0],
            settings.get('calibrationCenter')[1])

        # add points to dictionary
        for c in cursors:
            self.tangibleCursors[c.id] = tangibleCursor(x=c.x, y=c.y)
            self.tangibleCursors[c.id].calcOffset(calibrationCenter)
        # create triangles from points
        self.tangibleTriangles = createTrianglesFromCursors(cursors)
Exemplo n.º 3
0
	def compareTangibleTrianglesAndExternalTriangles(self, *args):
		self.externalCursors = args[0]
		# create all possible triangles from received cursors
		externalTriangles = createTrianglesFromCursors(self.externalCursors)
		
		tolerance = settings.get('tolerance')
		
		for externalTriangle in externalTriangles:
			for internalTriangle in self.tangibleTriangles:
		
				if compareTriangles(externalTriangle,internalTriangle,tolerance):
					# set last known position of tangible cursors and vote for them
					ids = internalTriangle.getIDs()
					self.setLastKnownPositions(ids, externalTriangle)
					self.voteForIDs(ids)
		
		# sort points by their received votes
		sortedKeys = []
		for key, value in sorted(self.tangibleCursors.iteritems(), key=lambda (k,v): (v.votes,k), reverse=True):
			sortedKeys.append(key)
		

		# check if their have been enough votes
		highestVotes	= self.tangibleCursors[sortedKeys[1]].votes
		neededVotes		= settings.get('neededVotes')
		if settings.get('debugVotes'):
			print "Highest",	highestVotes
			print "Needed",		neededVotes
		
		if highestVotes >= neededVotes:
			self.currentlyRecognized = True
			self.outOfJailCard = settings.get('outOfJailCard')
			
			self.lastSuccesfulRunIDs = []
			for tangibleCursorID in sortedKeys:
				oneSuccessful = self.tangibleCursorIDtoExternalID(tangibleCursorID)
				if oneSuccessful != []:
					self.lastSuccesfulRunIDs.append(oneSuccessful)
			
			# calculate tangible postion and rotation with best recognized cursors
			id1 = sortedKeys[0]
			id2 = sortedKeys[1]
			self.calculateTangiblePositionAndRotation(id1,id2)
			
		else:
			#compare current live IDs with last succeful recognized IDs
			liveIDs = []
			for externalCursor in self.externalCursors:
				liveIDs.append(externalCursor.id)
			cursorIntersection = filter(set(liveIDs).__contains__, self.lastSuccesfulRunIDs)
			
			#check if at least two cursors are left
			if len(cursorIntersection) > 1:
				self.currentlyRecognized = True
				self.outOfJailCard = settings.get('outOfJailCard')
				
				# take first two live ids and calculate with them
				id1 = cursorIntersection[0]
				id2 = cursorIntersection[1]
				self.calculateTangiblePositionAndRotationWithLiveIDs(id1,id2)
				
			else:
				# to prevent single "glitches" from disturbing the signal the tangible has some out of jail cards
				if self.outOfJailCard > 0:
					self.outOfJailCard -= 1
					self.currentlyRecognized = True
				else:
					self.currentlyRecognized = False
					if settings.get('debugVotes'):
						print 'No match for ID:', self.id		
				
		self.dropVotes()
Exemplo n.º 4
0
    def compareTangibleTrianglesAndExternalTriangles(self, *args):
        self.externalCursors = args[0]
        # create all possible triangles from received cursors
        externalTriangles = createTrianglesFromCursors(self.externalCursors)

        tolerance = settings.get('tolerance')

        for externalTriangle in externalTriangles:
            for internalTriangle in self.tangibleTriangles:

                if compareTriangles(externalTriangle, internalTriangle,
                                    tolerance):
                    # set last known position of tangible cursors and vote for them
                    ids = internalTriangle.getIDs()
                    self.setLastKnownPositions(ids, externalTriangle)
                    self.voteForIDs(ids)

        # sort points by their received votes
        sortedKeys = []
        for key, value in sorted(self.tangibleCursors.iteritems(),
                                 key=lambda (k, v): (v.votes, k),
                                 reverse=True):
            sortedKeys.append(key)

        # check if their have been enough votes
        highestVotes = self.tangibleCursors[sortedKeys[1]].votes
        neededVotes = settings.get('neededVotes')
        if settings.get('debugVotes'):
            print "Highest", highestVotes
            print "Needed", neededVotes

        if highestVotes >= neededVotes:
            self.currentlyRecognized = True
            self.outOfJailCard = settings.get('outOfJailCard')

            self.lastSuccesfulRunIDs = []
            for tangibleCursorID in sortedKeys:
                oneSuccessful = self.tangibleCursorIDtoExternalID(
                    tangibleCursorID)
                if oneSuccessful != []:
                    self.lastSuccesfulRunIDs.append(oneSuccessful)

            # calculate tangible postion and rotation with best recognized cursors
            id1 = sortedKeys[0]
            id2 = sortedKeys[1]
            self.calculateTangiblePositionAndRotation(id1, id2)

        else:
            #compare current live IDs with last succeful recognized IDs
            liveIDs = []
            for externalCursor in self.externalCursors:
                liveIDs.append(externalCursor.id)
            cursorIntersection = filter(
                set(liveIDs).__contains__, self.lastSuccesfulRunIDs)

            #check if at least two cursors are left
            if len(cursorIntersection) > 1:
                self.currentlyRecognized = True
                self.outOfJailCard = settings.get('outOfJailCard')

                # take first two live ids and calculate with them
                id1 = cursorIntersection[0]
                id2 = cursorIntersection[1]
                self.calculateTangiblePositionAndRotationWithLiveIDs(id1, id2)

            else:
                # to prevent single "glitches" from disturbing the signal the tangible has some out of jail cards
                if self.outOfJailCard > 0:
                    self.outOfJailCard -= 1
                    self.currentlyRecognized = True
                else:
                    self.currentlyRecognized = False
                    if settings.get('debugVotes'):
                        print 'No match for ID:', self.id

        self.dropVotes()