35 double maxFreq,
double planeWidth,
int direction,
37 bool setPos=
false,
double rotPos=0,
double tiltPos=0)
39 if (rot<0 || rot>360 || tilt<-90 || tilt>90)
50 double angle=acos(E(2,0)*Epos(2,0)+E(2,1)*Epos(2,1)+E(2,2)*Epos(2,2));
52 if (fabs(angle)<20 || fabs(180-angle)<20)
61 double sumNeg=0, sumPos=0;
63 double maxFreq2=maxFreq*maxFreq;
64 auto iPlaneWidth=(int)ceil(planeWidth);
65 for (
int ix=0; ix<=N; ix++)
68 double fx2=
XX(freq)*
XX(freq);
71 for (
int iy=-(
int)N; iy<=N; iy++)
74 double fx2fy2=fx2+
YY(freq)*
YY(freq);
77 for (
int iz=-iPlaneWidth; iz<=iPlaneWidth; iz++)
79 if (iz==0 || ix==0 || iy==0)
113 if ((negativeSum && !inverted) || (!negativeSum && inverted))
118 (*Vdraw)(idx)=2*direction*val;
125 (*Vdraw)(idx)=1.0/2.0*direction*val;
130 if (fabs(Nneg-Npos)/(0.5*(Nneg+Npos))>0.5)
142 return -(sumPos-sumNeg);
151 double _maxFreq,
double _planeWidth,
int _direction):
174 std::cout <<
"Evaluations= " <<
count/
nPop 175 <<
" energy= " <<
Energy()
199 return wegde_solver->EnergyFunction(p+1,dummy);
204 double &rot,
double &tilt,
211 double min_allowed[] = {0,-90};
212 double max_allowed[] = {360,90};
214 auto * solver =
new WedgeSolver(length,length*Npop,V,Vmag,maxFreq,planeWidth,direction);
215 solver->Setup( min_allowed, max_allowed,
stBest2Bin, 0.5, 0.8);
233 x(0)=bestSolution[0];
234 x(1)=bestSolution[1];
265 if (
ZZ(freqPos)<0 ||
ZZ(freqNeg)>0)
273 fn_vol = getParam(
"-i");
274 maxFreq = getDoubleParam(
"--maxFreq");
276 saveMarks = checkParam(
"--saveMarks");
277 saveMask = checkParam(
"--saveMask");
296 std::cout <<
"Detecting a missing wedge\n";
297 std::cout <<
"Input volume: " << fn_vol << std::endl
298 <<
"Maximum Freq.: " <<
maxFreq << std::endl
300 <<
"saveMarks: " << saveMarks << std::endl
301 <<
"saveMask: " << saveMask << std::endl
308 addUsageLine(
"Detect the orientation of the missing wedge in a tomogram. ");
309 addUsageLine(
"+For doing so it fits a couple of planes along which there is a maximum ");
310 addUsageLine(
"+variation between the energy of the Fourier transform on its left and ");
311 addUsageLine(
"+on its right. The missing wedge is coded with four angles (two for each ");
312 addUsageLine(
"+plane). You may also produce a mask with 1 where the missing wedge is, ");
313 addUsageLine(
"+and 0 where the data has been actually measured. Finally, you can also ");
314 addUsageLine(
"+produce a marked magnitude volume (i.e., the magnitude of the Fourier ");
315 addUsageLine(
"+transform where the position of the two planes have been marked). ");
316 addParamsLine(
" -i <file> : Input tomogram");
317 addParamsLine(
" [--maxFreq <f=0.25>] : Maximum frequency to fit the plane (normalized to 0.5)");
318 addParamsLine(
" [--width <w=2>] : Width of the probe plane");
319 addParamsLine(
" [--saveMarks] : Save the magnitude of the FFT with");
320 addParamsLine(
" : marks showing the two planes");
321 addParamsLine(
" [--saveMask] : Save a mask for the FFT of this tomogram");
322 addParamsLine(
" : 1=Missing wedge, 0=non missing wedge");
323 addExampleLine(
"xmipp_tomo_detect_missing_wedge -i tomogram.vol");
330 FileName fn_root=
V.name().withoutExtension();
354 Vdraw->write(fn_root+
"_marks.vol");
361 Vdraw->write(fn_root+
"_mask.vol");
364 std::cout <<
"Plane1: " <<
rotPos <<
" " <<
tiltPos << std::endl;
365 std::cout <<
"Plane2: " << rotNeg <<
" " << tiltNeg << std::endl;
double Energy() const
Call these functions after Solve() to get results.
void readParams()
Read parameters from command line.
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void defineParams()
Usage.
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
double EnergyFunction(double trial[], bool &bAtSolution)
void drawWedge(double rotPos, double tiltPos, double rotNeg, double tiltNeg, const MultidimArray< double > *V, const MultidimArray< double > *Vmag, MultidimArray< double > *Vdraw)
#define MULTIDIM_ARRAY(v)
void abs(Image< double > &op)
void lookForPlane(const MultidimArray< double > *V, const MultidimArray< double > *Vmag, double maxFreq, double planeWidth, int direction, double &rot, double &tilt, bool setPos=false, double rotPos=0, double tiltPos=0)
Matrix2D< T > transpose() const
#define DIGFREQ2FFT_IDX(freq, size, idx)
void FFT_idx2digfreq(T &v, const Matrix1D< int > &idx, Matrix1D< double > &freq)
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
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
__host__ __device__ float length(float2 v)
void show() const
Show parameters.
const MultidimArray< double > * Vmag
void direction(const MultidimArray< double > &orMap, MultidimArray< double > &qualityMap, double lambda, int size, MultidimArray< double > &dirMap, int x, int y)
void log10(Image< double > &op)
double wrapperFitnessDetectMissingWedge(double *p, void *extraArgs)
WedgeSolver(int dim, int pop, const MultidimArray< double > *_V, const MultidimArray< double > *_Vmag, double _maxFreq, double _planeWidth, int _direction)
#define M3x3_BY_V3x1(a, M, b)
double evaluatePlane(double rot, double tilt, const MultidimArray< double > *V, const MultidimArray< double > *Vmag, double maxFreq, double planeWidth, int direction, MultidimArray< double > *Vdraw=nullptr, bool setPos=false, double rotPos=0, double tiltPos=0)
const MultidimArray< double > * V
#define VECTOR_R3(v, x, y, z)
void initZeros(const MultidimArray< T1 > &op)
double * Solution(void)
Return best solution.
double fitness(double *p)
#define SPEED_UP_temps012
void produceSideInfo()
Produce side info.
void pop(struct stack_T *stack)