50 addUsageLine(
"Validate a 3D reconstruction from its projections attending to directionality and spread of the angular assignments from a given significant value");
53 addParamsLine(
" [--untiltcoor <md_file=\"\">] : Untilt coordinates");
54 addParamsLine(
" [--tiltcoor <md_file=\"\">] : Tilt coordinates");
55 addParamsLine(
" [--tiltmicsize <img_file=\"\">] : Tilt micrography");
56 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
58 addParamsLine(
" [--tiltangle <s=-1>] : Tilt angle estimation, the method will look for the assignment in the interval of [tiltangle-15º, til_angle+15º]");
60 addParamsLine(
" [--threshold <d=0.3>] : If the distance between two points is lesser than threshold*particlesize, they will be the same point");
64 float t1y,
float t2x,
float t2y,
float t3x,
float t3y,
68 double estimator, dist;
69 struct Point_T t_dist, t_closest;
76 for (
int i=0;
i<6;
i++)
79 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t1x, t1y, t2x, t2y, t3x, t3y, A_matrix, T, invW);}
81 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t1x, t1y, t3x, t3y, t2x, t2y, A_matrix, T, invW);
83 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t2x, t2y, t1x, t1y, t3x, t3y, A_matrix, T, invW);
85 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t2x, t2y, t3x, t3y, t1x, t1y, A_matrix, T, invW);
87 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t3x, t3y, t1x, t1y, t2x, t2y, A_matrix, T, invW);
89 def_affinity(u1x, u1y, u2x, u2y, u3x, u3y, t3x, t3y, t2x, t2y, t1x, t1y, A_matrix, T, invW);
98 double discriminant_A = 0.25*trace_A*trace_A - det_A;
103 double sqrt_aux =
sqrt(discriminant_A);
104 double Eig_A1 = trace_A/2 + sqrt_aux;
105 double Eig_A2 = trace_A/2 - sqrt_aux;
107 if (Eig_A1<0.34 || Eig_A2<0.34 || fabs(Eig_A1-1)>0.05)
116 for (
size_t tt=0; tt<len_u; tt++)
120 t_test = A_matrix*
u + T;
144 for (
size_t kk=0; kk<len_u; kk++)
148 counter = counter + 1;
151 dist2 =
VEC_ELEM(dist_vec,kk) + dist2;
152 inliers2 = inliers2 + 1;
160 if (inliers2 > bestInliers)
162 estimator = dist2/inliers2;
163 bestInliers = inliers2;
165 if (bestInliers>0.3*thrs)
170 std::cout << bestInliers << std::endl;
172 else if ((inliers2 == bestInliers) && (dist2/inliers2 < estimator) )
174 estimator = dist2/inliers2;
210 const double u_max,
const double u_min)
212 double window_p, window_m;
213 window_p = u_max + 1.2*
mshift;
214 window_m = u_min - 1.2*
mshift;
217 if (((t1<window_p) && (t2<window_p) && (t3<window_p)) && ((t1>window_m) && (t2>window_m) && (t3>window_m)))
227 std::cout <<
"Starting..." << std::endl;
231 size_t Ndim, Zdim, Ydim , Xdim, objId;
236 bool flag_assign =
true;
241 if ((exist1 && exist2) ==
true)
246 int x,
y, len_u=0, len_t=0;
252 for (
size_t objId : md_untilt.
ids())
269 for (
size_t objId : md_tilt.
ids())
290 if (len_u == 0 || len_t == 0)
295 if (flag_assign ==
true)
302 struct Point_T p, q, r, u1, u2, u3, t1, t2, t3;
303 MultidimArray<double> trig_untilt_area(tri_number_untilt+1), trig_tilt_area(tri_number_tilt+1), sortedArea;
304 Matrix1D<double> trig_untilt_area_1D(tri_number_untilt+1), trig_tilt_area_1D(tri_number_tilt+1);
306 for (
int i=1;
i<tri_number_untilt+1 ;
i++)
312 for (
int i=1;
i<tri_number_tilt+1 ;
i++)
318 trig_untilt_area.sort(sortedArea);
320 double threshold_area = sortedArea(
round((tri_number_untilt+1)*0.2) );
324 int bestInliers=0, bestInliers_con=0;
328 struct Point_T t_dist, t_closest;
332 double tilt_max = (
tiltest + 15)*
PI/180, tilt_min = (
tiltest - 15)*
PI/180, cos_tilt_max, cos_tilt_min;
341 cos_tilt_max= cos(tilt_max);
342 cos_tilt_min= cos(tilt_min);
349 std::cerr <<
"Exploring triangle matching" << std::endl;
356 std::cerr <<
"Coarse Phase" << std::endl;
358 for (
int k=0;
k<tri_number_untilt;
k++)
360 if (trig_untilt_area(
k) < threshold_area)
363 for (
int j=0;
j<tri_number_tilt;
j++)
366 if (trig_untilt_area(
k) < trig_tilt_area(
j))
369 if ( (trig_untilt_area(
k)*cos_tilt_min < trig_tilt_area(
j)) || (trig_untilt_area(
k)*cos_tilt_max > trig_tilt_area(
j)) )
377 double ux_max, uy_max, ux_min, uy_min;
387 t1.
y, t2.
x, t2.
y, t3.
x, t3.
y,
388 ux, uy, Xdim, Ydim, delaunay_tilt, bestInliers,
389 A_coarse, T_coarse,
false, thrs);
394 std::cout <<
"Coarse Inliers = " << bestInliers << std::endl;
399 std::cerr <<
"Refinement Phase" << std::endl;
410 for (
int k=0;
k<len_u;
k++)
414 t_test = A_coarse*
u + T_coarse;
427 VEC_ELEM(t_clo,count+bestInliers) = t_closest.
y;
434 MAT_ELEM(invW2, count+bestInliers, 5) = 1;
451 if ((count >= bestInliers) && (count >= 0.2*thrs))
464 std::cout <<
"Best fitting is gotten using refinement phase" << std::endl;
465 std::cout <<
"Refinement Inliers = " << count << std::endl;
466 std::cout <<
"Coarse Inliers = " << bestInliers << std::endl;
467 std::cout <<
"A" << def_A << std::endl;
468 std::cout <<
"---------------------------" << std::endl;
469 std::cout <<
"T" << def_T << std::endl;
472 if (((count <= bestInliers) && (bestInliers >= 0.2*thrs)) && !flag)
474 std::cout <<
"Best fitting is gotten using coarse phase" << std::endl;
475 std::cout <<
"Coarse Inliers = " << bestInliers << std::endl;
476 std::cout <<
"Refinement Inliers = " << count << std::endl;
479 std::cout <<
"A" << def_A << std::endl;
480 std::cout <<
"---------------------------" << std::endl;
481 std::cout <<
"T" << def_T << std::endl;
484 if (((count <=bestInliers || count >=bestInliers) && ((count < 0.2*thrs) || (bestInliers < 0.2*thrs))) && !flag)
486 std::cerr <<
" Matching not found" << std::endl;
487 std::cerr <<
" Starting contingency method" << std::endl;
488 std::cerr <<
" This phase can take a long time" << std::endl;
491 double window_t=window *(1-0.34);
492 std::vector<Matrix1D<double> > allTrianglesU;
494 for (
int k = 0;
k< len_u;
k++)
498 for (
int j=
k+1;
j<len_u;
j++)
505 for (
int l=
j+1; l<len_u; l++)
511 VEC_ELEM(triangleu,6) =
triangle_area(
VEC_ELEM(ux,
k),
VEC_ELEM(uy,
k),
VEC_ELEM(ux,
j),
VEC_ELEM(uy,
j),
VEC_ELEM(ux,l),
VEC_ELEM(uy,l));
512 if (
VEC_ELEM(triangleu,6) < threshold_area)
517 allTrianglesU.push_back(triangleu);
522 std::vector<Matrix1D<double> > allTrianglesT;
524 for (
int k = 0;
k< len_t;
k++)
528 for (
int j=
k+1;
j<len_t;
j++)
535 for (
int l=
j+1; l<len_t; l++)
540 VEC_ELEM(trianglet,6) =
triangle_area(
VEC_ELEM(tx,
k),
VEC_ELEM(ty,
k),
VEC_ELEM(tx,
j),
VEC_ELEM(ty,
j),
VEC_ELEM(tx,l),
VEC_ELEM(ty,l));
543 allTrianglesT.push_back(trianglet);
550 for (
size_t ku=0; ku<allTrianglesU.size(); ku++)
555 for (
size_t kt=0; kt<allTrianglesT.size(); kt++)
565 ux, uy, Xdim, Ydim, delaunay_tilt, bestInliers_con,
566 A_con, T_con,
true, thrs);
569 std::cout <<
"Contingency Inliers = " << bestInliers_con << std::endl;
570 if ((bestInliers_con > bestInliers) && (bestInliers_con>count))
572 std::cout <<
"Best fitting is gotten using contingency phase" << std::endl;
573 std::cout <<
"Contingency Inliers = " << bestInliers_con << std::endl;
574 std::cout <<
"Refinement Inliers = " << count << std::endl;
577 std::cout <<
"A" << def_A << std::endl;
578 std::cout <<
"---------------------------" << std::endl;
579 std::cout <<
"T" << def_T << std::endl;
590 for (
int k=0;
k<len_u;
k++)
594 t_test = def_A*
u + def_T;
622 std::cout <<
"WARNING: input pos. file does not exist, therefore output files are empty" << std::endl;
624 if (flag_assign ==
false)
626 std::cout <<
"WARNING: input pos file is empty." << std::endl;
void init_progress_bar(long total)
double getDoubleParam(const char *param, int arg=0)
void def_affinity(double u1x, double u1y, double u2x, double u2y, double u3x, double u3y, double t1x, double t1y, double t2x, double t2y, double t3x, double t3y, Matrix2D< double > &A, Matrix1D< double > &T, Matrix2D< double > &invW)
void sqrt(Image< double > &op)
void delete_Delaunay(struct Delaunay_T *delaunay)
int get_Face_Points(struct Delaunay_T *delaunay, int face_ID, struct Point_T *p, struct Point_T *q, struct Point_T *r)
void search_affine_transform(float u1x, float u1y, float u2x, float u2y, float u3x, float u3y, float t1x, float t1y, float t2x, float t2y, float t3x, float t3y, const Matrix1D< double > &ux, const Matrix1D< double > &uy, size_t Xdim, size_t Ydim, struct Delaunay_T &delaunay_tilt, int &bestInliers, Matrix2D< double > &A_coarse, Matrix1D< double > &T_coarse, bool contingency, int thrs)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
int insert_Point(struct Delaunay_T *delaunay, double x, double y)
double triangle_area(double x1, double y1, double x2, double y2, double x3, double y3)
#define MAT_ELEM(m, i, j)
void findMaximumMinimum(const float u1, const float u2, const float u3, double &u_max, double &u_min)
const char * getParam(const char *param, int arg=0)
bool select_Closest_Point(struct Delaunay_T *delaunay, struct Point_T *p, struct Point_T *q, double *lowest_Distance)
void progress_bar(long rlen)
int write_DCEL(struct DCEL_T *dcel, int type, const char *fileName)
int verbose
Verbosity level.
void solveLinearSystem(PseudoInverseHelper &h, Matrix1D< double > &result)
int get_Number_Real_Faces(struct DCEL_T *dcel)
int init_Delaunay(struct Delaunay_T *delaunay, int nPoints)
int create_Delaunay_Triangulation(struct Delaunay_T *delaunay, int createVoronoi)
void addUsageLine(const char *line, bool verbatim=false)
FileName getBaseName() const
bool checkwindow(const float t1, const float t2, const float t3, const double u_max, const double u_min)
void addParamsLine(const String &line)