#include <reconstructor.h>
Inheritance diagram for EMAN::nn4Reconstructor:
Public Member Functions | |
nn4Reconstructor () | |
nn4Reconstructor (const string &symmetry, int size, int npad) | |
virtual | ~nn4Reconstructor () |
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 = "nn4" |
Private Member Functions | |
void | buildFFTVolume () |
void | buildNormVolume () |
void | load_default_settings () |
Private Attributes | |
EMData * | m_volume |
EMData * | m_wptr |
EMData * | m_result |
bool | m_delete_volume |
bool | m_delete_weight |
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 |
float | m_wghta |
float | m_wghtb |
float | m_osnr |
Definition at line 730 of file reconstructor.h.
nn4Reconstructor::nn4Reconstructor | ( | ) |
nn4Reconstructor::nn4Reconstructor | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 1980 of file reconstructor.cpp.
References load_default_settings(), m_result, m_volume, m_wptr, EMAN::Reconstructor::print_params(), and setup().
01981 { 01982 m_volume = NULL; 01983 m_wptr = NULL; 01984 m_result = NULL; 01985 setup( symmetry, size, npad ); 01986 load_default_settings(); 01987 print_params(); 01988 }
nn4Reconstructor::~nn4Reconstructor | ( | ) | [virtual] |
Definition at line 1990 of file reconstructor.cpp.
References checked_delete(), m_delete_volume, m_delete_weight, m_result, m_volume, and m_wptr.
01991 { 01992 if( m_delete_volume ) checked_delete(m_volume); 01993 01994 if( m_delete_weight ) checked_delete( m_wptr ); 01995 01996 checked_delete( m_result ); 01997 }
void nn4Reconstructor::buildFFTVolume | ( | ) | [private] |
Definition at line 2083 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_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().
02083 { 02084 int offset = 2 - m_vnxp%2; 02085 02086 if( params.has_key("fftvol") ) { 02087 m_volume = params["fftvol"]; 02088 m_delete_volume = false; 02089 } else { 02090 m_volume = new EMData(); 02091 m_delete_volume = true; 02092 } 02093 02094 if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) { 02095 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp); 02096 m_volume->to_zero(); 02097 } 02098 // ---------------------------------------------------------------- 02099 // Added by Zhengfan Yang on 03/15/07 02100 // Original author: please check whether my revision is correct and 02101 // other Reconstructor need similiar revision. 02102 if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0); 02103 else m_volume->set_fftodd(1); 02104 // ---------------------------------------------------------------- 02105 02106 m_volume->set_nxc(m_vnxp/2); 02107 m_volume->set_complex(true); 02108 m_volume->set_ri(true); 02109 m_volume->set_fftpad(true); 02110 m_volume->set_attr("npad", m_npad); 02111 m_volume->set_array_offsets(0,1,1); 02112 }
void nn4Reconstructor::buildNormVolume | ( | ) | [private] |
Definition at line 2114 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().
02114 { 02115 02116 if( params.has_key("weight") ) { 02117 m_wptr = params["weight"]; 02118 m_delete_weight = false; 02119 } else { 02120 m_wptr = new EMData(); 02121 m_delete_weight = true; 02122 } 02123 02124 if( m_wptr->get_xsize() != m_vnxc+1 && 02125 m_wptr->get_ysize() != m_vnyp && 02126 m_wptr->get_zsize() != m_vnzp ) { 02127 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02128 m_wptr->to_zero(); 02129 } 02130 02131 m_wptr->set_array_offsets(0,1,1); 02132 }
EMData * nn4Reconstructor::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 2299 of file reconstructor.cpp.
References abs, circumf(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), ESTIMATE, EMAN::EMData::get_attr(), m_ndim, m_osnr, m_result, 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().
02300 { 02301 if( m_ndim==3 ) { 02302 m_volume->symplane0(m_wptr); 02303 } else { 02304 for( int i=1; i <= m_vnyp; ++i ) { 02305 02306 if( (*m_wptr)(0, i, 1)==0.0 ) { 02307 int j = m_vnyp + 1 - i; 02308 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1); 02309 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1); 02310 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1); 02311 } 02312 } 02313 } 02314 02315 02316 int box = 7; 02317 int kc = (box-1)/2; 02318 vector< float > pow_a( m_ndim*kc+1, 1.0 ); 02319 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta); 02320 pow_a.back()=0.0; 02321 02322 float alpha = 0.0; 02323 if( m_ndim==3) { 02324 int vol = box*box*box; 02325 float max = max3d( kc, pow_a ); 02326 alpha = ( 1.0f - 1.0f/(float)vol ) / max; 02327 } else { 02328 int ara = box*box; 02329 float max = max2d( kc, pow_a ); 02330 alpha = ( 1.0f - 1.0f/(float)ara ) / max; 02331 } 02332 02333 int ix,iy,iz; 02334 for (iz = 1; iz <= m_vnzp; iz++) { 02335 for (iy = 1; iy <= m_vnyp; iy++) { 02336 for (ix = 0; ix <= m_vnxc; ix++) { 02337 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!! 02338 float tmp; 02339 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr); 02340 02341 if( m_weighting == ESTIMATE ) { 02342 int cx = ix; 02343 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp; 02344 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp; 02345 float sum = 0.0; 02346 for( int ii = -kc; ii <= kc; ++ii ) { 02347 int nbrcx = cx + ii; 02348 if( nbrcx >= m_vnxc ) continue; 02349 for( int jj= -kc; jj <= kc; ++jj ) { 02350 int nbrcy = cy + jj; 02351 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue; 02352 02353 int kcz = (m_ndim==3) ? kc : 0; 02354 for( int kk = -kcz; kk <= kcz; ++kk ) { 02355 int nbrcz = cz + kk; 02356 if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue; 02357 if( nbrcx < 0 ) { 02358 nbrcx = -nbrcx; 02359 nbrcy = -nbrcy; 02360 nbrcz = -nbrcz; 02361 } 02362 int nbrix = nbrcx; 02363 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp; 02364 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp; 02365 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) { 02366 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk); 02367 sum = sum + pow_a[c]; 02368 } 02369 } 02370 } 02371 } 02372 float wght = 1.0f / ( 1.0f - alpha * sum ); 02373 tmp = tmp * wght; 02374 } 02375 (*m_volume)(2*ix,iy,iz) *= tmp; 02376 (*m_volume)(2*ix+1,iy,iz) *= tmp; 02377 } 02378 } 02379 } 02380 } 02381 02382 //if(m_ndim==2) printImage( m_volume ); 02383 02384 // back fft 02385 m_volume->do_ift_inplace(); 02386 02387 // EMData* win = m_volume->window_center(m_vnx); 02388 int npad = m_volume->get_attr("npad"); 02389 m_volume->depad(); 02390 circumf( m_volume, npad ); 02391 m_volume->set_array_offsets( 0, 0, 0 ); 02392 02393 m_result = m_volume->copy(); 02394 return m_result; 02395 }
virtual string EMAN::nn4Reconstructor::get_desc | ( | ) | const [inline, virtual] |
Get a clear, concise description of this class.
Implements EMAN::FactoryBase.
Definition at line 758 of file reconstructor.h.
virtual string EMAN::nn4Reconstructor::get_name | ( | ) | const [inline, virtual] |
Get the unique name of this class (especially for factory based instantiation access).
Implements EMAN::FactoryBase.
Definition at line 753 of file reconstructor.h.
References NAME.
00754 { 00755 return NAME; 00756 }
virtual TypeDict EMAN::nn4Reconstructor::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::FactoryBase.
Definition at line 768 of file reconstructor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
00769 { 00770 TypeDict d; 00771 d.put("size", EMObject::INT); 00772 d.put("npad", EMObject::INT); 00773 d.put("sign", EMObject::INT); 00774 d.put("ndim", EMObject::INT); 00775 d.put("snr", EMObject::FLOAT); 00776 d.put("symmetry", EMObject::STRING); 00777 d.put("snr", EMObject::FLOAT); 00778 d.put("fftvol", EMObject::EMDATA); 00779 d.put("weight", EMObject::EMDATA); 00780 d.put("weighting", EMObject::INT); 00781 return d; 00782 }
int nn4Reconstructor::insert_padfft_slice | ( | EMData * | padded, | |
const Transform & | trans, | |||
int | mult = 1 | |||
) |
Definition at line 2210 of file reconstructor.cpp.
References Assert, m_nsym, m_symmetry, m_volume, m_wptr, EMAN::EMData::nn(), and t.
Referenced by insert_slice().
02211 { 02212 Assert( padfft != NULL ); 02213 // insert slice for all symmetry related positions 02214 02215 for (int isym=0; isym < m_nsym; isym++) { 02216 Transform tsym = t.get_sym(m_symmetry, isym); 02217 02218 m_volume->nn( m_wptr, padfft, tsym, mult); 02219 } 02220 return 0; 02221 }
int nn4Reconstructor::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 2149 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_ndim, m_npad, m_vnx, m_vnxc, m_vnxp, m_vnyp, mult(), EMAN::padfft_slice(), and t.
02149 { 02150 // sanity checks 02151 if (!slice) { 02152 LOGERR("try to insert NULL slice"); 02153 return 1; 02154 } 02155 02156 int padffted= slice->get_attr_default( "padffted", 0 ); 02157 if( m_ndim==3 ) { 02158 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) { 02159 // FIXME: Why doesn't this throw an exception? 02160 LOGERR("Tried to insert a slice that is the wrong size."); 02161 return 1; 02162 } 02163 } else { 02164 Assert( m_ndim==2 ); 02165 if( slice->get_ysize() !=1 ) { 02166 LOGERR( "for 2D reconstruction, a line is excepted" ); 02167 return 1; 02168 } 02169 } 02170 02171 EMData* padfft = NULL; 02172 02173 if( padffted != 0 ) padfft = new EMData(*slice); 02174 else padfft = padfft_slice( slice, t, m_npad ); 02175 02176 int mult= slice->get_attr_default( "mult", 1 ); 02177 Assert( mult > 0 ); 02178 02179 if( m_ndim==3 ) { 02180 insert_padfft_slice( padfft, t, mult ); 02181 } else { 02182 float alpha = padfft->get_attr( "alpha" ); 02183 alpha = alpha/180.0f*M_PI; 02184 for(int i=0; i < m_vnxc+1; ++i ) { 02185 float xnew = i*cos(alpha); 02186 float ynew = -i*sin(alpha); 02187 float btqr = padfft->get_value_at( 2*i, 0, 0 ); 02188 float btqi = padfft->get_value_at( 2*i+1, 0, 0 ); 02189 if( xnew < 0.0 ) { 02190 xnew *= -1; 02191 ynew *= -1; 02192 btqi *= -1; 02193 } 02194 02195 int ixn = int(xnew+0.5+m_vnxp) - m_vnxp; 02196 int iyn = int(ynew+0.5+m_vnyp) - m_vnyp; 02197 02198 if(iyn < 0 ) iyn += m_vnyp; 02199 02200 (*m_volume)( 2*ixn, iyn+1, 1 ) += btqr *float(mult); 02201 (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * float(mult); 02202 (*m_wptr)(ixn,iyn+1, 1) += float(mult); 02203 } 02204 02205 } 02206 checked_delete( padfft ); 02207 return 0; 02208 }
void EMAN::nn4Reconstructor::load_default_settings | ( | ) | [inline, private] |
static Reconstructor* EMAN::nn4Reconstructor::NEW | ( | ) | [inline, static] |
Definition at line 763 of file reconstructor.h.
References nn4Reconstructor().
00764 { 00765 return new nn4Reconstructor(); 00766 }
void nn4Reconstructor::setup | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 2056 of file reconstructor.cpp.
References buildFFTVolume(), buildNormVolume(), ESTIMATE, EMAN::Transform::get_nsym(), 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, and m_wghta.
02057 { 02058 m_weighting = ESTIMATE; 02059 m_wghta = 0.2f; 02060 02061 m_symmetry = symmetry; 02062 m_npad = npad; 02063 m_nsym = Transform::get_nsym(m_symmetry); 02064 02065 m_vnx = size; 02066 m_vny = size; 02067 m_vnz = (m_ndim==3) ? size : 1; 02068 02069 m_vnxp = size*npad; 02070 m_vnyp = size*npad; 02071 m_vnzp = (m_ndim==3) ? size*npad : 1; 02072 02073 m_vnxc = m_vnxp/2; 02074 m_vnyc = m_vnyp/2; 02075 m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1; 02076 02077 buildFFTVolume(); 02078 buildNormVolume(); 02079 02080 }
void nn4Reconstructor::setup | ( | ) | [virtual] |
Initialize the reconstructor.
Implements EMAN::Reconstructor.
Definition at line 2037 of file reconstructor.cpp.
References EMAN::Dict::has_key(), m_ndim, m_osnr, EMAN::FactoryBase::params, and EMAN::Gatan::to_str().
Referenced by nn4Reconstructor().
02038 { 02039 int size = params["size"]; 02040 int npad = params["npad"]; 02041 02042 02043 string symmetry; 02044 if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str(); 02045 else symmetry = "c1"; 02046 02047 if( params.has_key("ndim") ) m_ndim = params["ndim"]; 02048 else m_ndim = 3; 02049 02050 if( params.has_key( "snr" ) ) m_osnr = 1.0f/float( params["snr"] ); 02051 else m_osnr = 0.0; 02052 02053 setup( symmetry, size, npad ); 02054 }
bool EMAN::nn4Reconstructor::m_delete_volume [private] |
Definition at line 794 of file reconstructor.h.
Referenced by buildFFTVolume(), and ~nn4Reconstructor().
bool EMAN::nn4Reconstructor::m_delete_weight [private] |
Definition at line 795 of file reconstructor.h.
Referenced by buildNormVolume(), and ~nn4Reconstructor().
int EMAN::nn4Reconstructor::m_ndim [private] |
Definition at line 801 of file reconstructor.h.
Referenced by finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_npad [private] |
Definition at line 799 of file reconstructor.h.
Referenced by buildFFTVolume(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_nsym [private] |
float EMAN::nn4Reconstructor::m_osnr [private] |
EMData* EMAN::nn4Reconstructor::m_result [private] |
Definition at line 793 of file reconstructor.h.
Referenced by finish(), nn4Reconstructor(), and ~nn4Reconstructor().
string EMAN::nn4Reconstructor::m_symmetry [private] |
int EMAN::nn4Reconstructor::m_vnx [private] |
int EMAN::nn4Reconstructor::m_vnxc [private] |
Definition at line 803 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_vnxp [private] |
Definition at line 802 of file reconstructor.h.
Referenced by buildFFTVolume(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_vny [private] |
int EMAN::nn4Reconstructor::m_vnyc [private] |
int EMAN::nn4Reconstructor::m_vnyp [private] |
Definition at line 802 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_vnz [private] |
int EMAN::nn4Reconstructor::m_vnzc [private] |
int EMAN::nn4Reconstructor::m_vnzp [private] |
Definition at line 802 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), and setup().
EMData* EMAN::nn4Reconstructor::m_volume [private] |
Definition at line 791 of file reconstructor.h.
Referenced by buildFFTVolume(), finish(), insert_padfft_slice(), nn4Reconstructor(), and ~nn4Reconstructor().
int EMAN::nn4Reconstructor::m_weighting [private] |
float EMAN::nn4Reconstructor::m_wghta [private] |
float EMAN::nn4Reconstructor::m_wghtb [private] |
Definition at line 807 of file reconstructor.h.
EMData* EMAN::nn4Reconstructor::m_wptr [private] |
Definition at line 792 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_padfft_slice(), nn4Reconstructor(), and ~nn4Reconstructor().
const string nn4Reconstructor::NAME = "nn4" [static] |