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

EMAN::nn4_ctfReconstructor Class Reference

nn4_ctf Direct Fourier Inversion Reconstructor More...

#include <reconstructor.h>

Inheritance diagram for EMAN::nn4_ctfReconstructor:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 nn4_ctfReconstructor ()
 nn4_ctfReconstructor (const string &symmetry, int size, int npad, float snr, int sign)
virtual ~nn4_ctfReconstructor ()
virtual void setup ()
 Initialize the reconstructor.
virtual int insert_slice (const EMData *const slice, const Transform &euler, const float weight=1.0)
 Insert a slice into a 3D volume, in a given orientation.
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.
TypeDict get_param_types () const
void setup (const string &symmetry, int size, int npad, float snr, int sign)
int insert_padfft_slice (EMData *padfft, const Transform &trans, int mult=1)
int insert_buffed_slice (const EMData *buffer, int mult)

Static Public Member Functions

ReconstructorNEW ()

Static Public Attributes

const string NAME = "nn4_ctf"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()

Private Attributes

EMDatam_volume
EMDatam_wptr
int m_vnx
int m_vny
int m_vnz
int m_vnzp
int m_vnyp
int m_vnxp
int m_vnxc
int m_vnyc
int m_vnzc
int m_npad
int m_sign
int m_varsnr
int m_weighting
float m_wghta
float m_wghtb
float m_snr
string m_symmetry
int m_nsym

Detailed Description

nn4_ctf Direct Fourier Inversion Reconstructor

Definition at line 1214 of file reconstructor.h.


Constructor & Destructor Documentation

nn4_ctfReconstructor::nn4_ctfReconstructor  ) 
 

Definition at line 3158 of file reconstructor.cpp.

References m_volume, and m_wptr.

03159 {
03160         m_volume  = NULL;
03161         m_wptr    = NULL;
03162 }

nn4_ctfReconstructor::nn4_ctfReconstructor const string &  symmetry,
int  size,
int  npad,
float  snr,
int  sign
 

Definition at line 3164 of file reconstructor.cpp.

References setup(), and sign.

03165 {
03166         setup( symmetry, size, npad, snr, sign );
03167 }

nn4_ctfReconstructor::~nn4_ctfReconstructor  )  [virtual]
 

Definition at line 3169 of file reconstructor.cpp.

03170 {
03171         //if( m_delete_volume ) checked_delete(m_volume);
03172 
03173         //if( m_delete_weight ) checked_delete( m_wptr );
03174 
03175         //checked_delete( m_result );
03176 }


Member Function Documentation

void nn4_ctfReconstructor::buildFFTVolume  )  [private]
 

Definition at line 3231 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::EMData::set_array_offsets(), EMAN::EMData::set_attr(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().

Referenced by setup().

03231                                           {
03232         int offset = 2 - m_vnxp%2;
03233 
03234         m_volume = params["fftvol"];
03235 
03236         if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) {
03237                 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp);
03238                 m_volume->to_zero();
03239         }
03240 
03241         m_volume->set_nxc(m_vnxp/2);
03242         m_volume->set_complex(true);
03243         m_volume->set_ri(true);
03244         m_volume->set_fftpad(true);
03245         m_volume->set_attr("npad", m_npad);
03246         m_volume->set_array_offsets(0,1,1);
03247 }

void nn4_ctfReconstructor::buildNormVolume  )  [private]
 

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

Referenced by setup().

03250 {
03251         m_wptr = params["weight"];
03252 
03253         if( m_wptr->get_xsize() != m_vnxc+1 && m_wptr->get_ysize() != m_vnyp && m_wptr->get_zsize() != m_vnzp ) {
03254                m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
03255                m_wptr->to_zero();
03256         }
03257 
03258         m_wptr->set_array_offsets(0,1,1);
03259 
03260 }

EMData * nn4_ctfReconstructor::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 3341 of file reconstructor.cpp.

