Last change
on this file was
2269,
checked in by ymipsl, 3 years ago
|
- Solve memory leak from remapper.
- shared_ptr add add for manage nodes.
YM
|
File size:
967 bytes
|
Line | |
---|
1 | #include <algorithm> |
---|
2 | #include "node.hpp" |
---|
3 | #include "elt.hpp" |
---|
4 | |
---|
5 | #include "circle.hpp" |
---|
6 | |
---|
7 | namespace sphereRemap |
---|
8 | { |
---|
9 | |
---|
10 | /* computes the radius of the smallest circle |
---|
11 | around the barycentre `x` of grid element `elt` |
---|
12 | which contains all vertices of `elt`. */ |
---|
13 | double cptRadius(Elt elt) |
---|
14 | { |
---|
15 | double squareradius = 0.0; |
---|
16 | int argmax = 0; |
---|
17 | // use cheep `squaredist` to find farthest vertex and compute radius as arcdistance only once |
---|
18 | for (int i = 0; i < elt.n; i++) |
---|
19 | { |
---|
20 | double dist2 = squaredist(elt.x, elt.vertex[i]); |
---|
21 | if (dist2 > squareradius) |
---|
22 | { |
---|
23 | squareradius = dist2; |
---|
24 | argmax = i; |
---|
25 | } |
---|
26 | } |
---|
27 | return arcdist(elt.x, elt.vertex[argmax]) + 1e-10; |
---|
28 | } |
---|
29 | |
---|
30 | void setCircleAndLink(Elt& elt, Node& leaf) |
---|
31 | { |
---|
32 | leaf.centre = elt.x; |
---|
33 | leaf.radius = cptRadius(elt); |
---|
34 | leaf.data = &elt; |
---|
35 | } |
---|
36 | |
---|
37 | void setCirclesAndLinks(Elt *elts, vector<NodePtr>& nodes) |
---|
38 | { |
---|
39 | for (int i = 0; i < nodes.size(); i++) |
---|
40 | setCircleAndLink(elts[i], *nodes[i]); |
---|
41 | } |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.