-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvstar.cpp
More file actions
181 lines (160 loc) · 3.99 KB
/
vstar.cpp
File metadata and controls
181 lines (160 loc) · 3.99 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Exposit Copyright (C) 2009,2010 Cristelle Barillon & Jean-Daniel Pauget
* efficiently stacking astro pics
*
* exposit@disjunkt.com - http://exposit.disjunkt.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* you can also try the web at http://www.gnu.org/
*
*/
#include <math.h>
#include <iostream>
#include "vstar.h"
namespace exposit {
using namespace std;
int VStar::distance_eucl (int rx, int ry) {
double da1 = x - rx,
da2 = y - ry,
d = sqrt (da1*da1 + da2*da2);
return (int) d;
}
int VStar::distance_eucl (VStar const &s) {
double da1 = x - s.x,
da2 = y - s.y,
d = sqrt (da1*da1 + da2*da2);
return (int) d;
}
int VStar::distance_2angles (VStar const &s) {
double da1 = a1 - s.a1,
da2 = a2 - s.a2,
d = sqrt (da1*da1 + da2*da2);
d *= 180.0/M_PI;
return (int) d;
}
int VStar::distance_3d (VStar const &s) {
double da0 = d0 - s.d0,
da1 = d1 - s.d1,
da2 = d2 - s.d2,
d = sqrt (da0*da0 + da1*da1 + da2*da2);
d /= 10; // JDJDJDJD il faudrait l'adapter a la taille de l'image .... initialement 3000x2000
return (int) d;
}
int VStar::distance_3mags (VStar const &s) {
double da0 = mag0 - s.mag0,
da1 = mag1 - s.mag1,
da2 = mag2 - s.mag2,
d = sqrt (da0*da0 + da1*da1 + da2*da2);
d *= 100;
return (int) d;
}
int VStar::distance (VStar const &s) {
double D0 = distance_2angles (s),
D1 = distance_3d (s),
d = sqrt (D0*D0 + D1*D1);
return (int) d;
}
void VStar::qualify0 (VStar const &s) {
int dx = s.x - x,
dy = s.y - y,
dd = dxxdyy (*this, s);
d0 = sqrt(dd);
if (d0 < 2.0) {
a0 = 0, d0 = 0, mag0 = 0;
return;
}
a0 = acos (dx/d0);
if (dy<0)
a0 = 2 * M_PI - a0;
mag0 = s.abs_magnitude / abs_magnitude;
}
void VStar::qualify1 (VStar const &s) {
int dx = s.x - x,
dy = s.y - y,
dd = dxxdyy (*this, s);
d1 = sqrt(dd);
if ((d0==0.0) || (d1 < 2.0)) {
a1 = 0, d1 = 0, mag1 = 0;
return;
}
a1 = acos (dx/d1);
if (dy<0)
a1 = 2 * M_PI - a1;
a1 -= a0;
if (a1 < 0)
a1 += 2 * M_PI;
mag1 = s.abs_magnitude / abs_magnitude;
}
void VStar::qualify2 (VStar const &s) {
int dx = s.x - x,
dy = s.y - y,
dd = dxxdyy (*this, s);
d2 = sqrt(dd);
if ((d0==0.0) || (d2 < 2.0)) {
a2 = 0, d2 = 0, mag2 = 0;
return;
}
a2 = acos (dx/d2);
if (dy<0)
a2 = 2 * M_PI - a2;
a2 -= a0;
if (a2 < 0)
a2 += 2 * M_PI;
mag2 = s.abs_magnitude / abs_magnitude;
}
bool VStar::qualify (multimap<int, VStar*> const &lvstar) {
if (lvstar.size() < 3)
return false;
multimap<int, VStar*>::const_iterator mi, mm=lvstar.end();
int i;
int vmax = 0;
for (i=0,mi=lvstar.begin() ; (i<3)&&(mi!=lvstar.end()) ;i++,mi++) {
if (mi->second->abs_magnitude >= vmax) {
mm = mi;
vmax = mi->second->abs_magnitude;
}
}
qualify0 (*(mm->second));
for (i=0,mi=lvstar.begin() ; (i<2)&&(mi!=lvstar.end()) ;mi++) {
if (mi != mm) {
switch (i) {
case 0:
qualify1 (*(mi->second));
i++;
break;
case 1:
qualify2 (*(mi->second));
i++;
break;
}
}
}
if (a2<a1) {
swap (a2,a1);
swap (d2,d1);
swap (mag2,mag1);
}
a2 -= a1;
if (a1 < 0)
a1 += 2 * M_PI;
return true;
}
int dxxdyy (VStar const &a, VStar const &b) {
int dx = a.x - b.x,
dy = a.y - b.y;
return dx*dx + dy*dy;
}
} // namespace exposit