mpicbg.models
Class SpringMesh

java.lang.Object
  extended by mpicbg.models.TransformMesh
      extended by mpicbg.models.SpringMesh
All Implemented Interfaces:
Serializable, CoordinateTransform, InverseCoordinateTransform, InvertibleCoordinateTransform

public class SpringMesh
extends TransformMesh

A TransformMesh with all Vertices being interconnected by springs. It implements the optimization straightforward as a dynamic process. A SpringMesh may or may not contain passive vertices that are not connected to other vertices of the mesh itself. Depending on their location, such passive vertices are moved by the respective AffineModel2D. Passive vertices are used to uni-directionally connect two SpringMeshes.

Author:
Stephan Saalfeld
See Also:
Serialized Form

Field Summary
protected  HashMap<AffineModel2D,Vertex> apv
           
protected  double damp
           
protected  HashSet<Vertex> fixedVertices
           
protected  double force
           
protected  double maxForce
           
protected  double maxSpeed
           
protected  double minForce
           
protected  HashMap<PointMatch,Vertex> pv
           
protected  HashMap<Vertex,AffineModel2D> pva
           
protected  ArrayList<Vertex> vertices
           
protected  HashMap<Vertex,PointMatch> vp
           
 
Fields inherited from class mpicbg.models.TransformMesh
av, defaultPointFactory, defaultPointMatchFactory, height, va, width
 
Constructor Summary
SpringMesh(int numX, double width, double height, double springWeight, double maxStretch, double damp)
           
SpringMesh(int numX, int numY, double width, double height, double springWeight, double maxStretch, double damp)
           
 
Method Summary
 void addPassiveVertex(Vertex vertex)
          Add a passive vertex.
 void addVertex(Vertex vertex, double weight)
          Add a Vertex to the mesh.
 void addVertexWeightedByDistance(Vertex vertex, double weight, double alpha)
          Add a Vertex to the mesh.
protected  void calculateForceAndSpeed(ErrorStatistic observer)
          Deprecated. Remains for legacy compatibility
 Vertex findClosestSourceVertex(double[] there)
          Find the closest Vertex to a given coordinate in terms of its source coordinates.
 Vertex findClosestTargetVertex(double[] there)
          Find the closest Vertex to a given coordinate in terms of its target coordinates.
 double getForce()
           
 ArrayList<Vertex> getVertices()
           
 Shape illustrateMesh()
          Create a Shape that illustrates the mesh.
 Shape illustrateSprings()
          Create a Shape that illustrates the .
 void illustrateSprings(ColorProcessor ip, double scale, double maxStretch)
          Paint all into a ColorProcessor.
 void illustrateSprings(ColorProcessor ip, double scale, double maxStretch, double offsetX, double offsetY)
          Paint all into a ColorProcessor.
 void init(CoordinateTransform t)
          TODO Not yet tested
 int numVertices()
           
 void optimize(double maxError, int maxIterations, int maxPlateauwidth)
          Optimize the mesh.
static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth)
          Optimize a Collection of connected SpringMeshes.
static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, boolean visualize)
          Optimize a Collection of connected SpringMeshes.
static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, double maxStepSize, boolean visualize)
          Optimize a Collection of connected SpringMeshes.
static void optimizeMeshes2(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth)
          Deprecated. Remains for reproducing legacy results
static void optimizeMeshes2(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, boolean visualize)
          Deprecated. Remains for reproducing legacy results
protected  void optimizeStep(ErrorStatistic observer)
          Performs one optimization step.
static ColorProcessor paintMeshes(Collection<SpringMesh> meshes, double scale)
           
static ColorProcessor paintSprings(Collection<SpringMesh> meshes, double scale, double maxStretch)
           
static ColorProcessor paintSprings(Collection<SpringMesh> meshes, int width, int height, double maxStretch)
           
protected static void println(String s)
           
 void removePassiveVertex(Vertex vertex)
          Remove a passive vertex.
 void scale(double scale)
          TODO Not yet tested
protected  void update(double dt)
          Move all vertices for a given Δt
 void updateAffines()
          Update all affine transformations.
protected  void updateDirection(double dt)
          Calculate motion vectors for all vertices.
protected  void updateForce(ErrorStatistic observer)
          Update force vectors for all vertices.
 void updatePassiveVertices()
           
protected  double weigh(double d, double alpha)
           
 
Methods inherited from class mpicbg.models.TransformMesh
addTriangle, apply, applyInPlace, applyInverse, applyInverseInPlace, bounds, createInverse, findClosestSourcePoint, findClosestTargetPoint, getAV, getHeight, getVA, getWidth, illustrateBestRigidSVG, illustrateMeshSVG, illustrateTriangle, isInConvexTargetPolygon, isInSourcePolygon, numY, updateAffine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fixedVertices

protected final HashSet<Vertex> fixedVertices

vertices

protected final ArrayList<Vertex> vertices

vp

protected final HashMap<Vertex,PointMatch> vp

pv

protected final HashMap<PointMatch,Vertex> pv

apv

protected final HashMap<AffineModel2D,Vertex> apv

pva

protected final HashMap<Vertex,AffineModel2D> pva

force

protected double force

minForce

protected double minForce

maxForce

protected double maxForce

maxSpeed

protected double maxSpeed

damp

protected double damp
Constructor Detail

SpringMesh

public SpringMesh(int numX,
                  int numY,
                  double width,
                  double height,
                  double springWeight,
                  double maxStretch,
                  double damp)

SpringMesh

public SpringMesh(int numX,
                  double width,
                  double height,
                  double springWeight,
                  double maxStretch,
                  double damp)
Method Detail

getVertices

public ArrayList<Vertex> getVertices()

numVertices

public int numVertices()

getForce

public double getForce()

