Brain.java
2.41 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package osp;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
/**
* This class is used in the generation of automatic solutions. <br>
* <br>
* It is able to :<br>
* <ul>
* <li>Search the barycenter of a skyObject list (and save it for later access).
* </li>
* <li>Calculate the ratio of objects affected to slits on a mask.</li>
* </ul>
*/
public class Brain {
// Attributes
// -----------
/**
* Barycenter of the sky objects. It's saved so it can be accessed multiple
* times without needing to recalculate it each time.
*/
private Point2D.Double bary;
/**
* Constructs a new brain.
*/
public Brain() {
bary = new Point2D.Double();
}
/**
* Computes the barycenter of the <a href="./SkyObject.html">SkyObject</a>
* list so (all objects have the same mass). The barycenter is saved for
* later access.
*
* @param so : The list of object to compute the barycenter of.
* @return bary : Barycenter of the sky objects.
*/
public Point2D.Double computeBary(List<SkyObject> so) {
List<Point2D.Double> lo = new ArrayList<Point2D.Double>();
for (int i = 0; i < so.size(); i++)
lo.add(so.get(i).getPosition());
bary.x = 0.0;
bary.y = 0.0;
for (int i = 0; i < lo.size(); i++) {
bary.x = bary.x + lo.get(i).getX();
bary.y = bary.y + lo.get(i).getY();
}
bary.x = bary.x / lo.size();
bary.y = bary.y / lo.size();
return bary;
}
/**
* Returns the barycenter. <b>The barycenter is not recalculated.</b> If it
* has not been previously calculated, the barycenter will have the
* coordinates (0,0).
*
* @return The barycenter previously calculated.
*/
public Point2D.Double getBary() {
return bary;
}
/**
* Computes and sets (in the mask) the ratio of objects on the image that
* are affected to slits on the current mask. It goes from 0, if no object
* is affected to a slit on the current mask, to 1, if all object of the
* image are affected to slits on the current mask.
*
* @param mask
* Mask concerned by the calculations.
*/
public void computeRatioAffectedSlit(Mask mask) {
double ratio = 0.0;
for (int i = 0; i < Mask.get_NBRSLITS_(); i++) {
if (mask.getSlit(i).getAffectedObject() != -1) {
ratio = ratio + 1;
}
}
ratio = ratio / mask.imagePater.getNbrObjects();
mask.ratioAffectedSlit = ratio;
}
}