26 double* a1 = (
double*)arg1;
27 double* a2 = (
double*)arg2;
28 return ((*a1) < (*a2) ? 1 : -1);
33 double* a1 = (
double*)arg1;
34 double* a2 = (
double*)arg2;
35 return ((*a1) > (*a2) ? 1 : -1);
60 double size1 = t1.
sizes[0];
62 err += fabs((size1 - size2)/size1);
63 for(d = 1; d < align_info.
dims; d ++) {
64 double size1 = t1.
sizes[d-1];
65 double size2 = t2.
sizes[d-1]/align_info.
factor[d-1];
70 double x2 = _x2*cos(align_info.
radians[d-1])+_y2*sin(align_info.
radians[d-1]);
71 double y2 = _y2*cos(align_info.
radians[d-1])-_x2*sin(align_info.
radians[d-1]);
72 x2 /= align_info.
factor[d-1];
73 y2 /= align_info.
factor[d];
74 err += fabs(((x2-x1)+(y2-y1)+(size2-size1))/size1);
76 for(d = 1 ; d < t1.
dims; d++) {
80 return err / (align_info.
dims + t1.
dims);
86 int dims = t1.
dims - 1;
88 align_info.
dims = dims;
89 align_info.
center = (
double*)malloc(
sizeof(
double)*(dims));
90 align_info.
offset = (
double*)malloc(
sizeof(
double)*(dims));
91 align_info.
radians = (
double*)malloc(
sizeof(
double)*(dims-1));
92 align_info.
factor = (
double*)malloc(
sizeof(
double)*(dims));
93 for(d = 0; d < dims; d++) {
100 for(d = 0; d < dims; d++) {
105 if(align_info.
radians[d] >= M_PI*2.0)
106 align_info.
radians[d] -= M_PI*2.0;
107 if(align_info.
radians[d] < 0.0)
108 align_info.
radians[d] += M_PI*2.0;
110 for(x = 0; x < t2.
dims; x++) {
115 align_info.
score = calc_match_score(t1, t2, align_info);
125 double *delta = (
double*)malloc(
sizeof(
double)*triangle.
dims);
126 double **diff = (
double**)malloc(
sizeof(
double*)*triangle.
dims);
127 triangle.
sizes = (
double*)malloc(
sizeof(
double)*triangle.
dims);
128 triangle.
ratios = (
double*)malloc(
sizeof(
double)*triangle.
dims);
130 triangle.
theta = (
double*)malloc(
sizeof(
double)*(triangle.
dims-1));
131 triangle.
index = 0.0;
133 for(d = 0; d < triangle.
dims; d++) {
134 diff[d] = (
double*)malloc(
sizeof(
double)*stars[d].
center.
dims);
135 for(x = 0; x < triangle.
dims-1; x++) {
137 delta[d] += pow(diff[d][x], 2);
139 delta[d] = sqrt(delta[d]);
141 for(d = 0; d < triangle.
dims; d++) {
142 for(x = 0; x < stars[0].
center.
dims - 1; x++) {
144 triangle.
theta[x] = acos(diff[d][x] / delta[d]);
147 if(triangle.
theta[x] >= M_PI*2.0)
148 triangle.
theta[x] -= M_PI*2.0;
149 if(triangle.
theta[x] < 0)
150 triangle.
theta[x] += M_PI*2.0;
152 double index = acos(diff[d][x] / delta[d]);
155 index -= triangle.
theta[x];
156 triangle.
index += index;
160 while(triangle.
index >= M_PI)
161 triangle.
index -= M_PI*2.0;
162 while(triangle.
index < -M_PI)
163 triangle.
index += M_PI*2.0;
165 for(d = 0; d < triangle.
dims; d++) {
169 triangle.
sizes[d] = delta[d];
170 triangle.
ratios[d] = delta[d] / delta[0];
184 double decimals = pow(10, tolerance);
188 int dims = stream1->
dims+1;
189 double min_score = 1.0;
190 double ratio = decimals*1600.0/div;
192 for(d = 0; d < stream1->
dims; d++) {
193 div += pow(stream2->
sizes[d], 2);
196 pwarn(
"decimals: %lf\n", decimals);
197 target_score = 1.0-target_score/100.0;
201 pgarb(
"creating triangles for reference frame...\n");
204 for(y = x+1; y < stream1->
stars_count-dims+1; y++) {
205 for(d = 0; d < dims; d++) {
206 stars[d] = stream1->
stars[y+d];
212 pgarb(
"creating triangles for current frame...\n");
216 for(d = 0; d < dims; d++) {
217 stars[d] = stream2->
stars[y+d];
227 if(align_info.
score < min_score) {
229 min_score = align_info.
score;
236 for(d = 0; d < stream1->
dims; d++) {
241 if(min_score < target_score)
243 if(fabs(phi * ratio * 10.0) < 1.0)
247 if(fabs(radians) * decimals * 10.0 < 1)
#define DSP_ALIGN_ROTATED
The stream is rotated by the reference.
#define DSP_ALIGN_NO_MATCH
No matches were found during comparison.
#define DSP_ALIGN_SCALED
The stream is scaled by the reference.
#define DSP_ALIGN_TRANSLATED
The stream is translated by the reference.
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 * 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 * ratios
The sizes of the triangle.
double * offset
Translation offset.
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_qsort_double_asc(const void *arg1, const void *arg2)
Callback function for qsort for double type ascending ordering.
dsp_align_info dsp_align_fill_info(dsp_triangle t1, dsp_triangle t2)
Fill a dsp_align_info struct by comparing two triangles.
int dsp_align_get_offset(dsp_stream_p stream1, dsp_stream_p stream2, double tolerance, double target_score)
Calculate offsets, rotation and scaling of two streams giving reference alignment point.
int dsp_qsort_star_diameter_asc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star ascending ordering by their diameters.
int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star descending ordering by their diameters.
int dsp_qsort_double_desc(const void *arg1, const void *arg2)
Callback function for qsort for double type descending ordering.
dsp_triangle dsp_align_calc_triangle(dsp_star *stars)
Create a dsp_triangle struct.
Alignment informations needed.
A star or object contained into a buffer.
Contains a set of informations and data relative to a buffer and how to use it.
A star or object contained into a buffer.