edu.stanford.hci.r3.pattern.coordinates.conversion
Class TiledPatternCoordinateConverter

java.lang.Object
  extended by edu.stanford.hci.r3.pattern.coordinates.conversion.TiledPatternCoordinateConverter
All Implemented Interfaces:
PatternCoordinateConverter

public class TiledPatternCoordinateConverter
extends java.lang.Object
implements PatternCoordinateConverter

Stores the bounds in physical (streaming) coordinates.

This software is distributed under the BSD License.


Constructor Summary
TiledPatternCoordinateConverter(java.lang.String regionName)
          A constructor for when you need to set the information later (The Lazy Approach).
TiledPatternCoordinateConverter(java.lang.String theRegionName, double leftMostPatternXCoord, double topMostPatternYCoord, int dotsAcross, int dotsDown)
          Used when you are creating a converter that lives on a SINGLE PATTERNED TILE.
TiledPatternCoordinateConverter(java.lang.String theRegionName, int startTile, int nTilesAcross, int nTilesDown, int dotsPerTileHoriz, int dotsPerTileVert, double numHorizDotsBetweenTiles, double numVertDotsBetweenTiles, double leftMostPatternX, double topMostPatternY, double numDotsAcross, double numDotsDown)
           This object deals with physical coordinates (the type that you get when you stream coordinates from the Nokia SU-1B).
 
Method Summary
 boolean contains(double xValPatternDots, double yValPatternDots)
          For performance, we precompute the boundaries and store just those numbers.
 boolean contains(StreamedPatternCoordinates location)
          If you have the values and do not need to create a StreamedPatternCoordinates object, use the other contains(...) method.
 double getArea()
           
 java.lang.String getRegionName()
           
 PercentageCoordinates getRelativeLocation(StreamedPatternCoordinates coord)
          Convert the input coordinate into a percentage location relative to this tile configuration (a region that has tiled pattern)
 int getTileNumber(StreamedPatternCoordinates coord)
          It tries to calculate the tile number given an input coordinate.
 void setOriginInDots(double leftMostPatternX, double topMostPatternY)
          What is the physical coordinate of the top-left corner of the top-left tile?
 void setPatternInformationByReadingItFrom(TiledPattern p)
          Reads in the information to define this coordinate converter.
 void setRegionName(java.lang.String rName)
           
 void setStartingTile(int startTile)
          The number of the first (top-left) tile; this is largely arbitrary, but _may_ correlate with a pattern file number N.pattern --> N as a starting tile number.
 void setTileConfiguration(int nTilesAcross, int nTilesDown)
          The number of tiles owned by this converter.
 void setTileSizeInDots(int dotsPerTileHoriz, int dotsPerTileVert)
          How wide and tall are these tiles? We assume uniform tiles (except for the rightmost and bottommost tiles)
 void setTileToTileOffsetInDots(double numHorizDotsBetweenTiles, double numVertDotsBetweenTiles)
           
 void setTotalSizeInDots(double numDotsAcross, double numDotsDown)
          Set the size of this tile configuration, irrespective of the tiling.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TiledPatternCoordinateConverter

public TiledPatternCoordinateConverter(java.lang.String regionName)
A constructor for when you need to set the information later (The Lazy Approach).

Parameters:
regionName - the Region that this coordinate converter was created for. The reason we don't pass in the whole region object is because this converter WILL be serialized and unserialized. Due to XStream's limitations, we will have to resolve the region at runtime using the region's name instead.

TiledPatternCoordinateConverter

public TiledPatternCoordinateConverter(java.lang.String theRegionName,
                                       double leftMostPatternXCoord,
                                       double topMostPatternYCoord,
                                       int dotsAcross,
                                       int dotsDown)
Used when you are creating a converter that lives on a SINGLE PATTERNED TILE.


TiledPatternCoordinateConverter

public TiledPatternCoordinateConverter(java.lang.String theRegionName,
                                       int startTile,
                                       int nTilesAcross,
                                       int nTilesDown,
                                       int dotsPerTileHoriz,
                                       int dotsPerTileVert,
                                       double numHorizDotsBetweenTiles,
                                       double numVertDotsBetweenTiles,
                                       double leftMostPatternX,
                                       double topMostPatternY,
                                       double numDotsAcross,
                                       double numDotsDown)

This object deals with physical coordinates (the type that you get when you stream coordinates from the Nokia SU-1B). They are all huge numbers, but we store them in PatternDots objects. Although we can convert the PatternDots objects into other Units, it doesn't really make sense, as the dots are specified in the world of Anoto's gargantuan pattern space. For example, if you converted the xOrigin to inches, you would get a beast of a number.

We precompute the boundaries so that we can do contains(...) tests faster.

