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

nn4_ctf_rectDirect Fourier Inversion Reconstructor More...

#include <reconstructor.h>

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

List of all members.

Public Member Functions

 nn4_ctf_rectReconstructor ()
 nn4_ctf_rectReconstructor (const string &symmetry, int size, int npad, float snr, int sign)
virtual ~nn4_ctf_rectReconstructor ()
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 *padfft, const Transform &trans, float mult=1)
int insert_buffed_slice (const EMData *buffer, float mult)

Static Public Member Functions

static ReconstructorNEW ()

Static Public Attributes

static const string NAME = "nn4_ctf_rect"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()

Private Attributes

EMDatam_volume
EMDatam_wptr
int m_vnx
int m_vny
int m_vnz
int m_vnzp
int m_vnyp
int m_vnxp
int m_vnxc
int m_vnyc
int m_vnzc
int m_count
float m_xratio
float m_yratio
float m_zratio
int m_sizeofprojection
int m_npad
int m_sign
int m_varsnr
int m_weighting
float m_wghta
float m_wghtb
float m_snr
string m_symmetry
int m_nsym

Detailed Description

nn4_ctf_rectDirect Fourier Inversion Reconstructor

Definition at line 1402 of file reconstructor.h.


Constructor & Destructor Documentation

nn4_ctf_rectReconstructor::nn4_ctf_rectReconstructor ( )

Definition at line 3770 of file reconstructor.cpp.

References m_volume, and m_wptr.

Referenced by NEW().

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

Definition at line 3776 of file reconstructor.cpp.

References setup().

{
        setup( symmetry, size, npad, snr, sign );
}
nn4_ctf_rectReconstructor::~nn4_ctf_rectReconstructor ( ) [virtual]

Definition at line 3781 of file reconstructor.cpp.

{
        //if( m_delete_volume ) checked_delete(m_volume);

        //if( m_delete_weight ) checked_delete( m_wptr );

        //checked_delete( m_result );
}

Member Function Documentation

void nn4_ctf_rectReconstructor::buildFFTVolume ( ) [private]
void nn4_ctf_rectReconstructor::buildNormVolume ( ) [private]
EMData * nn4_ctf_rectReconstructor::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 3967 of file reconstructor.cpp.

References abs, circumf_rect(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), ESTIMATE, EMAN::EMData::get_attr(), m_sign, m_snr, m_varsnr, m_vnxc, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, m_xratio, m_yratio, m_zratio, max, max3d(), EMAN::EMData::set_array_offsets(), sqrt(), and EMAN::EMData::symplane0_rect().

{
        m_volume->set_array_offsets(0, 1, 1);
        m_wptr->set_array_offsets(0, 1, 1);
        m_volume->symplane0_rect(m_wptr);

        int box = 7;
        int vol = box*box*box;
        int kc = (box-1)/2;
        vector< float > pow_a( 3*kc+1, 1.0 );
        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 );
        float alpha = ( 1.0f - 1.0f/(float)vol ) / max;
        float osnr = 1.0f/m_snr;

        // normalize
        int ix,iy,iz;
        for (iz = 1; iz <= m_vnzp; iz++) {
                for (iy = 1; iy <= m_vnyp; iy++) {
                        for (ix = 0; ix <= m_vnxc; ix++) {
                                if ( (*m_wptr)(ix,iy,iz) > 0.0f) {//(*v) should be treated as complex!!
                    float tmp=0.0f;
                    if( m_varsnr ) {
                        int iyp = (iy<=m_vnyc) ? iy - 1 : iy-m_vnyp-1;
                        int izp = (iz<=m_vnzc) ? iz - 1 : iz-m_vnzp-1;
                                    float freq = sqrt( (float)(ix*ix/(m_xratio*m_xratio)+iyp*iyp/(m_zratio*m_yratio)+izp*izp) );
                        tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+freq*osnr)*m_sign;
                    } else {
                        tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+osnr)*m_sign;
                    }

                                        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.0 ) {
                                                                                int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
                                                                                sum = sum + pow_a[c];
                                                                                  // if(ix%20==0 && iy%20==0 && iz%20==0)
                                                                                 //   std::cout << boost::format( "%4d %4d %4d %4d %10.3f" ) % nbrix % nbriy % nbriz % c % sum << std::endl;
                                                                        }
                                                                }
                                                        }
                                                }
                                                float wght = 1.0f / ( 1.0f - alpha * sum );
