// Produce side info ------------------------------------------------------- void ProgDetectMissingWedge::produceSideInfo() { V.read(fn_vol); FourierTransformer transformer; MultidimArray< std::complex<double> > Vfft; transformer.FourierTransform(MULTIDIM_ARRAY(V),Vfft,false); Vmag = new MultidimArray<double>(); Vmag->resize(Vfft); FOR_ALL_ELEMENTS_IN_ARRAY3D(*Vmag) (*Vmag)(k,i,j)=20*log10(abs(Vfft(k,i,j))); }
//#define DEBUG void spatial_Bspline032voxels(const GridVolume &vol_splines, MultidimArray<double> *vol_voxels, int Zdim, int Ydim, int Xdim) { // Resize and set starting corner ....................................... if (Zdim == 0 || Ydim == 0 || Xdim == 0) { Matrix1D<double> size = vol_splines.grid(0).highest - vol_splines.grid(0).lowest; Matrix1D<double> corner = vol_splines.grid(0).lowest; (*vol_voxels).initZeros(CEIL(ZZ(size)), CEIL(YY(size)), CEIL(XX(size))); STARTINGX(*vol_voxels) = FLOOR(XX(corner)); STARTINGY(*vol_voxels) = FLOOR(YY(corner)); STARTINGZ(*vol_voxels) = FLOOR(ZZ(corner)); } else { (*vol_voxels).initZeros(Zdim, Ydim, Xdim); (*vol_voxels).setXmippOrigin(); } // Convert each subvolume ............................................... for (size_t i = 0; i < vol_splines.VolumesNo(); i++) { spatial_Bspline032voxels_SimpleGrid(vol_splines(i)(), vol_splines.grid(i), vol_voxels); #ifdef DEBUG std::cout << "Spline grid no " << i << " stats: "; vol_splines(i)().printStats(); std::cout << std::endl; std::cout << "So far vol stats: "; (*vol_voxels).printStats(); std::cout << std::endl; VolumeXmipp save; save() = *vol_voxels; save.write((std::string)"PPPvoxels" + integerToString(i)); #endif } // Now normalise the resulting volume .................................. double inorm = 1.0 / sum_spatial_Bspline03_Grid(vol_splines.grid()); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) A3D_ELEM(*vol_voxels, k, i, j) *= inorm; // Set voxels outside interest region to minimum value ................. double R = vol_splines.grid(0).get_interest_radius(); if (R != -1) { double R2 = (R - 6) * (R - 6); // Compute minimum value within sphere double min_val = A3D_ELEM(*vol_voxels, 0, 0, 0); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) if (j*j + i*i + k*k <= R2 - 4) min_val = XMIPP_MIN(min_val, A3D_ELEM(*vol_voxels, k, i, j)); // Substitute minimum value R2 = (R - 2) * (R - 2); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) if (j*j + i*i + k*k >= R2) A3D_ELEM(*vol_voxels, k, i, j) = min_val; }
// Fill data array with oversampled Fourier transform, and calculate its power spectrum void Projector::computeFourierTransformMap(MultidimArray<DOUBLE> &vol_in, MultidimArray<DOUBLE> &power_spectrum, int current_size, int nr_threads, bool do_gridding) { MultidimArray<DOUBLE> Mpad; MultidimArray<Complex > Faux; FourierTransformer transformer; // DEBUGGING: multi-threaded FFTWs are giving me a headache? // For a long while: switch them off! //transformer.setThreadsNumber(nr_threads); DOUBLE normfft; // Size of padded real-space volume int padoridim = padding_factor * ori_size; // Initialize data array of the oversampled transform ref_dim = vol_in.getDim(); // Make Mpad switch (ref_dim) { case 2: Mpad.initZeros(padoridim, padoridim); normfft = (DOUBLE)(padding_factor * padding_factor); break; case 3: Mpad.initZeros(padoridim, padoridim, padoridim); if (data_dim ==3) normfft = (DOUBLE)(padding_factor * padding_factor * padding_factor); else normfft = (DOUBLE)(padding_factor * padding_factor * padding_factor * ori_size); break; default: REPORT_ERROR("Projector::computeFourierTransformMap%%ERROR: Dimension of the data array should be 2 or 3"); } // First do a gridding pre-correction on the real-space map: // Divide by the inverse Fourier transform of the interpolator in Fourier-space // 10feb11: at least in 2D case, this seems to be the wrong thing to do!!! // TODO: check what is best for subtomo! if (do_gridding)// && data_dim != 3) griddingCorrect(vol_in); // Pad translated map with zeros vol_in.setXmippOrigin(); Mpad.setXmippOrigin(); FOR_ALL_ELEMENTS_IN_ARRAY3D(vol_in) // This will also work for 2D A3D_ELEM(Mpad, k, i, j) = A3D_ELEM(vol_in, k, i, j); // Translate padded map to put origin of FT in the center CenterFFT(Mpad, true); // Calculate the oversampled Fourier transform transformer.FourierTransform(Mpad, Faux, false); // Free memory: Mpad no longer needed Mpad.clear(); // Resize data array to the right size and initialise to zero initZeros(current_size); // Fill data only for those points with distance to origin less than max_r // (other points will be zero because of initZeros() call above // Also calculate radial power spectrum power_spectrum.initZeros(ori_size / 2 + 1); MultidimArray<DOUBLE> counter(power_spectrum); counter.initZeros(); int max_r2 = r_max * r_max * padding_factor * padding_factor; FOR_ALL_ELEMENTS_IN_FFTW_TRANSFORM(Faux) // This will also work for 2D { int r2 = kp*kp + ip*ip + jp*jp; // The Fourier Transforms are all "normalised" for 2D transforms of size = ori_size x ori_size if (r2 <= max_r2) { // Set data array A3D_ELEM(data, kp, ip, jp) = DIRECT_A3D_ELEM(Faux, k, i, j) * normfft; // Calculate power spectrum int ires = ROUND( sqrt((DOUBLE)r2) / padding_factor ); // Factor two because of two-dimensionality of the complex plane DIRECT_A1D_ELEM(power_spectrum, ires) += norm(A3D_ELEM(data, kp, ip, jp)) / 2.; DIRECT_A1D_ELEM(counter, ires) += 1.; } } // Calculate radial average of power spectrum FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(power_spectrum) { if (DIRECT_A1D_ELEM(counter, i) < 1.) DIRECT_A1D_ELEM(power_spectrum, i) = 0.; else DIRECT_A1D_ELEM(power_spectrum, i) /= DIRECT_A1D_ELEM(counter, i); } transformer.cleanup(); }