Commit 5882aa7d authored by gsavin's avatar gsavin

Make greedy forces working. Still got some bugs.

parent efd546db
...@@ -253,7 +253,6 @@ public abstract class BoidForces { ...@@ -253,7 +253,6 @@ public abstract class BoidForces {
float aarea = 0.000001f; float aarea = 0.000001f;
Point3 lo = ((BoidGraph) boid.getGraph()).getLowAnchor(); Point3 lo = ((BoidGraph) boid.getGraph()).getLowAnchor();
Point3 hi = ((BoidGraph) boid.getGraph()).getHighAnchor(); Point3 hi = ((BoidGraph) boid.getGraph()).getHighAnchor();
Vector3 dir = getDirection();
Point3 nextPos = getNextPosition(); Point3 nextPos = getNextPosition();
if (nextPos.x + dir.data[0] <= lo.x + aarea) { if (nextPos.x + dir.data[0] <= lo.x + aarea) {
......
...@@ -35,6 +35,7 @@ import java.io.InputStream; ...@@ -35,6 +35,7 @@ import java.io.InputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import org.graphstream.boids.forces.greedy.GreedyForcesFactory;
import org.graphstream.boids.forces.ntree.NTreeForcesFactory; import org.graphstream.boids.forces.ntree.NTreeForcesFactory;
import org.graphstream.graph.Graph; import org.graphstream.graph.Graph;
import org.graphstream.graph.NodeFactory; import org.graphstream.graph.NodeFactory;
...@@ -143,7 +144,8 @@ public class BoidGraph extends AdjacencyListGraph { ...@@ -143,7 +144,8 @@ public class BoidGraph extends AdjacencyListGraph {
area = 1; area = 1;
maxSteps = 0; maxSteps = 0;
boidSpecies = new HashMap<String, BoidSpecies>(); boidSpecies = new HashMap<String, BoidSpecies>();
forcesFactory = new NTreeForcesFactory(this); forcesFactory = new GreedyForcesFactory(this);
//forcesFactory = new NTreeForcesFactory(this);
} }
public BoidGraph(String dgsConfig) throws IOException { public BoidGraph(String dgsConfig) throws IOException {
......
...@@ -30,40 +30,34 @@ package org.graphstream.boids.forces.greedy; ...@@ -30,40 +30,34 @@ package org.graphstream.boids.forces.greedy;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Random;
import org.graphstream.boids.Boid; import org.graphstream.boids.Boid;
import org.graphstream.boids.BoidForces; import org.graphstream.boids.BoidForces;
import org.graphstream.boids.BoidGraph; import org.graphstream.boids.BoidGraph;
import org.miv.pherd.geom.Point3; import org.miv.pherd.geom.Point3;
import org.miv.pherd.geom.Vector3;
public class GreedyForces extends BoidForces { public class GreedyForces extends BoidForces {
Point3 position; Point3 position;
Vector3 direction; Point3 nextPosition;
public GreedyForces(Boid b) { public GreedyForces(Boid b) {
super(b); super(b);
}
/* BoidGraph ctx = (BoidGraph) b.getGraph();
* (non-Javadoc) Random r = ctx.getRandom();
* Point3 lo = ctx.getLowAnchor();
* @see org.graphstream.boids.BoidForces#compute() Point3 hi = ctx.getHighAnchor();
*/
public void compute() {
BoidGraph g = (BoidGraph) boid.getGraph();
LinkedList<Boid> contacts = new LinkedList<Boid>();
Vector3 rep = new Vector3();
for (Boid b : g.<Boid> getEachNode()) { position = new Point3();
if (isVisible(boid, b.getPosition())) { nextPosition = new Point3();
actionWithNeighboor(b, rep);
contacts.add(b);
}
}
boid.checkNeighborhood(contacts.toArray(new Boid[contacts.size()])); position.x = r.nextDouble() * (hi.x - lo.x) + lo.x;
position.y = r.nextDouble() * (hi.y - lo.y) + lo.y;
position.z = r.nextDouble() * (hi.z - lo.z) + lo.z;
nextPosition.copy(position);
} }
/* /*
...@@ -84,23 +78,21 @@ public class GreedyForces extends BoidForces { ...@@ -84,23 +78,21 @@ public class GreedyForces extends BoidForces {
position.set(x, y, z); position.set(x, y, z);
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForces#getDirection()
*/
public Vector3 getDirection() {
return direction;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.graphstream.boids.BoidForces#getNeighborhood() * @see org.graphstream.boids.BoidForces#getNeighborhood()
*/ */
public Collection<Boid> getNeighborhood() { public Collection<Boid> getNeighborhood() {
// TODO Auto-generated method stub BoidGraph g = (BoidGraph) boid.getGraph();
return null; LinkedList<Boid> contacts = new LinkedList<Boid>();
for (Boid b : g.<Boid> getEachNode()) {
if (isVisible(boid, b.getPosition()))
contacts.add(b);
}
return contacts;
} }
/* /*
...@@ -109,7 +101,6 @@ public class GreedyForces extends BoidForces { ...@@ -109,7 +101,6 @@ public class GreedyForces extends BoidForces {
* @see org.graphstream.boids.BoidForces#getNextPosition() * @see org.graphstream.boids.BoidForces#getNextPosition()
*/ */
public Point3 getNextPosition() { public Point3 getNextPosition() {
// TODO Auto-generated method stub return nextPosition;
return null;
} }
} }
...@@ -31,10 +31,17 @@ package org.graphstream.boids.forces.greedy; ...@@ -31,10 +31,17 @@ package org.graphstream.boids.forces.greedy;
import org.graphstream.boids.Boid; import org.graphstream.boids.Boid;
import org.graphstream.boids.BoidForces; import org.graphstream.boids.BoidForces;
import org.graphstream.boids.BoidForcesFactory; import org.graphstream.boids.BoidForcesFactory;
import org.graphstream.boids.BoidGraph;
import org.miv.pherd.geom.Point3; import org.miv.pherd.geom.Point3;
public class GreedyForcesFactory implements BoidForcesFactory { public class GreedyForcesFactory implements BoidForcesFactory {
BoidGraph ctx;
public GreedyForcesFactory(BoidGraph ctx) {
this.ctx = ctx;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
...@@ -43,8 +50,7 @@ public class GreedyForcesFactory implements BoidForcesFactory { ...@@ -43,8 +50,7 @@ public class GreedyForcesFactory implements BoidForcesFactory {
* .boids.Boid) * .boids.Boid)
*/ */
public BoidForces createNewForces(Boid b) { public BoidForces createNewForces(Boid b) {
// TODO Auto-generated method stub return new GreedyForces(b);
return null;
} }
/* /*
...@@ -53,8 +59,13 @@ public class GreedyForcesFactory implements BoidForcesFactory { ...@@ -53,8 +59,13 @@ public class GreedyForcesFactory implements BoidForcesFactory {
* @see org.graphstream.boids.BoidForcesFactory#step() * @see org.graphstream.boids.BoidForcesFactory#step()
*/ */
public void step() { public void step() {
// TODO Auto-generated method stub for (Boid b : ctx.<Boid> getEachNode())
b.getForces().compute();
for (Boid b : ctx.<Boid> getEachNode()) {
BoidForces f = b.getForces();
f.getPosition().copy(f.getNextPosition());
}
} }
/* /*
...@@ -65,8 +76,5 @@ public class GreedyForcesFactory implements BoidForcesFactory { ...@@ -65,8 +76,5 @@ public class GreedyForcesFactory implements BoidForcesFactory {
* org.miv.pherd.geom.Point3) * org.miv.pherd.geom.Point3)
*/ */
public void resize(Point3 low, Point3 high) { public void resize(Point3 low, Point3 high) {
// TODO Auto-generated method stub
} }
} }
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