#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 792 of file reconstructor.h.
nn4Reconstructor::nn4Reconstructor | ( | ) |
nn4Reconstructor::nn4Reconstructor | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 1995 of file reconstructor.cpp.
References load_default_settings(), m_result, m_volume, m_wptr, EMAN::Reconstructor::print_params(), and setup().
01996 { 01997 m_volume = NULL; 01998 m_wptr = NULL; 01999 m_result = NULL; 02000 setup( symmetry, size, npad ); 02001 load_default_settings(); 02002 print_params(); 02003 }
nn4Reconstructor::~nn4Reconstructor | ( | ) | [virtual] |
Definition at line 2005 of file reconstructor.cpp.
References checked_delete(), m_delete_volume, m_delete_weight, m_result, m_volume, and m_wptr.
02006 { 02007 if( m_delete_volume ) 02008 checked_delete(m_volume); 02009 02010 if( m_delete_weight ) 02011 checked_delete( m_wptr ); 02012 02013 checked_delete( m_result ); 02014 }
void nn4Reconstructor::buildFFTVolume | ( | ) | [private] |
Definition at line 2109 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().
02109 { 02110 int offset = 2 - m_vnxp%2; 02111 02112 if( params.has_key("fftvol") ) { 02113 m_volume = params["fftvol"]; 02114 m_delete_volume = false; 02115 } else { 02116 m_volume = new EMData(); 02117 m_delete_volume = true; 02118 } 02119 02120 if( m_volume->get_xsize() != m_vnxp+offset && 02121 m_volume->get_ysize() != m_vnyp && 02122 m_volume->get_zsize() != m_vnzp ) { 02123 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp); 02124 m_volume->to_zero(); 02125 } 02126 // ---------------------------------------------------------------- 02127 // Added by Zhengfan Yang on 03/15/07 02128 // Original author: please check whether my revision is correct and 02129 // other Reconstructor need similiar revision. 02130 if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0); 02131 else m_volume->set_fftodd(1); 02132 // ---------------------------------------------------------------- 02133 02134 m_volume->set_nxc(m_vnxp/2); 02135 m_volume->set_complex(true); 02136 m_volume->set_ri(true); 02137 m_volume->set_fftpad(true); 02138 m_volume->set_attr("npad", m_npad); 02139 m_volume->set_array_offsets(0,1,1); 02140 }
void nn4Reconstructor::buildNormVolume | ( | ) | [private] |
Definition at line 2142 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().
02142 { 02143 02144 if( params.has_key("weight") ) { 02145 m_wptr = params["weight"]; 02146 m_delete_weight = false; 02147 } else { 02148 m_wptr = new EMData(); 02149 m_delete_weight = true; 02150 } 02151 02152 if( m_wptr->get_xsize() != m_vnxc+1 && 02153 m_wptr->get_ysize() != m_vnyp && 02154 m_wptr->get_zsize() != m_vnzp ) { 02155 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02156 m_wptr->to_zero(); 02157 } 02158 02159 m_wptr->set_array_offsets(0,1,1); 02160 }
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 2294 of file reconstructor.cpp.
References abs, circumference(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), ESTIMATE, 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().
02295 { 02296 if( m_ndim==3 ) { 02297 m_volume->symplane0(m_wptr); 02298 } else { 02299 for( int i=1; i <= m_vnyp; ++i ) { 02300 02301 if( (*m_wptr)(0, i, 1)==0.0 ) { 02302 int j = m_vnyp + 1 - i; 02303 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1); 02304 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1); 02305 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1); 02306 } 02307 } 02308 } 02309 02310 02311 int box = 7; 02312 int kc = (box-1)/2; 02313 vector< float > pow_a( m_ndim*kc+1, 1.0 ); 02314 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta); 02315 pow_a.back()=0.0; 02316 02317 float alpha = 0.0; 02318 if( m_ndim==3) { 02319 int vol = box*box*box; 02320 float max = max3d( kc, pow_a ); 02321 alpha = ( 1.0f - 1.0f/(float)vol ) / max; 02322 } else { 02323 int ara = box*box; 02324 float max = max2d( kc, pow_a ); 02325 alpha = ( 1.0f - 1.0f/(float)ara ) / max; 02326 } 02327 02328 int ix,iy,iz; 02329 for (iz = 1; iz <= m_vnzp; iz++) { 02330 for (iy = 1; iy <= m_vnyp; iy++) { 02331 for (ix = 0; ix <= m_vnxc; ix++) { 02332 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!! 02333 float tmp; 02334 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr); 02335 02336 if( m_weighting == ESTIMATE ) { 02337 int cx = ix; 02338 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp; 02339 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp; 02340 float sum = 0.0; 02341 for( int ii = -kc; ii <= kc; ++ii ) { 02342 int nbrcx = cx + ii; 02343 if( nbrcx >= m_vnxc ) continue; 02344 for( int jj= -kc; jj <= kc; ++jj ) { 02345 int nbrcy = cy + jj; 02346 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue; 02347 02348 int kcz = (m_ndim==3) ? kc : 0; 02349 for( int kk = -kcz; kk <= kcz; ++kk ) { 02350 int nbrcz = cz + kk; 02351 if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue; 02352 if( nbrcx < 0 ) { 02353 nbrcx = -nbrcx; 02354 nbrcy = -nbrcy; 02355 nbrcz = -nbrcz; 02356 } 02357 int nbrix = nbrcx; 02358 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp; 02359 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp; 02360 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) { 02361 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk); 02362 sum = sum + pow_a[c]; 02363 } 02364 } 02365 } 02366 } 02367 float wght = 1.0f / ( 1.0f - alpha * sum ); 02368 tmp = tmp * wght; 02369 } 02370 (*m_volume)(2*ix,iy,iz) *= tmp; 02371 (*m_volume)(2*ix+1,iy,iz) *= tmp; 02372 } 02373 } 02374 } 02375 } 02376 02377 //if(m_ndim==2) printImage( m_volume ); 02378 02379 // back fft 02380 m_volume->do_ift_inplace(); 02381 02382 // EMData* win = m_volume->window_center(m_vnx); 02383 m_volume->depad(); 02384 circumference( m_volume ); 02385 m_volume->set_array_offsets( 0, 0, 0 ); 02386 02387 m_result = m_volume->copy(); 02388 return m_result; 02389 }
virtual string EMAN::nn4Reconstructor::get_desc | ( | ) | const [inline, virtual] |
Get a clear, concise description of this class.
Implements EMAN::FactoryBase.
Definition at line 820 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 815 of file reconstructor.h.
References NAME.
00816 { 00817 return NAME; 00818 }
virtual TypeDict EMAN::nn4Reconstructor::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::FactoryBase.
Definition at line 830 of file reconstructor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
00831 { 00832 TypeDict d; 00833 d.put("size", EMObject::INT); 00834 d.put("npad", EMObject::INT); 00835 d.put("sign", EMObject::INT); 00836 d.put("ndim", EMObject::INT); 00837 d.put("snr", EMObject::FLOAT); 00838 d.put("symmetry", EMObject::STRING); 00839 d.put("snr", EMObject::FLOAT); 00840 d.put("fftvol", EMObject::EMDATA); 00841 d.put("weight", EMObject::EMDATA); 00842 d.put("weighting", EMObject::INT); 00843 return d; 00844 }
int nn4Reconstructor::insert_padfft_slice | ( | EMData * | padded, | |
const Transform & | trans, | |||
int | mult = 1 | |||
) |
Definition at line 2238 of file reconstructor.cpp.
References Assert, m_nsym, m_symmetry, m_volume, m_wptr, EMAN::EMData::nn(), and t.
Referenced by insert_slice().
02239 { 02240 Assert( padfft != NULL ); 02241 // insert slice for all symmetry related positions 02242 for (int isym=0; isym < m_nsym; isym++) { 02243 Transform tsym = t.get_sym(m_symmetry, isym); 02244 m_volume->nn( m_wptr, padfft, tsym, mult); 02245 } 02246 return 0; 02247 }
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 2177 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.
02177 { 02178 // sanity checks 02179 if (!slice) { 02180 LOGERR("try to insert NULL slice"); 02181 return 1; 02182 } 02183 02184 int padffted= slice->get_attr_default( "padffted", 0 ); 02185 if( m_ndim==3 ) { 02186 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) { 02187 // FIXME: Why doesn't this throw an exception? 02188 LOGERR("Tried to insert a slice that is the wrong size."); 02189 return 1; 02190 } 02191 } else { 02192 Assert( m_ndim==2 ); 02193 if( slice->get_ysize() !=1 ) { 02194 LOGERR( "for 2D reconstruction, a line is excepted" ); 02195 return 1; 02196 } 02197 } 02198 02199 EMData* padfft = NULL; 02200 02201 if( padffted != 0 ) padfft = new EMData(*slice); 02202 else padfft = padfft_slice( slice, t, m_npad ); 02203 02204 int mult= slice->get_attr_default( "mult", 1 ); 02205 Assert( mult > 0 ); 02206 02207 if( m_ndim==3 ) { 02208 insert_padfft_slice( padfft, t, mult ); 02209 } else { 02210 float alpha = padfft->get_attr( "alpha" ); 02211 alpha = alpha/180.0f*M_PI; 02212 for(int i=0; i < m_vnxc+1; ++i ) { 02213 float xnew = i*cos(alpha); 02214 float ynew = -i*sin(alpha); 02215 float btqr = padfft->get_value_at( 2*i, 0, 0 ); 02216 float btqi = padfft->get_value_at( 2*i+1, 0, 0 ); 02217 if( xnew < 0.0 ) { 02218 xnew *= -1; 02219 ynew *= -1; 02220 btqi *= -1; 02221 } 02222 02223 int ixn = int(xnew+0.5+m_vnxp) - m_vnxp; 02224 int iyn = int(ynew+0.5+m_vnyp) - m_vnyp; 02225 02226 if(iyn < 0 ) iyn += m_vnyp; 02227 02228 (*m_volume)( 2*ixn, iyn+1, 1 ) += btqr *float(mult); 02229 (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * float(mult); 02230 (*m_wptr)(ixn,iyn+1, 1) += float(mult); 02231 } 02232 02233 } 02234 checked_delete( padfft ); 02235 return 0; 02236 }
void EMAN::nn4Reconstructor::load_default_settings | ( | ) | [inline, private] |
static Reconstructor* EMAN::nn4Reconstructor::NEW | ( | ) | [inline, static] |
Definition at line 825 of file reconstructor.h.
References nn4Reconstructor().
00826 { 00827 return new nn4Reconstructor(); 00828 }
void nn4Reconstructor::setup | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 2082 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.
02083 { 02084 m_weighting = ESTIMATE; 02085 m_wghta = 0.2f; 02086 02087 m_symmetry = symmetry; 02088 m_npad = npad; 02089 m_nsym = Transform::get_nsym(m_symmetry); 02090 02091 m_vnx = size; 02092 m_vny = size; 02093 m_vnz = (m_ndim==3) ? size : 1; 02094 02095 m_vnxp = size*npad; 02096 m_vnyp = size*npad; 02097 m_vnzp = (m_ndim==3) ? size*npad : 1; 02098 02099 m_vnxc = m_vnxp/2; 02100 m_vnyc = m_vnyp/2; 02101 m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1; 02102 02103 buildFFTVolume(); 02104 buildNormVolume(); 02105 02106 }
void nn4Reconstructor::setup | ( | ) | [virtual] |
Initialize the reconstructor.
Implements EMAN::Reconstructor.
Definition at line 2054 of file reconstructor.cpp.
References EMAN::Dict::has_key(), m_ndim, m_osnr, EMAN::FactoryBase::params, and EMAN::Gatan::to_str().
Referenced by nn4Reconstructor().
02055 { 02056 int size = params["size"]; 02057 int npad = params["npad"]; 02058 02059 02060 string symmetry; 02061 if( params.has_key("symmetry") ) { 02062 symmetry = params["symmetry"].to_str(); 02063 } else { 02064 symmetry = "c1"; 02065 } 02066 02067 if( params.has_key("ndim") ) { 02068 m_ndim = params["ndim"]; 02069 } else { 02070 m_ndim = 3; 02071 } 02072 02073 if( params.has_key( "snr" ) ) { 02074 m_osnr = 1.0f/float( params["snr"] ); 02075 } else { 02076 m_osnr = 0.0; 02077 } 02078 02079 setup( symmetry, size, npad ); 02080 }
bool EMAN::nn4Reconstructor::m_delete_volume [private] |
Definition at line 856 of file reconstructor.h.
Referenced by buildFFTVolume(), and ~nn4Reconstructor().
bool EMAN::nn4Reconstructor::m_delete_weight [private] |
Definition at line 857 of file reconstructor.h.
Referenced by buildNormVolume(), and ~nn4Reconstructor().
int EMAN::nn4Reconstructor::m_ndim [private] |
Definition at line 863 of file reconstructor.h.
Referenced by finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_npad [private] |
Definition at line 861 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 855 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 865 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_vnxp [private] |
Definition at line 864 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 864 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 864 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), and setup().
EMData* EMAN::nn4Reconstructor::m_volume [private] |
Definition at line 853 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 869 of file reconstructor.h.
EMData* EMAN::nn4Reconstructor::m_wptr [private] |
Definition at line 854 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_padfft_slice(), nn4Reconstructor(), and ~nn4Reconstructor().
const string nn4Reconstructor::NAME = "nn4" [static] |