use of qupath.lib.objects.TMACoreObject in project qupath by qupath.
the class QuPathViewer method getTooltipText.
private String getTooltipText(final double x, final double y) {
// Try to show which TMA core is selected - if we have a TMA image
PathObjectHierarchy hierarchy = getHierarchy();
TMAGrid tmaGrid = hierarchy == null ? null : hierarchy.getTMAGrid();
if (tmaGrid != null) {
Point2D p = componentPointToImagePoint(x, y, null, false);
TMACoreObject core = PathObjectTools.getTMACoreForPixel(tmaGrid, p.getX(), p.getY());
if (core != null) {
if (core.isMissing())
return String.format("TMA Core %s\n(missing)", core.getName());
else
return String.format("TMA Core %s", core.getName());
}
}
return null;
}
use of qupath.lib.objects.TMACoreObject in project qupath by qupath.
the class IJExtension method extractOverlay.
/**
* Extract an ImageJ overlay for the specified region.
* @param hierarchy
* @param request
* @param options options to control which objects are being displayed
* @param filter optional additional filter used to determine which objects will be included (may be used in combination with options)
* @return
*/
public static Overlay extractOverlay(PathObjectHierarchy hierarchy, RegionRequest request, OverlayOptions options, Predicate<PathObject> filter) {
Overlay overlay = new Overlay();
double downsample = request.getDownsample();
double xOrigin = -request.getX() / downsample;
double yOrigin = -request.getY() / downsample;
// TODO: Permit filling/unfilling ROIs
for (PathObject child : hierarchy.getObjectsForRegion(PathObject.class, request, null)) {
if (filter != null && !filter.test(child))
continue;
if (child.hasROI()) {
// Check if this is displayed - skip it not
if (options != null && ((child instanceof PathDetectionObject && !options.getShowDetections()) || (child instanceof PathAnnotationObject && !options.getShowAnnotations()) || (child instanceof TMACoreObject && !options.getShowTMAGrid())))
continue;
boolean isCell = child instanceof PathCellObject;
Color color = ColorToolsAwt.getCachedColor(ColorToolsFX.getDisplayedColorARGB(child));
if (!(isCell && (options == null || !options.getShowCellBoundaries()))) {
Roi roi = IJTools.convertToIJRoi(child.getROI(), xOrigin, yOrigin, downsample);
roi.setStrokeColor(color);
roi.setName(child.getDisplayedName());
// roi.setStrokeWidth(2);
overlay.add(roi);
}
if (isCell && (options == null || options.getShowCellNuclei())) {
ROI nucleus = ((PathCellObject) child).getNucleusROI();
if (nucleus == null)
continue;
Roi roi = IJTools.convertToIJRoi(((PathCellObject) child).getNucleusROI(), xOrigin, yOrigin, downsample);
roi.setStrokeColor(color);
roi.setName(child.getDisplayedName() + " - nucleus");
overlay.add(roi);
}
}
}
return overlay;
}
use of qupath.lib.objects.TMACoreObject in project qupath by qupath.
the class MoveTool method mouseReleased.
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
if (e.isConsumed())
return;
var viewer = getViewer();
RoiEditor editor = viewer.getROIEditor();
if (editor != null && (editor.hasActiveHandle() || editor.isTranslating())) {
boolean roiChanged = (editor.isTranslating() && editor.finishTranslation()) || editor.hasActiveHandle();
editor.resetActiveHandle();
// if (editor.isTranslating())
// editor.finishTranslation();
e.consume();
PathObject pathObject = viewer.getSelectedObject();
if (requestParentClipping(e) && pathObject instanceof PathAnnotationObject) {
ROI roiNew = refineROIByParent(pathObject.getROI());
((PathAnnotationObject) pathObject).setROI(roiNew);
}
if (pathObject != null && pathObject.hasROI() && pathObject.getROI().isEmpty()) {
if (pathObject.getParent() != null)
viewer.getHierarchy().removeObject(pathObject, true);
viewer.setSelectedObject(null);
} else {
PathObjectHierarchy hierarchy = viewer.getHierarchy();
if (pathObject instanceof TMACoreObject) {
hierarchy.fireHierarchyChangedEvent(pathObject);
} else if (pathObject != null) {
// Handle ROI changes only if required
if (roiChanged) {
var updatedROI = editor.getROI();
if (pathObject.getROI() != updatedROI && pathObject instanceof PathROIObject)
((PathROIObject) pathObject).setROI(updatedROI);
// PathObject parentPrevious = pathObject.getParent();
hierarchy.removeObjectWithoutUpdate(pathObject, true);
if (getCurrentParent() == null || !PathPrefs.clipROIsForHierarchyProperty().get() || e.isShiftDown())
hierarchy.addPathObject(pathObject);
else
hierarchy.addPathObjectBelowParent(getCurrentParent(), pathObject, true);
// PathObject parentNew = pathObject.getParent();
// if (parentPrevious == parentNew)
// hierarchy.fireHierarchyChangedEvent(this, parentPrevious);
// else
// hierarchy.fireHierarchyChangedEvent(this);
}
}
viewer.setSelectedObject(pathObject);
}
}
// Optionally continue a dragging movement until the canvas comes to a standstill
if (pDragging != null && requestDynamicDragging && System.currentTimeMillis() - lastDragTimestamp < 100 && (dx * dx + dy * dy > viewer.getDownsampleFactor())) {
mover = new ViewerMover(viewer);
mover.startMoving(dx, dy, false);
} else
viewer.setDoFasterRepaint(false);
// Make sure we don't have a previous point (to prevent weird dragging artefacts)
pDragging = null;
// // If we were translating, stop
// if (editor.isTranslating()) {
// editor.finishTranslation();
// // TODO: Make this more efficient!
// viewer.getPathObjectHierarchy().fireHierarchyChangedEvent();
// return;
// }
}
use of qupath.lib.objects.TMACoreObject in project qupath by qupath.
the class PathClassifierTools method runClassifier.
/**
* Apply a classifier to the detection objects in a hierarchy.
* @param hierarchy
* @param classifier
*/
public static void runClassifier(final PathObjectHierarchy hierarchy, final PathObjectClassifier classifier) {
// Apply classifier to everything
// If we have a TMA grid, do one core at a time
long startTime = System.currentTimeMillis();
TMAGrid tmaGrid = hierarchy.getTMAGrid();
Collection<PathObject> pathObjects = new ArrayList<>();
int nClassified = 0;
// tmaGrid = null;
if (tmaGrid != null) {
for (TMACoreObject core : tmaGrid.getTMACoreList()) {
pathObjects = PathObjectTools.getDescendantObjects(core, pathObjects, PathDetectionObject.class);
nClassified += classifier.classifyPathObjects(pathObjects);
pathObjects.clear();
}
} else {
hierarchy.getObjects(pathObjects, PathDetectionObject.class);
nClassified = classifier.classifyPathObjects(pathObjects);
}
long endTime = System.currentTimeMillis();
logger.info(String.format("Classification time: %.2f seconds", (endTime - startTime) / 1000.));
// Fire a change event for all detection objects
if (nClassified > 0)
hierarchy.fireObjectClassificationsChangedEvent(classifier, hierarchy.getObjects(null, PathDetectionObject.class));
else
logger.warn("No objects classified!");
}
use of qupath.lib.objects.TMACoreObject in project qupath by qupath.
the class ImageJMacroRunner method runPlugin.
@Override
public boolean runPlugin(final PluginRunner<BufferedImage> runner, final String arg) {
if (!parseArgument(runner.getImageData(), arg))
return false;
if (dialog == null) {
dialog = new Stage();
dialog.initOwner(qupath.getStage());
dialog.setTitle("ImageJ macro runner");
BorderPane pane = new BorderPane();
if (arg != null)
macroText = arg;
// Create text area
final TextArea textArea = new TextArea();
textArea.setPrefRowCount(12);
textArea.setPrefSize(400, 400);
textArea.setWrapText(true);
textArea.setFont(Font.font("Courier"));
if (macroText != null)
textArea.setText(macroText);
BorderPane panelMacro = new BorderPane();
// panelMacro.setBorder(BorderFactory.createTitledBorder("Macro"));
panelMacro.setCenter(textArea);
ParameterPanelFX parameterPanel = new ParameterPanelFX(getParameterList(runner.getImageData()));
panelMacro.setBottom(parameterPanel.getPane());
// Create button panel
Button btnRun = new Button("Run");
btnRun.setOnAction(e -> {
macroText = textArea.getText().trim();
if (macroText.length() == 0)
return;
PathObjectHierarchy hierarchy = getHierarchy(runner);
PathObject pathObject = hierarchy.getSelectionModel().singleSelection() ? hierarchy.getSelectionModel().getSelectedObject() : null;
if (pathObject instanceof PathAnnotationObject || pathObject instanceof TMACoreObject) {
SwingUtilities.invokeLater(() -> {
runMacro(params, qupath.getViewer().getImageData(), qupath.getViewer().getImageDisplay(), pathObject, macroText);
});
} else {
// DisplayHelpers.showErrorMessage(getClass().getSimpleName(), "Sorry, ImageJ macros can only be run for single selected images");
// logger.warn("ImageJ macro being run in current thread");
// runPlugin(runner, arg); // TODO: Consider running in a background thread?
// Run in a background thread
Collection<? extends PathObject> parents = getParentObjects(runner);
if (parents.isEmpty()) {
Dialogs.showErrorMessage("ImageJ macro runner", "No annotation or TMA core objects selected!");
return;
}
List<Runnable> tasks = new ArrayList<>();
for (PathObject parent : parents) addRunnableTasks(qupath.getViewer().getImageData(), parent, tasks);
qupath.submitShortTask(() -> runner.runTasks(tasks, true));
// runner.runTasks(tasks);
// Runnable r = new Runnable() {
// public void run() {
// runPlugin(runner, arg);
// }
// };
// new Thread(r).start();
}
});
Button btnClose = new Button("Close");
btnClose.setOnAction(e -> dialog.hide());
GridPane panelButtons = PaneTools.createRowGridControls(btnRun, btnClose);
pane.setCenter(panelMacro);
pane.setBottom(panelButtons);
panelButtons.setPadding(new Insets(5, 0, 0, 0));
pane.setPadding(new Insets(10, 10, 10, 10));
dialog.setScene(new Scene(pane));
}
dialog.show();
return true;
}
Aggregations