Search in sources :

Example 31 with PathObject

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

the class PathObjectSelectionModel method setSelectedObjects.

/**
 * Specify a collection of objects to be selected, and which among them should be the primary.
 * <p>
 * Any previous selection is reset.
 *
 * @param pathObjects
 * @param primarySelectedObject
 */
public synchronized void setSelectedObjects(Collection<? extends PathObject> pathObjects, final PathObject primarySelectedObject) {
    if (pathObjects == null || pathObjects.isEmpty()) {
        clearSelection();
        return;
    }
    // Check if we have any changes to make
    if (pathObjectSelected == primarySelectedObject && selectedSet.size() == pathObjects.size() && selectedSet.containsAll(pathObjects))
        return;
    // Update selected objects
    PathObject previousSelected = pathObjectSelected;
    selectedSet.clear();
    selectedSet.addAll(pathObjects);
    // This shouldn't be needed... and yet it is?
    selectedSet.remove(null);
    // if (selectedObject == null) {
    // updateToLastSelectedObject();
    // } else
    pathObjectSelected = primarySelectedObject;
    firePathObjectSelectionChangedEvent(pathObjectSelected, previousSelected);
}
Also used : PathObject(qupath.lib.objects.PathObject)

Example 32 with PathObject

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

the class PathObjectSelectionModel method selectObjects.

/**
 * Ensure the specified objects are selected.
 * <p>
 * The selection state of other objects will not be modified.
 *
 * @param pathObjects
 */
public void selectObjects(Collection<? extends PathObject> pathObjects) {
    if (selectedSet.addAll(pathObjects)) {
        PathObject previousSelected = pathObjectSelected;
        if (previousSelected == null)
            updateToLastSelectedObject();
        firePathObjectSelectionChangedEvent(pathObjectSelected, previousSelected);
    }
}
Also used : PathObject(qupath.lib.objects.PathObject)

Example 33 with PathObject

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

the class PathObjectSelectionModel method setSelectedObject.

/**
 * Select the specified object to be the primary selected object, optionally retaining the
 * existing selected objects.
 *
 * @param pathObject
 * @param addToSelection add to the existing selection, rather than allowing only the specified object to be selected
 *
 * @see #setSelectedObject(PathObject)
 */
public void setSelectedObject(PathObject pathObject, boolean addToSelection) {
    if (!addToSelection) {
        setSelectedObject(pathObject);
        return;
    }
    if (pathObject == null)
        return;
    PathObject previousSelected = pathObjectSelected;
    selectedSet.add(pathObject);
    pathObjectSelected = pathObject;
    firePathObjectSelectionChangedEvent(pathObjectSelected, previousSelected);
}
Also used : PathObject(qupath.lib.objects.PathObject)

Example 34 with PathObject

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

the class AbstractPlugin method getTasks.

/**
 * Get a collection of tasks to perform.
 *
 * This will be called from {@link #runPlugin(PluginRunner, String)} <b>after</b> a call to {@link #parseArgument(ImageData, String)}.
 *
 * The default implementation simply calls {@link #getParentObjects(PluginRunner)}, then {@link #addRunnableTasks(ImageData, PathObject, List)}
 * for every parent object that was returned.
 *
 * @param runner
 * @return
 */
protected Collection<Runnable> getTasks(final PluginRunner<T> runner) {
    Collection<? extends PathObject> parentObjects = getParentObjects(runner);
    if (parentObjects == null || parentObjects.isEmpty())
        return Collections.emptyList();
    List<Runnable> tasks = new ArrayList<>(parentObjects.size());
    long startTime = System.currentTimeMillis();
    for (PathObject pathObject : parentObjects) {
        addRunnableTasks(runner.getImageData(), pathObject, tasks);
    }
    long endTime = System.currentTimeMillis();
    logger.debug("Time to add plugin tasks: {} ms", endTime - startTime);
    return tasks;
}
Also used : PathObject(qupath.lib.objects.PathObject) ArrayList(java.util.ArrayList)

Example 35 with PathObject

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

the class PathIO method exportObjectsAsGeoJSON.

/**
 * Export a collection of objects as a GeoJSON "FeatureCollection" to an output stream.
 * @param stream
 * @param pathObjects
 * @param options
 * @throws IOException
 */
