Class SvgTools.SvgBuilder

java.lang.Object
qupath.lib.extension.svg.SvgTools.SvgBuilder
Enclosing class:
SvgTools

public static class SvgTools.SvgBuilder extends Object
Builder class to enable the export of rendered QuPath objects as SVG images. This can be useful to generate high-quality figures using a vector representation of objects, which may be further customized in other applications (e.g. to change line thickness, color).
  • Constructor Details

    • SvgBuilder

      public SvgBuilder(QuPathViewer viewer)
      Create a builder initialized according to the current viewer.
      Parameters:
      viewer -
    • SvgBuilder

      public SvgBuilder()
      Create a new builder, which will later be customized.
  • Method Details

    • imageData

      public SvgTools.SvgBuilder imageData(ImageData<BufferedImage> imageData)
      Specify the ImageData. This is required if the underlying raster image will be included in any export.
      Parameters:
      imageData -
      Returns:
      this builder
    • hierarchy

      public SvgTools.SvgBuilder hierarchy(PathObjectHierarchy hierarchy)
      Specify the PathObjectHierarchy. This may be used instead of imageData(ImageData) if the raster image is not required.
      Parameters:
      hierarchy -
      Returns:
      this builder
    • pathObjects

      public SvgTools.SvgBuilder pathObjects(Collection<? extends PathObject> pathObjects)
      Specify a collection of objects to export. This may be used instead of imageData(ImageData) if the raster image is not required.
      Parameters:
      pathObjects -
      Returns:
      this builder
    • pathObjects

      public SvgTools.SvgBuilder pathObjects(PathObject... pathObjects)
      Specify an array of objects to export. This may be used instead of imageData(ImageData) if the raster image is not required.
      Parameters:
      pathObjects -
      Returns:
      this builder
    • includeOverlays

      public SvgTools.SvgBuilder includeOverlays(boolean doInclude)
      Specify whether overlays should be included. This only has an effect if images are also included, and a viewer is provided.
      Parameters:
      doInclude -
      Returns:
      this builder
    • options

      public SvgTools.SvgBuilder options(OverlayOptions options)
      Specify the overlay options to control display. This will override any previous customizations added to the builder.
      Parameters:
      options -
      Returns:
      this builder
    • fillAnnotations

      public SvgTools.SvgBuilder fillAnnotations(boolean doFill)
      Request whether annotations are drawn as 'filled' shapes.
      Parameters:
      doFill -
      Returns:
      this builder
    • fillDetections

      public SvgTools.SvgBuilder fillDetections(boolean doFill)
      Request whether detections are drawn as 'filled' shapes.
      Parameters:
      doFill -
      Returns:
      this builder
    • showSelection

      public SvgTools.SvgBuilder showSelection(boolean doShow)
      Request whether selected objects are displayed.
      Parameters:
      doShow -
      Returns:
      this builder
    • region

      public SvgTools.SvgBuilder region(ImageRegion region)
      Specify the region (in terms of the full resolution image space) for export. If a RegionRequest is supplied, the downsample factor will be used if none has otherwise been set.
      Parameters:
      region -
      Returns:
      this builder
    • downsample

      public SvgTools.SvgBuilder downsample(double downsample)
      Specify downsample factor (defined in terms of the full resolution image space).
      Parameters:
      downsample -
      Returns:
      this builder
    • width

      public SvgTools.SvgBuilder width(int width)
      Export image width.
      Parameters:
      width - width (in pixels) of the SVG image.
      Returns:
      this builder
    • height

      public SvgTools.SvgBuilder height(int height)
      Export image height.
      Parameters:
      height - height (in pixels) of the SVG image.
      Returns:
      this builder
    • size

      public SvgTools.SvgBuilder size(int width, int height)
      Export image size.
      Parameters:
      width - width (in pixels) of the SVG image.
      height - height (in pixels) of the SVG image.
      Returns:
      this builder
    • embedImages

      public SvgTools.SvgBuilder embedImages()
      Specify whether the underlying (raster) image should be embedded in any export. This requires that the constructor with a QuPathViewer is called to supply the necessary rendering settings.
      Returns:
      this builder
      See Also:
    • linkImages

      public SvgTools.SvgBuilder linkImages()
      Specify whether the underlying (raster) image should be included in any export. This requires that the constructor with a QuPathViewer is called to supply the necessary rendering settings.

      Only references are written, which means images must be written as separate files (which occurs automatically when using writeSVG(File)).

      Returns:
      this builder
      See Also:
    • images

      Specify if/how raster images should be included in the SVG.
      Parameters:
      include -
      Returns:
      this builder
    • writeSVG

      public void writeSVG(File file) throws IOException
      Write the SVG image to a file, including any references images if required.
      Parameters:
      file - SVG file to which the image should be written
      Throws:
      IOException
    • createDocument

      public String createDocument()
      Create a String representation of the SVG document.
      Returns:
      the SVG String