Package org.graphstream.ui.layout.springbox

Examples of org.graphstream.ui.layout.springbox.Energies


  @Override
  protected void repulsionN2(Vector3 delta) {
    SpringBox box = (SpringBox) this.box;
    boolean is3D = box.is3D();
    ParticleBox nodes = box.getSpatialIndex();
    Energies energies = box.getEnergies();
    Iterator<Object> i = nodes.getParticleIdIterator();

    while (i.hasNext()) {
      SpringBoxNodeParticle node = (SpringBoxNodeParticle) nodes
          .getParticle(i.next());

      if (node != this) {
        delta.set(node.pos.x - pos.x, node.pos.y - pos.y,
            is3D ? node.pos.z - pos.z : 0);

        double len = delta.normalize();

        if(len > 0) {
          if (len < box.k)
            len = box.k; // XXX NEW To prevent infinite
                  // repulsion.
       
          double factor = len != 0 ? ((box.K2 / (len * len)) * node.weight)
            : 0.00001;

          energies.accumulateEnergy(factor); // TODO check this
          delta.scalarMult(-factor);
          disp.add(delta);
        }
      }
    }
View Full Code Here


  }

  protected void recurseRepulsion(Cell cell, Vector3 delta) {
    SpringBox box = (SpringBox) this.box;
    boolean is3D = box.is3D();
    Energies energies = box.getEnergies();

    if (intersection(cell)) {
      if (cell.isLeaf()) {
        Iterator<? extends Particle> i = cell.getParticles();

        while (i.hasNext()) {
          SpringBoxNodeParticle node = (SpringBoxNodeParticle) i.next();

          if (node != this) {
            delta.set(node.pos.x - pos.x, node.pos.y - pos.y, is3D ? node.pos.z
                - pos.z : 0);

            double len = delta.normalize();

            if (len > 0)// && len < ( box.k * box.viewZone ) )
            {
              if (len < box.k)
                len = box.k; // XXX NEW To prevent infinite
                        // repulsion.
              double factor = len != 0 ? ((box.K2 / (len * len)) * node
                  .weight) : 0.00001;
              energies.accumulateEnergy(factor); // TODO check
                                // this
              repE += factor;
              delta.scalarMult(-factor);
              disp.add(delta);
            }
          }
        }
      } else {
        int div = cell.getSpace().getDivisions();

        for (int i = 0; i < div; i++)
          recurseRepulsion(cell.getSub(i), delta);
      }
    } else {
      if (cell != this.cell) {
        GraphCellData bary = (GraphCellData) cell.getData();

        double dist = bary.distanceFrom(pos);
        double size = cell.getSpace().getSize();

        if ((!cell.isLeaf())
            && ((size / dist) > box.getBarnesHutTheta())) {
          int div = cell.getSpace().getDivisions();

          for (int i = 0; i < div; i++)
            recurseRepulsion(cell.getSub(i), delta);
        } else {
          if (bary.weight != 0) {
            delta.set(bary.center.x - pos.x, bary.center.y - pos.y,
                is3D ? bary.center.z - pos.z : 0);

            double len = delta.normalize();

            if (len > 0) {
              if (len < box.k)
                len = box.k; // XXX NEW To prevent infinite
                        // repulsion.
              double factor = len != 0 ? ((box.K2 / (len * len)) * (bary.weight))
                  : 0.00001f;
              energies.accumulateEnergy(factor);
              delta.scalarMult(-factor);
              repE += factor;

              disp.add(delta);
            }
View Full Code Here

  @Override
  protected void attraction(Vector3 delta) {
    SpringBox box = (SpringBox) this.box;
    boolean is3D = box.is3D();
    Energies energies = box.getEnergies();
    int neighbourCount = neighbours.size();

    for (EdgeSpring edge : neighbours) {
      if (!edge.ignored) {
        NodeParticle other = edge.getOpposite(this);
        Point3 opos = other.getPosition();

        delta.set(opos.x - pos.x, opos.y - pos.y, is3D ? opos.z - pos.z
            : 0);

        double len = delta.normalize();
        double k = box.k * edge.weight;
        double factor = box.K1 * (len - k);

        // delta.scalarMult( factor );
        delta.scalarMult(factor * (1f / (neighbourCount * 0.1f)));
        // ^^^ XXX NEW inertia based on the node degree. This is one
        // of the amelioration of the Spring-Box algorithm. Compare
        // it to the Force-Atlas algorithm that does this on
        // **repulsion**.

        disp.add(delta);
        attE += factor;
        energies.accumulateEnergy(factor);
      }
    }
  }
View Full Code Here

  @Override
  protected void repulsionN2(Vector3 delta) {
    LinLog box = (LinLog) this.box;
    boolean is3D = box.is3D();
    ParticleBox nodes = box.getSpatialIndex();
    Energies energies = box.getEnergies();
    Iterator<Object> i = nodes.getParticleIdIterator();
    int deg = neighbours.size();

    while (i.hasNext()) {
      LinLogNodeParticle node = (LinLogNodeParticle) nodes
          .getParticle(i.next());

      if (node != this) {
        delta.set(node.pos.x - pos.x, node.pos.y - pos.y,
            is3D ? node.pos.z - pos.z : 0);

//        double len = delta.normalize();
        double len = delta.length();

        if(len > 0) {
          double degFactor = box.edgeBased ? deg * node.neighbours.size() : 1;
          double factor = 1;
          double r = box.r;

          factor = -degFactor * (Math.pow(len, r-2)) * node.weight * weight * box.rFactor;

          if(factor < -box.maxR) { factor = -box.maxR; }
         
          energies.accumulateEnergy(factor); // TODO check this
          delta.scalarMult(factor);
          disp.add(delta);
          repE += factor;
        }
      }
View Full Code Here

  }

  protected void recurseRepulsion(Cell cell, Vector3 delta) {
    LinLog box = (LinLog) this.box;
    boolean is3D = box.is3D();
    Energies energies = box.getEnergies();
    int deg = neighbours.size();

    if (intersection(cell)) {
      if (cell.isLeaf()) {
        Iterator<? extends Particle> i = cell.getParticles();

        while (i.hasNext()) {
          LinLogNodeParticle node = (LinLogNodeParticle) i.next();

          if (node != this) {
            delta.set(node.pos.x - pos.x, node.pos.y - pos.y, is3D ? node.pos.z
                - pos.z : 0);

            //double len = delta.normalize();
            double len = delta.length();

            if (len > 0) {
              double degFactor = box.edgeBased ? deg * node.neighbours.size() : 1;
              double factor = 1;
              double r = box.r;
             
              factor = -degFactor * (Math.pow(len, r-2)) * node.weight * weight * box.rFactor;
             
              if(factor < -box.maxR) { factor = -box.maxR; }

              energies.accumulateEnergy(factor)// TODO check this
              delta.scalarMult(factor);
              disp.add(delta);
              repE += factor;
            }
          }
        }
      } else {
        int div = cell.getSpace().getDivisions();

        for (int i = 0; i < div; i++)
          recurseRepulsion(cell.getSub(i), delta);
      }
    } else {
      if (cell != this.cell) {
        GraphCellData bary = (GraphCellData) cell.getData();
        double dist = bary.distanceFrom(pos);
        double size = cell.getSpace().getSize();

        if ((!cell.isLeaf())
            && ((size / dist) > box.getBarnesHutTheta())) {
          int div = cell.getSpace().getDivisions();

          for (int i = 0; i < div; i++)
            recurseRepulsion(cell.getSub(i), delta);
        } else {
          if (bary.weight != 0) {
            delta.set(bary.center.x - pos.x, bary.center.y - pos.y,
                is3D ? bary.center.z - pos.z : 0);

            //double len = delta.normalize();
            double len = delta.length();

            if (len > 0) {
              double degFactor = box.edgeBased ? deg * bary.degree : 1;
              double factor = 1;
              double r = box.r;
             
              factor = -degFactor * (Math.pow(len, r-2)) * bary.weight * weight * box.rFactor;

              if(factor < -box.maxR) { factor = -box.maxR; }
             
              energies.accumulateEnergy(factor)// TODO check this
              delta.scalarMult(factor);
              disp.add(delta);
              repE += factor;
            }
          }
View Full Code Here

  @Override
  protected void attraction(Vector3 delta) {
    LinLog box = (LinLog) this.box;
    boolean is3D = box.is3D();
    Energies energies = box.getEnergies();

    for (EdgeSpring edge : neighbours) {
      if (!edge.ignored) {
        LinLogNodeParticle other = (LinLogNodeParticle) edge.getOpposite(this);

        delta.set(other.pos.x - pos.x, other.pos.y - pos.y, is3D ? other.pos.z - pos.z : 0);

//        double len = delta.normalize();
        double len = delta.length();

        if(len > 0) {
          double factor = 1;
          double a = box.a;

          factor = (Math.pow(len, a-2)) * edge.weight * box.aFactor;

          energies.accumulateEnergy(factor);
          delta.scalarMult(factor);
          disp.add(delta);
          attE += factor;
        }
      }
View Full Code Here

TOP

Related Classes of org.graphstream.ui.layout.springbox.Energies

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.