Commit e88cc204 authored by Ant01n3's avatar Ant01n3

Corrected a bug on the way edges are added/removed.

parent a259c851
......@@ -92,16 +92,16 @@ public class Boid extends AdjacencyListNode {
}
protected void checkNeighborhood(BoidParticle... particles) {
System.err.printf("Boid %s :%n", id);
//System.err.printf("Boid %s :%n", id);
if (particles != null) {
Iterator<Boid> it = getNeighborNodeIterator();
LinkedList<Boid> toRemove = null;
System.err.printf("Sees [ ");
for(BoidParticle p : particles) {
System.err.printf("%s ", p.getBoid().id);
}
System.err.printf("]%nHas Neighbors [ ");
//System.err.printf("Sees [ ");
//for(BoidParticle p : particles) {
// System.err.printf("%s ", p.getBoid().id);
//}
//System.err.printf("]%nHas Neighbors [ ");
while (it.hasNext()) {
boolean found = false;
Boid b = it.next();
......@@ -112,17 +112,17 @@ System.err.printf("]%nHas Neighbors [ ");
break;
}
}
System.err.printf("%s(%b)", b.id, found);
//System.err.printf("%s(%b)", b.id, found);
if (!found && !forces.isVisible(b.particle, this.getPosition())) {
if (toRemove == null)
toRemove = new LinkedList<Boid>();
System.err.printf("(del)");
//System.err.printf("(del)");
toRemove.add(b);
}
}
System.err.printf("%n");
//System.err.printf("%n");
if (toRemove != null) {
for (Boid b : toRemove)
......@@ -131,16 +131,16 @@ System.err.printf("%n");
toRemove.clear();
toRemove = null;
}
System.err.printf("adds link to [ ");
//System.err.printf("adds link to [ ");
for (BoidParticle p : particles) {
if (getEdgeBetween(p.getBoid().getId()) == null) {
getGraph().addEdge(getEdgeId(this, p.getBoid()), getId(),
p.getBoid().getId());
System.err.printf("%s ", p.getBoid().id);
//System.err.printf("%s ", p.getBoid().id);
}
}
}
System.err.printf("]%n");
//System.err.printf("]%n");
}
public static final String getEdgeId(Boid b1, Boid b2) {
......
......@@ -51,7 +51,7 @@ public class BoidSpecies extends HashMap<String, Boid> {
/**
* The distance at which a boid is seen.
*/
public double viewZone = 0.3f;
public double viewZone = 0.15f;
/**
* The boid angle of view, [-1..1]. This is the cosine of the angle between the boid
......@@ -67,7 +67,7 @@ public class BoidSpecies extends HashMap<String, Boid> {
* accelerate the boid displacement, it also impacts the boid behaviour
* (oscillation around the destination point, etc.)
*/
public double speedFactor = 0.5f;
public double speedFactor = 0.3f;
/**
* Maximum speed bound.
......@@ -93,7 +93,7 @@ public class BoidSpecies extends HashMap<String, Boid> {
* boid an this barycenter. This factor is the importance of this vector in
* the boid direction.
*/
public double attractionFactor = 0.2f;
public double attractionFactor = 0.5f;
/**
* All the visible boids repulse the boid. The repulsion vector is the sum
......@@ -101,7 +101,7 @@ public class BoidSpecies extends HashMap<String, Boid> {
* boid, scaled by the number of visible boids. This factor is the
* importance of this vector in the boid direction.
*/
public double repulsionFactor = 0.002f;
public double repulsionFactor = 0.001f;
/**
* The inertia is the importance of the boid previous direction in the boid
......
......@@ -421,7 +421,7 @@ public class Context extends AdjacencyListGraph {
Camera cam = viewer.getDefaultView().getCamera();
cam.setGraphViewport(-2, -2, 2, 2);
cam.setGraphViewport(-ctx.area, -ctx.area, ctx.area, ctx.area);
for (int i = 0; i < species.count; i++)
ctx.addNode(String.format("boid%03d", i));
......
......@@ -30,8 +30,10 @@
*/
package org.graphstream.boids;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import org.graphstream.boids.Boid.BoidParticle;
import org.miv.pherd.Particle;
......@@ -125,8 +127,12 @@ public abstract class Forces {
repulsion.fill(0);
countAtt = 0;
countRep = 0;
Set<BoidParticle> contacts = new HashSet<BoidParticle>();
exploreTree(source, startCell);
exploreTree(source, startCell, contacts);
source.checkNeighborhood(contacts.toArray(new BoidParticle[contacts.size()]));
if (countAtt > 0) {
barycenter.scale(1f / countAtt, 1f / countAtt, 1f / countAtt);
......@@ -150,15 +156,15 @@ public abstract class Forces {
* @param cell
* The cell to explore recursively.
*/
protected void exploreTree(Boid source, Cell cell) {
protected void exploreTree(Boid source, Cell cell, Set<BoidParticle> contacts) {
if (intersection(source, cell)) {
if (cell.isLeaf()) {
forcesFromCell(source.getParticle(), cell);
forcesFromCell(source.getParticle(), cell, contacts);
} else {
int n = cell.getSpace().getDivisions();
for (int i = 0; i < n; ++i)
exploreTree(source, cell.getSub(i));
exploreTree(source, cell.getSub(i), contacts);
}
}
}
......@@ -172,18 +178,18 @@ public abstract class Forces {
* @param cell
* The cell.
*/
protected void forcesFromCell(BoidParticle source, Cell cell) {
protected void forcesFromCell(BoidParticle source, Cell cell, Set<BoidParticle> contacts) {
// BoidCellData data = (BoidCellData) cell.getData();
Iterator<? extends Particle> particles = cell.getParticles();
Vector3 rep = new Vector3();
LinkedList<BoidParticle> contacts = null;
//LinkedList<BoidParticle> contacts = null;
while (particles.hasNext()) {
Particle particle = particles.next();
if (particle instanceof BoidParticle) {
if (contacts == null)
contacts = new LinkedList<BoidParticle>();
//if (contacts == null)
// contacts = new LinkedList<BoidParticle>();
if (source != particle
&& isVisible(source, particle.getPosition())) {
......@@ -194,9 +200,9 @@ public abstract class Forces {
}
}
source.getBoid().checkNeighborhood(
contacts == null ? null : contacts
.toArray(new BoidParticle[contacts.size()]));
// source.getBoid().checkNeighborhood(
// contacts == null ? null : contacts
// .toArray(new BoidParticle[contacts.size()]));
// barycenter.move( data.getCenter() );
// direction.add( data.getDirection() );
......
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