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);
}
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);
}
}
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);
}
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;
}
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();
}
Aggregations