Search in sources :

Example 1 with TemporaryObject

use of qupath.lib.objects.TemporaryObject in project qupath by qupath.

the class PathObjectTileCache method addToCache.

/**
 * Add a PathObject to the cache, optionally including children.
 *
 * @param pathObject
 * @param includeChildren
 */
private void addToCache(PathObject pathObject, boolean includeChildren, Class<? extends PathObject> limitToClass) {
    // If the cache isn't active, we can ignore this... it will be constructed when it is needed
    if (!isActive())
        return;
    if (pathObject.hasROI()) {
        Class<? extends PathObject> cls = pathObject.getClass();
        if (limitToClass == null || cls == limitToClass) {
            SpatialIndex mapObjects = map.get(cls);
            if (mapObjects == null) {
                mapObjects = createSpatialIndex();
                map.put(cls, mapObjects);
            }
            Envelope envelope = getEnvelope(pathObject);
            mapObjects.insert(envelope, pathObject);
        }
    }
    // Add the children
    if (includeChildren && !(pathObject instanceof TemporaryObject) && pathObject.hasChildren()) {
        for (PathObject child : pathObject.getChildObjectsAsArray()) addToCache(child, includeChildren, limitToClass);
    }
}
Also used : PathObject(qupath.lib.objects.PathObject) SpatialIndex(org.locationtech.jts.index.SpatialIndex) TemporaryObject(qupath.lib.objects.TemporaryObject) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

Envelope (org.locationtech.jts.geom.Envelope)1 SpatialIndex (org.locationtech.jts.index.SpatialIndex)1 PathObject (qupath.lib.objects.PathObject)1 TemporaryObject (qupath.lib.objects.TemporaryObject)1