Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::nn4Reconstructor Class Reference

#include <reconstructor.h>

Inheritance diagram for EMAN::nn4Reconstructor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::nn4Reconstructor:

Collaboration graph
[legend]
List of all members.

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 EMDatafinish (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

ReconstructorNEW ()

Static Public Attributes

const string NAME = "nn4"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()
void load_default_settings ()

Private Attributes

EMDatam_volume
EMDatam_wptr
EMDatam_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

Constructor & Destructor Documentation

nn4Reconstructor::nn4Reconstructor  ) 
 

Definition at line 1871 of file reconstructor.cpp.

References m_result, m_volume, and m_wptr.

01872 {
01873         m_volume = NULL;
01874         m_wptr   = NULL;
01875         m_result = NULL;
01876 }

nn4Reconstructor::nn4Reconstructor const string &  symmetry,
int  size,
int  npad
 

Definition at line 1878 of file reconstructor.cpp.

References load_default_settings(), m_result, m_volume, m_wptr, EMAN::Reconstructor::print_params(), and setup().

01879 {
01880         m_volume = NULL;
01881         m_wptr   = NULL;
01882         m_result = NULL;
01883         setup( symmetry, size, npad );
01884         load_default_settings();
01885         print_params();
01886 }

nn4Reconstructor::~nn4Reconstructor  )  [virtual]
 

Definition at line 1888 of file reconstructor.cpp.

References checked_delete(), m_result, m_volume, and m_wptr.

01889 {
01890         if( m_delete_volume ) checked_delete(m_volume);
01891 
01892         if( m_delete_weight ) checked_delete( m_wptr );
01893 
01894         checked_delete( m_result );
01895 }


Member Function Documentation

void nn4Reconstructor::buildFFTVolume  )  [private]
 

Definition at line 1981 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::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().

01981                                       {
01982         int offset = 2 - m_vnxp%2;
01983 
01984         if( params.has_key("fftvol") ) {
01985                 m_volume = params["fftvol"];
01986                 m_delete_volume = false;
01987         } else {
01988                 m_volume = new EMData();
01989                 m_delete_volume = true;
01990         }
01991 
01992         if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) {
01993                 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp);
01994                 m_volume->to_zero();
01995         }
01996         // ----------------------------------------------------------------
01997         // Added by Zhengfan Yang on 03/15/07
01998         // Original author: please check whether my revision is correct and
01999         // other Reconstructor need similiar revision.
02000         if ( m_vnxp % 2 == 0 )  m_volume->set_fftodd(0);
02001         else                    m_volume->set_fftodd(1);
02002         // ----------------------------------------------------------------
02003 
02004         m_volume->set_nxc(m_vnxp/2);
02005         m_volume->set_complex(true);
02006         m_volume->set_ri(true);
02007         m_volume->set_fftpad(true);
02008         m_volume->set_attr("npad", m_npad);
02009         m_volume->set_array_offsets(0,1,1);
02010 }

void nn4Reconstructor::buildNormVolume  )  [private]
 

Definition at line 2012 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::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().

Referenced by setup().

02012                                        {
02013 
02014         if( params.has_key("weight") ) {
02015                 m_wptr = params["weight"];
02016                 m_delete_weight = false;
02017         } else {
02018                 m_wptr = new EMData();
02019                 m_delete_weight = true;
02020         }
02021 
02022         if( m_wptr->get_xsize() != m_vnxc+1 &&
02023                 m_wptr->get_ysize() != m_vnyp &&
02024                 m_wptr->get_zsize() != m_vnzp ) {
02025                 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
02026                 m_wptr->to_zero();
02027         }
02028 
02029         m_wptr->set_array_offsets(0,1,1);
02030 }

EMData * nn4Reconstructor::finish bool  doift = true  )  [virtual]
 

Finish reconstruction and return the complete model.

Parameters:
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
Returns:
The result 3D model.

Reimplemented from EMAN::Reconstructor.

Definition at line 2197 of file reconstructor.cpp.

