This repository was archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfarthest_point_sampling.js
More file actions
62 lines (47 loc) · 1.66 KB
/
farthest_point_sampling.js
File metadata and controls
62 lines (47 loc) · 1.66 KB
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
import { FibonacciHeap } from "@tyriar/fibonacci-heap";
import store from "../components/Store";
import { dijkstra } from "./geodesic_distance";
export const farthestPointSampling = (qType, source, count) => {
const logger = store;
const { graph, mesh } = store;
const { geometry } = mesh;
const { distances } = dijkstra(qType, source);
const allDistances = new Set([distances]);
const farthestPoints = [];
const farthestPointIndices = [];
let startTime, elapsedTime;
startTime = new Date();
logger && logger.log(`Executing Farthest Point Sampling...`);
for (let i = 0; i < count; i++) {
const cluster = new FibonacciHeap();
graph.vertices.forEach((vertex) => {
let minDistance = Infinity;
allDistances.forEach((distances) => {
const distance = distances.get(vertex);
if (distance < minDistance) {
minDistance = distance;
}
});
cluster.insert(-minDistance, vertex);
});
const point = cluster.extractMinimum().value;
if (i === 0) {
allDistances.clear();
}
allDistances.add(dijkstra(qType, point).distances);
farthestPoints.push(point);
}
elapsedTime = new Date() - startTime;
logger && logger.log(`\tdone in ${elapsedTime.toLocaleString()}ms.`);
farthestPoints.forEach((point) => {
geometry.vertices.forEach((vertex, index) => {
if (vertex === point) {
farthestPointIndices.push(index);
}
});
});
return {
farthestPoints,
farthestPointIndices,
};
};