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

static ReconstructorNEW ()

Static Public Attributes

static 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

Detailed Description

Definition at line 721 of file reconstructor.h.


Constructor & Destructor Documentation

nn4Reconstructor::nn4Reconstructor (  ) 

Definition at line 1867 of file reconstructor.cpp.

References m_result, m_volume, and m_wptr.

Referenced by NEW().

01868 {
01869     m_volume = NULL;
01870     m_wptr   = NULL;
01871     m_result = NULL;
01872 }

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

Definition at line 1874 of file reconstructor.cpp.

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

01875 {
01876     m_volume = NULL;
01877     m_wptr   = NULL;
01878     m_result = NULL;
01879         setup( symmetry, size, npad );
01880         load_default_settings();
01881         print_params();
01882 }

nn4Reconstructor::~nn4Reconstructor (  )  [virtual]

Definition at line 1884 of file reconstructor.cpp.

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

01885 {
01886     if( m_delete_volume )
01887         checked_delete(m_volume);
01888 
01889     if( m_delete_weight )
01890         checked_delete( m_wptr );
01891 
01892     checked_delete( m_result );
01893 }


Member Function Documentation

void nn4Reconstructor::buildFFTVolume (  )  [private]

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

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

void nn4Reconstructor::buildNormVolume (  )  [private]

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

02021                                        {
02022 
02023         if( params.has_key("weight") ) {
02024                 m_wptr = params["weight"];
02025                 m_delete_weight = false;
02026         } else {
02027                 m_wptr = new EMData();
02028                 m_delete_weight = true;
02029         }
02030 
02031         if( m_wptr->get_xsize() != m_vnxc+1 &&
02032                 m_wptr->get_ysize() != m_vnyp &&
02033                 m_wptr->get_zsize() != m_vnzp ) {
02034                 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
02035                 m_wptr->to_zero();
02036         }
02037 
02038         m_wptr->set_array_offsets(0,1,1);
02039 }

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 2173 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().

02174 {
02175         if( m_ndim==3 ) {
02176                 m_volume->symplane0(m_wptr);
02177         } else {
02178                 for( int i=1; i <= m_vnyp; ++i ) {
02179 
02180                         if( (*m_wptr)(0, i, 1)==0.0 ) {
02181                                 int j = m_vnyp + 1 - i;
02182                                 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1);
02183                                 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1);
02184                                 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1);
02185                         }
02186                 }
02187         }
02188 
02189 
02190         int box = 7;
02191         int kc = (box-1)/2;
02192         vector< float > pow_a( m_ndim*kc+1, 1.0 );
02193         for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
02194         pow_a.back()=0.0;
02195 
02196         float alpha = 0.0;
02197         if( m_ndim==3) {
02198                 int vol = box*box*box;
02199                 float max = max3d( kc, pow_a );
02200                 alpha = ( 1.0f - 1.0f/(float)vol ) / max;
02201         } else {
02202                 int ara = box*box;
02203                 float max = max2d( kc, pow_a );
02204                 alpha = ( 1.0f - 1.0f/(float)ara ) / max;
02205         }
02206 
02207         int ix,iy,iz;
02208         for (iz = 1; iz <= m_vnzp; iz++) {
02209                 for (iy = 1; iy <= m_vnyp; iy++) {
02210                         for (ix = 0; ix <= m_vnxc; ix++) {
02211                                 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!!
02212                                         float tmp;
02213                                         tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr);
02214 
02215                                         if( m_weighting == ESTIMATE ) {
02216                                                 int cx = ix;
02217                                                 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
02218                                                 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
02219                                                 float sum = 0.0;
02220                                                 for( int ii = -kc; ii <= kc; ++ii ) {
02221                                                         int nbrcx = cx + ii;
02222                                                         if( nbrcx >= m_vnxc ) continue;
02223                                                         for( int jj= -kc; jj <= kc; ++jj ) {
02224                                                                 int nbrcy = cy + jj;
02225                                                                 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
02226 
02227                                                                 int kcz = (m_ndim==3) ? kc : 0;
02228                                                                 for( int kk = -kcz; kk <= kcz; ++kk ) {
02229                                                                         int nbrcz = cz + kk;
02230                                                                         if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
02231                                                                         if( nbrcx < 0 ) {
02232                                                                                 nbrcx = -nbrcx;
02233                                                                                 nbrcy = -nbrcy;
02234                                                                                 nbrcz = -nbrcz;
02235                                                                         }
02236                                                                         int nbrix = nbrcx;
02237                                                                         int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
02238                                                                         int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
02239                                                                         if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
02240                                                                                 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
02241                                                                                 sum = sum + pow_a[c];
02242                                                                         }
02243                                                                 }
02244                                                         }
02245                                                 }
02246                                                 float wght = 1.0f / ( 1.0f - alpha * sum );
02247                                                 tmp = tmp * wght;
02248                                         }
02249                                         (*m_volume)(2*ix,iy,iz) *= tmp;
02250                                         (*m_volume)(2*ix+1,iy,iz) *= tmp;
02251                                 }
02252                         }
02253                 }
02254         }
02255 
02256         //if(m_ndim==2) printImage( m_volume );
02257 
02258         // back fft
02259         m_volume->do_ift_inplace();
02260 
02261         // EMData* win = m_volume->window_center(m_vnx);
02262         m_volume->depad();
02263         circumference( m_volume );
02264         m_volume->set_array_offsets( 0, 0, 0 );
02265 
02266     m_result = m_volume->copy();
02267         return m_result;
02268 }

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.

