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

Direct Fourier inversion Reconstructor for extremly rectangular object. More...

#include <reconstructor.h>

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

List of all members.

Public Member Functions

 nn4_rectReconstructor ()
 nn4_rectReconstructor (const string &symmetry, int size, int npad)
virtual ~nn4_rectReconstructor ()
virtual void setup ()
 Initialize the reconstructor.
virtual int insert_slice (const EMData *const slice, const Transform &euler, const float weight)
 Insert an image slice to the reconstructor.
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.
virtual TypeDict get_param_types () const
void setup (const string &symmetry, int size, int npad)
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 = "nn4_rect"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()
void load_default_settings ()

Private Attributes

EMDatam_volume
EMDatam_wptr
string m_symmetry
int m_weighting
int m_vnx
int m_vny
int m_vnz
int m_npad
int m_nsym
int m_ndim
int m_vnzp
int m_vnyp
int m_vnxp
int m_vnzc
int m_vnyc
int m_vnxc
int m_count
float m_xratio
float m_yratio
float m_zratio
float m_xscale
float m_yscale
int m_sizeofprojection
float m_wghta
float m_wghtb
float m_osnr

Detailed Description

Direct Fourier inversion Reconstructor for extremly rectangular object.

Definition at line 1046 of file reconstructor.h.


Constructor & Destructor Documentation

nn4_rectReconstructor::nn4_rectReconstructor ( )

Definition at line 2427 of file reconstructor.cpp.

References m_volume, and m_wptr.

Referenced by NEW().

{
        m_volume = NULL;
        m_wptr   = NULL;
}
nn4_rectReconstructor::nn4_rectReconstructor ( const string &  symmetry,
int  size,
int  npad 
)

Definition at line 2433 of file reconstructor.cpp.

References load_default_settings(), m_volume, m_wptr, EMAN::Reconstructor::print_params(), and setup().

{
        m_volume = NULL;
        m_wptr   = NULL;
        setup( symmetry, size, npad );
        load_default_settings();
        print_params();
}
nn4_rectReconstructor::~nn4_rectReconstructor ( ) [virtual]

Definition at line 2442 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_rectReconstructor::buildFFTVolume ( ) [private]

Definition at line 2523 of file reconstructor.cpp.

References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), m_npad, m_vnxp, m_vnyp, m_vnzp, m_volume, EMAN::FactoryBase::params, EMAN::EMData::set_array_offsets(), EMAN::EMData::set_attr(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().

Referenced by setup().

                                           {
        int offset = 2 - m_vnxp%2;

        m_volume = params["fftvol"];

        if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) {
                m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp);
                m_volume->to_zero();
        }
        // ----------------------------------------------------------------
        // Added by Zhengfan Yang on 03/15/07
        // Original author: please check whether my revision is correct and
        // other Reconstructor need similiar revision.
        if ( m_vnxp % 2 == 0 )  m_volume->set_fftodd(0);
        else                    m_volume->set_fftodd(1);
        // ----------------------------------------------------------------

        m_volume->set_nxc(m_vnxp/2);
        m_volume->set_complex(true);
        m_volume->set_ri(true);
        m_volume->set_fftpad(true);
        m_volume->set_attr("npad", m_npad);
        m_volume->set_array_offsets(0,1,1);
}
void nn4_rectReconstructor::buildNormVolume ( ) [private]
EMData * nn4_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 2761 of file reconstructor.cpp.

References abs, circumf_rect(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), ESTIMATE, EMAN::EMData::get_attr(), m_ndim, m_osnr, m_vnxc, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, max, max2d(), max3d(), EMAN::EMData::set_array_offsets(), and EMAN::EMData::symplane0_rect().

