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

static ReconstructorNEW ()

Static Public Attributes

static 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 997 of file reconstructor.h.


Constructor & Destructor Documentation

nn4_ctfReconstructor::nn4_ctfReconstructor (  ) 

Definition at line 3135 of file reconstructor.cpp.

References m_volume, and m_wptr.

Referenced by NEW().

03136 {
03137         m_volume  = NULL;
03138         m_wptr    = NULL;
03139 }

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

Definition at line 3141 of file reconstructor.cpp.

References setup().

03142 {
03143         setup( symmetry, size, npad, snr, sign );
03144 }

nn4_ctfReconstructor::~nn4_ctfReconstructor (  )  [virtual]

Definition at line 3146 of file reconstructor.cpp.

03147 {
03148         //if( m_delete_volume ) checked_delete(m_volume);
03149 
03150         //if( m_delete_weight ) checked_delete( m_wptr );
03151 
03152         //checked_delete( m_result );
03153 }


Member Function Documentation

void nn4_ctfReconstructor::buildFFTVolume (  )  [private]

Definition at line 3208 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_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().

Referenced by setup().

03208                                           {
03209         int offset = 2 - m_vnxp%2;
03210 
03211         m_volume = params["fftvol"];
03212 
03213         if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) {
03214                 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp);
03215                 m_volume->to_zero();
03216         }
03217 
03218         m_volume->set_nxc(m_vnxp/2);
03219         m_volume->set_complex(true);
03220         m_volume->set_ri(true);
03221         m_volume->set_fftpad(true);
03222         m_volume->set_attr("npad", m_npad);
03223         m_volume->set_array_offsets(0,1,1);
03224 }

void nn4_ctfReconstructor::buildNormVolume (  )  [private]

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

03227 {
03228         m_wptr = params["weight"];
03229 
03230         if( m_wptr->get_xsize() != m_vnxc+1 && m_wptr->get_ysize() != m_vnyp && m_wptr->get_zsize() != m_vnzp ) {
03231                m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
03232                m_wptr->to_zero();
03233         }
03234 
03235         m_wptr->set_array_offsets(0,1,1);
03236 
03237 }

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

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

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

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 1026 of file reconstructor.h.

01027                 {
01028                         return "Direct Fourier inversion reconstruction routine";
01029                 }

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 1021 of file reconstructor.h.

References NAME.

01022                 {
01023                         return NAME;
01024                 }

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 1037 of file reconstructor.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

01038                 {
01039                         TypeDict d;
01040                         d.put("size",           EMObject::INT);
01041                         d.put("npad",           EMObject::INT);
01042                         d.put("sign",           EMObject::INT);
01043                         d.put("symmetry",       EMObject::STRING);
01044                         d.put("snr",            EMObject::FLOAT);
01045                         d.put("fftvol",         EMObject::EMDATA);
01046                         d.put("weight",         EMObject::EMDATA);
01047                         d.put("weighting",      EMObject::INT);
01048                         d.put("varsnr",         EMObject::INT);
01049                         return d;
01050                 }

int nn4_ctfReconstructor::insert_buffed_slice ( const EMData buffer,
int  mult 
)

Definition at line 3277 of file reconstructor.cpp.

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

Referenced by insert_slice().

03278 {
03279         const float* bufdata = buffed->get_data();
03280         float* cdata = m_volume->get_data();
03281         float* wdata = m_wptr->get_data();
03282 
03283         int npoint = buffed->get_xsize()/4;
03284         for( int i=0; i < npoint; ++i ) {
03285 
03286                 int pos2 = int( bufdata[4*i] );
03287                 int pos1 = pos2 * 2;
03288                 cdata[pos1  ] += bufdata[4*i+1]*mult;
03289                 cdata[pos1+1] += bufdata[4*i+2]*mult;
03290                 wdata[pos2  ] += bufdata[4*i+3]*mult;
03291 /*
03292         std::cout << "pos1, pos2, ctfv1, ctfv2, ctf2: ";
03293         std::cout << pos1 << " " << bufdata[5*i+1] << " " << bufdata[5*i+2] << " ";
03294         std::cout << pos2 << " " << bufdata[5*i+4] << std::endl;
03295  */
03296         }
03297         return 0;
03298 }

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

Definition at line 3300 of file reconstructor.cpp.

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

Referenced by insert_slice().

03301 {
03302         Assert( padfft != NULL );
03303         float tmp = padfft->get_attr("ctf_applied");
03304         int   ctf_applied = (int) tmp;
03305         
03306         vector<Transform> tsym = t.get_sym_proj(m_symmetry);
03307         for (unsigned int isym=0; isym < tsym.size(); isym++) {
03308                 if(ctf_applied) m_volume->nn_ctf_applied(m_wptr, padfft, tsym[isym], mult);
03309                                 
03310                 else            m_volume->nn_ctf(m_wptr, padfft, tsym[isym], mult);
03311                 
03312         }
03313 
03314 
03315         return 0;
03316 
03317 }

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

Definition at line 3239 of file reconstructor.cpp.

References Assert, checked_delete(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), insert_buffed_slice(), insert_padfft_slice(), LOGERR, m_npad, m_vnx, mult(), EMAN::padfft_slice(), and t.

