コード例 #1
0
ファイル: findPoly.py プロジェクト: sietschie/animateWorms
def extendSkeletonTangentsToMatchSourceTangents(tangents, sourceTangents):
	extendedTangents = [];

	for i in range(len(tangents)):
		l1 = tangents[i][0]
		l2 = tangents[i][1]

		lmean = [ (l1[0] + l2[0])/2.0, (l1[1] + l2[1])/2.0 ]

		sl1 = sourceTangents[i][0]
		sl2 = sourceTangents[i][1]

		slmean = [ (sl1[0] + sl2[0])/2.0, (sl1[1] + sl2[1])/2.0 ]
		
		sDistL1 = vf.distance(sl1,slmean)
		distL1 = vf.distance(l1,lmean)
		
		diff = vf.pDiff(l1, lmean)
		extendedL1 = [ lmean[0] + sDistL1 * diff[0]/distL1, lmean[1] + sDistL1 * diff[1]/distL1 ]

		sDistL2 = vf.distance(sl2,slmean)
		distL2 = vf.distance(l2,lmean)
		
		diff = vf.pDiff(l2, lmean)
		extendedL2 = [ lmean[0] + sDistL2 * diff[0]/distL2, lmean[1] + sDistL2 * diff[1]/distL2 ]

		extendedTangents.append( [ extendedL1, extendedL2 ] )
	return extendedTangents
コード例 #2
0
ファイル: findPoly.py プロジェクト: sietschie/animateWorms
def extendSkeletonTangentsToObjectBorder(image, tangents):
	
	extendedTangents = [];
	
	for i in range(len(tangents)):
		l1 = tangents[i][0]
		l2 = tangents[i][1]
		
		lmean = [ (l1[0] + l2[0])/2.0, (l1[1] + l2[1])/2.0 ]
		
		# for l1
		
		diff = vf.pDiff(l1, lmean)
		dist = vf.pLength(diff)
		delta = [diff[0]/dist, diff[1]/dist]
		
		prolonged_l1 = l1
		while True:
			if not( prolonged_l1[0] >= 0 and prolonged_l1[0] < image.shape[1] and prolonged_l1[1] >= 0 and prolonged_l1[1] < image.shape[0]):
				# point has left the image
				
				prolonged_l1 = l1
				break
				
			pixel = image[int(prolonged_l1[1]),int(prolonged_l1[0])]
			
			if pixel[3] < 10: #entering the transparent zone, leaving the object
				break
				
			prolonged_l1 = [prolonged_l1[0] + delta[0], prolonged_l1[1] + delta[1]] 
		prolonged_l1 = (int(prolonged_l1[0]),int(prolonged_l1[1]))
		
		diff = vf.pDiff(l2, lmean)
		dist = vf.pLength(diff)
		delta = [diff[0]/dist, diff[1]/dist]

		prolonged_l2 = l2
		while True:
			if not( prolonged_l2[0] >= 0 and prolonged_l2[0] < image.shape[1] and prolonged_l2[1] >= 0 and prolonged_l2[1] < image.shape[0]):
				# point has left the image
				
				prolonged_l2 = l2
				#print 'point left the image'
				break
				
			pixel = image[int(prolonged_l2[1]),int(prolonged_l2[0])]
			
			if pixel[3] < 10: #entering the transparent zone, leaving the object
				#print 'found end of object'
				break
				
			prolonged_l2 = [prolonged_l2[0] + delta[0], prolonged_l2[1] + delta[1]] 
			#print prolonged_l2
		prolonged_l2 = (int(prolonged_l2[0]),int(prolonged_l2[1]))
		
		extendedTangents.append( [ prolonged_l1, prolonged_l2 ] )
		
		#print 'prolong: ', [l1,l2], [ prolonged_l1, prolonged_l2 ]
	return extendedTangents
コード例 #3
0
ファイル: findPoly.py プロジェクト: sietschie/animateWorms
def computeSkeletonTangents(skeletonPoints):

	length = 10;
	skeletonTangents = [  [(int(skeletonPoints[0][0] + length), int(skeletonPoints[0][1])), (int(skeletonPoints[0][0] - length), int(skeletonPoints[0][1])) ]];

	for i in range(len(skeletonPoints)-2):
		p1 = skeletonPoints[i]
		p2 = skeletonPoints[i+1]
		p3 = skeletonPoints[i+2]
		
		theta = vf.getTangentialAngle(p1,p2,p3);
		
		l1 = ( int(p2[0] + length*math.cos(theta)), int(p2[1] + length*math.sin(theta)));
		l2 = ( int(p2[0] - length*math.cos(theta)), int(p2[1] - length*math.sin(theta)));
		
		skeletonTangents.append([l1,l2])
		
	pDiff = vf.pDiff(skeletonPoints[-1], skeletonPoints[-2])
	
	l1 = ( int(skeletonTangents[-1][0][0] + pDiff[0]), int(skeletonTangents[-1][0][1] + pDiff[1]) )
	l2 = ( int(skeletonTangents[-1][1][0] + pDiff[0]), int(skeletonTangents[-1][1][1] + pDiff[1]) )
	skeletonTangents.append( [l1,l2] )
	
	
	return skeletonTangents
コード例 #4
0
def segmentsFromPointsToPolar(segments):
# convert so that each segment is described by a length and an angle
# the starting point is the end of the previous segment
	
	polarSegments = [segments[0]] # start point
	# sequential
	for i in range(1,len(segments)):
		p1 = segments[i-1]
		p2 = segments[i]
		
		distance = vf.distance(p2,p1)
		diff = vf.pDiff(p2, p1)
		theta = math.atan2(diff[0], -diff[1])
		
		polarSegments.append([distance, theta])
		
	return polarSegments
コード例 #5
0
	def test_pDiff(self):
		rp = vectorFunctions.pDiff(self.p4, self.p6)
		self.assertEqual(rp[0], -1)
		self.assertEqual(rp[1], 1)