{
        
        if( m_ndim==3 ) {
                m_volume->symplane0_rect(m_wptr);
        } else {
                for( int i=1; i <= m_vnyp; ++i ) {

                        if( (*m_wptr)(0, i, 1)==0.0 ) {
                                int j = m_vnyp + 1 - i;
                                (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1);
                                (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1);
                                (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1);
                        }
                }
        }


        int box = 7;
        int kc = (box-1)/2;
        vector< float > pow_a( m_ndim*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.back()=0.0;

        float alpha = 0.0;
        if( m_ndim==3) {
                int vol = box*box*box;
                float max = max3d( kc, pow_a );
                alpha = ( 1.0f - 1.0f/(float)vol ) / max;
        } else {
                int ara = box*box;
                float max = max2d( kc, pow_a );
                alpha = ( 1.0f - 1.0f/(float)ara ) / max;
        }

        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) {//(*v) should be treated as complex!!
                                        float tmp;
                                        tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr);
                                        
                                        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;

                                                                int kcz = (m_ndim==3) ? kc : 0;
                                                                for( int kk = -kcz; kk <= kcz; ++kk ) {
                                                                        int nbrcz = cz + kk;
                                                                        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 = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
                                                                                sum = sum + pow_a[c];
                                                                        }
                                                                }
                                                        }
                                                }
                                                float wght = 1.0f / ( 1.0f - alpha * sum );
                                                tmp = tmp * wght;
                                        }
                                        (*m_volume)(2*ix,iy,iz)   *= tmp;
                                        (*m_volume)(2*ix+1,iy,iz) *= tmp;
                                }
                        }
                }
        }

        //if(m_ndim==2) printImage( m_volume );

        // back fft
        m_volume->do_ift_inplace();

        
        int npad = m_volume->get_attr("npad");
        m_volume->depad();
        circumf_rect( m_volume, npad );
        //circumf_rect_new( m_volume, npad,m_xratio,m_yratio);
        m_volume->set_array_offsets( 0, 0, 0 );

        return 0;
}
virtual string EMAN::nn4_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 1074 of file reconstructor.h.

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

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::nn4_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 1084 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("sizeprojection", EMObject::INT);
                        d.put("sizex",          EMObject::INT);
                        d.put("sizey",          EMObject::INT);
                        d.put("sizez",          EMObject::INT);
                        d.put("xratio",         EMObject::FLOAT);
                        d.put("yratio",         EMObject::FLOAT);
                        d.put("zratio",         EMObject::FLOAT);
                        d.put("npad",           EMObject::INT);
                        d.put("sign",           EMObject::INT);
                        d.put("ndim",           EMObject::INT);
                        d.put("snr",            EMObject::FLOAT);
                        d.put("symmetry",       EMObject::STRING);
                        d.put("snr",            EMObject::FLOAT);
                        d.put("fftvol",         EMObject::EMDATA);
                        d.put("weight",         EMObject::EMDATA);
                        d.put("weighting",      EMObject::INT);
                        return d;
                }
int nn4_rectReconstructor::insert_padfft_slice ( EMData padded,
const Transform trans,
float  mult = 1 
)

Definition at line 2669 of file reconstructor.cpp.

References Assert, EMAN::Transform::get_sym_proj(), EMAN::EMData::insert_rect_slice(), m_npad, m_sizeofprojection, m_symmetry, m_volume, m_wptr, m_xratio, m_yratio, and m_zratio.

Referenced by insert_slice().

{
        Assert( padded != NULL );
                
        vector<Transform> tsym = t.get_sym_proj(m_symmetry);
        for (unsigned int isym=0; isym < tsym.size(); isym++)
                m_volume->insert_rect_slice(m_wptr, padded, tsym[isym], m_sizeofprojection, m_xratio, m_yratio, m_zratio, m_npad, weight);

        return 0;

}
int nn4_rectReconstructor::insert_slice ( const EMData *const  slice,
const Transform euler,
const float  weight 
) [virtual]

Insert an image slice to the reconstructor.

To insert multiple image slices, call this function multiple times.

Parameters:
sliceImage slice.
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.

Reimplemented from EMAN::Reconstructor.

Definition at line 2562 of file reconstructor.cpp.