References abs, circumf(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_attr(), m_vnyc, m_vnyp, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, max, max3d(), EMAN::EMData::set_array_offsets(), sqrt(), and EMAN::EMData::symplane0_ctf().

03342 {
03343         m_volume->set_array_offsets(0, 1, 1);
03344         m_wptr->set_array_offsets(0, 1, 1);
03345         m_volume->symplane0_ctf(m_wptr);
03346 
03347         int box = 7;
03348         int vol = box*box*box;
03349         int kc = (box-1)/2;
03350         vector< float > pow_a( 3*kc+1, 1.0 );
03351         for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
03352         pow_a[3*kc]=0.0;
03353 
03354 
03355         float max = max3d( kc, pow_a );
03356         float alpha = ( 1.0f - 1.0f/(float)vol ) / max;
03357         float osnr = 1.0f/m_snr;
03358 
03359         // normalize
03360         int ix,iy,iz;
03361         for (iz = 1; iz <= m_vnzp; iz++) {
03362                 for (iy = 1; iy <= m_vnyp; iy++) {
03363                         for (ix = 0; ix <= m_vnxc; ix++) {
03364                                 if ( (*m_wptr)(ix,iy,iz) > 0.0f) {//(*v) should be treated as complex!!
03365                                         int iyp = (iy<=m_vnyc) ? iy - 1 : iy-m_vnyp-1;
03366                                         int izp = (iz<=m_vnzc) ? iz - 1 : iz-m_vnzp-1;
03367                                         float tmp=0.0;
03368                                         if( m_varsnr )  {
03369                                                 float freq = sqrt( (float)(ix*ix+iyp*iyp+izp*izp) );
03370                                                 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+freq*osnr)*m_sign;
03371                                         } else  {
03372                                                 tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+osnr)*m_sign;
03373                                         }
03374 
03375                         if( m_weighting == ESTIMATE ) {
03376                                 int cx = ix;
03377                                 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
03378                                 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
03379                                 float sum = 0.0;
03380                                 for( int ii = -kc; ii <= kc; ++ii ) {
03381                                         int nbrcx = cx + ii;
03382                                         if( nbrcx >= m_vnxc ) continue;
03383                                         for( int jj= -kc; jj <= kc; ++jj ) {
03384                                                 int nbrcy = cy + jj;
03385                                                 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
03386                                                 for( int kk = -kc; kk <= kc; ++kk ) {
03387                                                         int nbrcz = cz + jj;
03388                                                         if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
03389                                                         if( nbrcx < 0 ) {
03390                                                                 nbrcx = -nbrcx;
03391                                                                 nbrcy = -nbrcy;
03392                                                                 nbrcz = -nbrcz;
03393                                                         }
03394 
03395                                                         int nbrix = nbrcx;
03396                                                         int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
03397                                                         int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
03398                                                         if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0.0 ) {
03399                                                                 int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
03400                                                                 sum = sum + pow_a[c];
03401                                                                   // if(ix%20==0 && iy%20==0 && iz%20==0)
03402                                                                  //   std::cout << boost::format( "%4d %4d %4d %4d %10.3f" ) % nbrix % nbriy % nbriz % c % sum << std::endl;
03403                                                         }
03404                                                 }
03405                                         }
03406                                 }
03407                                 float wght = 1.0f / ( 1.0f - alpha * sum );
03408 /*
03409                         if(ix%10==0 && iy%10==0)
03410                         {
03411                             std::cout << boost::format( "%4d %4d %4d " ) % ix % iy %iz;
03412                             std::cout << boost::format( "%10.3f %10.3f %10.3f " )  % tmp % wght % sum;
03413                             std::  << boost::format( "%10.3f %10.3e " ) % pow_b[r] % alpha;
03414                             std::cout << std::endl;
03415                         }
03416  */
03417                                 tmp = tmp * wght;
03418                                 }
03419                                 (*m_volume)(2*ix,iy,iz) *= tmp;
03420                                 (*m_volume)(2*ix+1,iy,iz) *= tmp;
03421                                 }
03422                         }
03423                 }
03424         }
03425 
03426         // back fft
03427         m_volume->do_ift_inplace();
03428         int npad = m_volume->get_attr("npad");
03429         m_volume->depad();
03430         circumf( m_volume, npad );
03431         m_volume->set_array_offsets( 0, 0, 0 );
03432 
03433         return 0;
03434 }

virtual string EMAN::nn4_ctfReconstructor::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 1243 of file reconstructor.h.

01244                 {
01245                         return "Direct Fourier inversion reconstruction routine";
01246                 }

virtual string EMAN::nn4_ctfReconstructor::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 1238 of file reconstructor.h.