References abs, circumf(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_attr(), m_ndim, m_result, m_vnyc, m_vnyp, m_volume, m_weighting, m_wghta, m_wptr, max, max2d(), max3d(), EMAN::EMData::set_array_offsets(), and EMAN::EMData::symplane0().

02198 {
02199         if( m_ndim==3 ) {
02200                 m_volume->symplane0(m_wptr);
02201         } else {
02202                 for( int i=1; i <= m_vnyp; ++i ) {
02203 
02204                         if( (*m_wptr)(0, i, 1)==0.0 ) {
02205                                 int j = m_vnyp + 1 - i;
02206                                 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1);
02207                                 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1);
02208                                 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1);
02209                         }
02210                 }
02211         }
02212 
02213 
02214         int box = 7;
02215         int kc = (box-1)/2;
02216         vector< float > pow_a( m_ndim*kc+1, 1.0 );
02217         for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
02218         pow_a.back()=0.0;
02219 
02220         float alpha = 0.0;
02221         if( m_ndim==3) {
02222                 int vol = box*box*box;
02223                 float max = max3d( kc, pow_a );
02224                 alpha = ( 1.0f - 1.0f/(float)vol ) / max;
02225         } else {
02226                 int ara = box*box;
02227                 float max = max2d( kc, pow_a );
02228                 alpha = ( 1.0f - 1.0f/(float)ara ) / max;
02229         }
02230 
02231         int ix,iy,iz;
02232         for (iz = 1; iz <= m_vnzp; iz++) {
02233                 for (iy = 1; iy <= m_vnyp; iy++) {
02234                         for (ix = 0; ix <= m_vnxc; ix++) {
02235                                 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!!
02236                                         float tmp;
02237                                         tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr);
02238 
02239                                         if( m_weighting == ESTIMATE ) {
02240                                                 int cx = ix;
02241                                                 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
02242                                                 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
02243                                                 float sum = 0.0;
02244                                                 for( int ii = -kc; ii <= kc; ++ii ) {
02245                                                         int nbrcx = cx + ii;
02246                                                         if( nbrcx >= m_vnxc ) continue;
02247                                                         for( int jj= -kc; jj <= kc; ++jj ) {
02248                                                                 int nbrcy = cy + jj;
02249                                                                 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
02250 
02251                                                                 int kcz = (m_ndim==3) ? kc : 0;
02252                                                                 for( int kk = -kcz; kk <= kcz; ++kk ) {
02253                                                                         int nbrcz = cz + kk;
02254                                                                         if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
02255                                                                         if( nbrcx < 0 ) {
02256                                                                                 nbrcx = -nbrcx;
02257                                                                                 nbrcy = -nbrcy;
02258                                                                                 nbrcz = -nbrcz;
02259                                                                         }
02260                                                                         int nbrix = nbrcx;
02261                                                                         int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
02262                                                                         int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
02263                                                                         if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
02264                                                                                 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
02265                                                                                 sum = sum + pow_a[c];
02266                                                                         }
02267                                                                 }
02268                                                         }
02269                                                 }
02270                                                 float wght = 1.0f / ( 1.0f - alpha * sum );
02271                                                 tmp = tmp * wght;
02272                                         }
02273                                         (*m_volume)(2*ix,iy,iz)   *= tmp;
02274                                         (*m_volume)(2*ix+1,iy,iz) *= tmp;
02275                                 }
02276                         }
02277                 }
02278         }
02279 
02280         //if(m_ndim==2) printImage( m_volume );
02281 
02282         // back fft
02283         m_volume->do_ift_inplace();
02284 
02285         // EMData* win = m_volume->window_center(m_vnx);
02286         int npad = m_volume->get_attr("npad");
02287         m_volume->depad();
02288         circumf( m_volume, npad );
02289         m_volume->set_array_offsets( 0, 0, 0 );
02290 
02291         m_result = m_volume->copy();
02292         return m_result;
02293 }

virtual string EMAN::nn4Reconstructor::get_desc  )  const [inline, virtual]
 

Get a clear, concise description of this class.

Returns:
a clear, concise description of this class

Implements EMAN::FactoryBase.

Definition at line 749 of file reconstructor.h.

00750                 {
00751                         return "Direct Fourier inversion routine";
00752                 }

virtual string EMAN::nn4Reconstructor::get_name  )  const [inline, virtual]
 

Get the unique name of this class (especially for factory based instantiation access).

Returns:
the unique name of this class

Implements EMAN::FactoryBase.

Definition at line 744 of file reconstructor.h.

00745                 {
00746                         return NAME;
00747                 }

virtual TypeDict EMAN::nn4Reconstructor::get_param_types  )  const [inline, virtual]
 

Returns:
a TypeDict defining and describing the feasible parameters of this class

Implements EMAN::FactoryBase.

Definition at line 759 of file reconstructor.h.

References EMAN::TypeDict::put().

