public class SpringMesh extends TransformMesh
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.Modifier and Type | Field and Description |
---|---|
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 |
av, defaultPointFactory, defaultPointMatchFactory, height, va, width
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
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
Spring s. |
void |
illustrateSprings(ij.process.ColorProcessor ip,
double scale,
double maxStretch)
Paint all
Spring s into a ColorProcessor . |
void |
illustrateSprings(ij.process.ColorProcessor ip,
double scale,
double maxStretch,
double offsetX,
double offsetY)
Paint all
Springs 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 ij.process.ColorProcessor |
paintMeshes(Collection<SpringMesh> meshes,
double scale) |
static ij.process.ColorProcessor |
paintSprings(Collection<SpringMesh> meshes,
double scale,
double maxStretch) |
static ij.process.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) |
addTriangle, apply, applyInPlace, applyInverse, applyInverseInPlace, bounds, createInverse, findClosestSourcePoint, findClosestTargetPoint, getAV, getHeight, getVA, getWidth, illustrateBestRigidSVG, illustrateMeshSVG, illustrateTriangle, isInConvexTargetPolygon, isInSourcePolygon, numY, updateAffine
protected final HashMap<Vertex,PointMatch> vp
protected final HashMap<PointMatch,Vertex> pv
protected final HashMap<AffineModel2D,Vertex> apv
protected final HashMap<Vertex,AffineModel2D> pva
protected double force
protected double minForce
protected double maxForce
protected double maxSpeed
protected double damp
public SpringMesh(int numX, int numY, double width, double height, double springWeight, double maxStretch, double damp)
public SpringMesh(int numX, double width, double height, double springWeight, double maxStretch, double damp)
public int numVertices()
public double getForce()
protected double weigh(double d, double alpha)
protected static void println(String s)
public final Vertex findClosestTargetVertex(double[] there)
Vertex
to a given coordinate in terms of its
target coordinates.there
- Vertex
public final Vertex findClosestSourceVertex(double[] there)
Vertex
to a given coordinate in terms of its
source coordinates.there
- Vertex
public void addPassiveVertex(Vertex vertex)
vertex
- public void removePassiveVertex(Vertex vertex)
vertex
- public void addVertex(Vertex vertex, double weight)
Vertex
to the mesh. Connect it to the closest vertex
of the actual mesh by a spring with the given weight.vertex
- weight
- public final void addVertexWeightedByDistance(Vertex vertex, double weight, double alpha)
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)vertex
- weight
- alpha
- protected void updateForce(ErrorStatistic observer)
observer
- protected void updateDirection(double dt)
dt
- protected void update(double dt)
dt
- protected void optimizeStep(ErrorStatistic observer) throws NotEnoughDataPointsException
observer
- collecting the error after updateNotEnoughDataPointsException
public void updatePassiveVertices()
public void updateAffines()
TransformMesh
updateAffines
in class TransformMesh
public void optimize(double maxError, int maxIterations, int maxPlateauwidth) throws NotEnoughDataPointsException
maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
public static final ij.process.ColorProcessor paintMeshes(Collection<SpringMesh> meshes, double scale)
public static final ij.process.ColorProcessor paintSprings(Collection<SpringMesh> meshes, double scale, double maxStretch)
public static final ij.process.ColorProcessor paintSprings(Collection<SpringMesh> meshes, int width, int height, double maxStretch)
public static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth) throws NotEnoughDataPointsException
Collection
of connected SpringMeshes
.maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
public static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, boolean visualize) throws NotEnoughDataPointsException
Collection
of connected SpringMeshes
.maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
public static void optimizeMeshes(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, double maxStepSize, boolean visualize) throws NotEnoughDataPointsException
Collection
of connected SpringMeshes
.maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
@Deprecated protected void calculateForceAndSpeed(ErrorStatistic observer)
observer
- @Deprecated public static void optimizeMeshes2(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth) throws NotEnoughDataPointsException
Collection
of connected SpringMeshes
.maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
@Deprecated public static void optimizeMeshes2(Collection<SpringMesh> meshes, double maxError, int maxIterations, int maxPlateauwidth, boolean visualize) throws NotEnoughDataPointsException
Collection
of connected SpringMeshes
.maxError
- do not accept convergence if error is > max_errormaxIterations
- stop after that many iterations even if there was
no minimum foundmaxPlateauwidth
- 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.NotEnoughDataPointsException
public Shape illustrateSprings()
Spring
s.public void illustrateSprings(ij.process.ColorProcessor ip, double scale, double maxStretch)
Spring
s into a ColorProcessor
.public void illustrateSprings(ij.process.ColorProcessor ip, double scale, double maxStretch, double offsetX, double offsetY)
Springs
into a ColorProcessor
.public Shape illustrateMesh()
illustrateMesh
in class TransformMesh
public void init(CoordinateTransform t)
init
in class TransformMesh
public void scale(double scale)
scale
in class TransformMesh
Copyright © 2015–2021 Fiji. All rights reserved.