01239                 {
01240                         return NAME;
01241                 }

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

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

Implements EMAN::FactoryBase.

Definition at line 1254 of file reconstructor.h.

References EMAN::TypeDict::put().

01255                 {
01256                         TypeDict d;
01257                         d.put("size",           EMObject::INT);
01258                         d.put("npad",           EMObject::INT);
01259                         d.put("sign",           EMObject::INT);
01260                         d.put("symmetry",       EMObject::STRING);
01261                         d.put("snr",            EMObject::FLOAT);
01262                         d.put("fftvol",         EMObject::EMDATA);
01263                         d.put("weight",         EMObject::EMDATA);
01264                         d.put("weighting",      EMObject::INT);
01265                         d.put("varsnr",         EMObject::INT);
01266                         return d;
01267                 }

int nn4_ctfReconstructor::insert_buffed_slice const EMData buffer,
int  mult
 

Definition at line 3300 of file reconstructor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), m_volume, and m_wptr.

03301 {
03302         const float* bufdata = buffed->get_data();
03303         float* cdata = m_volume->get_data();
03304         float* wdata = m_wptr->get_data();
03305 
03306         int npoint = buffed->get_xsize()/4;
03307         for( int i=0; i < npoint; ++i ) {
03308 
03309                 int pos2 = int( bufdata[4*i] );
03310                 int pos1 = pos2 * 2;
03311                 cdata[pos1  ] += bufdata[4*i+1]*mult;
03312                 cdata[pos1+1] += bufdata[4*i+2]*mult;
03313                 wdata[pos2  ] += bufdata[4*i+3]*mult;
03314 /*
03315         std::cout << "pos1, pos2, ctfv1, ctfv2, ctf2: ";
03316         std::cout << pos1 << " " << bufdata[5*i+1] << " " << bufdata[5*i+2] << " ";
03317         std::cout << pos2 << " " << bufdata[5*i+4] << std::endl;
03318  */
03319         }
03320         return 0;
03321 }

int nn4_ctfReconstructor::insert_padfft_slice EMData padfft,
const Transform trans,
int  mult = 1
 

Definition at line 3323 of file reconstructor.cpp.

References Assert, EMAN::EMData::get_attr(), EMAN::Transform::get_sym_proj(), m_symmetry, m_volume, m_wptr, mult(), EMAN::EMData::nn_ctf(), EMAN::EMData::nn_ctf_applied(), and t.

03324 {
03325         Assert( padfft != NULL );
03326         float tmp = padfft->get_attr("ctf_applied");
03327         int   ctf_applied = (int) tmp;
03328         
03329         vector<Transform> tsym = t.get_sym_proj(m_symmetry);
03330         for (unsigned int isym=0; isym < tsym.size(); isym++) {
03331                 if(ctf_applied) m_volume->nn_ctf_applied(m_wptr, padfft, tsym[isym], mult);             
03332                 else            m_volume->nn_ctf(m_wptr, padfft, tsym[isym], mult);
03333         }
03334 
03335 
03336         return 0;
03337 
03338 }

virtual int EMAN::nn4_ctfReconstructor::insert_slice const EMData *const   slice,
const Transform euler,
const float  weight = 1.0
[virtual]
 

Insert a slice into a 3D volume, in a given orientation.

Returns:
0 if successful, 1 otherwise
Parameters:
slice the image slice to be inserted into the 3D volume
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.
Exceptions:
NullPointerException if the input EMData pointer is null
ImageFormatException if the image is complex as opposed to real

Reimplemented from EMAN::Reconstructor.

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

Definition at line 1248 of file reconstructor.h.

01249                 {
01250                         return new nn4_ctfReconstructor();
01251                 }

void nn4_ctfReconstructor::setup const string &  symmetry,
int  size,
int  npad,
float  snr,
int  sign
 

Definition at line 3195 of file reconstructor.cpp.

References buildFFTVolume(), buildNormVolume(), EMAN::Transform::get_nsym(), EMAN::Dict::has_key(), m_npad, m_nsym, m_sign, m_snr, m_symmetry, m_vnx, m_vnxc, m_vnxp, m_vny, m_vnyc, m_vnyp, m_vnz, m_vnzc, m_vnzp, m_weighting, m_wghta, and m_wghtb.

