EMAN2
Defines | Enumerations | Functions
reconstructor.cpp File Reference
#include "reconstructor.h"
#include "plugins/reconstructor_template.h"
#include "ctf.h"
#include "emassert.h"
#include "symmetry.h"
#include <cstring>
#include <fstream>
#include <iomanip>
#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <gsl/gsl_statistics_double.h>
#include <gsl/gsl_fit.h>
#include <iostream>
#include <algorithm>
#include <sstream>
Include dependency graph for reconstructor.cpp:

Go to the source code of this file.

Defines

#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]
#define tw(i, j, k)   tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Enumerations

enum  weighting_method { NONE, ESTIMATE, VORONOI }

Functions

template<typename T >
void checked_delete (T *&x)
float max2d (int kc, const vector< float > &pow_a)
float max3d (int kc, const vector< float > &pow_a)
void printImage (const EMData *line)
void circumf (EMData *win, int npad)
void circumf_rect (EMData *win, int npad)

Define Documentation

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

Referenced by circumf(), and circumf_rect().

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.

#define tw (   i,
  j,
 
)    tw[ i-1 + (j-1+(k-1)*iy)*ix ]

Definition at line 4219 of file reconstructor.cpp.


Enumeration Type Documentation

Enumerator:
NONE 
ESTIMATE 
VORONOI 

Definition at line 2046 of file reconstructor.cpp.


Function Documentation

template<typename T >
void checked_delete ( T *&  x)
void circumf ( EMData win,
int  npad 
)

Definition at line 2255 of file reconstructor.cpp.

References abs, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and tw.

Referenced by EMAN::nn4_ctfwReconstructor::finish(), EMAN::nn4_ctfReconstructor::finish(), and EMAN::nn4Reconstructor::finish().

{
        float *tw = win->get_data();
        //  correct for the fall-off
        //  mask and subtract circumference average
        int ix = win->get_xsize();
        int iy = win->get_ysize();
        int iz = win->get_zsize();
        int L2 = (ix/2)*(ix/2);
        int L2P = (ix/2-1)*(ix/2-1);

        int IP = ix/2+1;
        int JP = iy/2+1;
        int KP = iz/2+1;

        //  sinc functions tabulated for fall-off
        float* sincx = new float[IP+1];
        float* sincy = new float[JP+1];
        float* sincz = new float[KP+1];

        sincx[0] = 1.0f;
        sincy[0] = 1.0f;
        sincz[0] = 1.0f;

        float cdf = M_PI/float(npad*2*ix);
        for (int i = 1; i <= IP; ++i)  sincx[i] = sin(i*cdf)/(i*cdf);
        cdf = M_PI/float(npad*2*iy);
        for (int i = 1; i <= JP; ++i)  sincy[i] = sin(i*cdf)/(i*cdf);
        cdf = M_PI/float(npad*2*iz);
        for (int i = 1; i <= KP; ++i)  sincz[i] = sin(i*cdf)/(i*cdf);
        for (int k = 1; k <= iz; ++k) {
                int kkp = abs(k-KP);
                for (int j = 1; j <= iy; ++j) {
                        cdf = sincy[abs(j- JP)]*sincz[kkp];
                        for (int i = 1; i <= ix; ++i)  tw(i,j,k) /= (sincx[abs(i-IP)]*cdf);
                }
        }

        delete[] sincx;
        delete[] sincy;
        delete[] sincz;

        float  TNR = 0.0f;
        size_t m = 0;
        for (int k = 1; k <= iz; ++k) {
                for (int j = 1; j <= iy; ++j) {
                        for (int i = 1; i <= ix; ++i) {
                                size_t LR = (k-KP)*(k-KP)+(j-JP)*(j-JP)+(i-IP)*(i-IP);
                                if (LR >= (size_t)L2P && LR<=(size_t)L2) {
                                        TNR += tw(i,j,k);
                                        ++m;
                                }
                        }
                }
        }

        TNR /=float(m);
        
        
        for (int k = 1; k <= iz; ++k) {
                for (int j = 1; j <= iy; ++j) {
                        for (int i = 1; i <= ix; ++i) {
                                size_t LR = (k-KP)*(k-KP)+(j-JP)*(j-JP)+(i-IP)*(i-IP);
                                if (LR<=(size_t)L2) tw(i,j,k) -= TNR;
                                else                tw(i,j,k) = 0.0f;

                        }
                }
        }

}
void circumf_rect ( EMData win,
int  npad 
)

Definition at line 2682 of file reconstructor.cpp.

References abs, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and tw.

Referenced by EMAN::nn4_ctf_rectReconstructor::finish(), and EMAN::nn4_rectReconstructor::finish().