00760                 {
00761                         TypeDict d;
00762                         d.put("size",           EMObject::INT);
00763                         d.put("npad",           EMObject::INT);
00764                         d.put("sign",           EMObject::INT);
00765                         d.put("ndim",           EMObject::INT);
00766                         d.put("snr",            EMObject::FLOAT);
00767                         d.put("symmetry",       EMObject::STRING);
00768                         d.put("snr",            EMObject::FLOAT);
00769                         d.put("fftvol",         EMObject::EMDATA);
00770                         d.put("weight",         EMObject::EMDATA);
00771                         d.put("weighting",      EMObject::INT);
00772                         return d;
00773                 }

int nn4Reconstructor::insert_padfft_slice EMData padded,
const Transform trans,
int  mult = 1
 

Definition at line 2108 of file reconstructor.cpp.

References Assert, EMAN::Transform::get_sym(), m_symmetry, m_volume, m_wptr, mult(), EMAN::EMData::nn(), and t.

Referenced by insert_slice().

02109 {
02110         Assert( padfft != NULL );
02111         // insert slice for all symmetry related positions
02112 
02113         for (int isym=0; isym < m_nsym; isym++) {
02114                 Transform tsym = t.get_sym(m_symmetry, isym);
02115         
02116                 m_volume->nn( m_wptr, padfft, tsym, mult);
02117         }
02118         return 0;
02119 }

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.

Parameters:
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
Returns:
0 if OK. 1 if error.

Reimplemented from EMAN::Reconstructor.

Definition at line 2047 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_vnxc, m_vnxp, m_vnyp, mult(), EMAN::padfft_slice(), and t.

02047                                                                                                     {
02048         // sanity checks
02049         if (!slice) {
02050                 LOGERR("try to insert NULL slice");
02051                 return 1;
02052         }
02053 
02054         int padffted= slice->get_attr_default( "padffted", 0 );
02055         if( m_ndim==3 ) {
02056                 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx)  ) {
02057                         // FIXME: Why doesn't this throw an exception?
02058                         LOGERR("Tried to insert a slice that is the wrong size.");
02059                         return 1;
02060                 }
02061         } else {
02062                 Assert( m_ndim==2 );
02063                 if( slice->get_ysize() !=1 ) {
02064                         LOGERR( "for 2D reconstruction, a line is excepted" );
02065                         return 1;
02066                 }
02067         }
02068 
02069         EMData* padfft = NULL;
02070 
02071         if( padffted != 0 ) padfft = new EMData(*slice);
02072         else                padfft = padfft_slice( slice, t,  m_npad );
02073 
02074         int mult= slice->get_attr_default( "mult", 1 );
02075         Assert( mult > 0 );
02076 
02077         if( m_ndim==3 ) {
02078                 insert_padfft_slice( padfft, t, mult );
02079         } else {
02080                 float alpha = padfft->get_attr( "alpha" );
02081                 alpha = alpha/180.0f*M_PI;
02082                 for(int i=0; i < m_vnxc+1; ++i ) {
02083                         float xnew = i*cos(alpha);
02084                         float ynew = -i*sin(alpha);
02085                         float btqr = padfft->get_value_at( 2*i, 0, 0 );
02086                         float btqi = padfft->get_value_at( 2*i+1, 0, 0 );
02087                         if( xnew < 0.0 ) {
02088                                 xnew *= -1;
02089                                 ynew *= -1;
02090                                 btqi *= -1;
02091                         }
02092 
02093                         int ixn = int(xnew+0.5+m_vnxp) - m_vnxp;
02094                         int iyn = int(ynew+0.5+m_vnyp) - m_vnyp;
02095 
02096                         if(iyn < 0 ) iyn += m_vnyp;
02097 
02098                         (*m_volume)( 2*ixn, iyn+1, 1 ) += btqr *float(mult);
02099                         (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * float(mult);
02100                         (*m_wptr)(ixn,iyn+1, 1) += float(mult);
02101                 }
02102 
02103         }
02104         checked_delete( padfft );
02105         return 0;
02106 }

void EMAN::nn4Reconstructor::load_default_settings  )  [inline, private]
 

Definition at line 800 of file reconstructor.h.

Referenced by nn4Reconstructor().

00801                 {
00802                         //params["use_weights"] = false;
00803                 }

Reconstructor* EMAN::nn4Reconstructor::NEW  )  [inline, static]
 

Definition at line 754 of file reconstructor.h.

00755                 {
00756                         return new nn4Reconstructor();
00757                 }

void nn4Reconstructor::setup const string &  symmetry,
int  size,
int  npad
 

Definition at line 1954 of file reconstructor.cpp.

References buildFFTVolume(), buildNormVolume(), 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.