03196 {
03197         m_weighting = ESTIMATE;
03198         if( params.has_key("weighting") ) {
03199                 int tmp = int( params["weighting"] );
03200                 if( tmp==0 ) m_weighting = NONE;
03201         }
03202 
03203 
03204 
03205         m_wghta = 0.2f;
03206         m_wghtb = 0.004f;
03207 
03208         m_symmetry = symmetry;
03209         m_npad = npad;
03210         m_sign = sign;
03211         m_nsym = Transform::get_nsym(m_symmetry);
03212 
03213         m_snr = snr;
03214 
03215         m_vnx = size;
03216         m_vny = size;
03217         m_vnz = size;
03218 
03219         m_vnxp = size*npad;
03220         m_vnyp = size*npad;
03221         m_vnzp = size*npad;
03222 
03223         m_vnxc = m_vnxp/2;
03224         m_vnyc = m_vnyp/2;
03225         m_vnzc = m_vnzp/2;
03226 
03227         buildFFTVolume();
03228         buildNormVolume();
03229 }

void nn4_ctfReconstructor::setup  )  [virtual]
 

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 3178 of file reconstructor.cpp.

References EMAN::Dict::has_key(), m_varsnr, and sign.

Referenced by nn4_ctfReconstructor().

03179 {
03180         if( ! params.has_key("size") ) throw std::logic_error("Error: image size is not given");
03181 
03182         int size = params["size"];
03183         int npad = params.has_key("npad") ? int(params["npad"]) : 4;
03184         // int sign = params.has_key("sign") ? int(params["sign"]) : 1;
03185         int sign = 1;
03186         string symmetry = params.has_key("symmetry")? params["symmetry"].to_str() : "c1";
03187 
03188         float snr = params["snr"];
03189 
03190         m_varsnr = params.has_key("varsnr") ? int(params["varsnr"]) : 0;
03191         setup( symmetry, size, npad, snr, sign );
03192 
03193 }


Member Data Documentation

int EMAN::nn4_ctfReconstructor::m_npad [private]
 

Definition at line 1283 of file reconstructor.h.

Referenced by buildFFTVolume(), and setup().

int EMAN::nn4_ctfReconstructor::m_nsym [private]
 

Definition at line 1290 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_sign [private]
 

Definition at line 1284 of file reconstructor.h.

Referenced by setup().

float EMAN::nn4_ctfReconstructor::m_snr [private]
 

Definition at line 1288 of file reconstructor.h.

Referenced by setup().

string EMAN::nn4_ctfReconstructor::m_symmetry [private]
 

Definition at line 1289 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

int EMAN::nn4_ctfReconstructor::m_varsnr [private]
 

Definition at line 1285 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnx [private]
 

Definition at line 1280 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnxc [private]
 

Definition at line 1282 of file reconstructor.h.

Referenced by buildNormVolume(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnxp [private]
 

Definition at line 1281 of file reconstructor.h.

Referenced by buildFFTVolume(), and setup().

int EMAN::nn4_ctfReconstructor::m_vny [private]
 

Definition at line 1280 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnyc [private]
 

Definition at line 1282 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnyp [private]
 

Definition at line 1281 of file reconstructor.h.

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

int EMAN::nn4_ctfReconstructor::m_vnz [private]
 

Definition at line 1280 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnzc [private]
 

Definition at line 1282 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnzp [private]
 

Definition at line 1281 of file reconstructor.h.

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

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

Definition at line 1278 of file reconstructor.h.

Referenced by buildFFTVolume(), finish(), insert_buffed_slice(), insert_padfft_slice(), and nn4_ctfReconstructor().

int EMAN::nn4_ctfReconstructor::m_weighting [private]
 

Definition at line 1286 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4_ctfReconstructor::m_wghta [private]
 

Definition at line 1287 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4_ctfReconstructor::m_wghtb [private]
 

Definition at line 1287 of file reconstructor.h.

Referenced by setup().

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

Definition at line 1279 of file reconstructor.h.

Referenced by buildNormVolume(), finish(), insert_buffed_slice(), insert_padfft_slice(), and nn4_ctfReconstructor().

const string nn4_ctfReconstructor::NAME = "nn4_ctf" [static]
 

Definition at line 85 of file reconstructor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:49:27 2013 for EMAN2 by  doxygen 1.3.9.1