EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
EMAN::nnSSNR_ctfReconstructor Class Reference

#include <reconstructor.h>

Inheritance diagram for EMAN::nnSSNR_ctfReconstructor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::nnSSNR_ctfReconstructor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nnSSNR_ctfReconstructor ()
 nnSSNR_ctfReconstructor (const string &symmetry, int size, int npad, float snr, int sign)
 ~nnSSNR_ctfReconstructor ()
virtual void setup ()
 Initialize the reconstructor.
virtual int insert_slice (const EMData *const slice, const Transform &euler, const float weight)
 Insert a slice into a 3D volume, in a given orientation.
virtual EMDatafinish (bool doift=true)
 Finish reconstruction and return the complete model.
virtual string get_name () const
 Get the unique name of this class (especially for factory based instantiation access)
virtual string get_desc () const
 Get a clear, concise description of this class.
TypeDict get_param_types () const
void setup (const string &symmetry, int size, int npad, float snr, int sign)
int insert_padfft_slice (EMData *padded, const Transform &trans, float mult=1)

Static Public Member Functions

static ReconstructorNEW ()

Static Public Attributes

static const string NAME = "nnSSNR_ctf"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()
void buildNorm2Volume ()
void buildNorm3Volume ()

Private Attributes

EMDatam_volume
EMDatam_wptr
EMDatam_wptr2
EMDatam_wptr3
string m_symmetry
int m_weighting
int m_vnx
int m_vny
int m_vnz
int m_npad
int m_nsym
int m_vnzp
int m_vnyp
int m_vnxp
int m_vnzc
int m_vnyc
int m_vnxc
float m_wghta
float m_wghtb
int m_sign
float m_snr
int wiener

Detailed Description

Definition at line 1494 of file reconstructor.h.


Constructor & Destructor Documentation

nnSSNR_ctfReconstructor::nnSSNR_ctfReconstructor ( )

Definition at line 4068 of file reconstructor.cpp.

References m_volume, m_wptr, m_wptr2, and m_wptr3.

Referenced by NEW().

{
        m_volume  = NULL;
        m_wptr    = NULL;
        m_wptr2   = NULL;
        m_wptr3   = NULL;
}
nnSSNR_ctfReconstructor::nnSSNR_ctfReconstructor ( const string &  symmetry,
int  size,
int  npad,
float  snr,
int  sign 
)

Definition at line 4076 of file reconstructor.cpp.

References m_volume, m_wptr, m_wptr2, m_wptr3, and setup().

{
        m_volume  = NULL;
        m_wptr    = NULL;
        m_wptr2   = NULL;
        m_wptr3   = NULL;

        setup( symmetry, size, npad, snr, sign );
}
nnSSNR_ctfReconstructor::~nnSSNR_ctfReconstructor ( )

Definition at line 4086 of file reconstructor.cpp.

{

        //if( m_delete_volume )  checked_delete(m_volume);
        //if( m_delete_weight )  checked_delete( m_wptr );
        //if( m_delete_weight2 ) checked_delete( m_wptr2 );
        //if( m_delete_weight3 ) checked_delete( m_wptr3 );
        //checked_delete( m_result );
}

Member Function Documentation

void nnSSNR_ctfReconstructor::buildFFTVolume ( ) [private]
void nnSSNR_ctfReconstructor::buildNorm2Volume ( ) [private]
void nnSSNR_ctfReconstructor::buildNorm3Volume ( ) [private]
void nnSSNR_ctfReconstructor::buildNormVolume ( ) [private]
EMData * nnSSNR_ctfReconstructor::finish ( bool  doift = true) [virtual]

Finish reconstruction and return the complete model.

Parameters:
doiftA flag indicating whether the returned object should be guaranteed to be in real-space (true) or should be left in whatever space the reconstructor generated
Returns:
The result 3D model.

Reimplemented from EMAN::Reconstructor.

Definition at line 4220 of file reconstructor.cpp.