References NAME.

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::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

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 2117 of file reconstructor.cpp.

References Assert, m_nsym, m_symmetry, m_volume, m_wptr, EMAN::EMData::nn(), and t.

Referenced by insert_slice().

02118 {
02119         Assert( padfft != NULL );
02120         // insert slice for all symmetry related positions
02121         for (int isym=0; isym < m_nsym; isym++) {
02122                 Transform tsym = t.get_sym(m_symmetry, isym);
02123                 m_volume->nn( m_wptr, padfft, tsym, mult);
02124         }
02125         return 0;
02126 }

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 2056 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.

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

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                 }

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

Definition at line 754 of file reconstructor.h.

References nn4Reconstructor().

00755                 {
00756                         return new nn4Reconstructor();
00757                 }

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

Definition at line 1961 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.

01962 {
01963         m_weighting = ESTIMATE;
01964         m_wghta = 0.2f;
01965 
01966         m_symmetry = symmetry;
01967         m_npad = npad;
01968         m_nsym = Transform::get_nsym(m_symmetry);
01969 
01970         m_vnx = size;
01971         m_vny = size;
01972         m_vnz = (m_ndim==3) ? size : 1;
01973 
01974         m_vnxp = size*npad;
01975         m_vnyp = size*npad;
01976         m_vnzp = (m_ndim==3) ? size*npad : 1;
01977 
01978         m_vnxc = m_vnxp/2;
01979         m_vnyc = m_vnyp/2;
01980         m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1;
01981 
01982         buildFFTVolume();
01983         buildNormVolume();
01984 
01985 }

void nn4Reconstructor::setup (  )  [virtual]

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 1933 of file reconstructor.cpp.

References EMAN::Dict::has_key(), m_ndim, m_osnr, EMAN::FactoryBase::params, and EMAN::Gatan::to_str().

Referenced by nn4Reconstructor().

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


Member Data Documentation

bool EMAN::nn4Reconstructor::m_delete_volume [private]

Definition at line 785 of file reconstructor.h.

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

bool EMAN::nn4Reconstructor::m_delete_weight [private]

Definition at line 786 of file reconstructor.h.

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

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 insert_padfft_slice(), and setup().

float EMAN::nn4Reconstructor::m_osnr [private]

Definition at line 799 of file reconstructor.h.

Referenced by finish(), and 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 insert_slice(), and setup().

int EMAN::nn4Reconstructor::m_vnxc [private]

Definition at line 794 of file reconstructor.h.

Referenced by buildNormVolume(), finish(), 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 finish(), and setup().

int EMAN::nn4Reconstructor::m_vnzp [private]

Definition at line 793 of file reconstructor.h.

Referenced by buildFFTVolume(), buildNormVolume(), finish(), 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 779 of file reconstructor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 12:44:26 2010 for EMAN2 by  doxygen 1.4.7