{
        float *tw = win->get_data();
        //  correct for the fall-off
        //  mask and subtract circumference average
        int ix = win->get_xsize();
        int iy = win->get_ysize();
        int iz = win->get_zsize();

        int IP = ix/2+1;
        int JP = iy/2+1;
        int KP = iz/2+1;
        
        //  sinc functions tabulated for fall-off
        float* sincx = new float[IP+1];
        float* sincy = new float[JP+1];
        float* sincz = new float[KP+1];

        sincx[0] = 1.0f;
        sincy[0] = 1.0f;
        sincz[0] = 1.0f;

        float cdf = M_PI/float(npad*2*ix);
        for (int i = 1; i <= IP; ++i)  sincx[i] = sin(i*cdf)/(i*cdf);
        cdf = M_PI/float(npad*2*iy);
        for (int i = 1; i <= JP; ++i)  sincy[i] = sin(i*cdf)/(i*cdf);
        cdf = M_PI/float(npad*2*iz);
        for (int i = 1; i <= KP; ++i)  sincz[i] = sin(i*cdf)/(i*cdf);
        for (int k = 1; k <= iz; ++k) {
                int kkp = abs(k-KP);
                for (int j = 1; j <= iy; ++j) {
                        cdf = sincy[abs(j- JP)]*sincz[kkp];
                        for (int i = 1; i <= ix; ++i)  tw(i,j,k) /= (sincx[abs(i-IP)]*cdf);
                }
        }

        delete[] sincx;
        delete[] sincy;
        delete[] sincz;
        
        
        
        float dxx = 1.0f/float(0.25*ix*ix);
        float dyy = 1.0f/float(0.25*iy*iy);
        
        
        
        float LR2=(float(ix)/2-1)*(float(ix)/2-1)*dxx;

        float  TNR = 0.0f;
        size_t m = 0;
        for (int k = 1; k <= iz; ++k) {
                for (int j = 1; j <= iy; ++j) {
                        for (int i = 1; i <= ix; ++i) {
                                float LR = (j-JP)*(j-JP)*dyy+(i-IP)*(i-IP)*dxx;
                                if (LR<=1.0f && LR >= LR2) {
                                        TNR += tw(i,j,k);
                                        ++m;
                                }
                        }
                }
        }

        TNR /=float(m);
        

        for (int k = 1; k <= iz; ++k) {
                for (int j = 1; j <= iy; ++j) {
                        for (int i = 1; i <= ix; ++i) {
                                float LR = (j-JP)*(j-JP)*dyy+(i-IP)*(i-IP)*dxx;
                                if (LR<=1.0f)  tw(i,j,k)=tw(i,j,k)-TNR;
                                else            tw(i,j,k) = 0.0f;       
                        }
                }
        }

}
float max2d ( int  kc,
const vector< float > &  pow_a 
)

Definition at line 2048 of file reconstructor.cpp.

References abs, and max.

Referenced by EMAN::nn4_rectReconstructor::finish(), and EMAN::nn4Reconstructor::finish().

{
        float max = 0.0;
        for( int i=-kc; i <= kc; ++i ) {
                for( int j=-kc; j <= kc; ++j ) {
                        if( i==0 && j==0 ) continue;
                        {
                                int c = 2*kc+1 - std::abs(i) - std::abs(j);
                                max = max + pow_a[c];
                        }
                }
        }
        return max;
}
float max3d ( int  kc,
const vector< float > &  pow_a 
)

Definition at line 2063 of file reconstructor.cpp.

References abs, and max.

Referenced by EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nn4_ctf_rectReconstructor::finish(), EMAN::nn4_ctfwReconstructor::finish(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::nn4_rectReconstructor::finish(), and EMAN::nn4Reconstructor::finish().

{
        float max = 0.0;
        for( int i=-kc; i <= kc; ++i ) {
                for( int j=-kc; j <= kc; ++j ) {
                        for( int k=-kc; k <= kc; ++k ) {
                                if( i==0 && j==0 && k==0 ) continue;
                                // if( i!=0 )
                                {
                                        int c = 3*kc+1 - std::abs(i) - std::abs(j) - std::abs(k);
                                        max = max + pow_a[c];
                                        // max = max + c * c;
                                        // max = max + c;
                                }
                        }
                }
        }
        return max;
}
void printImage ( const EMData line)

Definition at line 2168 of file reconstructor.cpp.

References Assert, EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nx, and ny.

{
        Assert( line->get_zsize()==1 );


        int nx = line->get_xsize();
        int ny = line->get_ysize();
        for( int j=0; j < ny; ++j ) {
                for( int i=0; i < nx; ++i )  printf( "%10.3f ", line->get_value_at(i,j) );
                printf( "\n" );
        }
}