References abs, EMAN::EMData::cmplx(), ESTIMATE, m_vnxc, m_vnxp, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, m_wptr2, m_wptr3, max, max3d(), nn(), norm(), EMAN::FactoryBase::params, EMAN::Util::round(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::symplane2(), EMAN::EMData::to_zero(), and EMAN::EMData::update().

{
/*
  I changed the code on 05/15/2008 so it only returns variance.
  Lines commented out are marked by //#
  The version prior to the currect changes is r1.190
  PAP
*/
        /***
            m_volume ctf*(P^2D->3D(F^3D))
            m_wptr   ctf^2
            m_wptr2  |P^2D->3D(F^3D)|^2
            m_wptr3  Kn
            nominator = sum_rot [ wght*signal ]
            denominator  = sum_rot[ wght*variance ]
                                                      ***/
        int kz, ky;
        int box = 7;
        int kc  = (box-1)/2;
        float alpha = 0.0;
        float argx, argy, argz;
        vector< float > pow_a( 3*kc+1, 1.0 );
        float w = params["w"];
        float dx2 = 1.0f/float(m_vnxc)/float(m_vnxc);
        float dy2 = 1.0f/float(m_vnyc)/float(m_vnyc);
#ifdef  _WIN32
        float dz2 = 1.0f/_cpp_max(float(m_vnzc),1.0f)/_cpp_max(float(m_vnzc),1.0f);
        int inc = Util::round(float(_cpp_max(_cpp_max(m_vnxc,m_vnyc),m_vnzc))/w);
#else
        float dz2 = 1.0f/std::max(float(m_vnzc),1.0f)/std::max(float(m_vnzc),1.0f);
        int inc = Util::round(float(std::max(std::max(m_vnxc,m_vnyc),m_vnzc))/w);
#endif  //_WIN32

        EMData* SSNR = params["SSNR"];
        SSNR->set_size(inc+1,4,1);
        //#EMData* vol_ssnr = new EMData();
        //#vol_ssnr->set_size(m_vnxp, m_vnyp, m_vnzp);
        //#vol_ssnr->to_zero();
        //#  new linea follow
        EMData* vol_ssnr = params["vol_ssnr"];
        vol_ssnr->set_size(m_vnxp+ 2 - m_vnxp%2, m_vnyp ,m_vnzp);
        vol_ssnr->to_zero();
        if ( m_vnxp % 2 == 0 ) vol_ssnr->set_fftodd(0);
        else                   vol_ssnr->set_fftodd(1);
        vol_ssnr->set_nxc(m_vnxc);
        vol_ssnr->set_complex(true);
        vol_ssnr->set_ri(true);
        vol_ssnr->set_fftpad(false);
        //#
        float *nom    = new float[inc+1];
        float *denom  = new float[inc+1];
        int  *ka     = new int[inc+1];
        int  *nn     = new int[inc+1];
        float wght = 1.f;
        for (int i = 0; i <= inc; i++) {
                nom[i]   = 0.0f;
                denom[i] = 0.0f;
                nn[i]    = 0;
                ka[i]    = 0;
        }
        m_volume->symplane2(m_wptr, m_wptr2, m_wptr3);
        if ( m_weighting == ESTIMATE ) {
                int vol = box*box*box;
                for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
                pow_a[3*kc] = 0.0;
                float max = max3d( kc, pow_a );
                alpha = ( 1.0f - 1.0f/(float)vol ) / max;
        }
        for (int iz = 1; iz <= m_vnzp; iz++) {
                if ( iz-1 > m_vnzc ) kz = iz-1-m_vnzp; else kz = iz-1;
                argz = float(kz*kz)*dz2;
                for (int iy = 1; iy <= m_vnyp; iy++) {
                        if ( iy-1 > m_vnyc ) ky = iy-1-m_vnyp; else ky = iy-1;
                        argy = argz + float(ky*ky)*dy2;
                        for (int ix = 0; ix <= m_vnxc; ix++) {
                                float Kn = (*m_wptr3)(ix,iy,iz);
                                argx = std::sqrt(argy + float(ix*ix)*dx2);
                                int r = Util::round(float(inc)*argx);
                                if ( r >= 0 && Kn > 4.5f ) {
                                        if ( m_weighting == ESTIMATE ) {
                                                int cx = ix;
                                                int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
                                                int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
                                                float sum = 0.0;
                                                for( int ii = -kc; ii <= kc; ++ii ) {
                                                        int nbrcx = cx + ii;
                                                        if( nbrcx >= m_vnxc ) continue;
                                                        for ( int jj= -kc; jj <= kc; ++jj ) {
                                                                int nbrcy = cy + jj;
                                                                if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
                                                                for( int kk = -kc; kk <= kc; ++kk ) {
                                                                        int nbrcz = cz + jj;
                                                                        if ( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
                                                                        if( nbrcx < 0 ) {
                                                                                nbrcx = -nbrcx;
                                                                                nbrcy = -nbrcy;
                                                                                nbrcz = -nbrcz;
                                                                        }
                                                                        int nbrix = nbrcx;
                                                                        int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
                                                                        int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
                                                                        if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
                                                                                int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
                                                                                sum = sum + pow_a[c];
                                                                        }
                                                                }
                                                        }
                                                }
//                                              int r = std::abs(cx) + std::abs(cy) + std::abs(cz);
                                                wght = 1.0f / ( 1.0f - alpha * sum );
                                        } // end of ( m_weighting == ESTIMATE )
                                        float nominator   = std::norm(m_volume->cmplx(ix,iy,iz))/(*m_wptr)(ix,iy,iz);
                                        float denominator = ((*m_wptr2)(ix,iy,iz)-std::norm(m_volume->cmplx(ix,iy,iz))/(*m_wptr)(ix,iy,iz))/(Kn-1.0f);
                                        // Skip Friedel related values
                                        if( (ix>0 || (kz>=0 && (ky>=0 || kz!=0)))) {
                                                if ( r <= inc ) {
                                                        nom[r]   += nominator*wght;
                                                        denom[r] += denominator/(*m_wptr)(ix,iy,iz)*wght;
                                                        nn[r]    += 2;
                                                        ka[r]    += int(Kn);
                                                }
/*
#ifdef  _WIN32
                                                float  tmp = _cpp_max(nominator/denominator/(*m_wptr)(ix,iy,iz)-1.0f,0.0f);
#else
                                                float  tmp = std::max(nominator/denominator/(*m_wptr)(ix,iy,iz)-1.0f,0.0f);
#endif  //_WIN32
                                                //  Create SSNR as a 3D array (-n/2:n/2+n%2-1)
                                                int iix = m_vnxc + ix; int iiy = m_vnyc + ky; int iiz = m_vnzc + kz;
                                                if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
                                                        (*vol_ssnr)(iix, iiy, iiz) = tmp;
                                                // Friedel part
                                                iix = m_vnxc - ix; iiy = m_vnyc - ky; iiz = m_vnzc - kz;
                                                if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
                                                        (*vol_ssnr)(iix, iiy, iiz) = tmp;
*/
                                        }
                                        (*vol_ssnr)(2*ix, iy-1, iz-1) = denominator*wght;
                                } // end of Kn>4.5 or whatever
                        }
                }
        }
        for (int i = 0; i <= inc; i++) {
                (*SSNR)(i,0,0) = nom[i];
                (*SSNR)(i,1,0) = denom[i];
                (*SSNR)(i,2,0) = static_cast<float>(nn[i]);
                (*SSNR)(i,3,0) = static_cast<float>(ka[i]);
        }
        vol_ssnr->update();

        delete[] nom;
        delete[] denom;
        delete[] nn;
        delete[] ka;

        return 0;
}
virtual string EMAN::nnSSNR_ctfReconstructor::get_desc ( ) const [inline, virtual]

Get a clear, concise description of this class.

Returns:
a clear, concise description of this class

Implements EMAN::FactoryBase.

Definition at line 1525 of file reconstructor.h.

                {
                        return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
                }
virtual string EMAN::nnSSNR_ctfReconstructor::get_name ( ) const [inline, virtual]

Get the unique name of this class (especially for factory based instantiation access)

Returns:
the unique name of this class

Implements EMAN::FactoryBase.

Definition at line 1520 of file reconstructor.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::nnSSNR_ctfReconstructor::get_param_types ( ) const [inline, virtual]
Returns:
a TypeDict defining and describing the feasible parameters of this class

Implements EMAN::FactoryBase.

Definition at line 1535 of file reconstructor.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

                {
                        TypeDict d;
                        d.put("size",     EMObject::INT);
                        d.put("npad",     EMObject::INT);
                        d.put("symmetry", EMObject::STRING);
                        d.put("fftvol",   EMObject::EMDATA);
                        d.put("fftwvol",  EMObject::EMDATA);
                        d.put("weight",   EMObject::EMDATA);
                        d.put("weight2",  EMObject::EMDATA);
                        d.put("weight3",  EMObject::EMDATA);
                        d.put("SSNR",     EMObject::EMDATA);
                        d.put("vol_ssnr", EMObject::EMDATA);
                        d.put("w",        EMObject::FLOAT);
                        d.put("sign",     EMObject::INT);
                        d.put("snr",      EMObject::FLOAT);
                        return d;
                }
int nnSSNR_ctfReconstructor::insert_padfft_slice ( EMData padded,
const Transform trans,
float  mult = 1 
)

Definition at line 4208 of file reconstructor.cpp.

References EMAN::Transform::get_sym(), m_nsym, m_symmetry, m_volume, m_wptr, m_wptr2, m_wptr3, and EMAN::EMData::nn_SSNR_ctf().

Referenced by insert_slice().

{

        // insert slice for all symmetry related positions
        for (int isym=0; isym < m_nsym; isym++) {
                Transform tsym = t.get_sym(m_symmetry, isym);
                m_volume->nn_SSNR_ctf(m_wptr, m_wptr2, m_wptr3, padfft, tsym, weight);
        }
        return 0;
}
int nnSSNR_ctfReconstructor::insert_slice ( const EMData *const  slice,
const Transform euler,
const float  weight 
) [virtual]

Insert a slice into a 3D volume, in a given orientation.

Returns:
0 if successful, 1 otherwise
Parameters:
slicethe image slice to be inserted into the 3D volume
eulerEuler angle of this image slice.
weightA weighting factor for this slice, generally the number of particles in a class-average. May be ignored by some reconstructors
Returns:
0 if OK. 1 if error.
Exceptions:
NullPointerExceptionif the input EMData pointer is null
ImageFormatExceptionif the image is complex as opposed to real

Reimplemented from EMAN::Reconstructor.

Definition at line 4184 of file reconstructor.cpp.

References checked_delete(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), insert_padfft_slice(), LOGERR, m_npad, m_vnx, and EMAN::padfft_slice().

                                                                                                            {
        // sanity checks
        if (!slice) {
                LOGERR("try to insert NULL slice");
                return 1;
        }
        if( weight > 0.0f ) {
                int padffted= slice->get_attr_default("padffted", 0);
                if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx)  ) {
                        // FIXME: Why doesn't this throw an exception?
                        LOGERR("Tried to insert a slice that is the wrong size.");
                        return 1;
                }
                EMData* padfft = NULL;

                if( padffted != 0 )  padfft = new EMData(*slice);
                else                 padfft = padfft_slice( slice, t, m_npad );

                insert_padfft_slice( padfft, t, weight );

                checked_delete( padfft );
        }
        return 0;
}
static Reconstructor* EMAN::nnSSNR_ctfReconstructor::NEW ( ) [inline, static]

