How to use the histomicstk.annotations_and_masks.pyrtree.rtree._NodeCursor function in histomicstk

To help you get started, we’ve selected a few histomicstk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
def create_leaf(cls, rooto, leaf_obj, leaf_rect):
        """Placeholder."""
        rect = Rect(leaf_rect.x, leaf_rect.y, leaf_rect.xx, leaf_rect.yy)
        rect.swapped_x = True  # Mark as leaf by setting the xswap flag.
        res = _NodeCursor.create(rooto, rect)
        idx = res.index
        res.first_child = rooto.leaf_count
        rooto.leaf_count += 1
        res.next_sibling = 0
        rooto.leaf_pool.append(leaf_obj)
        res._save_back()
        res._become(idx)
        assert(res.is_leaf())
        return res
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
def create(cls, rooto, rect):
        """Placeholder."""
        idx = rooto.count
        rooto.count += 1

        rooto._ensure_pool(idx + 1)
        # rooto.node_pool.extend([0,0])
        # rooto.rect_pool.extend([0,0,0,0])

        retv = _NodeCursor(rooto, idx, rect, 0, 0)

        retv._save_back()
        return retv
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
return

        t = time.clock()

        s_children = [c.lift() for c in self.children()]

        memo = {}

        clusterings = [
            k_means_cluster(self.root, k, s_children)
            for k in range(2, MAX_KMEANS)]
        score, bestcluster = max([(
            silhouette_coeff(c, memo), c) for c in clusterings])

        nodes = [
            _NodeCursor.create_with_children(c, self.root)
            for c in bestcluster if len(c) > 0]

        self._set_children(nodes)

        dur = (time.clock() - t)
        c = float(self.root.stats["overflow_f"])
        oa = self.root.stats["avg_overflow_t_f"]
        self.root.stats["avg_overflow_t_f"] = (
            dur / (c + 1.0)) + (c * oa / (c + 1.0))
        self.root.stats["overflow_f"] += 1
        self.root.stats["longest_overflow"] = max(
            self.root.stats["longest_overflow"], dur)
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
"avg_kmeans_iter_f": 0.0
        }

        # This round: not using objects directly -- they
        #   take up too much memory, and efficiency goes down the toilet
        #   (obviously) if things start to page.
        #  Less obviously: using object graph directly leads to really long GC
        #   pause times, too.
        # Instead, it uses pools of arrays:
        self.count = 0
        self.leaf_count = 0
        self.rect_pool = array.array('d')
        self.node_pool = array.array('L')
        self.leaf_pool = []  # leaf objects.

        self.cursor = _NodeCursor.create(self, NullRect)
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
def get_first_child(self):
        """Placeholder."""
        # fc = self.first_child
        c = _NodeCursor(self.root, 0, NullRect, 0, 0)
        c._become(self.first_child)
        return c
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
def insert(self, leafo, leafrect):
        """Placeholder."""
        index = self.index

        # tail recursion, made into loop:
        while True:
            if self.holds_leaves():
                self.rect = self.rect.union(leafrect)
                self._insert_child(_NodeCursor.create_leaf(
                    self.root, leafo, leafrect))

                self._balance()

                # done: become the original again
                self._become(index)
                return
            else:
                # Not holding leaves, move down a level in the tree:

                # Micro-optimization:
                #  inlining union() calls -- logic is:
                # ignored,child = min(
                #    [ ((c.rect.union(leafrect)).area() - c.rect.area(),
                #    c.index) for c in self.children() ])
                child = None
github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / pyrtree / rtree.py View on Github external
def create_with_children(cls, children, rooto):
        """Placeholder."""
        rect = union_all([c for c in children])
        # nr = Rect(rect.x,rect.y,rect.xx,rect.yy)
        assert(not rect.swapped_x)
        nc = _NodeCursor.create(rooto, rect)
        nc._set_children(children)
        assert(not nc.is_leaf())
        return nc