28static int dsp_qsort_delta_diff_desc (
const void *arg1,
const void *arg2)
32 return ((*a1).delta < (*a2).delta ? 1 : -1);
35static int dsp_qsort_delta_diff_asc (
const void *arg1,
const void *arg2)
39 return ((*a1).delta > (*a2).delta ? 1 : -1);
42static int dsp_qsort_triangle_delta_desc(
const void *arg1,
const void *arg2)
48 for(s = 0; s < (*a).stars_count; s++)
49 ret |= ((*a).sizes[s] < (*b).sizes[s]);
50 return (ret ? 1 : -1);
53static int dsp_qsort_triangle_delta_asc(
const void *arg1,
const void *arg2)
59 for(s = 0; s < (*a).stars_count; s++)
60 ret |= ((*a).sizes[s] > (*b).sizes[s]);
61 return (ret ? 1 : -1);
64static int dsp_qsort_triangle_diameter_desc(
const void *arg1,
const void *arg2)
70 for(s = 0; s < (*a).stars_count; s++) {
71 ret |= ((*a).stars[s].diameter < (*b).stars[s].diameter);
72 ret |= ((*a).stars[s].peak < (*b).stars[s].peak);
73 ret |= ((*a).stars[s].flux < (*b).stars[s].flux);
75 return (ret ? 1 : -1);
78static int dsp_qsort_triangle_diameter_asc(
const void *arg1,
const void *arg2)
84 for(s = 0; s < (*a).stars_count; s++) {
85 ret |= ((*a).stars[s].diameter > (*b).stars[s].diameter);
86 ret |= ((*a).stars[s].peak > (*b).stars[s].peak);
87 ret |= ((*a).stars[s].flux > (*b).stars[s].flux);
89 return (ret ? 1 : -1);
92static int dsp_qsort_star_diameter_desc(
const void *arg1,
const void *arg2)
96 return ((*a).diameter < (*b).diameter ? 1 : -1);
99static int dsp_qsort_star_diameter_asc(
const void *arg1,
const void *arg2)
103 return ((*a).diameter > (*b).diameter ? 1 : -1);
106static int dsp_qsort_double_desc (
const void *arg1,
const void *arg2)
108 double* a = (
double*)arg1;
109 double* b = (
double*)arg2;
110 return ((*a) < (*b) ? 1 : -1);
113static int dsp_qsort_double_asc (
const void *arg1,
const void *arg2)
115 double* a = (
double*)arg1;
116 double* b = (
double*)arg2;
117 return ((*a) > (*b) ? 1 : -1);
126 int num_baselines = stars_count*(stars_count-1)/2;
130 for(d = 0; d < align_info.
dims; d++) {
131 for(x = 0; x < stars_count; x++) {
139 for(x = 0; x < num_baselines; x++) {
153 align_info->
dims = dims;
154 align_info->
center = (
double*)malloc(
sizeof(
double)*(dims));
155 align_info->
offset = (
double*)malloc(
sizeof(
double)*(dims));
156 align_info->
radians = (
double*)malloc(
sizeof(
double)*(dims-1));
157 align_info->
factor = (
double*)malloc(
sizeof(
double)*(dims));
158 for(d = 0; d < dims; d++) {
159 align_info->
factor[d] = 0;
160 align_info->
offset[d] = 0;
161 align_info->
center[d] = 0;
165 for(d = 0; d < dims; d++) {
172 if(align_info->
radians[d] < 0.0)
175 for(x = 0; x < num_baselines; x++) {
178 align_info->
factor[d] /= num_baselines;
180 align_info->
score = calc_match_score(t1, t2, *align_info);
190 for(d = 0; d < t->
dims; d++) {
207 triangle->
sizes = (
double*)malloc(
sizeof(
double)*num_baselines);
208 triangle->
ratios = (
double*)malloc(
sizeof(
double)*num_baselines);
210 triangle->
theta = (
double*)malloc(
sizeof(
double)*(triangle->
dims-1));
211 triangle->
index = 0.0;
216 deltadiff[idx].
diff = (
double*)malloc(
sizeof(
double)*triangle->
dims);
217 for(d = 0; d < triangle->
dims; d++) {
219 deltadiff[idx].
delta += pow(deltadiff[idx].diff[d], 2);
221 deltadiff[idx].
delta = sqrt(deltadiff[idx].delta);
225 qsort(deltadiff, num_baselines,
sizeof(
delta_diff), dsp_qsort_delta_diff_desc);
226 for(d = 0; d < triangle->
dims-1; d++) {
227 triangle->
theta[d] = acos(deltadiff[0].diff[d] / deltadiff[0].delta);
228 if(deltadiff[0].diff[d+1] < 0)
230 for(x = 1; x < num_baselines; x++) {
231 double index = acos(deltadiff[x].diff[d] / deltadiff[x].delta);
232 if(deltadiff[x].diff[d+1] < 0)
233 index =
M_PI*2.0-index;
234 index -= triangle->
theta[d];
235 triangle->
index += index;
250 for(d = 0; d < num_baselines; d++) {
253 free(deltadiff[d].diff);
262 double decimals = pow(10, tolerance);
266 double ratio = decimals*1600.0/div;
268 for(d = 0; d < stream1->
dims; d++) {
269 div += pow(stream2->
sizes[d], 2);
272 pwarn(
"decimals: %lf\n", decimals);
273 target_score = (1.0-target_score / 100.0);
278 pgarb(
"creating triangles for reference frame...\n");
282 for(y = 0; y < num_stars; y++) {
289 pgarb(
"creating triangles for current frame...\n");
293 for(y = 0; y < num_stars; y++) {
325 for(d = 0; d < stream1->
dims; d++) {
330 if(floor(stream2->
align_info.
score * decimals) < floor(target_score * decimals))
332 if(fabs(phi * ratio * decimals) < 1.0)
336 if(floor(fabs(radians) * decimals) < 1)
int stars_count
The number of stars of the triangle.
dsp_point center
The center of the star.
int triangles_count
Triangles of stars or objects quantity.
int dims
Dimensions limit.
double * factor
Scaling factor.
double theta
The deviation of the star.
double * center
Center of rotation coordinates.
int * sizes
Sizes of each dimension.
double * location
Center of the point.
double * radians
Rotational offset.
double index
The index of the triangle.
dsp_star * stars
Stars or objects identified into the buffers - TODO.
dsp_star * stars
The stars of the triangle.
double * sizes
The sizes of the triangle.
int stars_count
Stars or objects quantity.
double diameter
The diameter of the star.
int dims
The dimensions of the triangle.
double * theta
The inclination of the triangle.
dsp_align_info align_info
Align/scale/rotation settings.
dsp_triangle * triangles
Triangles of stars or objects.
int dims
Number of dimensions of the buffers.
int triangles_count
Triangles quantity.
int dims
Dimensions limit of the point.
double peak
The peak of the star.
double * ratios
The sizes of the triangle.
dsp_triangle triangles[2]
Reference triangles.
double flux
The flux of the star.
double * offset
Translation offset.
DLL_EXPORT void dsp_stream_del_triangle(dsp_stream_p stream, int index)
Remove the triangle with index n to a DSP stream.
DLL_EXPORT void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle)
Add a triangle to the DSP Stream passed as argument.
int dsp_align_get_offset(dsp_stream_p stream1, dsp_stream_p stream2, double tolerance, double target_score, int num_stars)
Calculate offsets, rotation and scaling of two streams giving reference alignment point.
dsp_triangle * dsp_align_calc_triangle(dsp_star *stars, int num_stars)
Create a dsp_triangle struct.
dsp_align_info * dsp_align_fill_info(dsp_triangle t1, dsp_triangle t2)
Fill a dsp_align_info struct by comparing two triangles.
void dsp_align_free_triangle(dsp_triangle *t)
Free a dsp_triangle struct pointer.
Alignment information needed.
A star or object contained into a buffer.
Contains a set of information and data relative to a buffer and how to use it.
A star or object contained into a buffer.