#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 |
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 947 of file reconstructor.h.
nn4Reconstructor::nn4Reconstructor | ( | ) |
nn4Reconstructor::nn4Reconstructor | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 2002 of file reconstructor.cpp.
References load_default_settings(), m_volume, m_wptr, EMAN::Reconstructor::print_params(), and setup().
02003 { 02004 m_volume = NULL; 02005 m_wptr = NULL; 02006 setup( symmetry, size, npad ); 02007 load_default_settings(); 02008 print_params(); 02009 }
nn4Reconstructor::~nn4Reconstructor | ( | ) | [virtual] |
Definition at line 2011 of file reconstructor.cpp.
02012 { 02013 //if( m_delete_volume ) checked_delete(m_volume); 02014 02015 //if( m_delete_weight ) checked_delete( m_wptr ); 02016 02017 //checked_delete( m_result ); 02018 }
void nn4Reconstructor::buildFFTVolume | ( | ) | [private] |
Definition at line 2104 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().
02104 { 02105 int offset = 2 - m_vnxp%2; 02106 02107 m_volume = params["fftvol"]; 02108 02109 if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) { 02110 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp); 02111 m_volume->to_zero(); 02112 } 02113 // ---------------------------------------------------------------- 02114 // Added by Zhengfan Yang on 03/15/07 02115 // Original author: please check whether my revision is correct and 02116 // other Reconstructor need similiar revision. 02117 if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0); 02118 else m_volume->set_fftodd(1); 02119 // ---------------------------------------------------------------- 02120 02121 m_volume->set_nxc(m_vnxp/2); 02122 m_volume->set_complex(true); 02123 m_volume->set_ri(true); 02124 m_volume->set_fftpad(true); 02125 m_volume->set_attr("npad", m_npad); 02126 m_volume->set_array_offsets(0,1,1); 02127 }
void nn4Reconstructor::buildNormVolume | ( | ) | [private] |
Definition at line 2129 of file reconstructor.cpp.
References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), 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().
02129 { 02130 02131 m_wptr = params["weight"]; 02132 02133 if( m_wptr->get_xsize() != m_vnxc+1 && 02134 m_wptr->get_ysize() != m_vnyp && 02135 m_wptr->get_zsize() != m_vnzp ) { 02136 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp); 02137 m_wptr->to_zero(); 02138 } 02139 m_wptr->set_array_offsets(0,1,1); 02140 }
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 2310 of file reconstructor.cpp.
References abs, circumf(), 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().
02310 { 02311 02312 if( m_ndim==3 ) { 02313 m_volume->symplane0(m_wptr); 02314 } else { 02315 for( int i=1; i <= m_vnyp; ++i ) { 02316 02317 if( (*m_wptr)(0, i, 1)==0.0 ) { 02318 int j = m_vnyp + 1 - i; 02319 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1); 02320 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1); 02321 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1); 02322 } 02323 } 02324 } 02325 02326 02327 int box = 7; 02328 int kc = (box-1)/2; 02329 vector< float > pow_a( m_ndim*kc+1, 1.0 ); 02330 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta); 02331 pow_a.back()=0.0; 02332 02333 float alpha = 0.0; 02334 if( m_ndim==3) { 02335 int vol = box*box*box; 02336 float max = max3d( kc, pow_a ); 02337 alpha = ( 1.0f - 1.0f/(float)vol ) / max; 02338 } else { 02339 int ara = box*box; 02340 float max = max2d( kc, pow_a ); 02341 alpha = ( 1.0f - 1.0f/(float)ara ) / max; 02342 } 02343 02344 int ix,iy,iz; 02345 for (iz = 1; iz <= m_vnzp; iz++) { 02346 for (iy = 1; iy <= m_vnyp; iy++) { 02347 for (ix = 0; ix <= m_vnxc; ix++) { 02348 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!! 02349 float tmp; 02350 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr); 02351 02352 if( m_weighting == ESTIMATE ) { 02353 int cx = ix; 02354 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp; 02355 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp; 02356 float sum = 0.0; 02357 for( int ii = -kc; ii <= kc; ++ii ) { 02358 int nbrcx = cx + ii; 02359 if( nbrcx >= m_vnxc ) continue; 02360 for( int jj= -kc; jj <= kc; ++jj ) { 02361 int nbrcy = cy + jj; 02362 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue; 02363 02364 int kcz = (m_ndim==3) ? kc : 0; 02365 for( int kk = -kcz; kk <= kcz; ++kk ) { 02366 int nbrcz = cz + kk; 02367 if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue; 02368 if( nbrcx < 0 ) { 02369 nbrcx = -nbrcx; 02370 nbrcy = -nbrcy; 02371 nbrcz = -nbrcz; 02372 } 02373 int nbrix = nbrcx; 02374 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp; 02375 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp; 02376 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) { 02377 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk); 02378 sum = sum + pow_a[c]; 02379 } 02380 } 02381 } 02382 } 02383 float wght = 1.0f / ( 1.0f - alpha * sum ); 02384 tmp = tmp * wght; 02385 } 02386 (*m_volume)(2*ix,iy,iz) *= tmp; 02387 (*m_volume)(2*ix+1,iy,iz) *= tmp; 02388 } 02389 } 02390 } 02391 } 02392 02393 //if(m_ndim==2) printImage( m_volume ); 02394 02395 // back fft 02396 m_volume->do_ift_inplace(); 02397 02398 // EMData* win = m_volume->window_center(m_vnx); 02399 int npad = m_volume->get_attr("npad"); 02400 m_volume->depad(); 02401 circumf( m_volume, npad ); 02402 m_volume->set_array_offsets( 0, 0, 0 ); 02403 02404 return 0; 02405 }
virtual string EMAN::nn4Reconstructor::get_desc | ( | ) | const [inline, virtual] |
Get a clear, concise description of this class.
Implements EMAN::FactoryBase.
Definition at line 975 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 970 of file reconstructor.h.
References NAME.
00971 { 00972 return NAME; 00973 }
virtual TypeDict EMAN::nn4Reconstructor::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::FactoryBase.
Definition at line 985 of file reconstructor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
00986 { 00987 TypeDict d; 00988 d.put("size", EMObject::INT); 00989 d.put("npad", EMObject::INT); 00990 d.put("sign", EMObject::INT); 00991 d.put("ndim", EMObject::INT); 00992 d.put("snr", EMObject::FLOAT); 00993 d.put("symmetry", EMObject::STRING); 00994 d.put("snr", EMObject::FLOAT); 00995 d.put("fftvol", EMObject::EMDATA); 00996 d.put("weight", EMObject::EMDATA); 00997 d.put("weighting", EMObject::INT); 00998 return d; 00999 }
int nn4Reconstructor::insert_padfft_slice | ( | EMData * | padded, | |
const Transform & | trans, | |||
int | mult = 1 | |||
) |
Definition at line 2218 of file reconstructor.cpp.
References Assert, m_symmetry, m_volume, m_wptr, EMAN::EMData::nn(), and t.
Referenced by insert_slice().
02219 { 02220 Assert( padfft != NULL ); 02221 02222 vector<Transform> tsym = t.get_sym_proj(m_symmetry); 02223 for (unsigned int isym=0; isym < tsym.size(); isym++) { 02224 m_volume->nn( m_wptr, padfft, tsym[isym], mult); 02225 } 02226 02227 /*for (int isym=0; isym < m_nsym; isym++) { 02228 Transform tsym = t.get_sym(m_symmetry, isym); 02229 m_volume->nn( m_wptr, padfft, tsym, mult); 02230 }*/ 02231 return 0; 02232 }
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 2157 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.
02157 { 02158 // sanity checks 02159 if (!slice) { 02160 LOGERR("try to insert NULL slice"); 02161 return 1; 02162 } 02163 02164 int padffted= slice->get_attr_default( "padffted", 0 ); 02165 if( m_ndim==3 ) { 02166 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) { 02167 // FIXME: Why doesn't this throw an exception? 02168 LOGERR("Tried to insert a slice that is the wrong size."); 02169 return 1; 02170 } 02171 } else { 02172 Assert( m_ndim==2 ); 02173 if( slice->get_ysize() !=1 ) { 02174 LOGERR( "for 2D reconstruction, a line is excepted" ); 02175 return 1; 02176 } 02177 } 02178 02179 EMData* padfft = NULL; 02180 02181 if( padffted != 0 ) padfft = new EMData(*slice); 02182 else padfft = padfft_slice( slice, t, m_npad ); 02183 02184 int mult= slice->get_attr_default( "mult", 1 ); 02185 Assert( mult > 0 ); 02186 02187 if( m_ndim==3 ) { 02188 insert_padfft_slice( padfft, t, mult ); 02189 } else { 02190 float alpha = padfft->get_attr( "alpha" ); 02191 alpha = alpha/180.0f*M_PI; 02192 for(int i=0; i < m_vnxc+1; ++i ) { 02193 float xnew = i*cos(alpha); 02194 float ynew = -i*sin(alpha); 02195 float btqr = padfft->get_value_at( 2*i, 0, 0 ); 02196 float btqi = padfft->get_value_at( 2*i+1, 0, 0 ); 02197 if( xnew < 0.0 ) { 02198 xnew *= -1; 02199 ynew *= -1; 02200 btqi *= -1; 02201 } 02202 02203 int ixn = int(xnew+0.5+m_vnxp) - m_vnxp; 02204 int iyn = int(ynew+0.5+m_vnyp) - m_vnyp; 02205 02206 if(iyn < 0 ) iyn += m_vnyp; 02207 02208 (*m_volume)( 2*ixn, iyn+1, 1 ) += btqr *float(mult); 02209 (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * float(mult); 02210 (*m_wptr)(ixn,iyn+1, 1) += float(mult); 02211 } 02212 02213 } 02214 checked_delete( padfft ); 02215 return 0; 02216 }
void EMAN::nn4Reconstructor::load_default_settings | ( | ) | [inline, private] |
static Reconstructor* EMAN::nn4Reconstructor::NEW | ( | ) | [inline, static] |
Definition at line 980 of file reconstructor.h.
References nn4Reconstructor().
00981 { 00982 return new nn4Reconstructor(); 00983 }
void nn4Reconstructor::setup | ( | const string & | symmetry, | |
int | size, | |||
int | npad | |||
) |
Definition at line 2077 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.
02078 { 02079 m_weighting = ESTIMATE; 02080 m_wghta = 0.2f; 02081 02082 m_symmetry = symmetry; 02083 m_npad = npad; 02084 m_nsym = Transform::get_nsym(m_symmetry); 02085 02086 m_vnx = size; 02087 m_vny = size; 02088 m_vnz = (m_ndim==3) ? size : 1; 02089 02090 m_vnxp = size*npad; 02091 m_vnyp = size*npad; 02092 m_vnzp = (m_ndim==3) ? size*npad : 1; 02093 02094 m_vnxc = m_vnxp/2; 02095 m_vnyc = m_vnyp/2; 02096 m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1; 02097 02098 buildFFTVolume(); 02099 buildNormVolume(); 02100 02101 }
void nn4Reconstructor::setup | ( | ) | [virtual] |
Initialize the reconstructor.
Implements EMAN::Reconstructor.
Definition at line 2058 of file reconstructor.cpp.
References EMAN::Dict::has_key(), m_ndim, m_osnr, EMAN::FactoryBase::params, and EMAN::Gatan::to_str().
Referenced by nn4Reconstructor().
02059 { 02060 int size = params["size"]; 02061 int npad = params["npad"]; 02062 02063 02064 string symmetry; 02065 if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str(); 02066 else symmetry = "c1"; 02067 02068 if( params.has_key("ndim") ) m_ndim = params["ndim"]; 02069 else m_ndim = 3; 02070 02071 if( params.has_key( "snr" ) ) m_osnr = 1.0f/float( params["snr"] ); 02072 else m_osnr = 0.0; 02073 02074 setup( symmetry, size, npad ); 02075 }
int EMAN::nn4Reconstructor::m_ndim [private] |
Definition at line 1015 of file reconstructor.h.
Referenced by finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_npad [private] |
Definition at line 1013 of file reconstructor.h.
Referenced by buildFFTVolume(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_nsym [private] |
float EMAN::nn4Reconstructor::m_osnr [private] |
string EMAN::nn4Reconstructor::m_symmetry [private] |
int EMAN::nn4Reconstructor::m_vnx [private] |
int EMAN::nn4Reconstructor::m_vnxc [private] |
Definition at line 1017 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_slice(), and setup().
int EMAN::nn4Reconstructor::m_vnxp [private] |
Definition at line 1016 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 1016 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 1016 of file reconstructor.h.
Referenced by buildFFTVolume(), buildNormVolume(), finish(), and setup().
EMData* EMAN::nn4Reconstructor::m_volume [private] |
Definition at line 1008 of file reconstructor.h.
Referenced by buildFFTVolume(), finish(), insert_padfft_slice(), and nn4Reconstructor().
int EMAN::nn4Reconstructor::m_weighting [private] |
float EMAN::nn4Reconstructor::m_wghta [private] |
float EMAN::nn4Reconstructor::m_wghtb [private] |
Definition at line 1021 of file reconstructor.h.
EMData* EMAN::nn4Reconstructor::m_wptr [private] |
Definition at line 1009 of file reconstructor.h.
Referenced by buildNormVolume(), finish(), insert_padfft_slice(), and nn4Reconstructor().
const string nn4Reconstructor::NAME = "nn4" [static] |