def addEdge(self, points, simplifyEpsilon=0.5, container=True, figClass=fig.Polygon, **attr): """fe.addEdge(points, simplifyEpsilon, ...) Adds and returns exactly one fig.Polygon object representing the given points. You will probably want to use addClippedPoly() instead. If simplifyEpsilon (default: 0.5) is not None, simplifyPolygon is called on the *scaled* polygon (i.e. the default is to simplify the polygon to 0.5 fig units, which are integer anyways).""" if container == True: container = self.f o = self.offset + attr.get('offset', (0, 0)) if self.roi: o -= self.roi.begin() pp = Polygon([(o + point) * self.scale for point in points]) if simplifyEpsilon: pp = simplifyPolygon(pp, simplifyEpsilon) fp = figClass([intPos(v) for v in pp], closed=pp[0] == pp[-1]) for a in attr: if a != "offset": setattr(fp, a, attr[a]) container.append(fp) return fp
def addEdge(self, points, simplifyEpsilon = 0.5, container = True, figClass = fig.Polygon, **attr): """fe.addEdge(points, simplifyEpsilon, ...) Adds and returns exactly one fig.Polygon object representing the given points. You will probably want to use addClippedPoly() instead. If simplifyEpsilon (default: 0.5) is not None, simplifyPolygon is called on the *scaled* polygon (i.e. the default is to simplify the polygon to 0.5 fig units, which are integer anyways).""" if container == True: container = self.f o = self.offset + attr.get('offset', (0,0)) if self.roi: o -= self.roi.begin() pp = Polygon([(o + point) * self.scale for point in points]) if simplifyEpsilon: pp = simplifyPolygon(pp, simplifyEpsilon) fp = figClass([intPos(v) for v in pp], closed = pp[0] == pp[-1]) for a in attr: if a != "offset": setattr(fp, a, attr[a]) container.append(fp) return fp
def _calculateZoomedEdge(self, edgeLabel, edge): """Zoom edge according to zoom level. Does not do upperLeft() translation yet (only accounts for the pixel-center offset).""" offset = (self._zoom / 2.0 - 0.5, self._zoom / 2.0 - 0.5) origEdgePoints = (simplifyPolygon(edge * self._zoom, 0.1) + offset).roundToInteger() qpa = self._zoomedEdges[edgeLabel] if qpa == None or qpa.size() != len(origEdgePoints): qpa = QtGui.QPolygon(len(origEdgePoints)) self._zoomedEdges[edgeLabel] = qpa for i, pos in enumerate(origEdgePoints): qpa.setPoint(i, pos[0], pos[1]) return qpa
def _calculateZoomedEdge(self, edgeLabel, edge): """Zoom edge according to zoom level. Does not do upperLeft() translation yet (only accounts for the pixel-center offset).""" offset = (self._zoom / 2.0 - 0.5, self._zoom / 2.0 - 0.5) origEdgePoints = ( simplifyPolygon(edge * self._zoom, 0.1) + offset).roundToInteger() qpa = self._zoomedEdges[edgeLabel] if qpa == None or qpa.size() != len(origEdgePoints): qpa = QtGui.QPolygon(len(origEdgePoints)) self._zoomedEdges[edgeLabel] = qpa for i, pos in enumerate(origEdgePoints): qpa.setPoint(i, pos[0], pos[1]) return qpa
def faceCDTMap(face, imageSize, simplifyEpsilon = None, resample = None, onlyInner = True): """USAGE: dlm = faceCDTMap(face, mapSize) `face` should be a GeoMap.Face object, and all its contours will be extracted. `mapSize` is used to initialize the GeoMap with the resulting edges. Optional keyword parameters: simplifyEpsilon If given, each contour polygon is simplified by calling simplifyPolygon with this epsilon as parameter (default None -> don't use simplifyPolygon). markContour If True(default), the point list is expected to be a sorted list, and edges between successive entries are marked as contour edges (an exception is raised if such a connection is missing). A `jumpPoints` list is used to mark multiple contours. onlyInner If True(default), all edges outside (left) of the marked contour are removed in a post-processing step. (This has no effect if `markContour` is False.)""" polygons = [contourPoly(c) for c in face.contours()] if resample: polygons = [geomap.resamplePolygon(p, resample) for p in polygons] if simplifyEpsilon != None: polygons = [geomap.simplifyPolygon(p, simplifyEpsilon) for p in polygons] if triangle: result = constrainedDelaunayMap(polygons, imageSize) else: result = fakedConstrainedDelaunayMap(polygons, imageSize) return result
def levelSetMap(image, level = 0, sigma = None): siv = hasattr(image, "siv") and image.siv or vigra.SplineImageView3(image) zc = findZeroCrossingsOnGrid(siv, level) result = geomap.GeoMap(zc, [], image.size()) msg = progress.StatusMessage("- following level set contours") next = progress.ProgressHook(msg).rangeTicker(result.nodeCount) for node in result.nodeIter(): next() if node.isIsolated(): followContour(siv, level, result, node.label(), 0.1) maputils.mergeDegree2Nodes(result) result = maputils.copyMapContents( # compress labels and simplify polygons result, edgeTransform = lambda e: \ geomap.simplifyPolygon(e, 0.05, 0.2))[0] #maputils.connectBorderNodes(result, 0.01) result.sortEdgesEventually(0.4, 0.01) result.initializeMap() return result
def levelSetMap(image, level=0, sigma=None): siv = hasattr(image, "siv") and image.siv or vigra.SplineImageView3(image) zc = findZeroCrossingsOnGrid(siv, level) result = geomap.GeoMap(zc, [], image.size()) msg = progress.StatusMessage("- following level set contours") next = progress.ProgressHook(msg).rangeTicker(result.nodeCount) for node in result.nodeIter(): next() if node.isIsolated(): followContour(siv, level, result, node.label(), 0.1) maputils.mergeDegree2Nodes(result) result = maputils.copyMapContents( # compress labels and simplify polygons result, edgeTransform = lambda e: \ geomap.simplifyPolygon(e, 0.05, 0.2))[0] #maputils.connectBorderNodes(result, 0.01) result.sortEdgesEventually(0.4, 0.01) result.initializeMap() return result