Commit 5b92456d authored by gsavin's avatar gsavin

Greedy should works now.

parent 5882aa7d
......@@ -60,4 +60,9 @@ public interface BoidForcesFactory {
* @param maxz
*/
void resize(Point3 low, Point3 high);
/**
* Terminate all operations.
*/
void end();
}
......@@ -35,7 +35,6 @@ import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import org.graphstream.boids.forces.greedy.GreedyForcesFactory;
import org.graphstream.boids.forces.ntree.NTreeForcesFactory;
import org.graphstream.graph.Graph;
import org.graphstream.graph.NodeFactory;
......@@ -144,8 +143,7 @@ public class BoidGraph extends AdjacencyListGraph {
area = 1;
maxSteps = 0;
boidSpecies = new HashMap<String, BoidSpecies>();
forcesFactory = new GreedyForcesFactory(this);
//forcesFactory = new NTreeForcesFactory(this);
forcesFactory = new NTreeForcesFactory(this);
}
public BoidGraph(String dgsConfig) throws IOException {
......@@ -196,7 +194,12 @@ public class BoidGraph extends AdjacencyListGraph {
config.removeSink(this);
}
// Access
public void setForcesFactory(BoidForcesFactory bff) {
if (forcesFactory != null)
forcesFactory.end();
forcesFactory = bff;
}
public double getArea() {
return area;
......
......@@ -55,7 +55,7 @@ public class GreedyForces extends BoidForces {
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;
position.z = 0;
nextPosition.copy(position);
}
......
......@@ -35,7 +35,6 @@ import org.graphstream.boids.BoidGraph;
import org.miv.pherd.geom.Point3;
public class GreedyForcesFactory implements BoidForcesFactory {
BoidGraph ctx;
public GreedyForcesFactory(BoidGraph ctx) {
......@@ -61,7 +60,7 @@ public class GreedyForcesFactory implements BoidForcesFactory {
public void step() {
for (Boid b : ctx.<Boid> getEachNode())
b.getForces().compute();
for (Boid b : ctx.<Boid> getEachNode()) {
BoidForces f = b.getForces();
f.getPosition().copy(f.getNextPosition());
......@@ -77,4 +76,12 @@ public class GreedyForcesFactory implements BoidForcesFactory {
*/
public void resize(Point3 low, Point3 high) {
}
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForcesFactory#end()
*/
public void end() {
}
}
......@@ -33,6 +33,7 @@ import org.graphstream.boids.BoidForces;
import org.graphstream.boids.BoidGraph;
import org.graphstream.boids.BoidForcesFactory;
import org.graphstream.stream.ElementSink;
import org.graphstream.stream.GraphReplay;
import org.miv.pherd.ParticleBox;
import org.miv.pherd.geom.Point3;
import org.miv.pherd.ntree.Anchor;
......@@ -59,6 +60,11 @@ public class NTreeForcesFactory implements BoidForcesFactory, ElementSink {
new BoidCellData());
this.ctx = ctx;
GraphReplay replay = new GraphReplay("replay");
replay.addElementSink(this);
replay.replay(ctx);
replay.removeElementSink(this);
ctx.addElementSink(this);
}
......@@ -95,6 +101,16 @@ public class NTreeForcesFactory implements BoidForcesFactory, ElementSink {
space.resize(low, high);
}
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForcesFactory#end()
*/
public void end() {
ctx.removeElementSink(this);
pbox.removeAllParticles();
}
/*
* (non-Javadoc)
*
......
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