001/*
002 * Copyright 2006 - 2013
003 *     Stefan Balev     <stefan.balev@graphstream-project.org>
004 *     Julien Baudry    <julien.baudry@graphstream-project.org>
005 *     Antoine Dutot    <antoine.dutot@graphstream-project.org>
006 *     Yoann Pigné      <yoann.pigne@graphstream-project.org>
007 *     Guilhelm Savin   <guilhelm.savin@graphstream-project.org>
008 * 
009 * This file is part of GraphStream <http://graphstream-project.org>.
010 * 
011 * GraphStream is a library whose purpose is to handle static or dynamic
012 * graph, create them from scratch, file or any source and display them.
013 * 
014 * This program is free software distributed under the terms of two licenses, the
015 * CeCILL-C license that fits European law, and the GNU Lesser General Public
016 * License. You can  use, modify and/ or redistribute the software under the terms
017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
019 * the Free Software Foundation, either version 3 of the License, or (at your
020 * option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
024 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
025 * 
026 * You should have received a copy of the GNU Lesser General Public License
027 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
028 * 
029 * The fact that you are presently reading this means that you have had
030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
031 */
032package org.graphstream.ui.layout.springbox.implementations;
033
034import java.util.Random;
035
036import org.graphstream.ui.layout.springbox.BarnesHutLayout;
037import org.graphstream.ui.layout.springbox.NodeParticle;
038
039public class LinLog extends BarnesHutLayout {
040        protected double k = 1;
041
042        /**
043         * Default general attraction factor.
044         */
045        protected double aFactor = 1f;
046
047        /**
048         * Default general repulsion factor.
049         */
050        protected double rFactor = 1f;
051
052        protected boolean edgeBased = true;
053        
054        protected double maxR = 0.5;
055        
056        protected double a = 0;
057        
058        protected double r = -1.2;
059        
060        //protected
061        
062        /**
063         * New "LinLog" 2D Barnes-Hut simulation.
064         */
065        public LinLog() {
066                this(false);
067        }
068
069        /**
070         * New "LinLog" Barnes-Hut simulation.
071         * 
072         * @param is3D
073         *            If true the simulation dimensions count is 3 else 2.
074         */
075        public LinLog(boolean is3D) {
076                this(is3D, new Random(System.currentTimeMillis()));
077        }
078
079        /**
080         * New "LinLog" Barnes-Hut simulation.
081         * 
082         * @param is3D
083         *            If true the simulation dimensions count is 3 else 2.
084         * @param randomNumberGenerator
085         *            The random number generator to use.
086         */
087        public LinLog(boolean is3D, Random randomNumberGenerator) {
088                super(is3D, randomNumberGenerator);
089                setQuality(1);
090                force = 3;
091        }
092        
093        public void configure(double a, double r, boolean edgeBased, double force) {
094                this.a = a;
095                this.r = r;
096                this.edgeBased = edgeBased;
097                this.force = force;
098        }
099
100        @Override
101        public String getLayoutAlgorithmName() {
102                return "LinLog";
103        }
104
105        @Override
106        public void setQuality(double qualityLevel) {
107                super.setQuality(qualityLevel);
108
109                if (quality >= 1) {
110                        viewZone = -1;
111                } else {
112                        viewZone = k;
113                }
114        }
115        
116        @Override
117        public void compute() {
118                if(viewZone > 0)
119                        viewZone = area/1.5;
120                super.compute();
121        }
122
123        @Override
124        protected void chooseNodePosition(NodeParticle n0, NodeParticle n1) {
125//              double delta = k * 0.1;
126//              if (n0.getEdges().size() == 1 && n1.getEdges().size() > 1) {
127//                      org.miv.pherd.geom.Point3 pos = n1.getPosition();
128//                      n0.moveTo(pos.x + delta, pos.y + delta, pos.z + delta);
129//              } else if (n1.getEdges().size() == 1 && n0.getEdges().size() > 1) {
130//                      org.miv.pherd.geom.Point3 pos = n0.getPosition();
131//                      n1.moveTo(pos.x + delta, pos.y + delta, pos.z + delta);
132//              }
133        }
134
135        @Override
136        public NodeParticle newNodeParticle(String id) {
137                return new LinLogNodeParticle(this, id);
138        }
139}