/*
                        if(ix%10==0 && iy%10==0)
                        {
                            std::cout << boost::format( "%4d %4d %4d " ) % ix % iy %iz;
                            std::cout << boost::format( "%10.3f %10.3f %10.3f " )  % tmp % wght % sum;
                            std::  << boost::format( "%10.3f %10.3e " ) % pow_b[r] % alpha;
                            std::cout << std::endl;
                        }
 */
                                                tmp = tmp * wght;
                                        }
                                        (*m_volume)(2*ix,iy,iz) *= tmp;
                                        (*m_volume)(2*ix+1,iy,iz) *= tmp;
                                }
                        }
                }
        }

        // back fft
        m_volume->do_ift_inplace();
        int npad = m_volume->get_attr("npad");
        m_volume->depad();
        circumf_rect( m_volume, npad );
        m_volume->set_array_offsets( 0, 0, 0 );
        return 0;
}
virtual string EMAN::nn4_ctf_rectReconstructor::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 1431 of file reconstructor.h.

                {
                        return "Direct Fourier inversion reconstruction routine";
                }
virtual string EMAN::nn4_ctf_rectReconstructor::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 1426 of file reconstructor.h.

References NAME.

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

Implements EMAN::FactoryBase.

Definition at line 1442 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("sign",           EMObject::INT);
                        d.put("symmetry",       EMObject::STRING);
                        d.put("snr",            EMObject::FLOAT);
                        d.put("fftvol",         EMObject::EMDATA);
                        d.put("weight",         EMObject::EMDATA);
                        d.put("refvol",         EMObject::EMDATA);
                        d.put("weighting",  EMObject::INT);
                        d.put("varsnr",     EMObject::INT);
                        return d;
                }
int nn4_ctf_rectReconstructor::insert_buffed_slice ( const EMData buffer,
float  mult 
)

Definition at line 3929 of file reconstructor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), m_volume, m_wptr, and weight.

Referenced by insert_slice().

{
        const float* bufdata = buffed->get_data();
        float* cdata = m_volume->get_data();
        float* wdata = m_wptr->get_data();

        int npoint = buffed->get_xsize()/4;
        for( int i=0; i < npoint; ++i ) {

                int pos2 = int( bufdata[4*i] );
                int pos1 = pos2 * 2;
                cdata[pos1  ] += bufdata[4*i+1]*weight;
                cdata[pos1+1] += bufdata[4*i+2]*weight;
                wdata[pos2  ] += bufdata[4*i+3]*weight;
/*
        std::cout << "pos1, pos2, ctfv1, ctfv2, ctf2: ";
        std::cout << pos1 << " " << bufdata[5*i+1] << " " << bufdata[5*i+2] << " ";
        std::cout << pos2 << " " << bufdata[5*i+4] << std::endl;
 */
        }
        return 0;
}
int nn4_ctf_rectReconstructor::insert_padfft_slice ( EMData padfft,
const Transform trans,
float  mult = 1 
)

Definition at line 3953 of file reconstructor.cpp.

References EMAN::EMData::get_attr(), EMAN::Transform::get_sym_proj(), EMAN::EMData::insert_rect_slice_ctf(), EMAN::EMData::insert_rect_slice_ctf_applied(), m_npad, m_sizeofprojection, m_symmetry, m_volume, m_wptr, m_xratio, m_yratio, and m_zratio.

Referenced by insert_slice().

{
        float tmp = padfft->get_attr("ctf_applied");
        int   ctf_applied = (int) tmp;
        vector<Transform> tsym = t.get_sym_proj(m_symmetry);
        for (unsigned int isym=0; isym < tsym.size(); isym++) {
                if(ctf_applied) m_volume->insert_rect_slice_ctf_applied(m_wptr, padfft, tsym[isym], m_sizeofprojection, m_xratio,m_yratio, m_zratio, m_npad, weight);                   
                else            m_volume->insert_rect_slice_ctf(m_wptr, padfft, tsym[isym], m_sizeofprojection, m_xratio, m_yratio, m_zratio, m_npad, weight);  
        }

        return 0;
}
int nn4_ctf_rectReconstructor::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 3894 of file reconstructor.cpp.

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