03240 {
03241         // sanity checks
03242         if (!slice) {
03243                 LOGERR("try to insert NULL slice");
03244                 return 1;
03245         }
03246 
03247         int buffed = slice->get_attr_default( "buffed", 0 );
03248         if( buffed > 0 ) {
03249                 int mult = slice->get_attr_default( "mult", 1 );
03250                 insert_buffed_slice( slice, mult );
03251                 return 0;
03252         }
03253 
03254         int padffted= slice->get_attr_default("padffted", 0);
03255         if( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx)  )
03256         {
03257                 // FIXME: Why doesn't this throw an exception?
03258                 LOGERR("Tried to insert a slice that is the wrong size.");
03259                 return 1;
03260         }
03261 
03262         EMData* padfft = NULL;
03263 
03264         if( padffted != 0 ) padfft = new EMData(*slice);
03265         else                padfft = padfft_slice( slice, t, m_npad );
03266 
03267         int mult= slice->get_attr_default("mult", 1);
03268 
03269         Assert( mult > 0 );
03270         insert_padfft_slice( padfft, t, mult );
03271 
03272         checked_delete( padfft );
03273 
03274         return 0;
03275 }

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

Definition at line 1031 of file reconstructor.h.

References nn4_ctfReconstructor().

01032                 {
01033                         return new nn4_ctfReconstructor();
01034                 }

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

Definition at line 3172 of file reconstructor.cpp.

References buildFFTVolume(), buildNormVolume(), ESTIMATE, 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, m_wghtb, NONE, and EMAN::FactoryBase::params.

03173 {
03174         m_weighting = ESTIMATE;
03175         if( params.has_key("weighting") ) {
03176                 int tmp = int( params["weighting"] );
03177                 if( tmp==0 ) m_weighting = NONE;
03178         }
03179 
03180 
03181 
03182         m_wghta = 0.2f;
03183         m_wghtb = 0.004f;
03184 
03185         m_symmetry = symmetry;
03186         m_npad = npad;
03187         m_sign = sign;
03188         m_nsym = Transform::get_nsym(m_symmetry);
03189 
03190         m_snr = snr;
03191 
03192         m_vnx = size;
03193         m_vny = size;
03194         m_vnz = size;
03195 
03196         m_vnxp = size*npad;
03197         m_vnyp = size*npad;
03198         m_vnzp = size*npad;
03199 
03200         m_vnxc = m_vnxp/2;
03201         m_vnyc = m_vnyp/2;
03202         m_vnzc = m_vnzp/2;
03203 
03204         buildFFTVolume();
03205         buildNormVolume();
03206 }

void nn4_ctfReconstructor::setup (  )  [virtual]

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 3155 of file reconstructor.cpp.

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

Referenced by nn4_ctfReconstructor().

03156 {
03157         if( ! params.has_key("size") ) throw std::logic_error("Error: image size is not given");
03158 
03159         int size = params["size"];
03160         int npad = params.has_key("npad") ? int(params["npad"]) : 4;
03161         // int sign = params.has_key("sign") ? int(params["sign"]) : 1;
03162         int sign = 1;
03163         string symmetry = params.has_key("symmetry")? params["symmetry"].to_str() : "c1";
03164 
03165         float snr = params["snr"];
03166 
03167         m_varsnr = params.has_key("varsnr") ? int(params["varsnr"]) : 0;
03168         setup( symmetry, size, npad, snr, sign );
03169 
03170 }


Member Data Documentation

int EMAN::nn4_ctfReconstructor::m_npad [private]

Definition at line 1066 of file reconstructor.h.

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

int EMAN::nn4_ctfReconstructor::m_nsym [private]

Definition at line 1073 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_sign [private]

Definition at line 1067 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4_ctfReconstructor::m_snr [private]

Definition at line 1071 of file reconstructor.h.

Referenced by finish(), and setup().

string EMAN::nn4_ctfReconstructor::m_symmetry [private]

Definition at line 1072 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

int EMAN::nn4_ctfReconstructor::m_varsnr [private]

Definition at line 1068 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnx [private]

Definition at line 1063 of file reconstructor.h.

Referenced by insert_slice(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnxc [private]

Definition at line 1065 of file reconstructor.h.

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

int EMAN::nn4_ctfReconstructor::m_vnxp [private]

Definition at line 1064 of file reconstructor.h.

Referenced by buildFFTVolume(), and setup().

int EMAN::nn4_ctfReconstructor::m_vny [private]

Definition at line 1063 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnyc [private]

Definition at line 1065 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnyp [private]

Definition at line 1064 of file reconstructor.h.

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

int EMAN::nn4_ctfReconstructor::m_vnz [private]

Definition at line 1063 of file reconstructor.h.

Referenced by setup().

int EMAN::nn4_ctfReconstructor::m_vnzc [private]

Definition at line 1065 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nn4_ctfReconstructor::m_vnzp [private]

Definition at line 1064 of file reconstructor.h.

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

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

Definition at line 1061 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 1069 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4_ctfReconstructor::m_wghta [private]

Definition at line 1070 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nn4_ctfReconstructor::m_wghtb [private]

Definition at line 1070 of file reconstructor.h.

Referenced by setup().

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

Definition at line 1062 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 1058 of file reconstructor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:49:58 2011 for EMAN2 by  doxygen 1.4.7