Search in sources :

Example 1 with PathTask

use of qupath.lib.plugins.PathTask in project qupath by qupath.

the class FindConvexHullDetectionsPlugin method addRunnableTasks.

@Override
protected void addRunnableTasks(ImageData<T> imageData, PathObject parentObject, List<Runnable> tasks) {
    boolean deleteImmediately = Boolean.TRUE.equals(params.getBooleanParameterValue("deleteImmediately"));
    tasks.add(new PathTask() {

        private List<PathObject> toRemove;

        private int nRemoved;

        @Override
        public void run() {
            toRemove = getConvexHullDetections(imageData.getHierarchy(), parentObject, params.getIntParameterValue("nIterations"));
            nRemoved = toRemove.size();
        }

        @Override
        public void taskComplete(boolean wasCancelled) {
            if (wasCancelled)
                return;
            if (toRemove != null && !toRemove.isEmpty()) {
                if (deleteImmediately)
                    imageData.getHierarchy().removeObjects(toRemove, false);
                else {
                    imageData.getHierarchy().getSelectionModel().deselectObject(parentObject);
                    imageData.getHierarchy().getSelectionModel().selectObjects(toRemove);
                }
                toRemove = null;
                nObjectsRemoved.addAndGet(nRemoved);
            }
        }

        @Override
        public String getLastResultsDescription() {
            String process = deleteImmediately ? "Removed " : "Selected ";
            if (Boolean.TRUE.equals(params.getBooleanParameterValue("deleteImmediately")))
                if (nRemoved == 1)
                    return process + " 1 object";
            return process + nRemoved + " objects";
        }
    });
}
Also used : PathObject(qupath.lib.objects.PathObject) PathTask(qupath.lib.plugins.PathTask)

Aggregations

PathObject (qupath.lib.objects.PathObject)1 PathTask (qupath.lib.plugins.PathTask)1