Definition at line 1530 of file reconstructor.h.

References nnSSNR_ctfReconstructor().

                {
                        return new nnSSNR_ctfReconstructor();
                }
void nnSSNR_ctfReconstructor::setup ( ) [virtual]

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 4096 of file reconstructor.cpp.

References EMAN::Dict::has_key(), EMAN::FactoryBase::params, sign, and EMAN::Gatan::to_str().

Referenced by nnSSNR_ctfReconstructor().

{
        int  size = params["size"];
        int  npad = params["npad"];
        int  sign = params["sign"];
        float snr = params["snr"];
        string symmetry;
        if( params.has_key("symmetry") )  symmetry = params["symmetry"].to_str();
        else                              symmetry = "c1";
        
        setup( symmetry, size, npad, snr, sign );
}
void nnSSNR_ctfReconstructor::setup ( const string &  symmetry,
int  size,
int  npad,
float  snr,
int  sign 
)

Member Data Documentation

Definition at line 1567 of file reconstructor.h.

Referenced by buildFFTVolume(), insert_slice(), and setup().

Definition at line 1568 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1577 of file reconstructor.h.

Referenced by setup().

Definition at line 1578 of file reconstructor.h.

Referenced by setup().

Definition at line 1564 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1566 of file reconstructor.h.

Referenced by insert_slice(), and setup().

Definition at line 1569 of file reconstructor.h.

Referenced by buildFFTVolume(), finish(), and setup().

Definition at line 1566 of file reconstructor.h.

Referenced by setup().

Definition at line 1570 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1566 of file reconstructor.h.

Referenced by setup().

Definition at line 1570 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1565 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1575 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1576 of file reconstructor.h.

Referenced by setup().

const string nnSSNR_ctfReconstructor::NAME = "nnSSNR_ctf" [static]

Definition at line 1557 of file reconstructor.h.

Referenced by get_name().

Definition at line 1579 of file reconstructor.h.

Referenced by setup().


The documentation for this class was generated from the following files: