-
Notifications
You must be signed in to change notification settings - Fork 1
/
OctreeGraph.java
80 lines (63 loc) · 2.85 KB
/
OctreeGraph.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Jcg.geometry.Point_2;
import Jcg.geometry.Point_3;
import Jcg.geometry.Vector_3;
import Jcg.geometry.PointCloud_3;
import jdg.graph.AdjacencyListGraph;
import jdg.graph.Node;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
/**
* A class for representing an quadtree for graph layout computation (nodes store forces, barycenter and graph vertices)
*
* @author Luca Castelli Aleardi, Ecole Polytechnique
* @version december 2018
*/
public class OctreeGraph {
public OctreeNodeGraph root;
public OctreeGraph(AdjacencyListGraph g) {
/**
* Compute the bounding box
*/
ArrayList<Point_3> points_list = new ArrayList<>(g.sizeVertices());
ArrayList<Node> nodes = new ArrayList<>(g.sizeVertices());
for (Node u:g.vertices) {
points_list.add(u.p);
nodes.add(u);
}
PointCloud_3 pointCloud = new PointCloud_3(points_list);
System.out.println();
System.out.println("nb of points = "+ pointCloud.size());
// compute bounding box in dim 2
Point_3[] cube = new Point_3[]{new Point_3(pointCloud.min(0).getX(), pointCloud.min(1).getY(),0), new Point_3(pointCloud.max(0).getX(), pointCloud.max(1).getY(), 0)};
/**
* Compute the center and the side length of the bounding box
*/
Number coefficient[] = new Number[2]; // we want the mean of the cube, so we take the mean of the bounding box. But which form has the bounding box ???
Arrays.fill(coefficient, 0.5);
Point_3 center = Point_3.linearCombination(cube, coefficient);
double a = Math.max(Math.max(cube[1].x - cube[0].x, cube[1].y - cube[0].y), cube[1].z - cube[0].z) * 1.000000001;
//(double)pointCloud.min(0).distanceFrom(pointCloud.max(0)); //length of the side of the cube
/**
* Initialize the root node
*/
root = new OctreeNodeGraph(nodes, center, null, a, 0,0);
}
static double calc_a(ArrayList<Point_3> points_list) {
if(points_list.isEmpty()) return 0;
PointCloud_3 pointCloud = new PointCloud_3(points_list);
Point_3[] cube = pointCloud.boundingBox();
/**
* Compute the center and the side length of the bounding box
*/
return Math.max(Math.max(cube[1].x - cube[0].x, cube[1].y - cube[0].y), cube[1].z - cube[0].z) * 1.000000001;
}
static Point_3 calc_p(ArrayList<Point_3> points_list) {
if(points_list.isEmpty()) return null;
PointCloud_3 pointCloud = new PointCloud_3(points_list);
Point_3[] cube = pointCloud.boundingBox();
Number coefficient[] = new Number[2]; // we want the mean of the cube, so we take the mean of the bounding box. But which form has the bounding box ???
Arrays.fill(coefficient, 0.5);
return Point_3.linearCombination(cube, coefficient);
}
}