References Assert, checked_delete(), EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), insert_padfft_slice(), LOGERR, m_count, m_ndim, m_npad, m_sizeofprojection, m_vnxp, m_vnyp, m_volume, m_xratio, m_yratio, mult(), EMAN::padfft_slice(), sqrt(), and t.

                                                                                                         {
        // sanity checks


        if (!slice) {
                LOGERR("try to insert NULL slice");
                return 1;
        }

        int padffted= slice->get_attr_default( "padffted", 0 );
        if( m_ndim==3 ) {
                if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_sizeofprojection)  ) {
                        
                        // FIXME: Why doesn't this throw an exception?
                        LOGERR("Tried to insert a slice that is the wrong size.");
                        return 1;
                }
        } 
       if (m_ndim==2) {
                Assert( m_ndim==2 );
                if( slice->get_ysize() !=1 ) {
                        LOGERR( "for 2D reconstruction, a line is excepted" );
                        return 1;
                }
        }
        if( weight > 0.0f )  {

                EMData* padfft = NULL;

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

                Assert( mult > 0 );

                        if( m_ndim==3 ) {
                        insert_padfft_slice( padfft, t, weight );               
                
                } else {
                        float ellipse_length,ellipse_step,cos_alpha,sin_alpha;
                        int ellipse_length_int;
                        float alpha = padfft->get_attr( "alpha" );
                        alpha = alpha/180.0f*M_PI;
                        int loop_range;
                        float temp1,temp2;
                                        temp1=m_xratio*cos(alpha)*float(m_sizeofprojection*m_npad)/2;
                        temp2=m_yratio*sin(alpha)*float(m_sizeofprojection*m_npad)/2;
                        ellipse_length=sqrt(temp1*temp1+temp2*temp2);
                        ellipse_length_int=int(ellipse_length);
                        ellipse_step=0.5f*(m_sizeofprojection*m_npad)/float(ellipse_length_int);
                        loop_range=ellipse_length_int;
                        cos_alpha=temp1/ellipse_length;
                        sin_alpha=temp2/ellipse_length;
                        if(m_count%100==0)
                                        {
                                std::cout<<"#############################################################"<<std::endl;
                                std::cout<<"line insert start=="<<m_count<<std::endl;
                                std::cout<<"ellipse lenth=="<<ellipse_length_int<<"ellips step=="<<ellipse_step<<std::endl;
                                std::cout<<"loop_range"<<loop_range<<std::endl;
                                                        std::cout<<"x and y ratio=="<<m_xratio<<"  "<<m_yratio<<std::endl;
                                std::cout<<"cos sin of alpha=="<<cos(alpha)<<"   "<<sin(alpha)<<std::endl;
                                std::cout<<"cos sin of alpha_new==="<<cos_alpha<<sin_alpha<<std::endl;
                                std::cout<<"alpah dig==="<<cos_alpha<<sin_alpha<<std::endl;
                                std::cout<<"prjection maximum==="<<loop_range*ellipse_step<<"ideal maximum"<<m_sizeofprojection*m_npad/2<<std::endl;
                                std::cout<<"x_size=="<<m_volume->get_xsize()<<"y_size=="<<m_volume->get_ysize()<<std::endl;
                                std::cout<<"#############################################################"<<std::endl;


                                                

                        }
                        for(int i=0; i <=loop_range; ++i ) {
                                float xnew = i*cos_alpha;
                                float ynew = -i*sin_alpha;
                                if(m_count%100==0&&i==loop_range)
                                        std::cout<<"x_new=="<<xnew<<"Y_new=="<<ynew<<std::endl;
                                float btqr=0,btqi=0;
                                float xprj=i*ellipse_step;
                                float t=xprj-int(xprj);
                                btqr = (1-t)*padfft->get_value_at( 2*int(xprj), 0, 0 )+t*padfft->get_value_at( 2*(1+int(xprj)), 0, 0 );
                                btqi = (1-t)*padfft->get_value_at( 2*int(xprj)+1, 0, 0 )+t*padfft->get_value_at( 2*(1+int(xprj))+1, 0, 0 );
                                if( xnew < 0.0 ) {
                                        xnew *= -1;
                                        ynew *= -1;
                                        btqi *= -1;
                                }

                                int ixn = int(xnew+0.5+m_vnxp) - m_vnxp;
                                int iyn = int(ynew+0.5+m_vnyp) - m_vnyp;

                                if(iyn < 0 ) iyn += m_vnyp;
                                if(m_count%100==0&&i==loop_range)
                                        std::cout<<"xnn=="<<ixn<<"ynn=="<<iyn<<std::endl;
                                (*m_volume)( 2*ixn, iyn+1, 1 )   += btqr * weight;
                                (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * weight;
                                (*m_wptr)(ixn,iyn+1, 1) += weight;
                        }


                }
                checked_delete( padfft );
                return 0;
        }
}
void EMAN::nn4_rectReconstructor::load_default_settings ( ) [inline, private]

Definition at line 1132 of file reconstructor.h.

Referenced by nn4_rectReconstructor().

                {
                        //params["use_weights"] = false;
                }
static Reconstructor* EMAN::nn4_rectReconstructor::NEW ( ) [inline, static]

Definition at line 1079 of file reconstructor.h.

References nn4_rectReconstructor().

                {
                        return new nn4_rectReconstructor();
                }
void nn4_rectReconstructor::setup ( const string &  symmetry,
int  size,
int  npad 
)

Definition at line 2471 of file reconstructor.cpp.

References buildFFTVolume(), buildNormVolume(), ESTIMATE, EMAN::Transform::get_nsym(), EMAN::Dict::has_key(), m_ndim, m_npad, m_nsym, 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_xratio, m_yratio, m_zratio, and EMAN::FactoryBase::params.

{
        m_weighting = ESTIMATE;
        m_wghta = 0.2f;
        m_symmetry = symmetry;
        m_npad = npad;
        m_nsym = Transform::get_nsym(m_symmetry);

        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 = (m_ndim==3) ? sizeprojection : 1;
        
        m_xratio=float(m_vnx)/float(sizeprojection);    
        m_yratio=float(m_vny)/float(sizeprojection);
        m_zratio=float(m_vnz)/float(sizeprojection);

        m_vnxp = m_vnx*npad;
        m_vnyp = m_vny*npad;
        m_vnzp = (m_ndim==3) ? m_vnz*npad : 1;

        m_vnxc = m_vnxp/2;
        m_vnyc = m_vnyp/2;
        m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1;

        buildFFTVolume();
        buildNormVolume();
}
void nn4_rectReconstructor::setup ( ) [virtual]

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 2452 of file reconstructor.cpp.

References EMAN::Dict::has_key(), m_count, m_ndim, m_osnr, m_sizeofprojection, EMAN::FactoryBase::params, and EMAN::Gatan::to_str().

Referenced by nn4_rectReconstructor().

{
        m_sizeofprojection = params["sizeprojection"];
        int npad = params["npad"];
        m_count=0;

        string symmetry;
        if( params.has_key("symmetry") )  symmetry = params["symmetry"].to_str();
        else                               symmetry = "c1";

        if( params.has_key("ndim") )  m_ndim = params["ndim"];             
        else                            m_ndim = 3;
    
        if( params.has_key( "snr" ) )  m_osnr = 1.0f/float( params["snr"] );
        else                           m_osnr = 0.0;

        setup( symmetry, m_sizeofprojection, npad );
}

Member Data Documentation

Definition at line 1123 of file reconstructor.h.

Referenced by insert_slice(), and setup().

Definition at line 1120 of file reconstructor.h.

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

Definition at line 1118 of file reconstructor.h.

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

Definition at line 1119 of file reconstructor.h.

Referenced by setup().

Definition at line 1131 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1126 of file reconstructor.h.

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

Definition at line 1115 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1117 of file reconstructor.h.

Referenced by setup().

Definition at line 1122 of file reconstructor.h.

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

Definition at line 1121 of file reconstructor.h.

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

Definition at line 1117 of file reconstructor.h.

Referenced by setup().

Definition at line 1122 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1121 of file reconstructor.h.

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

Definition at line 1117 of file reconstructor.h.

Referenced by setup().

Definition at line 1122 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1121 of file reconstructor.h.

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

Definition at line 1116 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1129 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1130 of file reconstructor.h.

Definition at line 1124 of file reconstructor.h.

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

Definition at line 1125 of file reconstructor.h.

Definition at line 1124 of file reconstructor.h.

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

Definition at line 1125 of file reconstructor.h.

Definition at line 1124 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

const string nn4_rectReconstructor::NAME = "nn4_rect" [static]

Definition at line 1110 of file reconstructor.h.

Referenced by get_name().


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