public static void exportObjectsAsGeoJSON(OutputStream stream, Collection<? extends PathObject> pathObjects, GeoJsonExportOptions... options) throws IOException {
    Collection<GeoJsonExportOptions> optionList = Arrays.asList(options);
    // If exclude measurements, 'transform' each PathObject to get rid of measurements
    if (optionList.contains(GeoJsonExportOptions.EXCLUDE_MEASUREMENTS))
        pathObjects = pathObjects.stream().map(e -> PathObjectTools.transformObject(e, null, false)).collect(Collectors.toList());
    var writer = new OutputStreamWriter(new BufferedOutputStream(stream), StandardCharsets.UTF_8);
    var gson = GsonTools.getInstance(optionList.contains(GeoJsonExportOptions.PRETTY_JSON));
    if (optionList.contains(GeoJsonExportOptions.FEATURE_COLLECTION))
        gson.toJson(GsonTools.wrapFeatureCollection(pathObjects), writer);
    else if (pathObjects.size() == 1) {
        gson.toJson(pathObjects.iterator().next(), writer);
    } else {
        gson.toJson(pathObjects, new TypeToken<List<PathObject>>() {
        }.getType(), writer);
    }
    writer.flush();
}
Also used : Arrays(java.util.Arrays) ImageServer(qupath.lib.images.servers.ImageServer) BufferedInputStream(java.io.BufferedInputStream) TypeToken(com.google.gson.reflect.TypeToken) FeatureCollection(qupath.lib.io.PathObjectTypeAdapters.FeatureCollection) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) Category(java.util.Locale.Category) Locale(java.util.Locale) Gson(com.google.gson.Gson) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) ImageServerProvider(qupath.lib.images.servers.ImageServerProvider) Collection(java.util.Collection) PathObjects(qupath.lib.objects.PathObjects) Set(java.util.Set) EOFException(java.io.EOFException) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) PathObject(qupath.lib.objects.PathObject) Objects(java.util.Objects) List(java.util.List) Entry(java.util.Map.Entry) ImagePlane(qupath.lib.regions.ImagePlane) Geometry(org.locationtech.jts.geom.Geometry) ZipOutputStream(java.util.zip.ZipOutputStream) HashMap(java.util.HashMap) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) DefaultImageServerBuilder(qupath.lib.images.servers.ImageServerBuilder.DefaultImageServerBuilder) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) ColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains) OutputStreamWriter(java.io.OutputStreamWriter) ObjectOutputStream(java.io.ObjectOutputStream) GeometryTools(qupath.lib.roi.GeometryTools) LinkedHashSet(java.util.LinkedHashSet) OutputStream(java.io.OutputStream) ImageData(qupath.lib.images.ImageData) Logger(org.slf4j.Logger) Files(java.nio.file.Files) GeneralTools(qupath.lib.common.GeneralTools) Workflow(qupath.lib.plugins.workflow.Workflow) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ServerBuilder(qupath.lib.images.servers.ImageServerBuilder.ServerBuilder) InputStreamReader(java.io.InputStreamReader) File(java.io.File) PathObjectTools(qupath.lib.objects.PathObjectTools) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) InputStream(java.io.InputStream) OutputStreamWriter(java.io.OutputStreamWriter) List(java.util.List) ArrayList(java.util.ArrayList) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

PathObject (qupath.lib.objects.PathObject)182 ArrayList (java.util.ArrayList)84 ROI (qupath.lib.roi.interfaces.ROI)74 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)61 List (java.util.List)48 BufferedImage (java.awt.image.BufferedImage)37 IOException (java.io.IOException)37 PathClass (qupath.lib.objects.classes.PathClass)37 Collectors (java.util.stream.Collectors)35 PathAnnotationObject (qupath.lib.objects.PathAnnotationObject)34 Map (java.util.Map)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 ImageData (qupath.lib.images.ImageData)31 TMACoreObject (qupath.lib.objects.TMACoreObject)31 Collection (java.util.Collection)29 Collections (java.util.Collections)29 HashMap (java.util.HashMap)28 PathObjectTools (qupath.lib.objects.PathObjectTools)26 Arrays (java.util.Arrays)25