11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 1da47a91 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

before changing Rupperts algorithm.

parent b8da33b0
......@@ -238,6 +238,7 @@ ProjectView.btnSnapshot.tooltip=Snapshot
ProjectView.btnPNGSnapshot.tooltip=PNG Snapshot
ProjectView.btnSVGSnapshot.tooltip=SVG Snapshot
ProjectView.btnTikZSnapshot.tooltip=TikZ Snapshot
ProjectView.btnPolySnapshot.tooltip=Poly Snapshot
PostVis.menuFile.title=File
PostVis.menuSettings.title=Setting
PostVis.menuRecentFiles.title=Recent Files
......
......@@ -234,6 +234,7 @@ ProjectView.btnSnapshot.tooltip=Snapshot
ProjectView.btnPNGSnapshot.tooltip=PNG-Snapshot
ProjectView.btnSVGSnapshot.tooltip=SVG-Snapshot
ProjectView.btnTikZSnapshot.tooltip=TikZ-Snapshot
ProjectView.btnPolySnapshot.tooltip=Poly-Snapshot
PostVis.menuFile.title=Datei
PostVis.menuSettings.title=Einstellungen
PostVis.menuRecentFiles.title=K\u00FCrzlich verwendete Dateien
......
package org.vadere.gui.components.control.simulation;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.meshing.utils.io.poly.PolyGenerator;
import org.vadere.state.scenario.Obstacle;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.awt.event.ActionEvent;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import javax.swing.*;
public class ActionGeneratePoly extends AbstractAction {
private static Logger logger = Logger.getLogger(ActionGeneratePNG.class);
private static Resources resources = Resources.getInstance("global");
private final SimulationModel<? extends DefaultSimulationConfig> model;
public ActionGeneratePoly(final String name, Icon icon, final SimulationRenderer renderer,
final SimulationModel<? extends DefaultSimulationConfig> model) {
super(name, icon);
this.model = model;
}
@Override
public void actionPerformed(final ActionEvent e) {
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
File outputFile = new File(Messages.getString("FileDialog.filenamePrefix") + formattedDate + ".poly");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".poly") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".poly");
List<Obstacle> boundingObstacles = model.getTopography().getBoundaryObstacles();
Rectangle2D.Double boundWithBorder = model.getTopography().getBounds();
double boundWidth = model.getTopography().getBoundingBoxWidth();
VRectangle bound = new VRectangle(boundWithBorder.x + boundWidth, boundWithBorder.y + boundWidth, boundWithBorder.width - 2*boundWidth, boundWithBorder.height - 2*boundWidth);
List<Obstacle> obstacles = new ArrayList<>(model.getTopography().getObstacles());
obstacles.removeAll(model.getTopography().getBoundaryObstacles());
String polyString = PolyGenerator.toPSLG(
new VPolygon(bound),
obstacles.stream()
.map(obs -> obs.getShape())
.map(shape -> new VPolygon(shape))
.collect(Collectors.toList()));
try {
outputFile.createNewFile();
Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
out.write(polyString);
out.flush();
logger.info("generate new Poly.file: " + outputFile.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
}
}
}
}
......@@ -7,6 +7,7 @@ import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
import org.vadere.gui.components.control.ViewportChangeListener;
import org.vadere.gui.components.control.simulation.ActionGeneratePoly;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.utils.SwingUtils;
......@@ -174,7 +175,6 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
renderer,
model);
ActionGenerateSVG generateSVG = new ActionGenerateSVG(
Messages.getString("ProjectView.btnSVGSnapshot.tooltip"),
resources.getIcon("camera_svg.png", iconWidth, iconHeight),
......@@ -187,6 +187,12 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
renderer,
model);
ActionGeneratePoly generatePoly = new ActionGeneratePoly(
Messages.getString("ProjectView.btnPolySnapshot.tooltip"),
resources.getIcon("camera_poly.png", iconWidth, iconHeight),
renderer,
model);
ActionShowPotentialField showPotentialField = new ActionShowPotentialField(
"showPotentialField",
resources.getIcon("potentialField.png", iconWidth, iconHeight),
......@@ -222,6 +228,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
imgOptions.add(generatePNG);
imgOptions.add(generateSVG);
imgOptions.add(generateTikz);
imgOptions.add(generatePoly);
ActionOnlineVisMenu imgDialog = new ActionOnlineVisMenu(
"camera_menu",
......
......@@ -8,6 +8,7 @@ import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
import org.vadere.gui.components.control.ViewportChangeListener;
import org.vadere.gui.components.control.simulation.ActionGeneratePNG;
import org.vadere.gui.components.control.simulation.ActionGeneratePoly;
import org.vadere.gui.components.control.simulation.ActionGenerateSVG;
import org.vadere.gui.components.control.simulation.ActionGenerateTikz;
import org.vadere.gui.components.control.simulation.ActionSwapSelectionMode;
......@@ -242,11 +243,16 @@ public class PostvisualizationWindow extends JPanel implements Observer {
renderer, model);
AbstractAction tikzImg = new ActionGenerateTikz(Messages.getString("ProjectView.btnTikZSnapshot.tooltip"), resources.getIcon("camera_tikz.png", iconWidth, iconHeight),
renderer, model);
AbstractAction polyImg = new ActionGeneratePoly(Messages.getString("ProjectView.btnPolySnapshot.tooltip"), resources.getIcon("camera_poly.png", iconWidth, iconHeight),
renderer, model);
// add new ImageGenerator Action ...
imgOptions.add(pngImg);
imgOptions.add(svgImg);
imgOptions.add(tikzImg);
imgOptions.add(polyImg);
// add Action to List ....
ActionVisualizationMenu imgDialog = new ActionVisualizationMenu(
......
# a.poly
#
# The capital letter A
#
# Declare 29 vertices, 2 dimensions, 1 attribute, no boundary markers.
#
29 2 1 0
#
# List the vertices.
#
1 0.200000 -0.776400 -0.57
2 0.220000 -0.773200 -0.55
3 0.245600 -0.756400 -0.51
4 0.277600 -0.702000 -0.53
5 0.488800 -0.207600 0.28
6 0.504800 -0.207600 0.30
7 0.740800 -0.739600 0
8 0.756000 -0.761200 -0.01
9 0.774400 -0.772400 0
10 0.800000 -0.776400 0.02
11 0.800000 -0.792400 0.01
12 0.579200 -0.792400 -0.21
13 0.579200 -0.776400 -0.2
14 0.621600 -0.771600 -0.15
15 0.633600 -0.762800 -0.13
16 0.639200 -0.744400 -0.1
17 0.620800 -0.684400 -0.06
18 0.587200 -0.604400 -0.01
19 0.360800 -0.604400 -0.24
20 0.319200 -0.706800 -0.39
21 0.312000 -0.739600 -0.43
22 0.318400 -0.761200 -0.44
23 0.334400 -0.771600 -0.44
24 0.371200 -0.776400 -0.41
25 0.371200 -0.792400 -0.42
26 0.374400 -0.570000 -0.2
27 0.574400 -0.570000 0
28 0.473600 -0.330800 0.14
29 0.200000 -0.792400 -0.59
#
# Declare the number of segments.
#
29 0
#
# List the segments.
#
1 29 1
2 1 2
3 2 3
4 3 4
5 4 5
6 5 6
7 6 7
8 7 8
9 8 9
10 9 10
11 10 11
12 11 12
13 12 13
14 13 14
15 14 15
16 15 16
17 16 17
18 17 18
19 18 19
20 19 20
21 20 21
22 21 22
23 22 23
24 23 24
25 24 25
26 25 29
27 26 27
28 27 28
29 28 26
#
# Declare the number of holes.
#
1
#
# Define the hole.
#
1 0.47 -0.5
\ No newline at end of file
......@@ -5,6 +5,8 @@ import org.vadere.meshing.mesh.inter.IPointConstructor;
import org.vadere.meshing.mesh.triangulation.IEdgeLengthFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.GenEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.PEikMeshGen;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PDelaunayTriangulator;
import org.vadere.meshing.utils.io.poly.PolyGenerator;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.meshing.mesh.gen.PFace;
import org.vadere.meshing.mesh.gen.PHalfEdge;
......@@ -21,6 +23,7 @@ import org.vadere.util.math.IDistanceFunction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* Shows a very basic example how {@link GenEikMesh} can be used
......@@ -28,14 +31,54 @@ import java.util.List;
*/
public class EikMeshExamples {
public static void main(String... args) {
uniformMeshShapes();
public static void main(String... args) throws InterruptedException {
//delaunayTriangulation();
//uniformMeshShapes();
uniformMeshDiscFunction();
uniformMeshRingFunction();
combineDistanceFunctions();
//uniformMeshRingFunction();
/*combineDistanceFunctions();
edgeLengthFunction();
edgeLengthAndDistanceFunction();
userDefinedPoints();
userDefinedPoints();*/
}
public static void delaunayTriangulation() throws InterruptedException {
Random random = new Random(0);
int width = 10;
int height = 10;
int numberOfPoints = 200;
double linePoints = (int)Math.sqrt(numberOfPoints)+5;
List<EikMeshPoint> points = new ArrayList<>();
for(double i = 0; i < linePoints; i++) {
points.add(new EikMeshPoint(0.1, 0.1 + i / linePoints * (height-0.2), true));
points.add(new EikMeshPoint(0.1 + i / linePoints * (width-0.2), 0.1, true));
points.add(new EikMeshPoint(width-0.2, 0.1 + i / linePoints * (height-0.2), true));
points.add(new EikMeshPoint(0.1 + i / linePoints * (width-0.2), height-0.2, true));
}
for(int i = 0; i < numberOfPoints-15; i++) {
points.add(new EikMeshPoint(1.5 + random.nextDouble() * (width-3), 1.5 + random.nextDouble() * (height-3)));
}
var delaunayTriangulator = new PDelaunayTriangulator<>(points, (x, y) -> new EikMeshPoint(x, y, false));
var triangulation = delaunayTriangulator.generate();
var improver = new PEikMeshGen<>(p -> 1.0, triangulation);
var panel = new PMeshPanel<>(triangulation.getMesh(), 500, 500);
panel.display("A square mesh");
panel.repaint();
for(int i = 0; i < 1000; i++) {
Thread.sleep(5000);
improver.improve();
panel.repaint();
}
}
/**
......@@ -109,36 +152,48 @@ public class EikMeshExamples {
* The edgeLength is a measure for the approximate edge lengths of all edges since it is a uniform triangulation,
* i.e. the desired edge length function is a constant.
*/
public static void uniformMeshDiscFunction() {
public static void uniformMeshDiscFunction() throws InterruptedException {
// define a bounding box
VRectangle bound = new VRectangle(-0.1, -0.1, 2.2, 2.2);
// distance function that defines a disc with radius 1 at (1,1).
IDistanceFunction d = p -> Math.sqrt((p.getX() - 1) * (p.getX() - 1) + (p.getY() - 1) * (p.getY() - 1)) - 1.0;
//IDistanceFunction.createDisc(1, 1, 1.0);
VPoint center = new VPoint(1,1);
IDistanceFunction d = IDistanceFunction.createDisc(center.x, center.y, 1.0);
IEdgeLengthFunction h = p -> 1.0 + 5.0 * Math.abs(d.apply(p));
// define the EikMesh-Improver
double h0 = 0.1;
PEikMeshGen<EikMeshPoint, Double, Double> meshImprover = new PEikMeshGen<>(
d,
h,
p -> 1.0,
Arrays.asList(center),
h0,
bound,
(x, y) -> new EikMeshPoint(x, y, false));
meshImprover.generate();
//meshImprover.generate();
//System.out.println(TexGraphGenerator.toTikz(meshImprover.getMesh()));
// (optional) define the gui to display the mesh
//PMeshPanel<EikMeshPoint, Double, Double> meshPanel = new PMeshPanel<>(meshImprover.getMesh(), 1000, 800);
PMeshPanel<EikMeshPoint, Double, Double> meshPanel = new PMeshPanel<>(meshImprover.getMesh(), 1000, 800);
// generate the mesh
// display the mesh
//meshPanel.display("Geometry defined by a distance function (disc)");
meshPanel.display("Geometry defined by a distance function (disc)");
while (true) {
synchronized (meshImprover.getMesh()) {
meshImprover.improve();
}
Thread.sleep(100);
meshPanel.repaint();
}
//System.out.println(PolyGenerator.to2DPoly(meshImprover.getMesh()));
}
/**
......@@ -170,6 +225,8 @@ public class EikMeshExamples {
// generate the mesh
meshImprover.generate();
System.out.println(PolyGenerator.to2DPoly(meshImprover.getMesh()));
// display the mesh
meshPanel.display("Geometry defined by a distance function (ring)");
}
......
......@@ -12,10 +12,11 @@ import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.GenEikMesh;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.PEikMeshGen;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PContrainedDelaunayTriangulator;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PDelaunayRefinement;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PDelaunayTriangulation;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PVoronoiVertexInsertion;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PDelaunayTriangulator;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PDirichletRefinement;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PRuppertsTriangulator;
import org.vadere.meshing.utils.io.poly.PolyGenerator;
import org.vadere.meshing.utils.io.tex.TexGraphGenerator;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.data.cellgrid.PathFindingTag;
......@@ -26,26 +27,32 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VTriangle;
import org.vadere.util.math.DistanceFunction;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.util.math.InterpolationUtil;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MeshExamples {
public static void main(String... args) throws InterruptedException {
dirichletRefinment();
delaunayRefinment();
public static void main(String... args) throws InterruptedException, IOException {
ruppertsTriangulationPoly();
//delaunayTriangulation();
//dirichletRefinment();
//delaunayRefinment();
//constrainedDelaunayTriangulation();
}
public static void faceTest() throws InterruptedException {
......@@ -70,7 +77,7 @@ public class MeshExamples {
points.add(newPoint);
PDelaunayTriangulation<VPoint, Double, Double> delaunayTriangulation = new PDelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
PDelaunayTriangulator<VPoint, Double, Double> delaunayTriangulation = new PDelaunayTriangulator<>(points, (x, y) -> new VPoint(x, y));
delaunayTriangulation.generate();
System.out.println(TexGraphGenerator.toTikz(delaunayTriangulation.getMesh()));
......@@ -89,7 +96,7 @@ public class MeshExamples {
}
public static void square() {
PMesh<VPoint, Integer, Integer> mesh = new PMesh<>((x, y) -> new VPoint(x, y));
var mesh = new PMesh<>((x, y) -> new VPoint(x, y));
assert mesh.getNumberOfFaces() == 0;
......@@ -101,7 +108,7 @@ public class MeshExamples {
assert mesh.getNumberOfFaces() == 1;
PMeshPanel<VPoint, Integer, Integer> panel = new PMeshPanel<>(mesh, 500, 500);
var panel = new PMeshPanel<>(mesh, 500, 500);
panel.display("A square mesh");
panel.repaint();
......@@ -113,72 +120,121 @@ public class MeshExamples {
}
public static void delaunayTriangulation() {
// (1) generate a point set
Random random = new Random(0);
int width = 10;
int height = 10;
int numberOfPoints = 1000;
int numberOfPoints = 100;
Supplier<VPoint> supply = () -> new VPoint(random.nextDouble()*width, random.nextDouble()*height);
Stream<VPoint> randomPoints = Stream.generate(supply);
List<VPoint> points = randomPoints.limit(numberOfPoints).collect(Collectors.toList());
List<VPoint> points = new ArrayList<>();
for(int i = 0; i < numberOfPoints; i++) {
points.add(new VPoint(random.nextDouble() * width, random.nextDouble() * height));
}
// (2) compute the Delaunay triangulation
var delaunayTriangulator = new PDelaunayTriangulator<VPoint, Double, Double>(points, (x, y) -> new VPoint(x, y));
var triangulation = delaunayTriangulator.generate();
PDelaunayTriangulation<VPoint, Double, Double> delaunayTriangulation = new PDelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
delaunayTriangulation.generate();
// \definecolor{mygreen}{RGB}{85,168,104}
Color green = new Color(85, 168, 104);
Color red = new Color(196,78,82);
var face = triangulation.locateFace(new VPoint(5,5)).get();
var mesh = triangulation.getMesh();
var deletePoints = mesh.getVertices(face);
var surroundingFaces = mesh.getFaces(deletePoints.get(0));
var ringEdges = mesh
.streamEdges(deletePoints.get(0))
.map(edge -> mesh.getPrev(edge)).collect(Collectors.toList());
/*System.out.println(TexGraphGenerator.toTikz(
delaunayTriangulator.getMesh(),
f -> surroundingFaces.contains(f) ? red : Color.WHITE,
1.0f));*/
LinkedList<PHalfEdge<VPoint, Double, Double>> visitedEdges = delaunayTriangulation.generate().straightGatherWalk2D(5, 5, delaunayTriangulation.getMesh().getFace());
for(PFace<VPoint, Double, Double> face : delaunayTriangulation.getMesh().getFaces()) {
delaunayTriangulation.getMesh().setData(face, delaunayTriangulation.getMesh().toTriangle(face).getArea());
//triangulation.remove(deletePoints.get(0));
var face2 = triangulation.locateFace(new VPoint(5,5)).get();
var list = ringEdges.stream().map(e -> mesh.getFace(e)).collect(Collectors.toList());
surroundingFaces.addAll(list);
System.out.println(TexGraphGenerator.toTikz(
delaunayTriangulator.getMesh(),
// f -> surroundingFaces.contains(f) ? green : Color.WHITE,
1.0f));
LinkedList<PHalfEdge<VPoint, Double, Double>> visitedEdges = delaunayTriangulator.generate().straightGatherWalk2D(5, 5, delaunayTriangulator.getMesh().getFace());
for(PFace<VPoint, Double, Double> f : delaunayTriangulator.getMesh().getFaces()) {
delaunayTriangulator.getMesh().setData(f, delaunayTriangulator.getMesh().toTriangle(f).getArea());
}
double areaSum = delaunayTriangulation.getMesh().streamFaces().mapToDouble(f -> delaunayTriangulation.getMesh().getData(f).get()).sum();
double averageArea = areaSum / delaunayTriangulation.getMesh().getNumberOfFaces();
double areaSum = delaunayTriangulator.getMesh().streamFaces().mapToDouble(f -> delaunayTriangulator.getMesh().getData(f).get()).sum();
double averageArea = areaSum / delaunayTriangulator.getMesh().getNumberOfFaces();
System.out.println("Triangulated area = " + areaSum);
System.out.println("Average triangle area = " + averageArea);
System.out.println("Area triangulated = " + (100 * (areaSum / (width * height))) + " %");
VPoint q = delaunayTriangulation.getMesh().toTriangle(delaunayTriangulation.getMesh().getFace(visitedEdges.peekFirst())).midPoint();
Set<PFace<VPoint, Double, Double>> faceSet = visitedEdges.stream().map(e -> delaunayTriangulation.getMesh().getFace(e)).collect(Collectors.toSet());
VPoint q = delaunayTriangulator.getMesh().toTriangle(delaunayTriangulator.getMesh().getFace(visitedEdges.peekFirst())).midPoint();