Commit d88364f4 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

add new generic EikMeshGen types.

parent 0bf33145
Pipeline #72768 failed with stages
in 31 seconds
......@@ -30,7 +30,7 @@ import org.vadere.util.data.cellgrid.PathFindingTag;
import org.vadere.util.math.DistanceFunction;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.PEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.PEikMesh;
import org.vadere.util.voronoi.VoronoiDiagram;
import java.awt.*;
......
......@@ -15,7 +15,7 @@ import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.math.DistanceFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.AEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.AEikMesh;
import java.awt.*;
import java.io.IOException;
......
package org.vadere.meshing.examples;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.PEikMeshGen;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.meshing.mesh.gen.PFace;
import org.vadere.meshing.mesh.gen.PHalfEdge;
import org.vadere.meshing.mesh.gen.PVertex;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.PEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.PEikMesh;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -17,20 +20,20 @@ import org.vadere.util.math.IDistanceFunction;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
/**
* Shows a very basic example how {@link org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh} can be used
* Shows a very basic example how {@link EikMesh} can be used
* to mesh a simple geometry.
*/
public class EikMeshExamples {
public static void main(String... args) {
uniformMeshShapes();
uniformMeshDiscFunction();
uniformMeshRingFunction();
combineDistanceFunctions();
edgeLengthFunction();
edgeLengthAndDistanceFunction();
userDefinedPoints();
}
/**
......@@ -245,4 +248,62 @@ public class EikMeshExamples {
meshPanel.display("Distance dependent edge lengths");
}
/**
* This example is equal to {@link EikMeshExamples#edgeLengthAndDistanceFunction} but here we show how the user
* can introduce new data types. The user might want to define a new type of container / point to work with.
* This is easy to do due to the generic implementation of the meshing data structures and algorithms.
* First of all, new data type has to extends {@link EikMeshPoint}! Secondly, since the algorithm creates new points
* of an unknown data type to this implementation, it requires the information how such points can be created,
* i.e. it requires a {@link IPointConstructor} of points defined by the user. That is all!
*/
public static void userDefinedPoints() {
/**
* Some user defined
*/
class MyPoint extends EikMeshPoint {
private double value;
public MyPoint(double x, double y, boolean fixPoint) {
super(x, y, fixPoint);
this.value = 0;
}
}
// define a bounding box
VRectangle bound = new VRectangle(-0.1, -0.1, 2.2, 2.2);
// distance function that defines a ring with inner-radius 0.2 and outer-radius 1 at (1,1).
IDistanceFunction ringDistance = IDistanceFunction.createRing(1, 1, 0.2, 1.0);
final double factor = 6.0;
IEdgeLengthFunction edgeLengthFunction = p -> 1.0 + factor * Math.abs(ringDistance.apply(p));
// define the EikMesh-Improver
double edgeLength = 0.05;
// define your point constructor which will be used during the algorithm to create new points.
IPointConstructor<MyPoint> pointConstructor = (x, y) -> new MyPoint(x, y, false);
// like before but we have to add the point-constructor to the constructor of EikMesh and we use
// the more generic type PEikMeshGen instead of PEikMes!
PEikMeshGen<MyPoint> meshImprover = new PEikMeshGen<>(
ringDistance,
edgeLengthFunction,
edgeLength,
bound,
pointConstructor);
// (optional) define the gui to display the mesh
MeshPanel<MyPoint, PVertex<MyPoint>, PHalfEdge<MyPoint>, PFace<MyPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800,
bound);
// generate the mesh
meshImprover.generate();
// display the mesh
meshPanel.display("Distance dependent edge lengths");
}
}
package org.vadere.meshing.mesh.triangulation;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.util.geometry.shapes.IPoint;
import java.util.function.Function;
/**
* The edge-length function used in {@link org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh},
* The edge-length function used in {@link EikMesh},
* {@link org.vadere.meshing.mesh.triangulation.improver.distmesh.Distmesh} and some
* {@link org.vadere.meshing.mesh.triangulation.triangulator.ITriangulator} gives for every position
* in the 2D Euclidean space the desired relative length of an edge of a mesh. Relative in the sense
......
package org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen;
import org.jetbrains.annotations.NotNull;
import org.vadere.meshing.mesh.gen.AFace;
import org.vadere.meshing.mesh.gen.AHalfEdge;
import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.AVertex;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.math.IDistanceFunction;
import java.util.Collection;
public class AEikMeshGen<P extends EikMeshPoint> extends EikMesh<P, AVertex<P>, AHalfEdge<P>, AFace<P>> {
public AEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
@NotNull IEdgeLengthFunction edgeLengthFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull Collection<? extends VShape> obstacleShapes,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound, obstacleShapes,
() -> new AMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public AEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
@NotNull IEdgeLengthFunction edgeLengthFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound,
() -> new AMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public AEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, e -> 1.0, initialEdgeLen, bound,
() -> new AMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public AEikMeshGen(
@NotNull VPolygon polygon,
double initialEdgeLen,
@NotNull Collection<? extends VShape> obstacleShapes,
@NotNull IPointConstructor<P> pointConstructor) {
super(polygon, initialEdgeLen, obstacleShapes,
() -> new AMesh<>((x, y) -> pointConstructor.create(x, y)));
}
}
\ No newline at end of file
package org.vadere.meshing.mesh.triangulation.improver.eikmesh;
package org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
......@@ -11,6 +11,7 @@ import org.vadere.meshing.mesh.inter.IIncrementalTriangulation;
import org.vadere.meshing.mesh.inter.IVertex;
import org.vadere.meshing.mesh.triangulation.improver.IMeshImprover;
import org.vadere.meshing.mesh.triangulation.improver.distmesh.Parameters;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.triangulator.ITriangulator;
import org.vadere.meshing.mesh.triangulation.triangulator.UniformRefinementTriangulatorSFC;
import org.vadere.util.geometry.GeometryUtils;
......
package org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen;
import org.jetbrains.annotations.NotNull;
import org.vadere.meshing.mesh.gen.PFace;
import org.vadere.meshing.mesh.gen.PHalfEdge;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.gen.PVertex;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.math.IDistanceFunction;
import java.util.Collection;
public class PEikMeshGen<P extends EikMeshPoint> extends EikMesh<P, PVertex<P>, PHalfEdge<P>, PFace<P>> {
public PEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
@NotNull IEdgeLengthFunction edgeLengthFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull Collection<? extends VShape> obstacleShapes,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound, obstacleShapes,
() -> new PMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public PEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
@NotNull IEdgeLengthFunction edgeLengthFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound,
() -> new PMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public PEikMeshGen(
@NotNull IDistanceFunction distanceFunc,
double initialEdgeLen,
@NotNull VRectangle bound,
@NotNull IPointConstructor<P> pointConstructor) {
super(distanceFunc, e -> 1.0, initialEdgeLen, bound,
() -> new PMesh<>((x, y) -> pointConstructor.create(x, y)));
}
public PEikMeshGen(
@NotNull VPolygon polygon,
double initialEdgeLen,
@NotNull Collection<? extends VShape> obstacleShapes,
@NotNull IPointConstructor<P> pointConstructor) {
super(polygon, initialEdgeLen, obstacleShapes,
() -> new PMesh<>((x, y) -> pointConstructor.create(x, y)));
}
}
package org.vadere.meshing.mesh.triangulation.improver.eikmesh;
package org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl;
import org.jetbrains.annotations.NotNull;
import org.vadere.meshing.mesh.gen.AFace;
import org.vadere.meshing.mesh.gen.AHalfEdge;
import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.AVertex;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.AEikMeshGen;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -16,7 +19,7 @@ import java.util.Collection;
/**
* @author Benedikt Zoennchen
*/
public class AEikMesh extends EikMesh<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> {
public class AEikMesh extends AEikMeshGen<EikMeshPoint> {
public AEikMesh(
@NotNull IDistanceFunction distanceFunc,
@NotNull IEdgeLengthFunction edgeLengthFunc,
......@@ -24,7 +27,7 @@ public class AEikMesh extends EikMesh<EikMeshPoint, AVertex<EikMeshPoint>, AHalf
@NotNull VRectangle bound,
@NotNull Collection<? extends VShape> obstacleShapes) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound, obstacleShapes,
() -> new AMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
public AEikMesh(
......@@ -32,6 +35,6 @@ public class AEikMesh extends EikMesh<EikMeshPoint, AVertex<EikMeshPoint>, AHalf
double initialEdgeLen,
@NotNull Collection<? extends VShape> obstacleShapes) {
super(polygon, initialEdgeLen, obstacleShapes,
() -> new AMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
}
package org.vadere.meshing.mesh.triangulation.improver.eikmesh;
package org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl;
import org.jetbrains.annotations.NotNull;
import org.vadere.meshing.mesh.gen.PFace;
import org.vadere.meshing.mesh.gen.PHalfEdge;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.gen.PVertex;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.PEikMeshGen;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -16,7 +14,7 @@ import java.util.Collection;
/**
* @author Benedikt Zoennchen
*/
public class PEikMesh extends EikMesh<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> {
public class PEikMesh extends PEikMeshGen<EikMeshPoint> {
public PEikMesh(
@NotNull IDistanceFunction distanceFunc,
......@@ -26,7 +24,7 @@ public class PEikMesh extends EikMesh<EikMeshPoint, PVertex<EikMeshPoint>, PHalf
@NotNull Collection<? extends VShape> obstacleShapes) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound, obstacleShapes,
() -> new PMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
public PEikMesh(
......@@ -36,7 +34,7 @@ public class PEikMesh extends EikMesh<EikMeshPoint, PVertex<EikMeshPoint>, PHalf
@NotNull VRectangle bound) {
super(distanceFunc, edgeLengthFunc, initialEdgeLen, bound,
() -> new PMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
public PEikMesh(
......@@ -45,7 +43,7 @@ public class PEikMesh extends EikMesh<EikMeshPoint, PVertex<EikMeshPoint>, PHalf
@NotNull VRectangle bound) {
super(distanceFunc, e -> 1.0, initialEdgeLen, bound,
() -> new PMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
public PEikMesh(
......@@ -53,7 +51,7 @@ public class PEikMesh extends EikMesh<EikMeshPoint, PVertex<EikMeshPoint>, PHalf
double initialEdgeLen,
@NotNull Collection<? extends VShape> obstacleShapes) {
super(polygon, initialEdgeLen, obstacleShapes,
() -> new PMesh<>((x, y) -> new EikMeshPoint(x, y, false)));
(x, y) -> new EikMeshPoint(x, y, false));
}
}
......@@ -10,7 +10,7 @@ import org.vadere.meshing.mesh.gen.AVertex;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.utils.tex.TexGraphGenerator;
......
......@@ -8,7 +8,7 @@ import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.util.math.IDistanceFunction;
......
......@@ -11,7 +11,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.PEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.PEikMesh;
import java.util.ArrayList;
import java.util.List;
......
......@@ -15,7 +15,7 @@ import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import java.util.ArrayList;
import java.util.List;
......
......@@ -15,7 +15,7 @@ import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import java.util.ArrayList;
import java.util.List;
......
......@@ -22,7 +22,7 @@ import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import java.awt.*;
import java.util.ArrayList;
......
......@@ -9,7 +9,7 @@ import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.AVertex;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.distmesh.Distmesh;
......
......@@ -9,7 +9,7 @@ import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.AVertex;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.distmesh.Distmesh;
......
......@@ -33,7 +33,7 @@ import org.vadere.simulator.models.potential.solver.timecost.ITimeCostFunction;
import org.vadere.util.math.DistanceFunction;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.PEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.PEikMesh;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
......
......@@ -23,7 +23,7 @@ import org.vadere.util.math.DistanceFunction;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.distmesh.Distmesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import java.io.IOException;
import java.util.Collection;
......
......@@ -13,7 +13,7 @@ import org.vadere.meshing.mesh.gen.PVertex;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IIncrementalTriangulation;
import org.vadere.meshing.mesh.inter.IVertex;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.EikMesh;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment