#include <reconstructor.h>
Inheritance diagram for EMAN::nnSSNR_Reconstructor:
Public Member Functions | |
nnSSNR_Reconstructor () | |
nnSSNR_Reconstructor (const string &symmetry, int size, int npad) | |
~nnSSNR_Reconstructor () | |
virtual void | setup () |
Initialize the reconstructor. | |
virtual int | insert_slice (const EMData *const slice, const Transform &euler, const float weight=1.0) |
Insert an image slice to the reconstructor. | |
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. | |
virtual TypeDict | get_param_types () const |
void | setup (const string &symmetry, int size, int npad) |
int | insert_padfft_slice (EMData *padded, const Transform &trans, int mult=1) |
Static Public Member Functions | |
static Reconstructor * | NEW () |
Static Public Attributes | |
static const string | NAME = "nnSSNR" |
Private Member Functions | |
void | buildFFTVolume () |
void | buildNormVolume () |
void | buildNorm2Volume () |
Private Attributes | |
EMData * | m_volume |
EMData * | m_wptr |
EMData * | m_wptr2 |
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 |
Definition at line 1132 of file reconstructor.h.
nnSSNR_Reconstructor::nnSSNR_Reconstructor | ( | ) |
nnSSNR_Reconstructor::nnSSNR_Reconstructor | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
nnSSNR_Reconstructor::~nnSSNR_Reconstructor | ( | ) |
Definition at line 2865 of file reconstructor.cpp.
02866 { 02867 //if( m_delete_volume ) checked_delete(m_volume); 02868 02869 //if( m_delete_weight ) checked_delete( m_wptr ); 02870 02871 //if( m_delete_weight2 ) checked_delete( m_wptr2 ); 02872 02873 //checked_delete( m_result ); 02874 }
void nnSSNR_Reconstructor::buildFFTVolume | ( | ) | [private] |
Definition at line 2917 of file reconstructor.cpp.
References m_npad, m_vnxc, 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().
02917 { 02918 02919 m_volume = params["fftvol"]; 02920 m_volume->set_size(m_vnxp+ 2 - m_vnxp%2,m_vnyp,m_vnzp); 02921 m_volume->to_zero(); 02922 if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0); 02923 else m_volume->set_fftodd(1); 02924 02925 m_volume->set_nxc(m_vnxc); 02926 m_volume->set_complex(true); 02927 m_volume->set_ri(true); 02928 m_volume->set_fftpad(true); 02929 m_volume->set_attr("npad", m_npad); 02930 m_volume->set_array_offsets(0,1,1); 02931 }
void nnSSNR_Reconstructor::buildNorm2Volume | ( | ) | [private] |
Definition at line 2941 of file reconstructor.cpp.
References m_vnxc, m_vnyp, m_vnzp, m_wptr2, EMAN::FactoryBase::params, EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().
Referenced by setup().
02941 { 02942 02943 m_wptr2 = params["weight2"]; 02944 m_wptr2->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02945 m_wptr2->to_zero(); 02946 m_wptr2->set_array_offsets(0,1,1); 02947 }
void nnSSNR_Reconstructor::buildNormVolume | ( | ) | [private] |
Definition at line 2933 of file reconstructor.cpp.
References 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().
02933 { 02934 02935 m_wptr = params["weight"]; 02936 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02937 m_wptr->to_zero(); 02938 m_wptr->set_array_offsets(0,1,1); 02939 }
EMData * nnSSNR_Reconstructor::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 2992 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, 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::symplane1(), EMAN::EMData::to_zero(), and EMAN::EMData::update().
02993 { 02994 /* 02995 I changed the code on 05/15/2008 so it only returns variance. 02996 Lines commented out are marked by //# 02997 The version prior to the currect changes is r1.190 02998 PAP 02999 */ 03000 int kz, ky; 03001 //#int iix, iiy, iiz; 03002 int box = 7; 03003 int kc = (box-1)/2; 03004 float alpha = 0.0; 03005 float argx, argy, argz; 03006 vector< float > pow_a( 3*kc+1, 1.0 ); 03007 float w = params["w"]; 03008 EMData* SSNR = params["SSNR"]; 03009 //#EMData* vol_ssnr = new EMData(); 03010 //#vol_ssnr->set_size(m_vnxp, m_vnyp, m_vnzp); 03011 //#vol_ssnr->to_zero(); 03012 //# new line follow 03013 EMData* vol_ssnr = params["vol_ssnr"]; 03014 vol_ssnr->set_size(m_vnxp+ 2 - m_vnxp%2, m_vnyp ,m_vnzp); 03015 vol_ssnr->to_zero(); 03016 if ( m_vnxp % 2 == 0 ) vol_ssnr->set_fftodd(0); 03017 else vol_ssnr->set_fftodd(1); 03018 vol_ssnr->set_nxc(m_vnxc); 03019 vol_ssnr->set_complex(true); 03020 vol_ssnr->set_ri(true); 03021 vol_ssnr->set_fftpad(false); 03022 //# 03023 03024 float dx2 = 1.0f/float(m_vnxc)/float(m_vnxc); 03025 float dy2 = 1.0f/float(m_vnyc)/float(m_vnyc); 03026 #ifdef _WIN32 03027 float dz2 = 1.0f/_cpp_max(float(m_vnzc),1.0f)/_cpp_max(float(m_vnzc),1.0f); 03028 int inc = Util::round(float(_cpp_max(_cpp_max(m_vnxc,m_vnyc),m_vnzc))/w); 03029 #else 03030 float dz2 = 1.0f/std::max(float(m_vnzc),1.0f)/std::max(float(m_vnzc),1.0f); 03031 int inc = Util::round(float(std::max(std::max(m_vnxc,m_vnyc),m_vnzc))/w); 03032 #endif //_WIN32 03033 SSNR->set_size(inc+1,4,1); 03034 03035 float *nom = new float[inc+1]; 03036 float *denom = new float[inc+1]; 03037 int *nn = new int[inc+1]; 03038 int *ka = new int[inc+1]; 03039 float wght = 1.0f; 03040 for (int i = 0; i <= inc; i++) { 03041 nom[i] = 0.0f; 03042 denom[i] = 0.0f; 03043 nn[i] = 0; 03044 ka[i] = 0; 03045 } 03046 03047 m_volume->symplane1(m_wptr, m_wptr2); 03048 03049 if ( m_weighting == ESTIMATE ) { 03050 int vol = box*box*box; 03051 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta); 03052 pow_a[3*kc] = 0.0; 03053 float max = max3d( kc, pow_a ); 03054 alpha = ( 1.0f - 1.0f/(float)vol ) / max; 03055 } 03056 03057 for (int iz = 1; iz <= m_vnzp; iz++) { 03058 if ( iz-1 > m_vnzc ) kz = iz-1-m_vnzp; else kz = iz-1; 03059 argz = float(kz*kz)*dz2; 03060 for (int iy = 1; iy <= m_vnyp; iy++) { 03061 if ( iy-1 > m_vnyc ) ky = iy-1-m_vnyp; else ky = iy-1; 03062 argy = argz + float(ky*ky)*dy2; 03063 for (int ix = 0; ix <= m_vnxc; ix++) { 03064 float Kn = (*m_wptr)(ix,iy,iz); 03065 argx = std::sqrt(argy + float(ix*ix)*dx2); 03066 int r = Util::round(float(inc)*argx); 03067 if ( r >= 0 && Kn > 4.5f ) { 03068 if ( m_weighting == ESTIMATE ) { 03069 int cx = ix; 03070 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp; 03071 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp; 03072 03073 float sum = 0.0; 03074 for( int ii = -kc; ii <= kc; ++ii ) { 03075 int nbrcx = cx + ii; 03076 if( nbrcx >= m_vnxc ) continue; 03077 for ( int jj= -kc; jj <= kc; ++jj ) { 03078 int nbrcy = cy + jj; 03079 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue; 03080 for( int kk = -kc; kk <= kc; ++kk ) { 03081 int nbrcz = cz + jj; 03082 if ( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue; 03083 if( nbrcx < 0 ) { 03084 nbrcx = -nbrcx; 03085 nbrcy = -nbrcy; 03086 nbrcz = -nbrcz; 03087 } 03088 int nbrix = nbrcx; 03089 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp; 03090 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp; 03091 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) { 03092 int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk); 03093 sum = sum + pow_a[c]; 03094 } 03095 } 03096 } 03097 } 03098 wght = 1.0f / ( 1.0f - alpha * sum ); 03099 } // end of ( m_weighting == ESTIMATE ) 03100 float nominator = std::norm(m_volume->cmplx(ix,iy,iz)/Kn); 03101 float denominator = ((*m_wptr2)(ix,iy,iz)-nominator)/(Kn-1.0f); 03102 // Skip Friedel related values 03103 if( (ix>0 || (kz>=0 && (ky>=0 || kz!=0)))) { 03104 if ( r <= inc ) { 03105 nom[r] += nominator*wght; 03106 denom[r] += denominator/Kn*wght; 03107 nn[r] += 2; 03108 ka[r] += int(Kn); 03109 } 03110 /* 03111 #ifdef _WIN32 03112 //#float tmp = _cpp_max(nominator/denominator/Kn-1.0f,0.0f); 03113 #else 03114 //#float tmp = std::max(nominator/denominator/Kn-1.0f,0.0f); 03115 #endif //_WIN32 03116 // Create SSNR as a 3D array (-n/2:n/2+n%2-1) 03117 iix = m_vnxc + ix; iiy = m_vnyc + ky; iiz = m_vnzc + kz; 03118 if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp ) 03119 (*vol_ssnr)(iix, iiy, iiz) = tmp; 03120 // Friedel part 03121 iix = m_vnxc - ix; iiy = m_vnyc - ky; iiz = m_vnzc - kz; 03122 if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp ) 03123 (*vol_ssnr)(iix, iiy, iiz) = tmp; 03124 */ 03125 03126 } 03127 (*vol_ssnr)(2*ix, iy-1, iz-1) = nominator*wght;//Kn;//denominator*wght;// 03128 //(*vol_ssnr)(2*ix, iy-1, iz-1) = real(m_volume->cmplx(ix,iy,iz))*wght/Kn; 03129 //(*vol_ssnr)(2*ix+1, iy-1, iz-1) = imag(m_volume->cmplx(ix,iy,iz))*wght/Kn; 03130 } // end of Kn>4.5 03131 } 03132 } 03133 } 03134 03135 for (int i = 0; i <= inc; i++) { 03136 (*SSNR)(i,0,0) = nom[i]; 03137 (*SSNR)(i,1,0) = denom[i]; // variance 03138 (*SSNR)(i,2,0) = static_cast<float>(nn[i]); 03139 (*SSNR)(i,3,0) = static_cast<float>(ka[i]); 03140 } 03141 vol_ssnr->update(); 03142 03143 delete[] nom; 03144 delete[] denom; 03145 delete[] nn; 03146 delete[] ka; 03147 03148 return 0; 03149 }
virtual string EMAN::nnSSNR_Reconstructor::get_desc | ( | ) | const [inline, virtual] |
Get a clear, concise description of this class.
Implements EMAN::FactoryBase.
Definition at line 1161 of file reconstructor.h.
virtual string EMAN::nnSSNR_Reconstructor::get_name | ( | ) | const [inline, virtual] |
Get the unique name of this class (especially for factory based instantiation access).
Implements EMAN::FactoryBase.
Definition at line 1156 of file reconstructor.h.
References NAME.
01157 { 01158 return NAME; 01159 }
virtual TypeDict EMAN::nnSSNR_Reconstructor::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::FactoryBase.
Definition at line 1171 of file reconstructor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
01172 { 01173 TypeDict d; 01174 d.put("size", EMObject::INT); 01175 d.put("npad", EMObject::INT); 01176 d.put("symmetry", EMObject::STRING); 01177 d.put("fftvol", EMObject::EMDATA); 01178 d.put("weight", EMObject::EMDATA); 01179 d.put("weight2", EMObject::EMDATA); 01180 d.put("SSNR", EMObject::EMDATA); 01181 d.put("vol_ssnr", EMObject::EMDATA); 01182 d.put("w", EMObject::FLOAT); 01183 return d; 01184 }
int nnSSNR_Reconstructor::insert_padfft_slice | ( | EMData * | padded, | |
const Transform & | trans, | |||
int | mult = 1 | |||
) |
Definition at line 2979 of file reconstructor.cpp.
References Assert, m_nsym, m_symmetry, m_volume, m_wptr, m_wptr2, EMAN::EMData::nn_SSNR(), and t.
Referenced by insert_slice().
02980 { 02981 Assert( padfft != NULL ); 02982 // insert slice for all symmetry related positions 02983 for (int isym=0; isym < m_nsym; isym++) { 02984 Transform tsym = t.get_sym(m_symmetry, isym); 02985 m_volume->nn_SSNR( m_wptr, m_wptr2, padfft, tsym, mult); 02986 } 02987 return 0; 02988 }
int nnSSNR_Reconstructor::insert_slice | ( | const EMData *const | slice, | |
const Transform & | euler, | |||
const float | weight = 1.0 | |||
) | [virtual] |
Insert an image slice to the reconstructor.
To insert multiple image slices, call this function multiple times.
slice | Image slice. | |
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 |
Reimplemented from EMAN::Reconstructor.
Definition at line 2950 of file reconstructor.cpp.
References Assert, checked_delete(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), insert_padfft_slice(), LOGERR, m_npad, m_vnx, mult(), EMAN::padfft_slice(), and t.
02950 { 02951 // sanity checks 02952 if (!slice) { 02953 LOGERR("try to insert NULL slice"); 02954 return 1; 02955 } 02956 02957 int padffted=slice->get_attr_default( "padffted", 0 ); 02958 02959 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) { 02960 // FIXME: Why doesn't this throw an exception? 02961 LOGERR("Tried to insert a slice that has wrong size."); 02962 return 1; 02963 } 02964 02965 EMData* padfft = NULL; 02966 02967 if( padffted != 0 ) padfft = new EMData(*slice); 02968 else padfft = padfft_slice( slice, t, m_npad ); 02969 02970 int mult = slice->get_attr_default("mult", 1); 02971 02972 Assert( mult > 0 ); 02973 insert_padfft_slice( padfft, t, mult ); 02974 02975 checked_delete( padfft ); 02976 return 0; 02977 }
static Reconstructor* EMAN::nnSSNR_Reconstructor::NEW | ( | ) | [inline, static] |
Definition at line 1166 of file reconstructor.h.
References nnSSNR_Reconstructor().
01167 { 01168 return new nnSSNR_Reconstructor(); 01169 }
void nnSSNR_Reconstructor::setup | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 2888 of file reconstructor.cpp.
References buildFFTVolume(), buildNorm2Volume(), buildNormVolume(), ESTIMATE, EMAN::Transform::get_nsym(), 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, and m_wghtb.
02889 { 02890 02891 m_weighting = ESTIMATE; 02892 m_wghta = 0.2f; 02893 m_wghtb = 0.004f; 02894 02895 m_symmetry = symmetry; 02896 m_npad = npad; 02897 m_nsym = Transform::get_nsym(m_symmetry); 02898 02899 m_vnx = size; 02900 m_vny = size; 02901 m_vnz = size; 02902 02903 m_vnxp = size*npad; 02904 m_vnyp = size*npad; 02905 m_vnzp = size*npad; 02906 02907 m_vnxc = m_vnxp/2; 02908 m_vnyc = m_vnyp/2; 02909 m_vnzc = m_vnzp/2; 02910 02911 buildFFTVolume(); 02912 buildNormVolume(); 02913 buildNorm2Volume(); 02914 02915 }
void nnSSNR_Reconstructor::setup | ( | ) | [virtual] |
Initialize the reconstructor.
Implements EMAN::Reconstructor.
Definition at line 2876 of file reconstructor.cpp.
References EMAN::Dict::has_key(), EMAN::FactoryBase::params, and EMAN::Gatan::to_str().
Referenced by nnSSNR_Reconstructor().
02877 { 02878 int size = params["size"]; 02879 int npad = params["npad"]; 02880 02881 string symmetry; 02882 if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str(); 02883 else symmetry = "c1"; 02884 02885 setup( symmetry, size, npad ); 02886 }
int EMAN::nnSSNR_Reconstructor::m_npad [private] |
Definition at line 1199 of file reconstructor.h.
Referenced by buildFFTVolume(), insert_slice(), and setup().
int EMAN::nnSSNR_Reconstructor::m_nsym [private] |
string EMAN::nnSSNR_Reconstructor::m_symmetry [private] |
int EMAN::nnSSNR_Reconstructor::m_vnx [private] |
int EMAN::nnSSNR_Reconstructor::m_vnxc [private] |
Definition at line 1202 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNorm2Volume(), buildNormVolume(), finish(), and setup().
int EMAN::nnSSNR_Reconstructor::m_vnxp [private] |
Definition at line 1201 of file reconstructor.h.
Referenced by buildFFTVolume(), finish(), and setup().
int EMAN::nnSSNR_Reconstructor::m_vny [private] |
int EMAN::nnSSNR_Reconstructor::m_vnyc [private] |
int EMAN::nnSSNR_Reconstructor::m_vnyp [private] |
Definition at line 1201 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNorm2Volume(), buildNormVolume(), finish(), and setup().
int EMAN::nnSSNR_Reconstructor::m_vnz [private] |
int EMAN::nnSSNR_Reconstructor::m_vnzc [private] |
int EMAN::nnSSNR_Reconstructor::m_vnzp [private] |
Definition at line 1201 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNorm2Volume(), buildNormVolume(), finish(), and setup().
EMData* EMAN::nnSSNR_Reconstructor::m_volume [private] |
Definition at line 1193 of file reconstructor.h.
Referenced by buildFFTVolume(), finish(), insert_padfft_slice(), and nnSSNR_Reconstructor().
int EMAN::nnSSNR_Reconstructor::m_weighting [private] |
float EMAN::nnSSNR_Reconstructor::m_wghta [private] |
float EMAN::nnSSNR_Reconstructor::m_wghtb [private] |
EMData* EMAN::nnSSNR_Reconstructor::m_wptr [private] |
Definition at line 1194 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_padfft_slice(), and nnSSNR_Reconstructor().
EMData* EMAN::nnSSNR_Reconstructor::m_wptr2 [private] |
Definition at line 1195 of file reconstructor.h.
Referenced by buildNorm2Volume(), finish(), insert_padfft_slice(), and nnSSNR_Reconstructor().
const string nnSSNR_Reconstructor::NAME = "nnSSNR" [static] |