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 contextobjectArchive
: (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 objectReturns: This formatter for method chaining |
Layout Configuration
Method | Description |
---|---|
setTitle(String title) |
Set the title for the montage. Parameters: title - The title stringReturns: This formatter for method chaining |
setXAxisLabel(String label) |
Set the x-axis label. Parameters: label - The x-axis labelReturns: This formatter for method chaining |
setSpacing(int spacing) |
Set spacing between frames in the montage. Parameters: spacing - The spacing in pixelsReturns: This formatter for method chaining |
setCanvasWidth(int width) |
Set the width of each canvas for individual shapes. Parameters: width - Width in pixelsReturns: This formatter for method chaining |
setCanvasHeight(int height) |
Set the height of each canvas for individual shapes. Parameters: height - Height in pixelsReturns: This formatter for method chaining |
setHorizontalMargin(int margin) |
Set horizontal margin. Parameters: margin - Margin in pixelsReturns: This formatter for method chaining |
setVerticalMargin(int margin) |
Set vertical margin. Parameters: margin - Margin in pixelsReturns: 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 pointReturns: This formatter for method chaining |
setMaxT(int maxT) |
Set the maximum time point to include. Parameters: maxT - The maximum time pointReturns: This formatter for method chaining |
setFrameStep(int step) |
Set the step size between frames to include. Parameters: step - Include every Nth frameReturns: This formatter for method chaining |
setTimeUnitDivider(int divider) |
Set the time unit divider for converting time units. Parameters: divider - Division factor for time valuesReturns: 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 hideReturns: 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 scaleReturns: This formatter for method chaining |
showAxes(boolean show) |
Enable or disable axes. Parameters: show - True to show axes, false to hideReturns: This formatter for method chaining |
setXAxisPrecision(int precision) |
Set the precision for the time display. Parameters: precision - Number of decimal places to showReturns: This formatter for method chaining |
Font Configuration
Method | Description |
---|---|
setAxisFont(Font font) |
Set the font for axis text. Parameters: font - Font for the axis textReturns: This formatter for method chaining |
setAxisFontSize(int size) |
Set the axis font size. Parameters: size - Font size in pointsReturns: This formatter for method chaining |
setLabelFont(Font font) |
Set the font for labels. Parameters: font - Font for labelsReturns: This formatter for method chaining |
setLabelFontSize(int size) |
Set the label font size. Parameters: size - Font size in pointsReturns: This formatter for method chaining |
setTitleFont(Font font) |
Set the font for the title. Parameters: font - Font for the titleReturns: This formatter for method chaining |
setTitleFontSize(int size) |
Set the title font size. Parameters: size - Font size in pointsReturns: This formatter for method chaining |
Shape Styling
Method | Description |
---|---|
setShapeColor(Color color) |
Set the shape outline color. Parameters: color - Color for shape outlinesReturns: This formatter for method chaining |
setShapeLineWidth(float width) |
Set the shape line width. Parameters: width - Line width in pixelsReturns: This formatter for method chaining |
setFillShape(boolean fill) |
Enable or disable shape filling. Parameters: fill - True to fill shapes, false for outlines onlyReturns: 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 axesReturns: This formatter for method chaining |
setAxisLineWidth(float width) |
Set the axis line width. Parameters: width - Line width in pixelsReturns: 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 themeReturns: 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 toReturns: 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:
- Extracting shape data from the MartianObject for selected time points
- Optionally normalizing shapes to a common scale
- Drawing each shape on individual canvases
- Arranging canvases in horizontal or vertical layouts
- Adding time labels and axis labels as configured
- 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.