Commit 665a0995 authored by rhaase's avatar rhaase
Browse files

added functionalities for drawing paths

parent a45c9da5
package de.mpicbg.scf.skeletonanalysis;
import ij.gui.Line;
import ij.gui.OvalRoi;
import ij.gui.Overlay;
import ij.gui.Roi;
import ij.plugin.frame.Editor;
import sc.fiji.analyzeSkeleton.*;
import ij.ImagePlus;
import sc.fiji.analyzeSkeleton.Point;
import java.awt.Color;
import java.util.ArrayList;
/**
* Author: Robert Haase, Scientific Computing Facility, MPI-CBG Dresden, rhaase@mpi-cbg.de
* Date: September 2016
*/
public class PathDrawer {
ImagePlus target;
public PathDrawer(ImagePlus target)
{
this.target = target;
}
public void drawPath(ArrayList<Edge> path, Color color)
{
for (Edge edge : path)
{
drawEdge(edge, color);
}
}
public static void drawAllLeafs(SkeletonAnalyser skeletonAnalyser, ImagePlus imp, Color color)
{
ArrayList<Vertex> leafs = skeletonAnalyser.getLeafs();
PathDrawer pathDrawer = new PathDrawer(imp);
for (Vertex leaf : leafs)
{
pathDrawer.drawVertex(leaf, color);
}
}
public static void drawAllPathsToLargestJunction(SkeletonAnalyser skeletonAnalyser, ImagePlus imp, Color color)
{
Vertex largestJunction = skeletonAnalyser.getLargestJunction();
ArrayList<Vertex> leafs = skeletonAnalyser.getLeafs();
System.out.println("Largest junction: " + largestJunction);
System.out.println("number of leafs: " + leafs.size());
//PathDrawer.drawAllLeafs(skeletonAnalyser, imp, color);
PathDrawer pathDrawer = new PathDrawer(imp);
//pathDrawer.drawPath(skeletonAnalyser.getAllEdges(), color);
for (Vertex leaf : leafs)
{
ArrayList<Edge> path = skeletonAnalyser.getShortestPath(largestJunction, leaf);
System.out.println("Path " + path);
if (path != null)
{
pathDrawer.drawPath(path, color);
}
}
}
private void drawEdge(Edge edge, Color color) {
drawVertex(edge.getV1(), color);
drawVertex(edge.getV2(), color);
/*for (Point point : edge.getSlabs()) {
drawPoint(point, Color.red);
}*/
// if (edge.getSlabs().size() > 0) {
//drawPoint(edge.getSlabs().get(0), color);
//drawPoint(edge.getSlabs().get(edge.getSlabs().size() - 1), color);
// }
ArrayList<Point> polyline = new ArrayList<Point>();
polyline.add(SkeletonAnalyser.getCenterOfJunction(edge.getV1()));
polyline.addAll(edge.getSlabs());
polyline.add(SkeletonAnalyser.getCenterOfJunction(edge.getV2()));
drawPolygon(polyline, color);
}
private void drawVertex(Vertex v, Color color) {
//drawPoint(v.getPoints().get(0), Color.red);
sc.fiji.analyzeSkeleton.Point average = SkeletonAnalyser.getCenterOfJunction(v);
drawPoint(average, color);
}
private void drawPoint(sc.fiji.analyzeSkeleton.Point point, Color color) {
double radius = 1;
Roi roi = new OvalRoi(point.x-radius / 2+0.5, point.y- radius / 2+0.5, radius+0.5, radius+0.5);
roi.setStrokeColor(color);
//target.setRoi(roi);
fixRoiInOverlay(roi);
}
private void fixRoiInOverlay(Roi roi) {
if (target.getOverlay() == null) {
target.setOverlay(new Overlay());
}
target.getOverlay().add(roi);
}
private void drawPolygon(ArrayList<Point> list, Color color)
{
Point predecessor = null;
for (Point point : list)
{
if (predecessor != null)
{
Roi roi = new Line(point.x+0.5, point.y+0.5, predecessor.x+0.5, predecessor.y+0.5);
//()Roi(point.x, point.y, 2, 2);
roi.setStrokeColor(color);
fixRoiInOverlay(roi);
}
predecessor = point;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment