mpicbg.models
Class TransformMesh

java.lang.Object
  extended by mpicbg.models.TransformMesh
All Implemented Interfaces:
Serializable, CoordinateTransform, InverseCoordinateTransform, InvertibleCoordinateTransform
Direct Known Subclasses:
CoordinateTransformMesh, MovingLeastSquaresMesh, SpringMesh

public class TransformMesh
extends Object
implements InvertibleCoordinateTransform

Triangular transformation mesh. See an example to find out how the mesh is constructed: numX = 4; numY = 3:

 *---*---*---*
 |\ / \ / \ /|
 | *---*---* |
 |/ \ / \ / \|
 *---*---*---*
 |\ / \ / \ /|
 | *---*---* |
 |/ \ / \ / \|
 *---*---*---*
 
Each vertex is given as a PointMatch with p1 being the original point and p2 being the transferred point. Keep in mind that Points store local and world coordinates with local coordinates being constant and world coordinates being mutable. That is initially p1.l = p1.w = p2.l while p1.w is the transferred location of the vertex. Three adjacent vertices span a triangle. All pixels inside a triangle will be transferred by a 2d affine transform that is defined by the three vertices. Given the abovementioned definition of a vertex as PointMatch, this 2d affine transform is a forward transform (p1.l->p2.w).

Author:
Stephan Saalfeld
See Also:
Serialized Form

Field Summary
protected  HashMap<AffineModel2D,ArrayList<PointMatch>> av
           
protected static PointFactory<Point> defaultPointFactory
           
protected static PointMatchFactory<PointMatch> defaultPointMatchFactory
           
protected  double height
           
protected  HashMap<PointMatch,ArrayList<AffineModel2D>> va
           
protected  double width
           
 
Constructor Summary
  TransformMesh(int numX, double width, double height)
           
  TransformMesh(int numX, int numY, double width, double height)
           
protected TransformMesh(int numX, int numY, double width, double height, PointFactory<?> pointFactory, PointMatchFactory<?> pointMatchFactory)
           
 
Method Summary
 void addTriangle(ArrayList<PointMatch> t)
          Add a triangle defined by 3 PointMatches that defines an AffineTransform2D.
 double[] apply(double[] location)
          Apply the CoordinateTransform to a location.
 void applyInPlace(double[] location)
          Apply the CoordinateTransform to a location.
 double[] applyInverse(double[] location)
          Apply the inverse of the model to a point location
 void applyInverseInPlace(double[] location)
          apply the inverse of the model to a point location
 void bounds(double[] min, double[] max)
          Calculate bounding box
 TransformMesh createInverse()
          TODO Not yet tested
 PointMatch findClosestSourcePoint(double[] there)
          Find the closest source point to a given coordinate.
 PointMatch findClosestTargetPoint(double[] there)
          Find the closest target point to a given coordinate.
 HashMap<AffineModel2D,ArrayList<PointMatch>> getAV()
           
 double getHeight()
           
 HashMap<PointMatch,ArrayList<AffineModel2D>> getVA()
           
 double getWidth()
           
 String illustrateBestRigidSVG()
          Create an SVG path that illustrates the best regid approximation of the mesh as a rotated square.
 Shape illustrateMesh()
          Create a Shape that illustrates the mesh.
 String illustrateMeshSVG()
          Create an SVG path that illustrates the mesh.
protected  void illustrateTriangle(AffineModel2D ai, GeneralPath path)
           
 void init(CoordinateTransform t)
          Initialize the mesh with a CoordinateTransform.
static boolean isInConvexTargetPolygon(ArrayList<PointMatch> pm, double[] t)
          Checks if a location is inside a given polygon at the target side or not.
static boolean isInSourcePolygon(ArrayList<PointMatch> pm, double[] t)
          Checks if a location is inside a given polygon at the source side or not.
protected static int numY(int numX, double width, double height)
           
 void scale(double scale)
          Scale all vertex coordinates
 void updateAffine(PointMatch p)
          Update all affine transformations that would have been affected by a given Vertex.
 void updateAffines()
          Update all affine transformations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected final double width

height

protected final double height

av

protected final HashMap<AffineModel2D,ArrayList<PointMatch>> av

va

protected final HashMap<PointMatch,ArrayList<AffineModel2D>> va

defaultPointFactory

protected static final PointFactory<Point> defaultPointFactory

defaultPointMatchFactory

