syntax = "proto3";

package biopb.ome;

option java_package = "biopb.ome";
option java_multiple_files = true;

import "biopb/ome/bindata.proto";


// A matrix used to transform the shape.
// ⎡ A00, A01, A02 ⎤
// ⎢ A10, A11, A12 ⎥
// ⎣ 0,   0,   1   ⎦
message AffineTransform {
    float a00 = 1;
    float a01 = 2;
    float a02 = 3;
    float a10 = 4;
    float a11 = 5;
    float a12 = 6;
}


// A simple rectangle object. If rotation is required apply a transformation at
// the Shape level.
//
message Rectangle {

    // The X value of the left edge or the rectangle. [units pixels]
    float x = 1; // required

    // The Y value of the left edge or the rectangle. [units pixels]
    float y = 2; // required

    float width = 3; // required

    float heigh = 4; // required
}


// The Mask ROI shape is a link to a BinData object that is a BIT mask drawn on
// top of the image as an ROI. It is applied at the same scale, pixel to pixel,
// as the Image the ROI is applied to, unless a transform is applied at the
// shape level.
//
message Mask {

    // The X coordinate of the left side of the image. [units pixels]
    float x = 1;

    // The Y coordinate of the top side of the image. [units pixels]
    float y = 2;

    float width = 3; // required

    float heigh = 4; // required

    BinData bin_data = 5; // required
}

message Point {
    float x = 1;
    float y = 2;    
}

// A simple ellipse object. If rotation is required apply a transformation at
// the Shape level.
//
message Ellipse {
    // The X coordinate of the center of the ellipse. [units pixels]
    float x = 1;

    // The Y coordinate of the center of the ellipse. [units pixels]
    float y = 2;

    // The horizontal radius of the ellipse. [units pixels]
    float radius_x = 3;

    // The vertical radius of the ellipse. [units pixels]
    float radius_y = 4;
}


//A straight line defined by it's end points.
//
message Line {

    // The X coordinate of the start of the line. [units pixels]
    float x1 = 1;

    // The Y coordinate of the start of the line. [units pixels]
    float y1 = 2;

    // The X coordinate of the end of the line. [units pixels]
    float x2 = 3;

    // The Y coordinate of the end of the line. [units pixels]
    float y2 = 4;
}


// The Polyline defines open shapes formed of straight lines. Note: Polyline
// uses counterclockwise winding (this is the default OpenGL behavior)
//
message PolyLine {
    // The points of the polyline 
    // NOTE:OME-XML uses a string representation here
    repeated Point points = 1;

    enum Marker {
        UNSPECIFIED = 0;
        ARROW = 1;
        OTHER = 2;
    }    
    
    Marker marker_start = 2;

    Marker marker_end = 3;
}

// The Polygon defines closed shapes formed of straight lines. Note: Polygon
// uses counterclockwise winding (this is the default OpenGL behavior)
//
message Polygon {
    // The points of the polygon
    // NOTE:OME-XML uses a string representation here
    repeated Point points = 1;
}


// The text label. Any transformation should be applied at the
// shape level.
//
message Label {
    // This defines the X coordinate of the current text position of the first
    // character in the string. [units pixels]
    float x = 1; // required

    // This defines the Y coordinate of the current text position of the first
    // character in the string. [units pixels]
    float y = 2; // required
}


// The shape element contains a single specific ROI shape and links that to any
// channels, and a timepoint and a z-section. It also records any transform
// applied to the ROI shape.
//
message Shape {
    // This is a matrix used to transform the shape. The element has 6 xsd:float
    // attributes. If the element is present then all 6 values must be included.
    AffineTransform transform = 2;

    // The color of the fill. Default is solid white
    optional uint32 fill_color = 3;

    // The rule used to decide which parts of the shape to fill. [enumeration]
    enum FillRule {
        UNSPECIFIED = 0;
        EVENODD = 1;
        NONZERO = 2;
        OTHER = 3;
    }
    FillRule fill_rule = 4;

    // The color of the stroke. Default is solid white.
    optional uint32 stroke_color = 5;

    // The width of the stroke. Units are set by StrokeWidthUnit.
    optional float stroke_width = 6;

    // The units used for the stroke width. default is "pixel"
    string stroke_width_unit = 7;

    // e.g. "none", "10 20 30 10"
    string stoke_dash_array = 8;

    // Text lable
    string text = 9;

    // The font family used to draw the text.
    // Note: these values are all lower case so they match
    // the standard HTML/CSS values. "fantasy" has been
    // included for completeness; we do not recommend its
    // regular use. This attribute is under consideration
    // for removal from the OME-XML schema.
    string font_family = 10;

    // Size of the font. Units are set by FontSizeUnit.
    optional float font_size = 11;

    // The units used for the font size.
    string font_size_unit = 12;

    // The style and weight applied to the text.
    // This is a simplified combination of the HTML/CSS
    // attributes font-style AND font-weight.
    string font_style = 13;

    // Controls whether the shape is locked and read only,
    // true is locked, false is editable.
    optional bool locked = 14;

    // The z-section the ROI applies to. If not specified then the ROI applies
    // to all the z-sections of the image. [units:none] This is numbered from 0.
    optional uint32 the_z = 15;

    // The timepoint the ROI applies to. If not specified then the ROI applies
    // to all the timepoints of the image. [units:none] This is numbered from 0.
    optional uint32 the_t = 16;

    // The channel the ROI applies to. If not specified then the ROI applies to
    // all the channels of the image. [units:none] This is numbered from 0.
    optional uint32 the_c = 17;

    repeated string annotation_ids = 18;

    oneof shape_group {

        Rectangle rectangle = 19;

        Mask mask = 20;

        Point point = 21;

        Ellipse ellipse = 22;

        Line line = 23;

        PolyLine polyLine = 24;

        Polygon polygon = 25;

        Label label = 26;
    }    
}

// A four dimensional 'Region of Interest'. If they are not used, and the Image
// has more than one plane, the entire set of planes is assumed to be included
// in the ROI. Multiple ROIs may be specified.
//
message ROI {
    // The Name identifies the ROI to the user. [plain-text string]
    string name = 2;

    // A description for the ROI. [plain-text multi-line string]
    string description = 3;

    repeated Shape shapes = 4;

    repeated string annotation_ids = 6;
}
