Commit 7cce3d9c authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

improve garbage collection for the meshes, fix bug in walk and jump algorithm,...

improve garbage collection for the meshes, fix bug in walk and jump algorithm, prepare for mesh drawing into a panel for the gui.
parent 392cb49e
...@@ -26,6 +26,7 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -26,6 +26,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showPedestrians = true; private boolean showPedestrians = true;
private boolean showWalkdirection = false; private boolean showWalkdirection = false;
private boolean showTargetPotentialField = false; private boolean showTargetPotentialField = false;
private boolean showTargetPotentielFieldMesh = false;
private boolean showPotentialField = false; private boolean showPotentialField = false;
private boolean showTrajectories = false; private boolean showTrajectories = false;
private boolean showGrid = false; private boolean showGrid = false;
...@@ -64,6 +65,7 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -64,6 +65,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
this.showStairs = config.showStairs; this.showStairs = config.showStairs;
this.showGroups = config.showGroups; this.showGroups = config.showGroups;
this.showPotentialField = config.showPotentialField; this.showPotentialField = config.showPotentialField;
this.showTargetPotentielFieldMesh = config.showTargetPotentielFieldMesh;
} }
public boolean isShowGroups() { public boolean isShowGroups() {
...@@ -110,6 +112,15 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -110,6 +112,15 @@ public class DefaultSimulationConfig extends DefaultConfig {
return showTargets; return showTargets;
} }
public void setShowTargetPotentielFieldMesh(final boolean showTargetPotentielFieldMesh) {
this.showTargetPotentielFieldMesh = showTargetPotentielFieldMesh;
setChanged();
}
public boolean isShowTargetPotentielFieldMesh() {
return showTargetPotentielFieldMesh;
}
public void setShowTargets(boolean showTargets) { public void setShowTargets(boolean showTargets) {
this.showTargets = showTargets; this.showTargets = showTargets;
setChanged(); setChanged();
......
...@@ -4,7 +4,11 @@ package org.vadere.gui.components.model; ...@@ -4,7 +4,11 @@ package org.vadere.gui.components.model;
import java.util.Collection; import java.util.Collection;
import java.util.function.Function; import java.util.function.Function;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.models.potential.solver.calculators.mesh.PotentialPoint;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.IPoint; import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
...@@ -38,8 +42,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends ...@@ -38,8 +42,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return config; return config;
} }
public double getPotential(final int x, final int y) { public IMesh<? extends IPotentialPoint, ?, ?, ?> getDiscretization() {
return getPotentialField().apply(pixelToWorld(new VPoint(x, y))); return new PMesh<IPotentialPoint>((x,y) -> new PotentialPoint(x,y));
} }
/*public double getPotential(final int x, final int y) { /*public double getPotential(final int x, final int y) {
......
...@@ -2,9 +2,12 @@ package org.vadere.gui.components.view; ...@@ -2,9 +2,12 @@ package org.vadere.gui.components.view;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.model.IDefaultModel; import org.vadere.gui.components.model.IDefaultModel;
import org.vadere.meshing.mesh.gen.MeshRenderer;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.ScenarioElement; import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Stairs; import org.vadere.state.scenario.Stairs;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.Vector2D; import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.util.geometry.shapes.VCircle; import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VLine; import org.vadere.util.geometry.shapes.VLine;
...@@ -63,7 +66,6 @@ public abstract class DefaultRenderer { ...@@ -63,7 +66,6 @@ public abstract class DefaultRenderer {
targetGraphics2D.dispose(); targetGraphics2D.dispose();
} }
public void renderGraphics(final Graphics2D targetGraphics2D, final int width, final int height) { public void renderGraphics(final Graphics2D targetGraphics2D, final int width, final int height) {
targetGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); targetGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
...@@ -594,6 +596,11 @@ public abstract class DefaultRenderer { ...@@ -594,6 +596,11 @@ public abstract class DefaultRenderer {
} }
} }
protected void renderMesh(final Graphics2D g, @NotNull final IMesh<? extends IPotentialPoint, ?, ?, ?> mesh, final int width, final int height) {
MeshRenderer<? extends IPotentialPoint, ?, ?, ?> meshRenderer = new MeshRenderer<>(mesh);
meshRenderer.render(g, width, height);
}
protected void renderVoronoiDiagram(final Graphics2D g, final VoronoiDiagram voronoiDiagram) { protected void renderVoronoiDiagram(final Graphics2D g, final VoronoiDiagram voronoiDiagram) {
synchronized (voronoiDiagram) { synchronized (voronoiDiagram) {
if (voronoiDiagram != null) { if (voronoiDiagram != null) {
......
...@@ -99,6 +99,10 @@ public abstract class SimulationRenderer extends DefaultRenderer { ...@@ -99,6 +99,10 @@ public abstract class SimulationRenderer extends DefaultRenderer {
renderVoronoiDiagram(graphics, model.getVoronoiDiagram()); renderVoronoiDiagram(graphics, model.getVoronoiDiagram());
} }
if(model.config.isShowTargetPotentielFieldMesh()) {
renderMesh(graphics, model.getDiscretization(), width, height);
}
renderSimulationContent(graphics); renderSimulationContent(graphics);
if (model.isElementSelected()) { if (model.isElementSelected()) {
......
...@@ -7,13 +7,17 @@ import org.jetbrains.annotations.Nullable; ...@@ -7,13 +7,17 @@ import org.jetbrains.annotations.Nullable;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel; import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import org.vadere.gui.onlinevisualization.view.MainPanel; import org.vadere.gui.onlinevisualization.view.MainPanel;
import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow; import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.control.PassiveCallback; import org.vadere.simulator.control.PassiveCallback;
import org.vadere.simulator.models.potential.fields.IPotentialField; import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget; import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import java.util.function.Function;
public class OnlineVisualization implements PassiveCallback { public class OnlineVisualization implements PassiveCallback {
/** /**
...@@ -28,18 +32,21 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -28,18 +32,21 @@ public class OnlineVisualization implements PassiveCallback {
public final IPotentialField potentialFieldTarget; public final IPotentialField potentialFieldTarget;
public final Agent selectedAgent; public final Agent selectedAgent;
public final IPotentialField potentialField; public final IPotentialField potentialField;
public final Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations;
public ObservationAreaSnapshotData( public ObservationAreaSnapshotData(
final double simTimeInSec, final double simTimeInSec,
@NotNull final Topography scenario, @NotNull final Topography scenario,
@Nullable final IPotentialField potentialFieldTarget, @Nullable final IPotentialField potentialFieldTarget,
@Nullable final IPotentialField potentialField, @Nullable final IPotentialField potentialField,
@Nullable final Agent selectedAgent) { @Nullable final Agent selectedAgent,
@Nullable final Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations) {
this.simTimeInSec = simTimeInSec; this.simTimeInSec = simTimeInSec;
this.scenario = scenario; this.scenario = scenario;
this.potentialFieldTarget = potentialFieldTarget; this.potentialFieldTarget = potentialFieldTarget;
this.potentialField = potentialField; this.potentialField = potentialField;
this.selectedAgent = selectedAgent; this.selectedAgent = selectedAgent;
this.discretizations = discretizations;
} }
} }
...@@ -117,6 +124,7 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -117,6 +124,7 @@ public class OnlineVisualization implements PassiveCallback {
synchronized (model.getDataSynchronizer()) { synchronized (model.getDataSynchronizer()) {
/* Push new snapshot of the observation area to the draw thread. */ /* Push new snapshot of the observation area to the draw thread. */
IPotentialField pft = (model.config.isShowTargetPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.getSolution() : null; IPotentialField pft = (model.config.isShowTargetPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.getSolution() : null;
Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations = (model.config.isShowTargetPotentielFieldMesh() && potentialFieldTarget != null) ? potentialFieldTarget.getDiscretization() : null;
IPotentialField pedPotentialField = null; IPotentialField pedPotentialField = null;
Agent selectedAgent = null; Agent selectedAgent = null;
...@@ -125,7 +133,7 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -125,7 +133,7 @@ public class OnlineVisualization implements PassiveCallback {
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1); pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
} }
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent); ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent, discretizations);
model.pushObservationAreaSnapshot(data); model.pushObservationAreaSnapshot(data);
} }
} }
......
...@@ -11,8 +11,12 @@ import java.util.stream.Collectors; ...@@ -11,8 +11,12 @@ import java.util.stream.Collectors;
import org.vadere.gui.components.model.DefaultSimulationConfig; import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel; import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization; import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.models.potential.fields.IPotentialField; import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.solver.calculators.mesh.PotentialPoint;
import org.vadere.state.scenario.*; import org.vadere.state.scenario.*;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.IPoint; import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.voronoi.VoronoiDiagram; import org.vadere.util.voronoi.VoronoiDiagram;
...@@ -33,6 +37,8 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -33,6 +37,8 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
private IPotentialField potentialField = null; private IPotentialField potentialField = null;
private Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations = null;
private Agent agent = null; private Agent agent = null;
/** /**
...@@ -112,6 +118,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -112,6 +118,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget; potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget;
potentialField = observationAreaSnapshot.potentialField; potentialField = observationAreaSnapshot.potentialField;
agent = observationAreaSnapshot.selectedAgent; agent = observationAreaSnapshot.selectedAgent;
discretizations = observationAreaSnapshot.discretizations;
/* /*
* if(topography == null || * if(topography == null ||
...@@ -201,6 +208,15 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -201,6 +208,15 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
return f; return f;
} }
@Override
public IMesh<? extends IPotentialPoint, ?, ?, ?> getDiscretization() {
if(discretizations != null && config.isShowTargetPotentielFieldMesh() && agent.equals(getSelectedElement())) {
return discretizations.apply(agent);
}
return new PMesh<IPotentialPoint>((x, y) -> new PotentialPoint(x, y));
}
@Override @Override
public double getGridResolution() { public double getGridResolution() {
return config.getGridWidth(); return config.getGridWidth();
......
...@@ -2,6 +2,7 @@ package org.vadere.gui.projectview; ...@@ -2,6 +2,7 @@ package org.vadere.gui.projectview;
import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.lang3.time.StopWatch;
import org.vadere.gui.components.utils.Recorder; import org.vadere.gui.components.utils.Recorder;
import org.vadere.meshing.mesh.gen.MeshRenderer;
import org.vadere.util.visualization.ColorHelper; import org.vadere.util.visualization.ColorHelper;
import org.vadere.util.geometry.GeometryUtils; import org.vadere.util.geometry.GeometryUtils;
import org.vadere.meshing.mesh.gen.AFace; import org.vadere.meshing.mesh.gen.AFace;
...@@ -61,8 +62,11 @@ public class RecordTriangulationMovie { ...@@ -61,8 +62,11 @@ public class RecordTriangulationMovie {
//ColorHelper.numberToHurColor((float)f.getId() / meshImprover.getMesh().getNumberOfFaces()); //ColorHelper.numberToHurColor((float)f.getId() / meshImprover.getMesh().getNumberOfFaces());
//new ColorHelper(meshImprover.getMesh().getNumberOfFaces()).numberToColor(f.getId()); //new ColorHelper(meshImprover.getMesh().getNumberOfFaces()).numberToColor(f.getId());
MeshRenderer<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> meshRenderer = new MeshRenderer<>(
meshImprover.getMesh(), f -> false, colorFunction1);
MeshPanel<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> distmeshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> distmeshPanel = new MeshPanel<>(
meshImprover.getMesh(), f -> false, bbound.getWidth()*1000, bbound.getHeight()*1000, bbound, colorFunction1); meshRenderer, bbound.getWidth()*1000, bbound.getHeight()*1000);
JFrame frame = distmeshPanel.display(); JFrame frame = distmeshPanel.display();
frame.setVisible(true); frame.setVisible(true);
...@@ -84,16 +88,15 @@ public class RecordTriangulationMovie { ...@@ -84,16 +88,15 @@ public class RecordTriangulationMovie {
while (nSteps < 300) { while (nSteps < 300) {
nSteps++; nSteps++;
distmeshPanel.refresh();
if(!meshImprover.initializationFinished()) { if(!meshImprover.initializationFinished()) {
addPictures(recorder, distmeshPanel, 10); addPictures(recorder, meshRenderer, 10, (int)bbound.getWidth()*1000, (int)bbound.getHeight()*1000);
} }
else if(finished) { else if(finished) {
finished = false; finished = false;
addPictures(recorder, distmeshPanel, 20); addPictures(recorder, meshRenderer, 20, (int)bbound.getWidth()*1000, (int)bbound.getHeight()*1000);
} }
addPictures(recorder, distmeshPanel, 5); addPictures(recorder, meshRenderer, 5, (int)bbound.getWidth()*1000, (int)bbound.getHeight()*1000);
/*try { /*try {
...@@ -114,11 +117,13 @@ public class RecordTriangulationMovie { ...@@ -114,11 +117,13 @@ public class RecordTriangulationMovie {
} }
public static void addPictures(Recorder recorder, public static void addPictures(Recorder recorder,
MeshPanel<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> distmeshPanel, MeshRenderer<EikMeshPoint, AVertex<EikMeshPoint>, AHalfEdge<EikMeshPoint>, AFace<EikMeshPoint>> renderer,
int frames) throws IOException { int frames,
int width,
int height) throws IOException {
for(int i = 0; i < frames; i++) { for(int i = 0; i < frames; i++) {
recorder.addPicture(distmeshPanel.getImage()); recorder.addPicture(renderer.renderImage(width, height));
} }
} }
......
...@@ -30,7 +30,7 @@ public class DelaunayTriangulationExamples { ...@@ -30,7 +30,7 @@ public class DelaunayTriangulationExamples {
randomTriangulator.generate(); randomTriangulator.generate();
// display the result // display the result
MeshPanel meshPanel = new MeshPanel(triangulation.getMesh(), 500, 500, bound); MeshPanel meshPanel = new MeshPanel(triangulation.getMesh(), 500, 500);
meshPanel.display(); meshPanel.display();
} }
......
...@@ -65,8 +65,7 @@ public class EikMeshExamples { ...@@ -65,8 +65,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
new VRectangle(boundary.getBounds()));
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -99,8 +98,7 @@ public class EikMeshExamples { ...@@ -99,8 +98,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -133,8 +131,7 @@ public class EikMeshExamples { ...@@ -133,8 +131,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -166,8 +163,7 @@ public class EikMeshExamples { ...@@ -166,8 +163,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -201,8 +197,7 @@ public class EikMeshExamples { ...@@ -201,8 +197,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -238,8 +233,7 @@ public class EikMeshExamples { ...@@ -238,8 +233,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>( MeshPanel<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
...@@ -297,8 +291,7 @@ public class EikMeshExamples { ...@@ -297,8 +291,7 @@ public class EikMeshExamples {
// (optional) define the gui to display the mesh // (optional) define the gui to display the mesh
MeshPanel<MyPoint, PVertex<MyPoint>, PHalfEdge<MyPoint>, PFace<MyPoint>> meshPanel = new MeshPanel<>( MeshPanel<MyPoint, PVertex<MyPoint>, PHalfEdge<MyPoint>, PFace<MyPoint>> meshPanel = new MeshPanel<>(
meshImprover.getMesh(), 1000, 800, meshImprover.getMesh(), 1000, 800);
bound);
// generate the mesh // generate the mesh
meshImprover.generate(); meshImprover.generate();
......
...@@ -381,6 +381,28 @@ public class AMesh<P extends IPoint> implements IMesh<P, AVertex<P>, AHalfEdge<P ...@@ -381,6 +381,28 @@ public class AMesh<P extends IPoint> implements IMesh<P, AVertex<P>, AHalfEdge<P
return () -> streamEdges().iterator(); return () -> streamEdges().iterator();
} }
@Override
public AVertex<P> getRandomVertex(@NotNull Random random) {
int startIndex = random.nextInt(vertices.size());
int index = startIndex;
// look above
while (index < vertices.size() && isDestroyed(vertices.get(index))) {
index++;
}
// look below
if(isDestroyed(vertices.get(index))) {
index = startIndex - 1;
while (index >= 0 && isDestroyed(vertices.get(index))) {
index--;
}
}
return vertices.get(index);
}
@Override @Override
public int getNumberOfVertices() { public int getNumberOfVertices() {
return numberOfVertices; return numberOfVertices;
......
...@@ -82,7 +82,7 @@ public class IncrementalTriangulation<P extends IPoint, V extends IVertex<P>, E ...@@ -82,7 +82,7 @@ public class IncrementalTriangulation<P extends IPoint, V extends IVertex<P>, E
private static Logger log = LogManager.getLogger(IncrementalTriangulation.class); private static Logger log = LogManager.getLogger(IncrementalTriangulation.class);
static { static {
ITriConnectivity.log.setLevel(Level.DEBUG); ITriConnectivity.log.setLevel(Level.INFO);
} }
/** /**
......
...@@ -27,8 +27,7 @@ public class JumpAndWalk<P extends IPoint, V extends IVertex<P>, E extends IHalf ...@@ -27,8 +27,7 @@ public class JumpAndWalk<P extends IPoint, V extends IVertex<P>, E extends IHalf
} }
private Optional<F> getStartFace(final IPoint endPoint) { private Optional<F> getStartFace(final IPoint endPoint) {
List<V> vertices = triangulation.getMesh().getVertices(); int n = triangulation.getMesh().getNumberOfVertices();
int n = vertices.size();
if(n < 20) { if(n < 20) {
return Optional.empty(); return Optional.empty();
...@@ -38,8 +37,8 @@ public class JumpAndWalk<P extends IPoint, V extends IVertex<P>, E extends IHalf ...@@ -38,8 +37,8 @@ public class JumpAndWalk<P extends IPoint, V extends IVertex<P>, E extends IHalf
double max = Math.pow(n, 1.0/3.0); double max = Math.pow(n, 1.0/3.0);
for(int i = 0; i < max; i++) {