-
Notifications
You must be signed in to change notification settings - Fork 1
/
Octree.java
68 lines (55 loc) · 2.54 KB
/
Octree.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
import Jcg.geometry.Point_3;
import Jcg.geometry.PointCloud_3;
import java.util.ArrayList;
import java.util.Arrays;
/**
* A class for representing an Octree
*
* @author Luca Castelli Aleardi, Ecole Polytechnique
* @version december 2018
*/
public class Octree {
public OctreeNode root;
public Octree(Point_3[] points) {
/**
* Compute the bounding box
*/
ArrayList<Point_3> points_list = new ArrayList<>(points.length);
for (Point_3 p : points) {
points_list.add(p);
}
PointCloud_3 pointCloud = new PointCloud_3(points_list);
Point_3[] cube = pointCloud.boundingBox();
/**
* 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.
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;
/**
* Initialize the root node
*/
root = new OctreeNode(points_list, center, null, a, 0,0);
}
// compute the smallest radius of a centered sphere containing a given set of points in a cube
static double calc_a(ArrayList<Point_3> points_list,Point_3 p) {
if(points_list.size()<2) 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;
return 2*Math.max(Math.max(Math.max(cube[1].x - p.x,p.x - cube[0].x), Math.max(cube[1].y-p.y,p.y-cube[0].y)), Math.max(cube[1].z-p.z,p.z-cube[0].z)) * 1.000000001;
}
// compute the center of the bounding box of a given set of points
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);
}
}