{
        // sanity checks
        if (!slice) {
                LOGERR("try to insert NULL slice");
                return 1;
        }
        if(weight >0.0f )  {
                int buffed = slice->get_attr_default( "buffed", 0 );
                if( buffed > 0 ) {
                        insert_buffed_slice( slice, weight );
                        return 0;
                }

                int padffted= slice->get_attr_default("padffted", 0);
                //if( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx)  )
                if( padffted==0 && (slice->get_xsize()!=slice->get_ysize())  )
                {
                        // 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::nn4_ctf_rectReconstructor::NEW ( ) [inline, static]

Definition at line 1436 of file reconstructor.h.

References nn4_ctf_rectReconstructor().

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

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 3790 of file reconstructor.cpp.

References EMAN::Dict::has_key(), m_sizeofprojection, m_varsnr, EMAN::FactoryBase::params, and sign.

Referenced by nn4_ctf_rectReconstructor().

{
        if( ! params.has_key("sizeprojection") ) throw std::logic_error("Error: projection size is not given");
        m_sizeofprojection = params["sizeprojection"];
        int npad = params.has_key("npad") ? int(params["npad"]) : 4;
        // int sign = params.has_key("sign") ? int(params["sign"]) : 1;
        int sign = 1;
        string symmetry = params.has_key("symmetry")? params["symmetry"].to_str() : "c1";

        float snr = params["snr"];

        m_varsnr = params.has_key("varsnr") ? int(params["varsnr"]) : 0;
        setup( symmetry, m_sizeofprojection, npad, snr, sign );

}
void nn4_ctf_rectReconstructor::setup ( const string &  symmetry,
int  size,
int  npad,
float  snr,
int  sign 
)

Definition at line 3806 of file reconstructor.cpp.

References buildFFTVolume(), buildNormVolume(), ESTIMATE, EMAN::Transform::get_nsym(), EMAN::Dict::has_key(), m_npad, m_nsym, m_sign, m_snr, m_symmetry, m_vnx, m_vnxc, m_vnxp, m_vny, m_vnyc, m_vnyp, m_vnz, m_vnzc, m_vnzp, m_weighting, m_wghta, m_wghtb, m_xratio, m_yratio, m_zratio, NONE, EMAN::FactoryBase::params, and sign.

{
        m_weighting = ESTIMATE;
        if( params.has_key("weighting") ) {
                int tmp = int( params["weighting"] );
                if( tmp==0 ) m_weighting = NONE;
        }

        m_wghta = 0.2f;
        m_wghtb = 0.004f;

        m_symmetry = symmetry;
        m_npad = npad;
        m_sign = sign;
        m_nsym = Transform::get_nsym(m_symmetry);

        m_snr = snr;
        if (params.has_key("sizex"))  m_vnx = params["sizex"];
        else if (params.has_key("xratio")) {
                float temp=params["xratio"];
                m_vnx=int(float(sizeprojection)*temp);
        } else  m_vnx=sizeprojection;

        if (params.has_key("sizey"))  m_vny = params["sizey"];
        else if (params.has_key("yratio")) {
                float temp=params["yratio"];
                m_vny=int(float(sizeprojection)*temp);
        }
        else m_vny=sizeprojection;
        
        if (params.has_key("sizez"))  m_vnz = params["sizez"];
        else if (params.has_key("zratio")) {
                float temp=params["zratio"];
                m_vnz=int(float(sizeprojection)*temp);
        }
        else m_vnz=sizeprojection;

        
        m_xratio=float(m_vnx)/float(sizeprojection);    
        m_yratio=float(m_vny)/float(sizeprojection);
        m_zratio=float(m_vnz)/float(sizeprojection);

        //std::cout<<"xratio=="<<m_xratio<<"yratio=="<<m_yratio<<std::endl;
        //std::cout<<"sx=="<<m_vnx<<"sy=="<<m_vny<<"sz=="<<m_vnz<<std::endl;

        m_vnxp = m_vnx*npad;
        m_vnyp = m_vny*npad;
        m_vnzp = m_vnz*npad;

        m_vnxc = m_vnxp/2;
        m_vnyc = m_vnyp/2;
        m_vnzc = m_vnzp/2;

        buildFFTVolume();
        buildNormVolume();
}

Member Data Documentation

Definition at line 1472 of file reconstructor.h.

Definition at line 1475 of file reconstructor.h.

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

Definition at line 1482 of file reconstructor.h.

Referenced by setup().

Definition at line 1476 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1474 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1480 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1481 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1477 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1469 of file reconstructor.h.

Referenced by setup().

Definition at line 1471 of file reconstructor.h.

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

Definition at line 1470 of file reconstructor.h.

Referenced by buildFFTVolume(), and setup().

Definition at line 1469 of file reconstructor.h.

Referenced by setup().

Definition at line 1471 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1470 of file reconstructor.h.

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

Definition at line 1469 of file reconstructor.h.

Referenced by setup().

Definition at line 1471 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1470 of file reconstructor.h.

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

Definition at line 1478 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1479 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1479 of file reconstructor.h.

Referenced by setup().

Definition at line 1473 of file reconstructor.h.

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

Definition at line 1473 of file reconstructor.h.

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

Definition at line 1473 of file reconstructor.h.

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

const string nn4_ctf_rectReconstructor::NAME = "nn4_ctf_rect" [static]

Definition at line 1464 of file reconstructor.h.

Referenced by get_name().


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