01955 {
01956         m_weighting = ESTIMATE;
01957         m_wghta = 0.2f;
01958 
01959         m_symmetry = symmetry;
01960         m_npad = npad;
01961         m_nsym = Transform::get_nsym(m_symmetry);
01962 
01963         m_vnx = size;
01964         m_vny = size;
01965         m_vnz = (m_ndim==3) ? size : 1;
01966 
01967         m_vnxp = size*npad;
01968         m_vnyp = size*npad;
01969         m_vnzp = (m_ndim==3) ? size*npad : 1;
01970 
01971         m_vnxc = m_vnxp/2;
01972         m_vnyc = m_vnyp/2;
01973         m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1;
01974 
01975         buildFFTVolume();
01976         buildNormVolume();
01977 
01978 }

void nn4Reconstructor::setup  )  [virtual]
 

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 1935 of file reconstructor.cpp.

References EMAN::Dict::has_key(), m_ndim, and m_osnr.

Referenced by nn4Reconstructor().

01936 {
01937         int size = params["size"];
01938         int npad = params["npad"];
01939 
01940 
01941         string symmetry;
01942         if( params.has_key("symmetry") )  symmetry = params["symmetry"].to_str();
01943         else                               symmetry = "c1";
01944 
01945         if( params.has_key("ndim") )  m_ndim = params["ndim"];
01946         else                          m_ndim = 3;
01947 
01948         if( params.has_key( "snr" ) )  m_osnr = 1.0f/float( params["snr"] );
01949         else                           m_osnr = 0.0;
01950 
01951         setup( symmetry, size, npad );
01952 }


Member Data Documentation

bool EMAN::nn4Reconstructor::m_delete_volume [private]
 

Definition at line 785 of file reconstructor.h.

Referenced by buildFFTVolume().

bool EMAN::nn4Reconstructor::m_delete_weight [private]
 

Definition at line 786 of file reconstructor.h.

Referenced by buildNormVolume().

int EMAN::nn4Reconstructor::m_ndim [private]
 

Definition at line 792 of file reconstructor.h.

Referenced by finish(), insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_npad [private]
 

Definition at line 790 of file reconstructor.h.

Referenced by buildFFTVolume(), insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_nsym [private]
 

Definition at line 791 of file reconstructor.h.

Referenced by setup().

float EMAN::nn4Reconstructor::m_osnr [private]
 

Definition at line 799 of file reconstructor.h.

Referenced by setup().

EMData* EMAN::nn4Reconstructor::m_result [private]
 

Definition at line 784 of file reconstructor.h.

Referenced by finish(), nn4Reconstructor(), and ~nn4Reconstructor().

string EMAN::nn4Reconstructor::m_symmetry [private]
 

Definition at line 787 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

int EMAN::nn4Reconstructor::m_vnx [private]
 

Definition at line 789 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4Reconstructor::m_vnxc [private]
 

Definition at line 794 of file reconstructor.h.

Referenced by buildNormVolume(), insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_vnxp [private]
 

Definition at line 793 of file reconstructor.h.

Referenced by buildFFTVolume(), insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_vny [private]
 

Definition at line 789 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4Reconstructor::m_vnyc [private]
 

Definition at line 794 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nn4Reconstructor::m_vnyp [private]
 

Definition at line 793 of file reconstructor.h.

Referenced by buildFFTVolume(), buildNormVolume(), finish(), insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_vnz [private]
 

Definition at line 789 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4Reconstructor::m_vnzc [private]
 

Definition at line 794 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4Reconstructor::m_vnzp [private]
 

Definition at line 793 of file reconstructor.h.

Referenced by buildFFTVolume(), buildNormVolume(), and setup().

EMData* EMAN::nn4Reconstructor::m_volume [private]
 

Definition at line 782 of file reconstructor.h.

Referenced by buildFFTVolume(), finish(), insert_padfft_slice(), nn4Reconstructor(), and ~nn4Reconstructor().

int EMAN::nn4Reconstructor::m_weighting [private]
 

Definition at line 788 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4Reconstructor::m_wghta [private]
 

Definition at line 797 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4Reconstructor::m_wghtb [private]
 

Definition at line 798 of file reconstructor.h.

EMData* EMAN::nn4Reconstructor::m_wptr [private]
 

Definition at line 783 of file reconstructor.h.

Referenced by buildNormVolume(), finish(), insert_padfft_slice(), nn4Reconstructor(), and ~nn4Reconstructor().

const string nn4Reconstructor::NAME = "nn4" [static]
 

Definition at line 77 of file reconstructor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:34 2010 for EMAN2 by  doxygen 1.3.9.1