-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstargroup.cpp
More file actions
142 lines (113 loc) · 2.76 KB
/
Copy pathstargroup.cpp
File metadata and controls
142 lines (113 loc) · 2.76 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "stargroup.h"
#include "probe.h"
#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;
/**
A StarGroup is the data structure that holds the list of stars
in a probe configuration. It is useful to have its own data structure
so that it can independently check for the right number of magnitudes,
and do so for phasing and 4probe configurations.
**/
#define PI 3.14159265350
StarGroup::StarGroup() { }
StarGroup::~StarGroup() { }
StarGroup::StarGroup(vector<Star> _stars) {
stars = _stars;
update_mags();
}
void StarGroup::add_star(Star _star) {
stars.push_back(_star);
}
Star StarGroup::star_at(int idx) {
return stars[idx];
}
void StarGroup::update_mags() {
for(vector<Star>::iterator it = stars.begin(); it != stars.end(); ++it) {
mags.push_back(it->r);
}
}
int int_frequency(int x, vector<int> l) {
int freq = 0;
for (vector<int>::iterator it = l.begin(); it != l.end(); ++it) {
if (*it == x) {
freq += 1;
}
}
return freq;
}
int StarGroup::wfsmag() {
vector<int>::iterator mag;
for (mag=mags.begin(); mag != mags.end(); mag++) {
if (int_frequency(*mag, mags) >= 3) {
return *mag;
}
}
return 0;
}
int StarGroup::gdrmag() {
if (int_frequency(mags[0], mags) == 4) { return mags[0]; }
vector<int>::iterator mag;
for (mag=mags.begin(); mag != mags.end(); mag++) {
if (int_frequency(*mag, mags) == 1) {
return *mag;
}
}
return 0;
}
string StarGroup::magpair() {
std::ostringstream res;
res << wfsmag() << ":" << gdrmag();
return res.str();
}
int StarGroup::valid_for_phasing(int J) {
for (int i=0; i<stars.size(); i++) {
for (int j=0; j<stars.size(); j++) {
if (i == j) { continue; }
if (stars[i].x == stars[j].x && stars[i].y == stars[j].y) {
return 0;
}
}
}
int magcount = 0;
for (Star s : stars) {
if (s.r <= J) {
magcount++;
}
}
if (magcount < 3) {
return 0;
}
return 1;
}
int StarGroup::valid(int W, int G) {
Point origin(0, 1);
double angle;
for (int i=0; i<stars.size(); i++) {
for (int j=0; j<stars.size(); j++) {
if (i == j) { continue; }
if (stars[i].x == stars[j].x && stars[i].y == stars[j].y) {
return 0;
}
}
}
double R_1 = stars[0].r;
double R_2 = stars[1].r;
double R_3 = stars[2].r;
double R_4 = stars[3].r;
if ( ((R_1 > G) || (R_2 > W) || (R_3 > W) || (R_4 > W))
&& ((R_1 > W) || (R_2 > G) || (R_3 > W) || (R_4 > W))
&& ((R_1 > W) || (R_2 > W) || (R_3 > G) || (R_4 > W))
&& ((R_1 > W) || (R_2 > W) || (R_3 > W) || (R_4 > G)) ) {
return 0;
}
return 1;
}
void StarGroup::print() {
std::cerr << endl;
for ( Star s : stars ) {
s.point().print("m");
}
std::cerr << endl;
}