Commit 965fe344 authored by gsavin's avatar gsavin

Some clean after merge-for-conflict time :)

parent e4e34fd9
......@@ -86,9 +86,12 @@
<resources>
<!-- Resources other than classes are included here. -->
<!--<resource>
<resource>
<directory>src</directory>
</resource>-->
<includes>
<include>org/graphstream/boids/configExample.dgs</include>
</includes>
</resource>
</resources>
<plugins>
......@@ -97,9 +100,6 @@
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>org/graphstream/boids/gui/**</exclude>
</excludes>
</configuration>
</plugin>
......
/*
* Copyright 2006 - 2011
* Julien Baudry <julien.baudry@graphstream-project.org>
* Copyright 2006 - 2012
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@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
* graph, create them from scratch, file or any source and display them.
* 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
......@@ -33,7 +31,6 @@ package org.graphstream.boids;
import java.util.Iterator;
import java.util.LinkedList;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.AbstractGraph;
import org.graphstream.graph.implementations.AdjacencyListNode;
import org.miv.pherd.Particle;
......@@ -44,18 +41,19 @@ import org.miv.pherd.geom.Vector3;
* Represents a single bird-oid object.
*
* <p>
* A boid is both a particle in the forces system used to compute the position and motion
* of the object, and a GraphStream node. This allows to consider a graph made of
* all the boids.
* A boid is both a particle in the forces system used to compute the position
* and motion of the object, and a GraphStream node. This allows to consider a
* graph made of all the boids.
* </p>
*
* <p>
* The boid is in fact split in two parts, the {@link Boid} class itself and the
* {@link BoidParticle} inner class that represents the boid in the forces system. The
* boid particle in turn contains a {@link Forces} object that represents all the forces
* exercising on the boid. Globally, the {@link Boid} class acts on the graph and updates
* its position, creating links toward other boids/nodes that it sees, whereas the
* {@link BoidParticle} and the {@link Forces} are used to compute the boid position.
* The boid is in fact split in two parts, the {@link Boid} class itself and the
* {@link BoidParticle} inner class that represents the boid in the forces
* system. The boid particle in turn contains a {@link BoidForces} object that
* represents all the forces exercising on the boid. Globally, the {@link Boid}
* class acts on the graph and updates its position, creating links toward other
* boids/nodes that it sees, whereas the {@link BoidParticle} and the
* {@link BoidForces} are used to compute the boid position.
* </p>
*
* @author Guilhelm Savin
......@@ -65,42 +63,52 @@ public class Boid extends AdjacencyListNode {
protected final BoidSpecies species;
protected BoidParticle particle;
/** Parameters of this group of boids. */
/** The set of forces acting on this particle. */
protected Forces forces;
protected BoidForces forces;
/**
* New boid as a node in the given graph.
*
* @param graph The graph this boids pertains to.
* @param id The boid identifier in the graph and in the force system.
*
* @param graph
* The graph this boids pertains to.
* @param id
* The boid identifier in the graph and in the force system.
*/
super((AbstractGraph) graph, id);
public Boid(AbstractGraph graph, BoidSpecies species, String id) {
super(graph, id);
this.particle = new BoidParticle((Context) graph);
this.particle = new BoidParticle((BoidGraph) graph);
this.species = species;
this.forces = getDefaultForces();
}
/** Force the position of the boid in space. */
/**
* Force the position of the boid in space.
*/
public void setPosition(double x, double y, double z) {
particle.setPosition(x, y, z);
}
/** Actual position of the boid in space. */
/**
* Actual position of the boid in space.
*/
public Point3 getPosition() {
return particle.getPosition();
}
/** Set of parameters used by this boid group. */
/**
* Set of parameters used by this boid group.
*/
public BoidSpecies getSpecies() {
return species;
}
/** Change boid group and set of parameters. */
/** The underlying particle of the force system this boids is linked to. */
/**
* The underlying particle of the force system this boids is linked to.
*/
public BoidParticle getParticle() {
return particle;
}
......@@ -109,8 +117,8 @@ public class Boid extends AdjacencyListNode {
* The forces acting on the boids, this is a set of vectors and parameters
* computed at each time step.
*/
public Forces getDefaultForces() {
return new Forces.BasicForces();
public BoidForces getDefaultForces() {
return new BoidForces.BasicForces();
}
protected void checkNeighborhood(BoidParticle... particles) {
......@@ -154,9 +162,10 @@ public class Boid extends AdjacencyListNode {
}
/**
* Compute the edge identifier between two boids knowing their individual identifiers.
* This method ensures the identifiers are always in the same order so that we get the
* same edge whatever the order of the parameters b1 and b2.
* Compute the edge identifier between two boids knowing their individual
* identifiers. This method ensures the identifiers are always in the same
* order so that we get the same edge whatever the order of the parameters
* b1 and b2.
*/
public static final String getEdgeId(Boid b1, Boid b2) {
if (b1.hashCode() > b2.hashCode()) {
......@@ -169,29 +178,40 @@ public class Boid extends AdjacencyListNode {
}
/**
* Internal representation of the boid position, and direction in the forces system.
* Internal representation of the boid position, and direction in the forces
* system.
*
* @author Guilhelm Savin
* @author Antoine Dutot
*/
class BoidParticle extends Particle {
/** Direction of the boid. */
/**
* Direction of the boid.
*/
protected Vector3 dir;
/** Set of global parameters. */
protected Context ctx;
/** Number of boids in view at each step. */
/**
* Set of global parameters.
*/
protected BoidGraph ctx;
/**
* Number of boids in view at each step.
*/
protected int contacts = 0;
/** Number of boids of my group in view at each step. */
/**
* Number of boids of my group in view at each step.
*/
protected int mySpeciesContacts = 0;
/**
/**
* New particle.
* @param ctx The set of global parameters.
*
* @param ctx
* The set of global parameters.
*/
public BoidParticle(Context ctx) {
public BoidParticle(BoidGraph ctx) {
super(Boid.this.getId(), ctx.random.nextDouble() * (ctx.area * 2)
- ctx.area, ctx.random.nextDouble() * (ctx.area * 2)
- ctx.area, 0);
......
/*
* 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;
import java.util.Iterator;
......
/*
* Copyright 2006 - 2011
* Julien Baudry <julien.baudry@graphstream-project.org>
* Copyright 2006 - 2012
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@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
* graph, create them from scratch, file or any source and display them.
* 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
......@@ -57,7 +55,7 @@ import java.util.Random;
* @author Guilhelm Savin
* @author Antoine Dutot
*/
public class Context extends AdjacencyListGraph {
public class BoidGraph extends AdjacencyListGraph {
public static enum Parameter {
MAX_STEPS, AREA, SLEEP_TIME, STORE_FORCES_ATTRIBUTES, REMOVE_CAUGHT_BOIDS, NORMALIZE_MODE, RANDOM_SEED
......@@ -131,7 +129,7 @@ public class Context extends AdjacencyListGraph {
/**
* New context.
*/
public Context() {
public BoidGraph() {
super("boids-context");
setNodeFactory(new BoidFactory());
......@@ -153,7 +151,7 @@ public class Context extends AdjacencyListGraph {
pbox = new ParticleBox(maxParticlesPerCell, space, new BoidCellData());
}
public Context(String dgsConfig) throws IOException {
public BoidGraph(String dgsConfig) throws IOException {
this();
loadDGSConfiguration(dgsConfig);
}
......@@ -279,7 +277,7 @@ public class Context extends AdjacencyListGraph {
else {
try {
Class<?> classObj = Class.forName(clazz);
Object obj = classObj.getConstructor(Context.class,
Object obj = classObj.getConstructor(BoidGraph.class,
String.class).newInstance(this, name);
if (obj instanceof BoidSpecies) {
......@@ -406,6 +404,15 @@ public class Context extends AdjacencyListGraph {
return loop;
}
@Override
public Viewer display(boolean autoLayout) {
Viewer v = super.display(autoLayout);
Camera cam = v.getDefaultView().getCamera();
cam.setGraphViewport(-area, -area, area, area);
return v;
}
protected void sleep(int milliseconds) {
try {
Thread.sleep(milliseconds);
......@@ -498,33 +505,16 @@ public class Context extends AdjacencyListGraph {
}
public static void main(String... args) {
Context ctx = new Context();
// BoidSpecies species = ctx.addDefaultSpecies();
// species.angleOfView = 0;
// species.setCount(100);
BoidGraph ctx = new BoidGraph();
try {
ctx.loadDGSConfiguration(Context.class
ctx.loadDGSConfiguration(BoidGraph.class
.getResourceAsStream("configExample.dgs"));
} catch (Exception e1) {
e1.printStackTrace();
}
Viewer viewer = ctx.display(false);
Camera cam = viewer.getDefaultView().getCamera();
cam.setGraphViewport(-ctx.area, -ctx.area, ctx.area, ctx.area);
// species.setCount(100);
while (true) {
ctx.stepBegins(0);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
ctx.display(false);
ctx.loop();
}
}
\ No newline at end of file
/*
* 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;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import org.graphstream.boids.Context;
import org.graphstream.boids.BoidGraph;
/**
* Parameters for each boids species.
......@@ -15,7 +43,9 @@ import org.graphstream.boids.Context;
public class BoidSpecies implements Iterable<Boid> {
private static final long serialVersionUID = 6005548670964581065L;
/** Kinds of parameters. */
/**
* Kinds of parameters.
*/
public static enum Parameter {
COUNT, ANGLE_OF_VIEW, VIEW_ZONE, SPEED_FACTOR, MAX_SPEED, MIN_SPEED, WIDTH, TRAIL, DIRECTION_FACTOR, ATTRACTION_FACTOR, REPULSION_FACTOR, INERTIA, FEAR_FACTOR
}
......@@ -23,7 +53,7 @@ public class BoidSpecies implements Iterable<Boid> {
/**
* Shared settings.
*/
protected Context ctx;
protected BoidGraph ctx;
/**
* The species name.
......@@ -102,9 +132,9 @@ public class BoidSpecies implements Iterable<Boid> {
*/
protected Color color = new Color(1, 0, 0);
// /**
// * The size of the trail in the GUI if any.
// */
// /**
// * The size of the trail in the GUI if any.
// */
protected int trail = 0;
/**
......@@ -115,10 +145,11 @@ public class BoidSpecies implements Iterable<Boid> {
protected HashMap<String, Boid> boids;
private int currentIndex = 0;
private long timestamp = System.nanoTime();
/**
* New default species with a random color.
*/
public BoidSpecies(Context ctx, String name) {
public BoidSpecies(BoidGraph ctx, String name) {
this.boids = new HashMap<String, Boid>();
this.ctx = ctx;
this.name = name;
......@@ -129,6 +160,7 @@ public class BoidSpecies implements Iterable<Boid> {
public String getName() {
return name;
}
public Iterator<Boid> iterator() {
return boids.values().iterator();
}
......@@ -160,9 +192,9 @@ public class BoidSpecies implements Iterable<Boid> {
case WIDTH:
width = Integer.parseInt(val);
break;
// case TRAIL:
// trail = Integer.parseInt(val);
// break;
// case TRAIL:
// trail = Integer.parseInt(val);
// break;
case DIRECTION_FACTOR:
directionFactor = Double.parseDouble(val);
break;
......@@ -211,7 +243,6 @@ public class BoidSpecies implements Iterable<Boid> {
public int getPopulation() {
return boids.size();
*/
}
/**
......@@ -220,12 +251,6 @@ public class BoidSpecies implements Iterable<Boid> {
public void setCount(int count) {
while (boids.size() < count)
ctx.addNode(createNewId());
/**
* The species name.
*/
/**
* Change the species name.
*/
}
/**
......@@ -347,8 +372,8 @@ public class BoidSpecies implements Iterable<Boid> {
}
/**
* Change the inertia is the importance of the boid previous direction in the boid
* direction.
* Change the inertia is the importance of the boid previous direction in
* the boid direction.
*/
public void setInertia(double inertia) {
this.inertia = inertia;
......@@ -383,9 +408,9 @@ public class BoidSpecies implements Iterable<Boid> {
this.color = color;
}
// public void setTrail(int trail) {
// this.trail = trail;
// }
// public void setTrail(int trail) {
// this.trail = trail;
// }
/**
* Change the width of the particle in the GUI if any.
......
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