Beispiel #1
0
	def getFeretSegments(self, n):
		self.__boolFS=True
		if(not self.__boolFL):
			self.__FeretAxis()
		radius=self.getMinF()
		lsegment=self.__line.getLength()/((n-1)*2)
		xo=self.__x1
		yo=self.__y1
		xf=self.__x2
		yf=self.__y2
		angle1=self.getAngF()*(math.pi/180)
		angle2=self.getAngF()*(math.pi/180)+(math.pi/2)
		avancex=(lsegment*2)*math.cos(angle1)
		avancey=(lsegment*2)*math.sin(angle1)
		delta90x=(radius)*math.cos(angle2)
		delta90y=(radius)*math.sin(angle2)
		self.__line.setWidth(int(lsegment*2))
		#self.__image.setRoi(self.__line)
		tempcontour=self.__contour.clone()
		shapeContour=ShapeRoi(tempcontour)
		segsRoi=[]
		for i in range(n):
			tempLine=Line(xo-delta90x, yo+delta90y, xo+delta90x, yo-delta90y)
			tempLine.setWidth(int(lsegment*2))
			poly=tempLine.getPolygon()
			roipol=PolygonRoi(poly, Roi.POLYGON)
			shapePoly= ShapeRoi(roipol)
			interShape=shapePoly.and(shapeContour)
			segsRoi.append(interShape.shapeToRoi())
			xo=xo+avancex
			yo=yo-avancey

		
		#self.__image.setRoi(self.__contour, True)
		#time.sleep(0)
		self.__line.setWidth(0)
		#self.__image.setRoi(tempcontour)
		
		#self.__image.updateAndDraw() 
		
		return segsRoi # return Roi array
Beispiel #2
0
	def getMidSegments(self, n=10, r=5, tool=0):
		self.__boolMS=True
		if(not self.__boolML):
			self.__midline()
		lsegment=int(len(self.__midLine)/n)
		if lsegment<2:lsegment=2
		ls2=int(len(self.__midLine)/(2*n))
		if ls2<1: ls2=1
		ip=self.__image.getProcessor()
		#print(len(self.__midLine), lsegment, ls2)
		xo=self.__MidBouts[0][0]
		yo=self.__MidBouts[0][1]
		xf=self.__MidBouts[1][0]
		yf=self.__MidBouts[1][1]
		line1=Line(xo,yo,xf,yf)
		line1.setWidth(0)
		angles=[line1.getAngle(self.__midLine[i][0], self.__midLine[i][1], self.__midLine[i+lsegment][0], self.__midLine[i+lsegment][1]) for i in range(0,len(self.__midLine)-lsegment,lsegment)]
		points=[self.__midLine[i] for i in range(0,len(self.__midLine),lsegment)]
		lastangle=line1.getAngle(self.__midLine[-ls2][0],self.__midLine[-ls2][1],self.__midLine[-1][0],self.__midLine[-1][1])
		angles.append(lastangle)
		tempcontour=self.__contour.clone()
		shapeContour=ShapeRoi(tempcontour)
		angles=[angle*(math.pi/180)+(math.pi/2) for angle in angles]
		line1.setWidth((ls2+1)*2)
		segsRoi=[]
		linesRois=[]
		cRois=[]
		for i in range(len(angles)):
			x=points[i][0]
			y=points[i][1]
			cRois.append(PointRoi(x,y))
			if tool==0: # ligne perpendiculaire d'epaiseur  (ls2+1)*2
				line1.setWidth((ls2+1)*2)
				x1=x+r*math.cos(angles[i])
				y1=y-r*math.sin(angles[i])
				x2=x-r*math.cos(angles[i])
				y2=y+r*math.sin(angles[i])
				#print(x, y, x1, y1, x2, y2)
				tempLine=Line(x1,y1,x2,y2)
				linesRois.append(tempLine)
				tempLine.setWidth((ls2+1)*2)
				#self.__image.setRoi(tempLine, True)
				#time.sleep(0.3)
				poly=tempLine.getPolygon()
				roipol=PolygonRoi(poly, Roi.POLYGON)
				shapePoly= ShapeRoi(roipol)
			elif tool==1:
				#r1=r*0.7
				x1=x+r
				y1=y-r
				x2=x-r
				y2=y+r
				ellipse=EllipseRoi(x1, y1, x2, y2, 1)
				linesRois.append(ellipse)
				#print(x, y, x1, y1, x2, y2)
				#self.__image.setRoi(ellipse, True)
				shapePoly= ShapeRoi(ellipse)
				#time.sleep(0.3)
			else:
				x1=x
				y1=y
				line1.setWidth(r)
				if (i+1)<len(points):
					x2=points[i+1][0]
					y2=points[i+1][1]
				else:
					#x1=x+lsegment*math.cos(angles[i]-(math.pi/2))
					#y1=y-lsegment*math.sin(angles[i]-(math.pi/2))
					x2=x+lsegment*math.cos(angles[i]-(math.pi/2))
					y2=y-lsegment*math.sin(angles[i]-(math.pi/2))
					#x2=xf
					#y2=yf
				
				tempLine=Line(x1,y1,x2,y2)
				linesRois.append(tempLine)
				tempLine.setWidth(r)
				#self.__image.setRoi(tempLine, True)
				#time.sleep(0.5)
				poly=tempLine.getPolygon()
				roipol=PolygonRoi(poly, Roi.POLYGON)
				shapePoly= ShapeRoi(roipol)
			
			interShape=shapePoly.and(shapeContour)
			interRoi=interShape.shapeToRoi()
			segsRoi.append(interShape.shapeToRoi())
		line1.setWidth(0)
		return (segsRoi, linesRois, cRois)