protected static final PointMatchFactory<PointMatch> defaultPointMatchFactory
Constructor Detail

TransformMesh

protected TransformMesh(int numX,
                        int numY,
                        double width,
                        double height,
                        PointFactory<?> pointFactory,
                        PointMatchFactory<?> pointMatchFactory)

TransformMesh

public TransformMesh(int numX,
                     int numY,
                     double width,
                     double height)

TransformMesh

public TransformMesh(int numX,
                     double width,
                     double height)
Method Detail

getWidth

public double getWidth()

getHeight

public double getHeight()

getAV

public HashMap<AffineModel2D,ArrayList<PointMatch>> getAV()

getVA

public HashMap<PointMatch,ArrayList<AffineModel2D>> getVA()

numY

protected static final int numY(int numX,
                                double width,
                                double height)

addTriangle

public void addTriangle(ArrayList<PointMatch> t)
Add a triangle defined by 3 PointMatches that defines an AffineTransform2D.

Parameters:
t - 3 PointMatches (will not be copied, so do not reuse this list!)

illustrateTriangle

protected void illustrateTriangle(AffineModel2D ai,
                                  GeneralPath path)

illustrateMesh

public Shape illustrateMesh()
Create a Shape that illustrates the mesh.

Returns:
the illustration

illustrateMeshSVG

public String illustrateMeshSVG()
Create an SVG path that illustrates the mesh.

Returns:
svg path-definition

illustrateBestRigidSVG

public String illustrateBestRigidSVG()
Create an SVG path that illustrates the best regid approximation of the mesh as a rotated square.

Returns:
svg path-definition

updateAffine

public void updateAffine(PointMatch p)
Update all affine transformations that would have been affected by a given Vertex.

Parameters:
p -

updateAffines

public void updateAffines()
Update all affine transformations.


findClosestSourcePoint

public PointMatch findClosestSourcePoint(double[] there)
Find the closest source point to a given coordinate. Each vertex being defined by a PointMatch, the source coordinates are the local coordinates of the source point.

Parameters:
there -
Returns:
closest PointMatch in terms of the source point

findClosestTargetPoint

public PointMatch findClosestTargetPoint(double[] there)
Find the closest target point to a given coordinate. Each vertex being defined by a PointMatch, the target coordinates are the world coordinates of the target point.

Parameters:
there -
Returns:
closest PointMatch in terms of the target point

isInConvexTargetPolygon

public static boolean isInConvexTargetPolygon(ArrayList<PointMatch> pm,
                                              double[] t)
Checks if a location is inside a given polygon at the target side or not.

Parameters:
pm -
t -
Returns:

isInSourcePolygon

public static final boolean isInSourcePolygon(ArrayList<PointMatch> pm,
                                              double[] t)
Checks if a location is inside a given polygon at the source side or not.

Parameters:
pm -
t -
Returns:

apply

public double[] apply(double[] location)
Description copied from interface: CoordinateTransform
Apply the CoordinateTransform to a location.

Specified by:
apply in interface CoordinateTransform
Returns:
transformed location

applyInPlace

public void applyInPlace(double[] location)
Description copied from interface: CoordinateTransform
Apply the CoordinateTransform to a location.

Specified by:
applyInPlace in interface CoordinateTransform

applyInverse

public double[] applyInverse(double[] location)
                      throws NoninvertibleModelException
Description copied from interface: InverseCoordinateTransform
Apply the inverse of the model to a point location

Specified by:
applyInverse in interface InverseCoordinateTransform
Returns:
transformed point
Throws:
NoninvertibleModelException

applyInverseInPlace

public void applyInverseInPlace(double[] location)
                         throws NoninvertibleModelException
Description copied from interface: InverseCoordinateTransform
apply the inverse of the model to a point location

Specified by:
applyInverseInPlace in interface InverseCoordinateTransform
Throws:
NoninvertibleModelException

createInverse

public TransformMesh createInverse()
TODO Not yet tested

Specified by:
createInverse in interface InvertibleCoordinateTransform

init

public void init(CoordinateTransform t)
Initialize the mesh with a CoordinateTransform.

Parameters:
t -

scale

public void scale(double scale)
Scale all vertex coordinates

Parameters:
scale -

bounds

public void bounds(double[] min,
                   double[] max)
Calculate bounding box

Parameters:
min -
max -


Copyright © 2007-2016 Fiji. All Rights Reserved.