Object Formatter

The ObjectShapeFormatter class creates visualizations of object shapes over time from a MartianObject. It provides extensive control over the appearance and layout of shape montages, including orientation options, styling, and export capabilities.

Constructors

ObjectShapeFormatter(Context context)
ObjectShapeFormatter(Context context, ObjectArchive objectArchive)

Creates a new formatter for object shapes.

Parameters:

  • context: The SciJava context
  • objectArchive: (Optional) The archive containing the objects

Methods

Object Configuration

Method Description
setObject(MartianObject martianObject) Set the object to use for shape visualization.
Returns: This formatter for method chaining
setObject(String UID) Set the object to use by UID (requires ObjectArchive to be set).
Parameters: UID - The unique identifier of the object
Returns: This formatter for method chaining

Layout Configuration

Method Description
setTitle(String title) Set the title for the montage.
Parameters: title - The title string
Returns: This formatter for method chaining
setXAxisLabel(String label) Set the x-axis label.
Parameters: label - The x-axis label
Returns: This formatter for method chaining
setSpacing(int spacing) Set spacing between frames in the montage.
Parameters: spacing - The spacing in pixels
Returns: This formatter for method chaining
setCanvasWidth(int width) Set the width of each canvas for individual shapes.
Parameters: width - Width in pixels
Returns: This formatter for method chaining
setCanvasHeight(int height) Set the height of each canvas for individual shapes.
Parameters: height - Height in pixels
Returns: This formatter for method chaining
setHorizontalMargin(int margin) Set horizontal margin.
Parameters: margin - Margin in pixels
Returns: This formatter for method chaining
setVerticalMargin(int margin) Set vertical margin.
Parameters: margin - Margin in pixels
Returns: This formatter for method chaining

Time Range Configuration

Method Description
setMinT(int minT) Set the minimum time point to include.
Parameters: minT - The minimum time point
Returns: This formatter for method chaining
setMaxT(int maxT) Set the maximum time point to include.
Parameters: maxT - The maximum time point
Returns: This formatter for method chaining
setFrameStep(int step) Set the step size between frames to include.
Parameters: step - Include every Nth frame
Returns: This formatter for method chaining
setTimeUnitDivider(int divider) Set the time unit divider for converting time units.
Parameters: divider - Division factor for time values
Returns: This formatter for method chaining

Display Options

Method Description
showTimeLabels(boolean show) Enable or disable time labels.
Parameters: show - True to show time labels, false to hide
Returns: This formatter for method chaining
normalizeShapes(boolean normalize) Enable or disable shape normalization (scaling to fit canvas).
Parameters: normalize - True to normalize shapes, false to use original scale
Returns: This formatter for method chaining
showAxes(boolean show) Enable or disable axes.
Parameters: show - True to show axes, false to hide
Returns: This formatter for method chaining
setXAxisPrecision(int precision) Set the precision for the time display.
Parameters: precision - Number of decimal places to show
Returns: This formatter for method chaining

Font Configuration

Method Description
setAxisFont(Font font) Set the font for axis text.
Parameters: font - Font for the axis text
Returns: This formatter for method chaining
setAxisFontSize(int size) Set the axis font size.
Parameters: size - Font size in points
Returns: This formatter for method chaining
setLabelFont(Font font) Set the font for labels.
Parameters: font - Font for labels
Returns: This formatter for method chaining
setLabelFontSize(int size) Set the label font size.
Parameters: size - Font size in points
Returns: This formatter for method chaining
setTitleFont(Font font) Set the font for the title.
Parameters: font - Font for the title
Returns: This formatter for method chaining
setTitleFontSize(int size) Set the title font size.
Parameters: size - Font size in points
Returns: This formatter for method chaining

Shape Styling

Method Description
setShapeColor(Color color) Set the shape outline color.
Parameters: color - Color for shape outlines
Returns: This formatter for method chaining
setShapeLineWidth(float width) Set the shape line width.
Parameters: width - Line width in pixels
Returns: This formatter for method chaining
setFillShape(boolean fill) Enable or disable shape filling.
Parameters: fill - True to fill shapes, false for outlines only
Returns: This formatter for method chaining
setFillColor(Color color) Set the fill color for shapes.
Parameters: color - Fill color (can include alpha transparency)
Returns: This formatter for method chaining

Axis Styling

Method Description
setAxisColor(Color color) Set the axis color.
Parameters: color - Color for axes
Returns: This formatter for method chaining
setAxisLineWidth(float width) Set the axis line width.
Parameters: width - Line width in pixels
Returns: This formatter for method chaining

Orientation Configuration

Method Description
rightVerticalOrientation() Set orientation to vertical with 90° right rotation. Shapes displayed in vertical column with time increasing downward.
Returns: This formatter for method chaining
leftVerticalOrientation() Set orientation to vertical with 90° left rotation. Shapes displayed in vertical column with time increasing downward.
Returns: This formatter for method chaining
horizontalOrientation() Reset to default horizontal layout.
Returns: This formatter for method chaining

Theme Configuration

Method Description
setDarkTheme(boolean darkTheme) Enable or disable dark theme.
Parameters: darkTheme - True for dark theme, false for light theme
Returns: This formatter for method chaining

Building and Export

Method Description
build() Build the shape montage.
Returns: This formatter after creating the montage
getHtmlEncodedImage() Get the HTML-encoded image as a data URL string.
Returns: Base64-encoded PNG image with data URL prefix
getImage() Get the buffered image.
Returns: The montage as a BufferedImage
saveAsPNG(String path) Save the montage as a PNG file.
Parameters: path - The file path to save to
Returns: This formatter for method chaining
saveAsSVG(String path) Save the montage as an SVG file.
Parameters: path - The file path to save to (should end with .svg)
Returns: This formatter for method chaining

Example Usage

// Create the formatter
ObjectShapeFormatter formatter = new ObjectShapeFormatter(context, objectArchive);

// Configure and build
formatter
    .setObject("objectUID")
    .setTitle("Object Shapes Over Time")
    .setXAxisLabel("Time (frames)")
    .setSpacing(10)
    .setCanvasWidth(150)
    .setCanvasHeight(150)
    .setMinT(0)
    .setMaxT(49)
    .setFrameStep(2)
    .showTimeLabels(true)
    .normalizeShapes(true)
    .setShapeColor(Color.BLUE)
    .setFillShape(true)
    .rightVerticalOrientation()
    .setDarkTheme(true)
    .build();

// Get the result
String dataUrl = formatter.getHtmlEncodedImage();

Implementation Details

The ObjectShapeFormatter creates a montage of object shapes across time by:

  1. Extracting shape data from the MartianObject for selected time points
  2. Optionally normalizing shapes to a common scale
  3. Drawing each shape on individual canvases
  4. Arranging canvases in horizontal or vertical layouts
  5. Adding time labels and axis labels as configured
  6. Supporting both PNG and SVG export formats

The formatter supports both horizontal and vertical orientations, with vertical orientations rotating both the shapes and text appropriately for the new layout.