weigh

protected double weigh(double d,
                       double alpha)

println

protected static void println(String s)

findClosestTargetVertex

public final Vertex findClosestTargetVertex(double[] there)
Find the closest Vertex to a given coordinate in terms of its target coordinates.

Parameters:
there -
Returns:
closest Vertex

findClosestSourceVertex

public final Vertex findClosestSourceVertex(double[] there)
Find the closest Vertex to a given coordinate in terms of its source coordinates.

Parameters:
there -
Returns:
closest Vertex

addPassiveVertex

public void addPassiveVertex(Vertex vertex)
Add a passive vertex. Associate it with the triangle by whom it is contained.

Parameters:
vertex -

removePassiveVertex

public void removePassiveVertex(Vertex vertex)
Remove a passive vertex.

Parameters:
vertex -

addVertex

public void addVertex(Vertex vertex,
                      double weight)
Add a Vertex to the mesh. Connect it to the closest vertex of the actual mesh by a spring with the given weight.

Parameters:
vertex -
weights -

addVertexWeightedByDistance

public final void addVertexWeightedByDistance(Vertex vertex,
                                              double weight,
                                              double alpha)
Add a Vertex to the mesh. Connect it to all other Vertices by springs that are weighted by their length. The weight is defined by 1/(l^2*alpha)

Parameters:
vertex -
weight -
alpha -

updateForce

protected void updateForce(ErrorStatistic observer)
Update force vectors for all vertices.

Parameters:
observer -

updateDirection

protected void updateDirection(double dt)
Calculate motion vectors for all vertices.

Parameters:
observer -

update

protected void update(double dt)
Move all vertices for a given Δt

Parameters:
t -

optimizeStep

protected void optimizeStep(ErrorStatistic observer)
                     throws NotEnoughDataPointsException
Performs one optimization step.

Parameters:
observer - collecting the error after update
Throws:
NotEnoughDataPointsException

updatePassiveVertices

public void updatePassiveVertices()

updateAffines

public void updateAffines()
Description copied from class: TransformMesh
Update all affine transformations.

Overrides:
updateAffines in class TransformMesh

optimize

public void optimize(double maxError,
                     int maxIterations,
                     int maxPlateauwidth)
              throws NotEnoughDataPointsException
Optimize the mesh.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

paintMeshes

public static final ColorProcessor paintMeshes(Collection<SpringMesh> meshes,
                                               double scale)

paintSprings

public static final ColorProcessor paintSprings(Collection<SpringMesh> meshes,
                                                double scale,
                                                double maxStretch)

paintSprings

public static final ColorProcessor paintSprings(Collection<SpringMesh> meshes,
                                                int width,
                                                int height,
                                                double maxStretch)

optimizeMeshes

public static void optimizeMeshes(Collection<SpringMesh> meshes,
                                  double maxError,
                                  int maxIterations,
                                  int maxPlateauwidth)
                           throws NotEnoughDataPointsException
Optimize a Collection of connected SpringMeshes.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

optimizeMeshes

public static void optimizeMeshes(Collection<SpringMesh> meshes,
                                  double maxError,
                                  int maxIterations,
                                  int maxPlateauwidth,
                                  boolean visualize)
                           throws NotEnoughDataPointsException
Optimize a Collection of connected SpringMeshes.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

optimizeMeshes

public static void optimizeMeshes(Collection<SpringMesh> meshes,
                                  double maxError,
                                  int maxIterations,
                                  int maxPlateauwidth,
                                  double maxStepSize,
                                  boolean visualize)
                           throws NotEnoughDataPointsException
Optimize a Collection of connected SpringMeshes.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

calculateForceAndSpeed

@Deprecated
protected void calculateForceAndSpeed(ErrorStatistic observer)
Deprecated. Remains for legacy compatibility

Calculate force and speed vectors for all vertices.

Parameters:
observer -

optimizeMeshes2

@Deprecated
public static void optimizeMeshes2(Collection<SpringMesh> meshes,
                                              double maxError,
                                              int maxIterations,
                                              int maxPlateauwidth)
                            throws NotEnoughDataPointsException
Deprecated. Remains for reproducing legacy results

Optimize a Collection of connected SpringMeshes.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

optimizeMeshes2

@Deprecated
public static void optimizeMeshes2(Collection<SpringMesh> meshes,
                                              double maxError,
                                              int maxIterations,
                                              int maxPlateauwidth,
                                              boolean visualize)
                            throws NotEnoughDataPointsException
Deprecated. Remains for reproducing legacy results

Optimize a Collection of connected SpringMeshes.

Parameters:
maxError - do not accept convergence if error is > max_error
maxIterations - stop after that many iterations even if there was no minimum found
maxPlateauwidth - convergence is reached if the average slope in an interval of this size is 0.0 (in double accuracy). This prevents the algorithm from stopping at plateaus smaller than this value.
Throws:
NotEnoughDataPointsException

illustrateSprings

public Shape illustrateSprings()
Create a Shape that illustrates the .

Returns:
illustration

illustrateSprings

public void illustrateSprings(ColorProcessor ip,
                              double scale,
                              double maxStretch)
Paint all into a ColorProcessor.


illustrateSprings

public void illustrateSprings(ColorProcessor ip,
                              double scale,
                              double maxStretch,
                              double offsetX,
                              double offsetY)
Paint all into a ColorProcessor.


illustrateMesh

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

Overrides:
illustrateMesh in class TransformMesh
Returns:
the illustration

init

public void init(CoordinateTransform t)
TODO Not yet tested

Overrides:
init in class TransformMesh

scale

public void scale(double scale)
TODO Not yet tested

Overrides:
scale in class TransformMesh


Copyright © 2007-2016 Fiji. All Rights Reserved.