Commit 8cb3920b authored by gsavin's avatar gsavin

Prepare greedy forces

parent 45b2834c
/* /*
* Copyright 2006 - 2011 * Copyright 2006 - 2012
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org> * Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org> * Guilhelm Savin <guilhelm.savin@graphstream-project.org>
* *
* This file is part of GraphStream <http://graphstream-project.org>. * This file is part of gs-boids <http://graphstream-project.org>.
* *
* GraphStream is a library whose purpose is to handle static or dynamic * gs-boids is a library whose purpose is to provide a boid behavior to a set of
* graph, create them from scratch, file or any source and display them. * particles.
* *
* This program is free software distributed under the terms of two licenses, the * This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public * CeCILL-C license that fits European law, and the GNU Lesser General Public
...@@ -30,11 +28,35 @@ ...@@ -30,11 +28,35 @@
*/ */
package org.graphstream.boids; package org.graphstream.boids;
public interface BoidsForcesFactory { /**
* Object used to create and compute forces of boids.
*
*/
public interface BoidForcesFactory {
/**
* Create a new forces object for a boid.
*
* @param b
* the boid
* @return a new forces object associate with the boid
*/
BoidForces createNewForces(Boid b); BoidForces createNewForces(Boid b);
/**
* Compute forces for all boids.
*/
void step(); void step();
/**
* Resize the space.
*
* @param minx
* @param miny
* @param minz
* @param maxx
* @param maxy
* @param maxz
*/
void resize(double minx, double miny, double minz, double maxx, void resize(double minx, double miny, double minz, double maxx,
double maxy, double maxz); double maxy, double maxz);
} }
...@@ -117,7 +117,7 @@ public class BoidGraph extends AdjacencyListGraph { ...@@ -117,7 +117,7 @@ public class BoidGraph extends AdjacencyListGraph {
*/ */
protected Random random; protected Random random;
protected BoidsForcesFactory forcesFactory; protected BoidForcesFactory forcesFactory;
/** /**
* New context. * New context.
......
/*
* Copyright 2006 - 2012
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of gs-boids <http://graphstream-project.org>.
*
* gs-boids is a library whose purpose is to provide a boid behavior to a set of
* particles.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.boids.forces.greedy;
import org.graphstream.boids.Boid;
import org.graphstream.boids.BoidForces;
import org.miv.pherd.geom.Point3;
public class GreedyForces extends BoidForces {
public void compute() {
// TODO Auto-generated method stub
}
public Point3 getPosition() {
// TODO Auto-generated method stub
return null;
}
public boolean isVisible(Boid boid, Point3 other) {
// TODO Auto-generated method stub
return false;
}
public void setPosition(double x, double y, double z) {
// TODO Auto-generated method stub
}
}
/*
* Copyright 2006 - 2012
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of gs-boids <http://graphstream-project.org>.
*
* gs-boids is a library whose purpose is to provide a boid behavior to a set of
* particles.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.boids.forces.greedy;
import org.graphstream.boids.Boid;
import org.graphstream.boids.BoidForces;
import org.graphstream.boids.BoidForcesFactory;
public class GreedyForcesFactory implements BoidForcesFactory {
public BoidForces createNewForces(Boid b) {
// TODO Auto-generated method stub
return null;
}
public void resize(double minx, double miny, double minz, double maxx,
double maxy, double maxz) {
// TODO Auto-generated method stub
}
public void step() {
// TODO Auto-generated method stub
}
}
/*
* Copyright 2006 - 2012
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of gs-boids <http://graphstream-project.org>.
*
* gs-boids is a library whose purpose is to provide a boid behavior to a set of
* particles.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.boids.forces.ntree; package org.graphstream.boids.forces.ntree;
import java.util.HashSet; import java.util.HashSet;
...@@ -33,14 +61,29 @@ public class NTreeForces extends BoidForces { ...@@ -33,14 +61,29 @@ public class NTreeForces extends BoidForces {
this.p = p; this.p = p;
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForces#getPosition()
*/
public Point3 getPosition() { public Point3 getPosition() {
return p.getPosition(); return p.getPosition();
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForces#setPosition(double, double, double)
*/
public void setPosition(double x, double y, double z) { public void setPosition(double x, double y, double z) {
p.setPosition(x, y, z); p.setPosition(x, y, z);
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForces#compute()
*/
public void compute() { public void compute() {
Cell startCell = p.getCell().getTree().getRootCell(); Cell startCell = p.getCell().getTree().getRootCell();
......
/* /*
* Copyright 2006 - 2011 * Copyright 2006 - 2012
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org> * Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org> * Guilhelm Savin <guilhelm.savin@graphstream-project.org>
* *
* This file is part of GraphStream <http://graphstream-project.org>. * This file is part of gs-boids <http://graphstream-project.org>.
* *
* GraphStream is a library whose purpose is to handle static or dynamic * gs-boids is a library whose purpose is to provide a boid behavior to a set of
* graph, create them from scratch, file or any source and display them. * particles.
* *
* This program is free software distributed under the terms of two licenses, the * This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public * CeCILL-C license that fits European law, and the GNU Lesser General Public
...@@ -34,7 +32,7 @@ import org.graphstream.boids.Boid; ...@@ -34,7 +32,7 @@ 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.graphstream.boids.BoidSpecies; import org.graphstream.boids.BoidSpecies;
import org.graphstream.boids.BoidsForcesFactory; import org.graphstream.boids.BoidForcesFactory;
import org.graphstream.stream.ElementSink; import org.graphstream.stream.ElementSink;
import org.miv.pherd.Particle; import org.miv.pherd.Particle;
import org.miv.pherd.ParticleBox; import org.miv.pherd.ParticleBox;
...@@ -43,7 +41,7 @@ import org.miv.pherd.ntree.Anchor; ...@@ -43,7 +41,7 @@ import org.miv.pherd.ntree.Anchor;
import org.miv.pherd.ntree.CellSpace; import org.miv.pherd.ntree.CellSpace;
import org.miv.pherd.ntree.OctreeCellSpace; import org.miv.pherd.ntree.OctreeCellSpace;
public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { public class NTreeForcesFactory implements BoidForcesFactory, ElementSink {
protected CellSpace space; protected CellSpace space;
/** /**
...@@ -62,21 +60,39 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -62,21 +60,39 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
this.pbox = new ParticleBox(maxParticlesPerCell, space, this.pbox = new ParticleBox(maxParticlesPerCell, space,
new BoidCellData()); new BoidCellData());
this.ctx = ctx; this.ctx = ctx;
ctx.addElementSink(this); ctx.addElementSink(this);
} }
/*
* (non-Javadoc)
*
* @see
* org.graphstream.boids.BoidForcesFactory#createNewForces(org.graphstream
* .boids.Boid)
*/
public BoidForces createNewForces(Boid b) { public BoidForces createNewForces(Boid b) {
BoidParticle p = new BoidParticle(b); BoidParticle p = new BoidParticle(b);
NTreeForces f = new NTreeForces(p); NTreeForces f = new NTreeForces(p);
return f; return f;
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForcesFactory#step()
*/
public void step() { public void step() {
pbox.step(); pbox.step();
} }
/*
* (non-Javadoc)
*
* @see org.graphstream.boids.BoidForcesFactory#resize(double, double,
* double, double, double, double)
*/
public void resize(double minx, double miny, double minz, double maxx, public void resize(double minx, double miny, double minz, double maxx,
double maxy, double maxz) { double maxy, double maxz) {
Anchor lo = new Anchor(minx, miny, minz); Anchor lo = new Anchor(minx, miny, minz);
...@@ -126,6 +142,11 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -126,6 +142,11 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
.getRandom().nextDouble(), 0); .getRandom().nextDouble(), 0);
} }
/*
* (non-Javadoc)
*
* @see org.miv.pherd.Particle#move(int)
*/
@Override @Override
public void move(int time) { public void move(int time) {
BoidSpecies species = b.getSpecies(); BoidSpecies species = b.getSpecies();
...@@ -163,10 +184,20 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -163,10 +184,20 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
moved = true; moved = true;
} }
/*
* (non-Javadoc)
*
* @see org.miv.pherd.Particle#inserted()
*/
@Override @Override
public void inserted() { public void inserted() {
} }
/*
* (non-Javadoc)
*
* @see org.miv.pherd.Particle#removed()
*/
@Override @Override
public void removed() { public void removed() {
} }
...@@ -222,14 +253,18 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -222,14 +253,18 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.graphstream.stream.ElementSink#edgeRemoved(java.lang.String, long, java.lang.String) *
* @see org.graphstream.stream.ElementSink#edgeRemoved(java.lang.String,
* long, java.lang.String)
*/ */
public void edgeRemoved(String sourceId, long timeId, String edgeId) { public void edgeRemoved(String sourceId, long timeId, String edgeId) {
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.graphstream.stream.ElementSink#graphCleared(java.lang.String, long) *
* @see org.graphstream.stream.ElementSink#graphCleared(java.lang.String,
* long)
*/ */
public void graphCleared(String sourceId, long timeId) { public void graphCleared(String sourceId, long timeId) {
pbox.removeAllParticles(); pbox.removeAllParticles();
...@@ -237,16 +272,20 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -237,16 +272,20 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.graphstream.stream.ElementSink#nodeAdded(java.lang.String, long, java.lang.String) *
* @see org.graphstream.stream.ElementSink#nodeAdded(java.lang.String, long,
* java.lang.String)
*/ */
public void nodeAdded(String sourceId, long timeId, String nodeId) { public void nodeAdded(String sourceId, long timeId, String nodeId) {
Boid b = ctx.getNode(nodeId); Boid b = ctx.getNode(nodeId);
pbox.addParticle(((NTreeForces) b.getForces()).p); pbox.addParticle(((NTreeForces) b.getForces()).p);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.graphstream.stream.ElementSink#nodeRemoved(java.lang.String, long, java.lang.String) *
* @see org.graphstream.stream.ElementSink#nodeRemoved(java.lang.String,
* long, java.lang.String)
*/ */
public void nodeRemoved(String sourceId, long timeId, String nodeId) { public void nodeRemoved(String sourceId, long timeId, String nodeId) {
Boid b = ctx.getNode(nodeId); Boid b = ctx.getNode(nodeId);
...@@ -255,7 +294,9 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink { ...@@ -255,7 +294,9 @@ public class NTreeForcesFactory implements BoidsForcesFactory, ElementSink {
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.graphstream.stream.ElementSink#stepBegins(java.lang.String, long, double) *
* @see org.graphstream.stream.ElementSink#stepBegins(java.lang.String,
* long, double)
*/ */
public void stepBegins(String sourceId, long timeId, double step) { public void stepBegins(String sourceId, long timeId, double step) {
} }
......
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