de.unihalle.informatik.MiToBo.core.datatypes
Class MTBContour2D

java.lang.Object
  extended by de.unihalle.informatik.Alida.operator.ALDData
      extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBContour2D
All Implemented Interfaces:
java.lang.Cloneable

public class MTBContour2D
extends de.unihalle.informatik.Alida.operator.ALDData
implements java.lang.Cloneable

Class to create 2D contour objects with a vector of points, belonging to the contour. Every contour can include a set of inner contours.

Author:
misiak

Field Summary
private  java.util.Vector<MTBContour2D> inner
          Set of inner contours if available.
private  int pointNum
          The number of contour points.
private  java.util.Vector<java.awt.geom.Point2D.Double> points
          The contour pixels.
 
Constructor Summary
MTBContour2D()
          Standard constructor.
MTBContour2D(java.util.Vector<java.awt.geom.Point2D.Double> _points)
          Constructor to create an 2D contour object from a 2D point vector.
 
Method Summary
 void addInner(MTBContour2D C)
          Add a inner contour to the existing contour object.
 void addPixel(int x, int y)
          Add a 2D point to the existing contour.
 MTBContour2D clone()
          Override java.lang.Object.clone() to create and return a copy of this object.
 int countInner()
          Get the number of inner contours including in the contour object.
 java.util.Vector<MTBContour2D> getAllInner()
          Get all inner contours from the contour object.
 double[] getBoundingBox()
          Calculates the axes-parallel bounding box of the contour.
 int[] getChaincode()
          Calculates chaincode from the outer contour.
 MTBContour2D getContour()
          Get a Contour2D copy of this object.
 double getContourLength()
          Calculates the length of the outer contour using it's chaincode.
 MTBContour2D getInner(int index)
          Get a specific inner contour from the contour object.
 java.awt.geom.Point2D.Double getPointAt(int index)
          Get a specific 2D point belonging to the contour object.
 int getPointNum()
          Get the number of points of the contour object.
 java.util.Vector<java.awt.geom.Point2D.Double> getPoints()
          Get all points belonging to the contour object.
 MTBRegion2D getRegion(int imageSizeX, int imageSizeY)
          Method to get the included region in a 2D contour as Region2D object.
 void setInner(java.util.Vector<MTBContour2D> C)
          Set the inner contours of the contour object.
 MTBImage toMTBImage(java.lang.String file, MTBImage image)
          Method to save a contour with all inner contours in a given MTBImage image.
 MTBImageByte toMTBImageByte(java.lang.String file, int width, int height)
          Method to save a contour with all inner contours on a binary image with specific width and height.
 
Methods inherited from class de.unihalle.informatik.Alida.operator.ALDData
cloneProperties, getLocation, getProperty, getPropertyKeys, print, setLocation, setProperty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inner

private java.util.Vector<MTBContour2D> inner
Set of inner contours if available.


pointNum

private int pointNum
The number of contour points.


points

private java.util.Vector<java.awt.geom.Point2D.Double> points
The contour pixels.

Constructor Detail

MTBContour2D

public MTBContour2D()
Standard constructor. Creates an empty 2D contour object.


MTBContour2D

public MTBContour2D(java.util.Vector<java.awt.geom.Point2D.Double> _points)
Constructor to create an 2D contour object from a 2D point vector.

Parameters:
_points - vector with 2D points
Method Detail

addInner

public void addInner(MTBContour2D C)
Add a inner contour to the existing contour object.

Parameters:
C - the new 2D inner contour

addPixel

public void addPixel(int x,
                     int y)
Add a 2D point to the existing contour.

Parameters:
x - x-coordinate of the new point
y - y-coordinate of the new point

clone

public MTBContour2D clone()
Override java.lang.Object.clone() to create and return a copy of this object.

Overrides:
clone in class java.lang.Object

countInner

public int countInner()
Get the number of inner contours including in the contour object.

Returns:
The number of inner contours.

getAllInner

public java.util.Vector<MTBContour2D> getAllInner()
Get all inner contours from the contour object.

Returns:
All inner contours as vector 2D contour objects.

getBoundingBox

public double[] getBoundingBox()
Calculates the axes-parallel bounding box of the contour.

The function extracts the coordinates of the upper left and lower right corner of the bounding box of the contour. Note that the there is at least one point of the contour lying on each side of the bounding box, i.e. the contour not just touches the box, but lies on it.

The result array contains the corner coordinates in the following order: [xmin, ymin, xmax, ymax]

Returns:
Coordinates of upper left and lower right corners.

getChaincode

public int[] getChaincode()
Calculates chaincode from the outer contour. The contour points must be stored in consecutive order and the contour must be closed!

Returns:
Chaincode of outer contour.

getContour

public MTBContour2D getContour()
Get a Contour2D copy of this object.

Returns:
Copy of this Contour2D object.

getContourLength

public double getContourLength()
Calculates the length of the outer contour using it's chaincode.

Returns:
Length of the contour.

getInner

public MTBContour2D getInner(int index)
Get a specific inner contour from the contour object.

Parameters:
index - specific index of the inner contour to get from the inner contour vector
Returns:
Inner contour at the specific index as 2D contour object.

getPointAt

public java.awt.geom.Point2D.Double getPointAt(int index)
Get a specific 2D point belonging to the contour object.

Returns:
2D point at specific index.

getPointNum

public int getPointNum()
Get the number of points of the contour object.

Returns:
Number of contour points.

getPoints

public java.util.Vector<java.awt.geom.Point2D.Double> getPoints()
Get all points belonging to the contour object.

Returns:
Vector with all 2D points of the contour.

getRegion

public MTBRegion2D getRegion(int imageSizeX,
                             int imageSizeY)
                      throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                             de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to get the included region in a 2D contour as Region2D object.

Parameters:
imageSizeX - width of image that includes the region
imageSizeY - height of image that includes the region
Returns:
2D region included in the 2D contour.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

setInner

public void setInner(java.util.Vector<MTBContour2D> C)
Set the inner contours of the contour object.

Parameters:
C - vector with the inner contours belonging to the contour object

toMTBImage

public MTBImage toMTBImage(java.lang.String file,
                           MTBImage image)
                    throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                           de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to save a contour with all inner contours in a given MTBImage image.

Parameters:
file - path where the file should be saved, can be null
image - image where the contours should be drawn in
Returns:
2D inner- and outer-contours in a binary image of type MTBImageByte.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

toMTBImageByte

public MTBImageByte toMTBImageByte(java.lang.String file,
                                   int width,
                                   int height)
                            throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                   de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to save a contour with all inner contours on a binary image with specific width and height.

Parameters:
file - path where the file should be saved, can be null
width - width of the binary image
height - height of the binary image
Returns:
2D inner- and outer-contours in a binary image of type MTBImageByte.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException