#include <reconstructor.h>
Inheritance diagram for EMAN::nn4_ctfReconstructor:
Public Member Functions | |
nn4_ctfReconstructor () | |
nn4_ctfReconstructor (const string &symmetry, int size, int npad, float snr, int sign) | |
virtual | ~nn4_ctfReconstructor () |
virtual void | setup () |
Initialize the reconstructor. | |
virtual int | insert_slice (const EMData *const slice, const Transform &euler, const float weight=1.0) |
Insert a slice into a 3D volume, in a given orientation. | |
virtual EMData * | finish (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, int mult=1) |
int | insert_buffed_slice (const EMData *buffer, int mult) |
Static Public Member Functions | |
static Reconstructor * | NEW () |
Static Public Attributes | |
static const string | NAME = "nn4_ctf" |
Private Member Functions | |
void | buildFFTVolume () |
void | buildNormVolume () |
Private Attributes | |
EMData * | m_volume |
EMData * | m_result |
EMData * | m_wptr |
bool | m_delete_volume |
bool | m_delete_weight |
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_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 |
Definition at line 967 of file reconstructor.h.
nn4_ctfReconstructor::nn4_ctfReconstructor | ( | ) |
nn4_ctfReconstructor::nn4_ctfReconstructor | ( | const string & | symmetry, | |
int | size, | |||
int | npad, | |||
float | snr, | |||
int | sign | |||
) |
nn4_ctfReconstructor::~nn4_ctfReconstructor | ( | ) | [virtual] |
Definition at line 2732 of file reconstructor.cpp.
References checked_delete(), m_delete_volume, m_delete_weight, m_result, m_volume, and m_wptr.
02733 { 02734 if( m_delete_volume ) checked_delete(m_volume); 02735 02736 if( m_delete_weight ) checked_delete( m_wptr ); 02737 02738 checked_delete( m_result ); 02739 }
void nn4_ctfReconstructor::buildFFTVolume | ( | ) | [private] |
Definition at line 2794 of file reconstructor.cpp.
References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), m_delete_volume, 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_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().
Referenced by setup().
02794 { 02795 int offset = 2 - m_vnxp%2; 02796 if( params.has_key("fftvol") ) { 02797 m_volume = params["fftvol"]; 02798 m_delete_volume = false; 02799 } else { 02800 m_volume = new EMData(); 02801 m_delete_volume = true; 02802 } 02803 02804 if( m_volume->get_xsize() != m_vnxp+offset && 02805 m_volume->get_ysize() != m_vnyp && 02806 m_volume->get_zsize() != m_vnzp ) 02807 { 02808 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp); 02809 m_volume->to_zero(); 02810 } 02811 02812 m_volume->set_nxc(m_vnxp/2); 02813 m_volume->set_complex(true); 02814 m_volume->set_ri(true); 02815 m_volume->set_fftpad(true); 02816 m_volume->set_attr("npad", m_npad); 02817 m_volume->set_array_offsets(0,1,1); 02818 }
void nn4_ctfReconstructor::buildNormVolume | ( | ) | [private] |
Definition at line 2820 of file reconstructor.cpp.
References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), m_delete_weight, m_vnxc, m_vnyp, m_vnzp, m_wptr, EMAN::FactoryBase::params, EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().
Referenced by setup().
02821 { 02822 if( params.has_key("weight") ) 02823 { 02824 m_wptr = params["weight"]; 02825 m_delete_weight = false; 02826 } else { 02827 m_wptr = new EMData(); 02828 m_delete_weight = true; 02829 } 02830 02831 if( m_wptr->get_xsize() != m_vnxc+1 && 02832 m_wptr->get_ysize() != m_vnyp && 02833 m_wptr->get_zsize() != m_vnzp ) 02834 { 02835 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02836 m_wptr->to_zero(); 02837 } 02838 02839 m_wptr->set_array_offsets(0,1,1); 02840 02841 }
EMData * nn4_ctfReconstructor::finish | ( | bool | doift = true |
) | [virtual] |
Finish reconstruction and return the complete model.
doift | A 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 |
Reimplemented from EMAN::Reconstructor.
Definition at line 2923 of file reconstructor.cpp.
References abs, circumference(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), ESTIMATE, m_result, m_sign, m_snr, m_varsnr, m_vnxc, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, max, max3d(), EMAN::EMData::set_array_offsets(), sqrt(), and EMAN::EMData::symplane0_ctf().
02924 { 02925 m_volume->set_array_offsets(0, 1, 1); 02926 m_wptr->set_array_offsets(0, 1, 1); 02927 m_volume->symplane0_ctf(m_wptr); 02928 02929 int box = 7; 02930 int vol = box*box*box; 02931 int kc = (box-1)/2; 02932 vector< float > pow_a( 3*kc+1, 1.0 ); 02933 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta); 02934 pow_a[3*kc]=0.0; 02935 02936 02937 float max = max3d( kc, pow_a ); 02938 float alpha = ( 1.0f - 1.0f/(float)vol ) / max; 02939 float osnr = 1.0f/m_snr; 02940 02941 // normalize 02942 int ix,iy,iz; 02943 for (iz = 1; iz <= m_vnzp; iz++) { 02944 for (iy = 1; iy <= m_vnyp; iy++) { 02945 for (ix = 0; ix <= m_vnxc; ix++) { 02946 if ( (*m_wptr)(ix,iy,iz) > 0.0f) {//(*v) should be treated as complex!! 02947 int iyp = (iy<=m_vnyc) ? iy - 1 : iy-m_vnyp-1; 02948 int izp = (iz<=m_vnzc) ? iz - 1 : iz-m_vnzp-1; 02949 float tmp=0.0; 02950 if( m_varsnr ) 02951 { 02952 float freq = sqrt( (float)(ix*ix+iyp*iyp+izp*izp) ); 02953 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+freq*osnr)*m_sign; 02954 } 02955 else 02956 { 02957 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+osnr)*m_sign; 02958 } 02959 02960 if( m_weighting == ESTIMATE ) { 02961 int cx = ix; 02962 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp; 02963 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp; 02964 float sum = 0.0; 02965 for( int ii = -kc; ii <= kc; ++ii ) { 02966 int nbrcx = cx + ii; 02967 if( nbrcx >= m_vnxc ) continue; 02968 for( int jj= -kc; jj <= kc; ++jj ) { 02969 int nbrcy = cy + jj; 02970 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue; 02971 for( int kk = -kc; kk <= kc; ++kk ) { 02972 int nbrcz = cz + jj; 02973 if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue; 02974 if( nbrcx < 0 ) { 02975 nbrcx = -nbrcx; 02976 nbrcy = -nbrcy; 02977 nbrcz = -nbrcz; 02978 } 02979 02980 int nbrix = nbrcx; 02981 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp; 02982 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp; 02983 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0.0 ) { 02984 int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk); 02985 sum = sum + pow_a[c]; 02986 // if(ix%20==0 && iy%20==0 && iz%20==0) 02987 // std::cout << boost::format( "%4d %4d %4d %4d %10.3f" ) % nbrix % nbriy % nbriz % c % sum << std::endl; 02988 } 02989 } 02990 } 02991 } 02992 float wght = 1.0f / ( 1.0f - alpha * sum ); 02993 /* 02994 if(ix%10==0 && iy%10==0) 02995 { 02996 std::cout << boost::format( "%4d %4d %4d " ) % ix % iy %iz; 02997 std::cout << boost::format( "%10.3f %10.3f %10.3f " ) % tmp % wght % sum; 02998 std:: << boost::format( "%10.3f %10.3e " ) % pow_b[r] % alpha; 02999 std::cout << std::endl; 03000 } 03001 */ 03002 tmp = tmp * wght; 03003 } 03004 (*m_volume)(2*ix,iy,iz) *= tmp; 03005 (*m_volume)(2*ix+1,iy,iz) *= tmp; 03006 } 03007 } 03008 } 03009 } 03010 03011 // back fft 03012 m_volume->do_ift_inplace(); 03013 m_volume->depad(); 03014 circumference( m_volume ); 03015 m_volume->set_array_offsets( 0, 0, 0 ); 03016 m_result = m_volume->copy(); 03017 return m_result; 03018 }
virtual string EMAN::nn4_ctfReconstructor::get_desc | ( | ) | const [inline, virtual] |
Get a clear, concise description of this class.
Implements EMAN::FactoryBase.
Definition at line 996 of file reconstructor.h.
virtual string EMAN::nn4_ctfReconstructor::get_name | ( | ) | const [inline, virtual] |
Get the unique name of this class (especially for factory based instantiation access).
Implements EMAN::FactoryBase.
Definition at line 991 of file reconstructor.h.
References NAME.
00992 { 00993 return NAME; 00994 }
TypeDict EMAN::nn4_ctfReconstructor::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::FactoryBase.
Definition at line 1007 of file reconstructor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
01008 { 01009 TypeDict d; 01010 d.put("size", EMObject::INT); 01011 d.put("npad", EMObject::INT); 01012 d.put("sign", EMObject::INT); 01013 d.put("symmetry", EMObject::STRING); 01014 d.put("snr", EMObject::FLOAT); 01015 d.put("fftvol", EMObject::EMDATA); 01016 d.put("weight", EMObject::EMDATA); 01017 d.put("weighting", EMObject::INT); 01018 d.put("varsnr", EMObject::INT); 01019 return d; 01020 }
int nn4_ctfReconstructor::insert_buffed_slice | ( | const EMData * | buffer, | |
int | mult | |||
) |
Definition at line 2882 of file reconstructor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), m_volume, and m_wptr.
Referenced by insert_slice().
02883 { 02884 const float* bufdata = buffed->get_data(); 02885 float* cdata = m_volume->get_data(); 02886 float* wdata = m_wptr->get_data(); 02887 02888 int npoint = buffed->get_xsize()/4; 02889 for( int i=0; i < npoint; ++i ) { 02890 02891 int pos2 = int( bufdata[4*i] ); 02892 int pos1 = pos2 * 2; 02893 cdata[pos1 ] += bufdata[4*i+1]*mult; 02894 cdata[pos1+1] += bufdata[4*i+2]*mult; 02895 wdata[pos2 ] += bufdata[4*i+3]*mult; 02896 /* 02897 std::cout << "pos1, pos2, ctfv1, ctfv2, ctf2: "; 02898 std::cout << pos1 << " " << bufdata[5*i+1] << " " << bufdata[5*i+2] << " "; 02899 std::cout << pos2 << " " << bufdata[5*i+4] << std::endl; 02900 */ 02901 } 02902 return 0; 02903 }
int nn4_ctfReconstructor::insert_padfft_slice | ( | EMData * | padfft, | |
const Transform & | trans, | |||
int | mult = 1 | |||
) |
Definition at line 2905 of file reconstructor.cpp.
References Assert, EMAN::EMData::get_attr(), m_nsym, m_symmetry, m_volume, m_wptr, EMAN::EMData::nn_ctf(), EMAN::EMData::nn_ctf_applied(), and t.
Referenced by insert_slice().
02906 { 02907 Assert( padfft != NULL ); 02908 float tmp = padfft->get_attr("ctf_applied"); 02909 int ctf_applied = (int) tmp; 02910 02911 for( int isym=0; isym < m_nsym; isym++) { 02912 Transform tsym = t.get_sym( m_symmetry, isym ); 02913 02914 if(ctf_applied) m_volume->nn_ctf_applied(m_wptr, padfft, tsym, mult); 02915 else m_volume->nn_ctf(m_wptr, padfft, tsym, mult); 02916 } 02917 02918 return 0; 02919 02920 }
int nn4_ctfReconstructor::insert_slice | ( | const EMData *const | slice, | |
const Transform & | euler, | |||
const float | weight = 1.0 | |||
) | [virtual] |
Insert a slice into a 3D volume, in a given orientation.
slice | the image slice to be inserted into the 3D volume | |
euler | Euler angle of this image slice. | |
weight | A weighting factor for this slice, generally the number of particles in a class-average. May be ignored by some reconstructors |
NullPointerException | if the input EMData pointer is null | |
ImageFormatException | if the image is complex as opposed to real |
Reimplemented from EMAN::Reconstructor.
Definition at line 2843 of file reconstructor.cpp.
References Assert, checked_delete(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), insert_buffed_slice(), insert_padfft_slice(), LOGERR, m_npad, m_vnx, mult(), EMAN::padfft_slice(), and t.
02844 { 02845 // sanity checks 02846 if (!slice) { 02847 LOGERR("try to insert NULL slice"); 02848 return 1; 02849 } 02850 02851 int buffed = slice->get_attr_default( "buffed", 0 ); 02852 if( buffed > 0 ) 02853 { 02854 int mult = slice->get_attr_default( "mult", 1 ); 02855 insert_buffed_slice( slice, mult ); 02856 return 0; 02857 } 02858 02859 int padffted= slice->get_attr_default("padffted", 0); 02860 if( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) 02861 { 02862 // FIXME: Why doesn't this throw an exception? 02863 LOGERR("Tried to insert a slice that is the wrong size."); 02864 return 1; 02865 } 02866 02867 EMData* padfft = NULL; 02868 02869 if( padffted != 0 ) padfft = new EMData(*slice); 02870 else padfft = padfft_slice( slice, t, m_npad ); 02871 02872 int mult= slice->get_attr_default("mult", 1); 02873 02874 Assert( mult > 0 ); 02875 insert_padfft_slice( padfft, t, mult ); 02876 02877 checked_delete( padfft ); 02878 02879 return 0; 02880 }
static Reconstructor* EMAN::nn4_ctfReconstructor::NEW | ( | ) | [inline, static] |
Definition at line 1001 of file reconstructor.h.
References nn4_ctfReconstructor().
01002 { 01003 return new nn4_ctfReconstructor(); 01004 }
void nn4_ctfReconstructor::setup | ( | const string & | symmetry, | |
int | size, | |||
int | npad, | |||
float | snr, | |||
int | sign | |||
) |
Definition at line 2758 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, NONE, and EMAN::FactoryBase::params.
02759 { 02760 m_weighting = ESTIMATE; 02761 if( params.has_key("weighting") ) { 02762 int tmp = int( params["weighting"] ); 02763 if( tmp==0 ) m_weighting = NONE; 02764 } 02765 02766 02767 02768 m_wghta = 0.2f; 02769 m_wghtb = 0.004f; 02770 02771 m_symmetry = symmetry; 02772 m_npad = npad; 02773 m_sign = sign; 02774 m_nsym = Transform::get_nsym(m_symmetry); 02775 02776 m_snr = snr; 02777 02778 m_vnx = size; 02779 m_vny = size; 02780 m_vnz = size; 02781 02782 m_vnxp = size*npad; 02783 m_vnyp = size*npad; 02784 m_vnzp = size*npad; 02785 02786 m_vnxc = m_vnxp/2; 02787 m_vnyc = m_vnyp/2; 02788 m_vnzc = m_vnzp/2; 02789 02790 buildFFTVolume(); 02791 buildNormVolume(); 02792 }
void nn4_ctfReconstructor::setup | ( | ) | [virtual] |
Initialize the reconstructor.
Implements EMAN::Reconstructor.
Definition at line 2741 of file reconstructor.cpp.
References EMAN::Dict::has_key(), m_varsnr, EMAN::FactoryBase::params, and sign.
Referenced by nn4_ctfReconstructor().
02742 { 02743 if( ! params.has_key("size") ) throw std::logic_error("Error: image size is not given"); 02744 02745 int size = params["size"]; 02746 int npad = params.has_key("npad") ? int(params["npad"]) : 4; 02747 // int sign = params.has_key("sign") ? int(params["sign"]) : 1; 02748 int sign = 1; 02749 string symmetry = params.has_key("symmetry")? params["symmetry"].to_str() : "c1"; 02750 02751 float snr = params["snr"]; 02752 02753 m_varsnr = params.has_key("varsnr") ? int(params["varsnr"]) : 0; 02754 setup( symmetry, size, npad, snr, sign ); 02755 02756 }
bool EMAN::nn4_ctfReconstructor::m_delete_volume [private] |
Definition at line 1034 of file reconstructor.h.
Referenced by buildFFTVolume(), and ~nn4_ctfReconstructor().
bool EMAN::nn4_ctfReconstructor::m_delete_weight [private] |
Definition at line 1035 of file reconstructor.h.
Referenced by buildNormVolume(), and ~nn4_ctfReconstructor().
int EMAN::nn4_ctfReconstructor::m_npad [private] |
Definition at line 1039 of file reconstructor.h.
Referenced by buildFFTVolume(), insert_slice(), and setup().
int EMAN::nn4_ctfReconstructor::m_nsym [private] |
EMData* EMAN::nn4_ctfReconstructor::m_result [private] |
Definition at line 1032 of file reconstructor.h.
Referenced by finish(), nn4_ctfReconstructor(), and ~nn4_ctfReconstructor().
int EMAN::nn4_ctfReconstructor::m_sign [private] |
float EMAN::nn4_ctfReconstructor::m_snr [private] |
string EMAN::nn4_ctfReconstructor::m_symmetry [private] |
int EMAN::nn4_ctfReconstructor::m_varsnr [private] |
int EMAN::nn4_ctfReconstructor::m_vnx [private] |
int EMAN::nn4_ctfReconstructor::m_vnxc [private] |
Definition at line 1038 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), and setup().
int EMAN::nn4_ctfReconstructor::m_vnxp [private] |
int EMAN::nn4_ctfReconstructor::m_vny [private] |
int EMAN::nn4_ctfReconstructor::m_vnyc [private] |
int EMAN::nn4_ctfReconstructor::m_vnyp [private] |
Definition at line 1037 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), and setup().
int EMAN::nn4_ctfReconstructor::m_vnz [private] |
int EMAN::nn4_ctfReconstructor::m_vnzc [private] |
int EMAN::nn4_ctfReconstructor::m_vnzp [private] |
Definition at line 1037 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), and setup().
EMData* EMAN::nn4_ctfReconstructor::m_volume [private] |
Definition at line 1031 of file reconstructor.h.
Referenced by buildFFTVolume(), finish(), insert_buffed_slice(), insert_padfft_slice(), nn4_ctfReconstructor(), and ~nn4_ctfReconstructor().
int EMAN::nn4_ctfReconstructor::m_weighting [private] |
float EMAN::nn4_ctfReconstructor::m_wghta [private] |
float EMAN::nn4_ctfReconstructor::m_wghtb [private] |
EMData* EMAN::nn4_ctfReconstructor::m_wptr [private] |
Definition at line 1033 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_buffed_slice(), insert_padfft_slice(), nn4_ctfReconstructor(), and ~nn4_ctfReconstructor().
const string nn4_ctfReconstructor::NAME = "nn4_ctf" [static] |