@ElementReaderMetadata(name="ROI set file (SVG)", elementType=FileLinkElement.class, mimeTypes="image/svg+xml", processedType=AbstractOverlaysAlias.class, hidden=true) public class SVGFileToAbstractOverlayReader extends Object implements ElementReader<FileLinkElement,net.imagej.overlay.AbstractOverlay[]>
Modifier and Type | Field and Description |
---|---|
private org.scijava.Context |
ij |
private String |
warningMessage |
Constructor and Description |
---|
SVGFileToAbstractOverlayReader() |
Modifier and Type | Method and Description |
---|---|
private net.imagej.overlay.AbstractOverlay |
arcAsEllipse(String code,
String param,
double[] start,
String pathData,
Element n)
Attempt to generate an ellipse overlay from an arc path
|
private int |
getFirstPathInstructionEnd(String pathData)
Get the end index of the first path data instruction in
pathData . |
private int |
getFirstTransformEnd(String transformList)
Get the index of the end of the first transform string in a
transform attribute list. |
private ArrayList<String> |
listPathInstructions(String pathData)
Make a path data
String into a convenient List ! |
private Document |
loadDocument(File file)
Load the DOM from an SVG file
|
private net.imagej.overlay.AbstractOverlay |
makeEllipseOverlay(double cx,
double cy,
double rx,
double ry,
Element element)
Generate an overlay from parsed ellipse data
|
private net.imagej.overlay.AbstractOverlay |
parseCircle(Element n)
Generate an overlay from a
circle element |
private ArrayList<net.imagej.overlay.AbstractOverlay> |
parseDocument(Document dom)
Get the list of overlays that can be created from the DOM
|
private net.imagej.overlay.AbstractOverlay |
parseEllipse(Element n)
Generate an overlay from an
ellipse element |
private double |
parseLength(String length)
Parse an SVG length
String (possibly with units), and convert to pixels |
private net.imagej.overlay.AbstractOverlay |
parseLine(Element n)
Generate an overlay from a
line element. |
private ArrayList<Double> |
parseListOfNumbers(String list)
Parse a list of numbers, possibly with units
|
private ArrayList<double[]> |
parseListOfPoints(String list)
Parse a list of points, as used in
polygon and polyline elements |
private net.imagej.overlay.AbstractOverlay |
parseNode(Node n)
Generate an overlay from an SVG node
|
private net.imagej.overlay.AbstractOverlay |
parsePath(Element n)
Generate an overlay from a
path element |
private net.imagej.overlay.AbstractOverlay |
parsePolygon(Element n)
Generate an overlay from a
polygon element |
private net.imagej.overlay.AbstractOverlay |
parsePolyline(Element n)
Generate an overlay from a
polyline element |
private net.imagej.overlay.AbstractOverlay |
parseRect(Element n)
Generate an overlay from a
rect element |
private double[] |
parseTransform(double[] point,
String transform)
Transform a coordinate pair
|
net.imagej.overlay.AbstractOverlay[] |
read(FileLinkElement elementToRead)
Convert "underlying" data to "processed" data.
|
private double[] |
reflect(double[] a,
double[] b)
Point
a reflected about point b |
private double[] |
transformMatrix(double[] point,
double[] matrix)
Apply a matrix transformation.
|
private double[] |
transformRotate(double[] point,
double a)
Apply a rotation about the origin
|
private double[] |
transformRotate(double[] point,
double a,
double cx,
double cy)
Apply a rotation about center point
{cx,cy} |
private double[] |
transformScale(double[] point,
double sx,
double sy)
Apply a scale
|
private double[] |
transformSkewX(double[] point,
double a)
Skew along the x-axis
|
private double[] |
transformSkewY(double[] point,
double a)
Skew along the y-axis
|
private double[] |
transformToDocumentSpace(double[] point,
Node n)
Transform a point (
{x,y} ) to document space
by recursively looking for transform attributes in
the given nodes and all parent nodes. |
private double[] |
transformTranslate(double[] point,
double tx,
double ty)
Apply a translation
|
private double[] |
vectorAdd(double[] a,
double[] b)
Vectorized add function
|
private double[] |
vectorNegate(double[] a)
Multiply a vector by
-I |
private org.scijava.Context ij
private String warningMessage
public net.imagej.overlay.AbstractOverlay[] read(FileLinkElement elementToRead) throws SlideSetException
ElementReader
read
in interface ElementReader<FileLinkElement,net.imagej.overlay.AbstractOverlay[]>
elementToRead
- The DataElement
containing
the "underlying" data which should be translated.SlideSetException
private Document loadDocument(File file) throws SlideSetException
SlideSetException
private ArrayList<net.imagej.overlay.AbstractOverlay> parseDocument(Document dom)
private net.imagej.overlay.AbstractOverlay parseNode(Node n) throws SVGParseException
n
- The nodenull
if an overlay cannot
be created from the nodeSVGParseException
private net.imagej.overlay.AbstractOverlay parsePolyline(Element n) throws SVGParseException
polyline
elementSVGParseException
private net.imagej.overlay.AbstractOverlay parsePolygon(Element n) throws SVGParseException
polygon
elementSVGParseException
private net.imagej.overlay.AbstractOverlay parseLine(Element n) throws SVGParseException
line
element.
Lines with the same start and end points will
generate point overlays.SVGParseException
private net.imagej.overlay.AbstractOverlay parseCircle(Element n) throws SVGParseException
circle
elementSVGParseException
private net.imagej.overlay.AbstractOverlay parseEllipse(Element n) throws SVGParseException
ellipse
elementSVGParseException
private net.imagej.overlay.AbstractOverlay makeEllipseOverlay(double cx, double cy, double rx, double ry, Element element) throws SVGParseException
SVGParseException
private net.imagej.overlay.AbstractOverlay parseRect(Element n) throws SVGParseException
rect
elementSVGParseException
private net.imagej.overlay.AbstractOverlay parsePath(Element n) throws SVGParseException
path
elementSVGParseException
private net.imagej.overlay.AbstractOverlay arcAsEllipse(String code, String param, double[] start, String pathData, Element n) throws SVGParseException
SVGParseException
private double[] reflect(double[] a, double[] b)
a
reflected about point b
private double[] vectorAdd(double[] a, double[] b)
private double[] vectorNegate(double[] a)
-I
private ArrayList<String> listPathInstructions(String pathData) throws SVGParseException
String
into a convenient List
!SVGParseException
private int getFirstPathInstructionEnd(String pathData)
pathData
.
Does not really verify that the instruction is correctly formed,
but identifies the end of the instruction, assuming it is correctly formed.
Note that this won't work if pathData
has leading white space!private ArrayList<double[]> parseListOfPoints(String list) throws NumberFormatException, SVGParseException
polygon
and polyline
elementsList
of points: (x, y)
NumberFormatException
SVGParseException
private ArrayList<Double> parseListOfNumbers(String list) throws NumberFormatException, SVGParseException
private double parseLength(String length) throws SVGParseException, NumberFormatException
String
(possibly with units), and convert to pixelsprivate double[] transformToDocumentSpace(double[] point, Node n) throws SVGParseException
{x,y}
) to document space
by recursively looking for transform attributes in
the given nodes and all parent nodes.point
- n
- {x,y}
SVGParseException
private int getFirstTransformEnd(String transformList) throws SVGParseException
transform
attribute list.transformList
- The transform
attribute value,
possibly specifying a list of transforms.transformList
.
If there are no more transforms in the list, returns 0
.SVGParseException
- If a formatting error is detected,
but error detection is not guaranteed.private double[] parseTransform(double[] point, String transform) throws SVGParseException
point
- {x,y}
transform
- The transform{x,y}
SVGParseException
private double[] transformMatrix(double[] point, double[] matrix)
WARNING - Matrix specification (by row) differs from standard SVG order (by column)
point
- {x,y}
matrix
- {a,c,e,b,d,f}
{x,y}
private double[] transformTranslate(double[] point, double tx, double ty)
point
- {x,y}
tx
- Delta xty
- Delta y{x,y}
private double[] transformScale(double[] point, double sx, double sy)
point
- {x,y}
sx
- x scale factorsy
- y scale factor{x,y}
private double[] transformRotate(double[] point, double a)
point
- {x,y}
a
- Angle, in degrees{x,y}
private double[] transformRotate(double[] point, double a, double cx, double cy)
{cx,cy}
point
- {x,y}
a
- Angle, in degrees{x,y}
private double[] transformSkewX(double[] point, double a)
point
- {x,y}
a
- Angle, in degrees{x,y}
private double[] transformSkewY(double[] point, double a)
point
- {x,y}
a
- Angle, in degrees{x,y}
Copyright © 2023. All rights reserved.