示例#1
0
 def __isub__(self, intersectWith):
     if (isinstance(intersectWith, Area)):
         a1 = Area(LineUtils().lineToGeneralPath(self.autoStroke()))
         a1.subtract(intersectWith)
         self.__dict__["line"] = self.maybeFix(LineUtils().piToCachedLine(
             a1.getPathIterator(None)))
     return self
def findMergedContour(project):
	# Find the two bezier Profile instances that define the contour
	# and merge them into a single Area.
	lys = project.getRootLayerSet()
	contour = Area()
	for profile in lys.getDisplayables(Profile):
		pt = project.findProjectThing(profile)
		if pt is None:
			print "null pt for profile ", profile
			continue
		if pt.getParent().getParent().getTitle() == "contour":
			contour.add(Area(profile.getPerimeter()))

	# Extract a single Polygon from the Area
	pols = M.getPolygons(contour)
	if len(pols) > 1:
		print "More than one polygon for the contour!"
	return pols[0]
def scaleContour(pol, scale):
	# Scale up the polygon relative to its center
	cx = 0
	cy = 0
	for i in range(pol.npoints):
		cx += pol.xpoints[i]
		cy += pol.ypoints[i]

	cx /= pol.npoints
	cy /= pol.npoints

	aff = AffineTransform(1, 0, 0, 1, -cx, -cy)
	aff.preConcatenate(AffineTransform(scale, 0, 0, scale, 0, 0))
	aff.preConcatenate(AffineTransform(1, 0, 0, 1, cx, cy))

	tmp = Area(pol)
	tmp.transform(aff)
	return M.getPolygons(tmp)[0]
def fixAreatreeArea(areatree):
    # Append a 1-pixel square area for nodes without any area
    # this will fix using findZDisplayables for finding areatree, 
    #     including connector.getTargets(), connector.getOrigins() etc.
    if not isinstance(areatree, AreaTree):
        print "Error: input must be an AreaTree"
        return
    root = areatree.getRoot()
    if root is None:
        return
    for nd in root.getSubtreeNodes():
        a = nd.getArea()
        a.add(Area(Rectangle(int(nd.getX()), int(nd.getY()), 1, 1)))
        nd.setData(a)
def findLocals(project, pol):
	# Test if any node of every treeline is outside the polygon,
	# to determine if a neuron is local or not.
	lys = project.getRootLayerSet()
	trees = [t for t in lys.getZDisplayables(Treeline)]
	trees = trees + [t for t in lys.getZDisplayables(AreaTree)]

	tags = {}

	for tree in trees:
		# Make the polygon local to the tree coordinates
		a = Area(pol)
		a.transform(tree.getAffineTransform().createInverse())
		localPol = M.getPolygons(a)[0]
		isLocal = False
		for node in tree.getRoot().getSubtreeNodes():
			if localPol.contains(node.x, node.y):
				continue
			isLocal = True
			break
		tags[tree.getId()] = isLocal

	return tags
示例#6
0
文件: TweakTools.py 项目: EQ4/Field
	def __isub__(self, intersectWith):
		if (isinstance(intersectWith, Area)):
			a1 = Area(LineUtils().lineToGeneralPath(self.autoStroke()))
			a1.subtract(intersectWith)
			self.__dict__["line"] = self.maybeFix(LineUtils().piToCachedLine(a1.getPathIterator(None)))
		return self
示例#7
0
        layerset = areatree.getLayerSet()
        calibration = layerset.getCalibration()
        affine = areatree.getAffineTransform()
        # outAndInArray = areatree.findConnectors()
        for nd in root.getSubtreeNodes():
            # get node coordinates, from tut on web
            fp = array([nd.getX(), nd.getY()], 'f')
            affine.transform(fp, 0, fp, 0, 1)
            x = fp[0] * calibration.pixelWidth
            y = fp[1] * calibration.pixelHeight
            z = nd.getLayer().getZ(
            ) * calibration.pixelWidth  # a TrakEM2 oddity

            # get node connections, in/out synapse number, synapse id
            # NOTE: this method seems to be affected by display zoom value
            area = Area(Rectangle(int(fp[0]), int(fp[1]), 1, 1))
            # area.transform(affine)
            inAndOuts = layerset.findZDisplayables(Connector, nd.getLayer(),
                                                   area, False, False)
            outgoing = []
            incoming = []
            for connector in inAndOuts:
                if connector is None:
                    break
                if connector.intersectsOrigin(area, nd.getLayer()):
                    outgoing.append(connector)
                else:
                    incoming.append(connector)
            nInputs = len(incoming)
            nOutputs = len(outgoing)
            outgoingIds = [oc.getId() for oc in outgoing]
示例#8
0
def squarea(
    self, offset
):  #This is the default area generator. It will be overridden by certain shapes.
    return Area(Rectangle2D.Double(-offset.x, -offset.y, 1, 1))
示例#9
0
 def area(self):
     return Area(LineUtils().lineToGeneralPath(self.__dict__["line"]))
示例#10
0
def toArea2(self):
	"""Convert this line to a java.geom.Area"""
	return Area(LineUtils().lineToGeneralPath(self))