Parameters:
theRegionName - The region that this converter was created for.
startTile - the number that you assign to the top-left tile
nTilesAcross - width of this tile configuration, in # of tiles
nTilesDown - height of this tile configuration, in # of tiles
dotsPerTileHoriz - width of each tile, in # dots
dotsPerTileVert - height of each tile, in # dots
leftMostPatternX - left boundary in pattern dots
topMostPatternY - top boundary, in pattern dots
numDotsAcross - width of entire region in dots, not including the between-tile padding
numDotsDown - height of entire region in dots, not including the padding in between tiles
numHorizDotsBetweenTiles - the horizontal padding between adjacent tiles
numVertDotsBetweenTiles - the vertical padding between adjacent tiles (tends to be 0, in our experience)
Method Detail

contains

public boolean contains(double xValPatternDots,
                        double yValPatternDots)
For performance, we precompute the boundaries and store just those numbers. This method's likely faster than the other contains test, especially if you already have the x and y values and do not need to create a StreamedPatternLocation object.

Parameters:
xValPatternDots - x value of the location, in PatternDots (physical/streamed coordinates)
yValPatternDots - y value of the location, in PatternDots (physical/streamed coordinates)
Returns:
WARNING: POSSIBLY BUGGY, Due to New way of iterating through Pattern TODO: Fix Bug ~Here.... TODO: Implement a FASTER reject. Contains is called many many times. We want to reject as soon as is possible. Also, rejects happen a lot more than accepts.

contains

public boolean contains(StreamedPatternCoordinates location)
If you have the values and do not need to create a StreamedPatternCoordinates object, use the other contains(...) method.

Specified by:
contains in interface PatternCoordinateConverter
Parameters:
location -
Returns:
whether the tile configuration contains this location

getArea

public double getArea()
Specified by:
getArea in interface PatternCoordinateConverter
Returns:
the area, in pattern dots squared, of this patch.

getRegionName

public java.lang.String getRegionName()
Specified by:
getRegionName in interface PatternCoordinateConverter
Returns:

getRelativeLocation

public PercentageCoordinates getRelativeLocation(StreamedPatternCoordinates coord)
Convert the input coordinate into a percentage location relative to this tile configuration (a region that has tiled pattern)

Specified by:
getRelativeLocation in interface PatternCoordinateConverter
Returns:

getTileNumber

public int getTileNumber(StreamedPatternCoordinates coord)
It tries to calculate the tile number given an input coordinate.
[0][1][2]
[3][4][5]
This should work if the pattern space is short and wide, or thin and tall...

Parameters:
coord -
Returns:
the tile number of this coordinate. Returns -1 if this coordinate is not contained by this tile configuration.

setOriginInDots

public void setOriginInDots(double leftMostPatternX,
                            double topMostPatternY)
What is the physical coordinate of the top-left corner of the top-left tile?

Parameters:
leftMostPatternX -
topMostPatternY -

setPatternInformationByReadingItFrom

public void setPatternInformationByReadingItFrom(TiledPattern p)
Reads in the information to define this coordinate converter.

Parameters:
p - the tiled pattern object produced by sheet renderers.

setRegionName

public void setRegionName(java.lang.String rName)
Parameters:
rName - the name of the region that this converter manages. It's important to keep your regions uniquely identifiable.

setStartingTile

public void setStartingTile(int startTile)
The number of the first (top-left) tile; this is largely arbitrary, but _may_ correlate with a pattern file number N.pattern --> N as a starting tile number. This makes calculations easier for certain operations, such as finding out which page of a notebook your user has written on.

Parameters:
startTile -

setTileConfiguration

public void setTileConfiguration(int nTilesAcross,
                                 int nTilesDown)
The number of tiles owned by this converter. Usually, this converter will map to a region on a sheet. This means that the tiledPatternConverter will need to know how many tiles of pattern the region contains. It will then help us find out where on the region we are.

Parameters:
nTilesAcross -
nTilesDown -

setTileSizeInDots

public void setTileSizeInDots(int dotsPerTileHoriz,
                              int dotsPerTileVert)
How wide and tall are these tiles? We assume uniform tiles (except for the rightmost and bottommost tiles)

Parameters:
dotsPerTileHoriz -
dotsPerTileVert -

setTileToTileOffsetInDots

public void setTileToTileOffsetInDots(double numHorizDotsBetweenTiles,
                                      double numVertDotsBetweenTiles)
Parameters:
numHorizDotsBetweenTiles -
numVertDotsBetweenTiles -

setTotalSizeInDots

public void setTotalSizeInDots(double numDotsAcross,
                               double numDotsDown)
Set the size of this tile configuration, irrespective of the tiling. This SHOULD be able to calculate the extra space on the last tile that is NOT a part of our configuration.

Parameters:
numDotsAcross -
numDotsDown -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

Copyright 2006 Stanford University