Class ObjectLocationsSpreadSheetReader

  • All Implemented Interfaces:
    CleanUpHandler, Destroyable, GlobalInfoSupporter, FileFormatHandler, LoggingLevelHandler, LoggingSupporter, OptionHandler, ShallowCopySupporter<AbstractReportReader>, SizeOfHandler, Stoppable, StoppableWithFeedback, ReportReader<Report>, StringReportReader<Report>, ObjectPrefixHandler, Serializable, Comparable

    public class ObjectLocationsSpreadSheetReader
    extends AbstractReportReader<Report>
    implements ObjectPrefixHandler, StringReportReader<Report>
    Reads object locations from a spreadsheet into a report.
    Top/left column is required.
    Either right/bottom or width/height need to be supplied.
    In addition, polygon coordinates (X and Y coordinates as comma-separated lists in two separate columns) can be read as well.
    If the coordinates/dimensions represent normalized ones (ie 0-1), then specify the width/height of the image to relate them back to actual pixel-based sizes.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -input <adams.core.io.PlaceholderFile> (property: input)
        The file to read and turn into a report.
        default: ${CWD}
     
    -reader <adams.data.io.input.SpreadSheetReader> (property: reader)
        The reader to use for reading the spreadsheet data.
        default: adams.data.io.input.CsvSpreadSheetReader -data-row-type adams.data.spreadsheet.DenseDataRow -spreadsheet-type adams.data.spreadsheet.DefaultSpreadSheet
     
    -row-finder <adams.data.spreadsheet.rowfinder.RowFinder> (property: rowFinder)
        The row finder to use for selecting a subset before extracting object locations.
        default: adams.data.spreadsheet.rowfinder.AllFinder
     
    -col-left <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colLeft)
        The column containing the left coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-top <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colTop)
        The column containing the top coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-right <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colRight)
        The column containing the right coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-bottom <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colBottom)
        The column containing the bottom coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-width <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colWidth)
        The column containing the width coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-height <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colHeight)
        The column containing the height coordinate.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-polygon-x <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colPolygonX)
        The column containing the X coordinates of the polygon (comma-separated
        list of coordinates); cannot be used without bounding box.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-polygon-y <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colPolygonY)
        The column containing the Y coordinates of the polygon (comma-separated
        list of coordinates); cannot be used without bounding box.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -col-type <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: colType)
        The column containing the object label.
        default:
        example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -range-meta-data <adams.data.spreadsheet.SpreadSheetColumnRange> (property: rangeMetaData)
        The columns to store as meta-data; all other columns get automatically excluded
        from the meta-data.
        default:
        example: A range is a comma-separated list of single 1-based indices or sub-ranges of indices ('start-end'); 'inv(...)' inverts the range '...'; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
     
    -use-normalized <boolean> (property: useNormalized)
        If enabled, the coordinates/dimensions are interpreted as normalized (0-
        1) rather than absolute pixels.
        default: false
     
    -width <int> (property: width)
        The width of the image to use when reading normalized coordinates/dimensions.
        default: 1000
        minimum: 1
     
    -height <int> (property: height)
        The height of the image to use when reading normalized coordinates/dimensions.
        default: 1000
        minimum: 1
     
    -prefix <java.lang.String> (property: prefix)
        The report field prefix used in the report.
        default: Object.
     
    -label-suffix <java.lang.String> (property: labelSuffix)
        The suffix to use in the report for labels.
        default: type
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_RowFinder

        protected RowFinder m_RowFinder
        the row finder to apply before extracting the objects.
      • m_UseNormalized

        protected boolean m_UseNormalized
        whether to use normalized coordinates/dimensions.
      • m_Width

        protected int m_Width
        the image width to use as basis for normalized coordinates/dimensions.
      • m_Height

        protected int m_Height
        the image height to use as basis for normalized coordinates/dimensions.
      • m_Prefix

        protected String m_Prefix
        the prefix to use.
      • m_LabelSuffix

        protected String m_LabelSuffix
        the label suffix to use.
    • Constructor Detail

      • ObjectLocationsSpreadSheetReader

        public ObjectLocationsSpreadSheetReader()
    • Method Detail

      • setReader

        public void setReader​(SpreadSheetReader value)
        Sets the spreadsheet reader to use.
        Parameters:
        value - the reader
      • getReader

        public SpreadSheetReader getReader()
        Returns the spreadsheet reader in use.
        Returns:
        the reader
      • readerTipText

        public String readerTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setRowFinder

        public void setRowFinder​(RowFinder value)
        Sets the row finder to use for selecting a subset before extracting object locations.
        Parameters:
        value - the finder
      • getRowFinder

        public RowFinder getRowFinder()
        Returns the row finder to use for selecting a subset before extracting object locations.
        Returns:
        the finder
      • rowFinderTipText

        public String rowFinderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColLeft

        public void setColLeft​(SpreadSheetColumnIndex value)
        Sets the column containing the left coordinate.
        Parameters:
        value - the column
      • getColLeft

        public SpreadSheetColumnIndex getColLeft()
        Returns the column containing the left coordinate.
        Returns:
        the column
      • colLeftTipText

        public String colLeftTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColTop

        public void setColTop​(SpreadSheetColumnIndex value)
        Sets the column containing the top coordinate.
        Parameters:
        value - the column
      • getColTop

        public SpreadSheetColumnIndex getColTop()
        Returns the column containing the top coordinate.
        Returns:
        the column
      • colTopTipText

        public String colTopTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColRight

        public void setColRight​(SpreadSheetColumnIndex value)
        Sets the column containing the right coordinate.
        Parameters:
        value - the column
      • getColRight

        public SpreadSheetColumnIndex getColRight()
        Returns the column containing the right coordinate.
        Returns:
        the column
      • colRightTipText

        public String colRightTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColBottom

        public void setColBottom​(SpreadSheetColumnIndex value)
        Sets the column containing the bottom coordinate.
        Parameters:
        value - the column
      • getColBottom

        public SpreadSheetColumnIndex getColBottom()
        Returns the column containing the bottom coordinate.
        Returns:
        the column
      • colBottomTipText

        public String colBottomTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColWidth

        public void setColWidth​(SpreadSheetColumnIndex value)
        Sets the column containing the width coordinate.
        Parameters:
        value - the column
      • getColWidth

        public SpreadSheetColumnIndex getColWidth()
        Returns the column containing the width coordinate.
        Returns:
        the column
      • colWidthTipText

        public String colWidthTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColHeight

        public void setColHeight​(SpreadSheetColumnIndex value)
        Sets the column containing the height coordinate.
        Parameters:
        value - the column
      • getColHeight

        public SpreadSheetColumnIndex getColHeight()
        Returns the column containing the height coordinate. Cannot be used without bounding box.
        Returns:
        the column
      • colHeightTipText

        public String colHeightTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColPolygonX

        public void setColPolygonX​(SpreadSheetColumnIndex value)
        Sets the column containing the X coordinates of the polygon (comma-separated list of coordinates). Cannot be used without bounding box.
        Parameters:
        value - the column
      • getColPolygonX

        public SpreadSheetColumnIndex getColPolygonX()
        Returns the column containing the X coordinates of the polygon (comma-separated list of coordinates).
        Returns:
        the column
      • colPolygonXTipText

        public String colPolygonXTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColPolygonY

        public void setColPolygonY​(SpreadSheetColumnIndex value)
        Sets the column containing the Y coordinates of the polygon (comma-separated list of coordinates). Cannot be used without bounding box.
        Parameters:
        value - the column
      • getColPolygonY

        public SpreadSheetColumnIndex getColPolygonY()
        Returns the column containing the Y coordinates of the polygon (comma-separated list of coordinates). Cannot be used without bounding box.
        Returns:
        the column
      • colPolygonYTipText

        public String colPolygonYTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColType

        public void setColType​(SpreadSheetColumnIndex value)
        Sets the column containing the object label.
        Parameters:
        value - the column
      • getColType

        public SpreadSheetColumnIndex getColType()
        Returns the column containing the object label.
        Returns:
        the column
      • colTypeTipText

        public String colTypeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseNormalized

        public void setUseNormalized​(boolean value)
        Sets whether the coordinates/dimensions are interpreted as normalized (0-1) rather than absolute pixels.
        Parameters:
        value - true if normalized
      • getUseNormalized

        public boolean getUseNormalized()
        Returns whether the coordinates/dimensions are interpreted as normalized (0-1) rather than absolute pixels.
        Returns:
        true if normalized
      • useNormalizedTipText

        public String useNormalizedTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setWidth

        public void setWidth​(int value)
        Sets the width of the image to use when reading normalized coordinates/dimensions.
        Parameters:
        value - the image width
      • getWidth

        public int getWidth()
        Returns the width of the image to use when reading normalized coordinates/dimensions.
        Returns:
        the image width
      • widthTipText

        public String widthTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setHeight

        public void setHeight​(int value)
        Sets the height of the image to use when reading normalized coordinates/dimensions.
        Parameters:
        value - the image height
      • getHeight

        public int getHeight()
        Returns the height of the image to use when reading normalized coordinates/dimensions.
        Returns:
        the image height
      • heightTipText

        public String heightTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setRangeMetaData

        public void setRangeMetaData​(SpreadSheetColumnRange value)
        Sets the range of columns to store as meta-data.
        Parameters:
        value - the column range
      • getRangeMetaData

        public SpreadSheetColumnRange getRangeMetaData()
        Returns the range of columns to store as meta-data.
        Returns:
        the column range
      • rangeMetaDataTipText

        public String rangeMetaDataTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrefix

        public void setPrefix​(String value)
        Sets the field prefix used in the report.
        Specified by:
        setPrefix in interface ObjectPrefixHandler
        Parameters:
        value - the field prefix
      • prefixTipText

        public String prefixTipText()
        Returns the tip text for this property.
        Specified by:
        prefixTipText in interface ObjectPrefixHandler
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelSuffix

        public void setLabelSuffix​(String value)
        Sets the field suffix used in the report for labels.
        Parameters:
        value - the field suffix
      • getLabelSuffix

        public String getLabelSuffix()
        Returns the field suffix used in the report for labels.
        Returns:
        the field suffix
      • labelSuffixTipText

        public String labelSuffixTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • determineParentID

        protected int determineParentID​(Report report)
        Tries to determine the parent ID for the current report.
        Specified by:
        determineParentID in class AbstractReportReader<Report>
        Parameters:
        report - the report to determine the ID for
        Returns:
        the parent database ID, -1 if it cannot be determined
      • parseCoords

        protected double[] parseCoords​(String coords)
        Parses comma-separated list of coordinates and returns a double array.
        Parameters:
        coords - the coordinates to parse
        Returns:
        the parsed values, empty array if failed to parse
      • multipleCoords

        protected double[] multipleCoords​(double[] coords,
                                          double factor)
        Multiplies the coordinates by the specified factor (in-place).
        Parameters:
        coords - the coordinates to update
        factor - the factor to use
        Returns:
        the updated coordinates
      • coordsToList

        protected String coordsToList​(double[] coords)
        Turns the coordinates into a comma-separated list.
        Parameters:
        coords - the coordinates to convert
        Returns:
        the comma-separated list
      • convert

        protected List<Report> convert​(SpreadSheet sheet)
        Converts the spreadsheet into report(s).
        Parameters:
        sheet - the spreadsheet to convert
        Returns:
        the reports that were read