EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
EMAN::nn4Reconstructor Class Reference

#include <reconstructor.h>

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

Public Member Functions

 nn4Reconstructor ()
 
 nn4Reconstructor (const string &symmetry, int size, int npad)
 
virtual ~nn4Reconstructor ()
 
virtual void setup ()
 Initialize the reconstructor. More...
 
virtual int insert_slice (const EMData *const slice, const Transform &euler, const float weight)
 Insert an image slice to the reconstructor. More...
 
virtual EMDatafinish (bool doift=true)
 Finish reconstruction and return the complete model. More...
 
virtual string get_name () const
 Get the unique name of this class (especially for factory based instantiation access) More...
 
virtual string get_desc () const
 Get a clear, concise description of this class. More...
 
virtual TypeDict get_param_types () const
 
void setup (const string &symmetry, int size, int npad)
 
int insert_padfft_slice (EMData *padded, const Transform &trans, float mult=1)
 
- Public Member Functions inherited from EMAN::Reconstructor
 Reconstructor ()
 
virtual ~Reconstructor ()
 
virtual void setup_seed (EMData *seed, float seed_weight)
 Initialize the reconstructor with a seed volume. More...
 
virtual void setup_seedandweights (EMData *seed, EMData *weight)
 Initialize the reconstructor with a seed volume, as above. More...
 
virtual EMDatapreprocess_slice (const EMData *const slice, const Transform &t=Transform())
 While you can just insert unprocessed slices, if you call preprocess_slice yourself, and insert the returned slice instead, repeatedly, it can save a fair bit of computation. More...
 
int insert_slice (const EMData *const slice, const Transform &euler)
 
virtual int determine_slice_agreement (EMData *slice, const Transform &euler, const float weight=1.0, bool sub=true)
 Compares a slice to the current reconstruction volume and computes a normalization factor and quality. More...
 
virtual EMDataprojection (const Transform &euler, int ret_fourier=1)
 This will create a projection from the current reconstruction. More...
 
virtual void clear ()
 set the volume and tmp_volume data to zero, for use in Monte Carlo reconstructors More...
 
void print_params () const
 Print the current parameters to std::out. More...
 
EMObjectoperator[] (const string &key)
 
- Public Member Functions inherited from EMAN::FactoryBase
 FactoryBase ()
 
virtual ~FactoryBase ()
 
Dict get_params () const
 get a copy of the parameters of this class More...
 
void set_params (const Dict &new_params)
 Set new parameters. More...
 
void set_param (const string key, const EMObject val)
 
void insert_params (const Dict &new_params)
 Insert parameters. More...
 
Dict copy_relevant_params (const FactoryBase *const that) const
 

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

Additional Inherited Members

- Protected Attributes inherited from EMAN::FactoryBase
Dict params
 This is the dictionary the stores the parameters of the object. More...
 

Detailed Description

Definition at line 1012 of file reconstructor.h.

Constructor & Destructor Documentation

◆ nn4Reconstructor() [1/2]

nn4Reconstructor::nn4Reconstructor ( )

Definition at line 3164 of file reconstructor.cpp.

3165{
3166 m_volume = NULL;
3167 m_wptr = NULL;
3168}

References m_volume, and m_wptr.

Referenced by NEW().

◆ nn4Reconstructor() [2/2]

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

Definition at line 3170 of file reconstructor.cpp.

3171{
3172 setup( symmetry, size, npad );
3174 //print_params();
3175}
virtual void setup()
Initialize the reconstructor.

References load_default_settings(), and setup().

◆ ~nn4Reconstructor()

nn4Reconstructor::~nn4Reconstructor ( )
virtual

Definition at line 3177 of file reconstructor.cpp.

3178{
3179 //if( m_delete_volume ) checked_delete(m_volume);
3180
3181 //if( m_delete_weight ) checked_delete( m_wptr );
3182
3183 //checked_delete( m_result );
3184}

Member Function Documentation

◆ buildFFTVolume()

void nn4Reconstructor::buildFFTVolume ( )
private

Definition at line 3233 of file reconstructor.cpp.

3233 {
3234 int offset = 2 - m_vnxp%2;
3235
3236 m_volume = params["fftvol"];
3237
3238 if( m_volume->get_xsize() != m_vnxp+offset && m_volume->get_ysize() != m_vnyp && m_volume->get_zsize() != m_vnzp ) {
3239 m_volume->set_size(m_vnxp+offset,m_vnyp,m_vnzp);
3240 m_volume->to_zero();
3241 }
3242 // ----------------------------------------------------------------
3243 // Added by Zhengfan Yang on 03/15/07
3244 // Original author: please check whether my revision is correct and
3245 // other Reconstructor need similiar revision.
3246 if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0);
3247 else m_volume->set_fftodd(1);
3248 // ----------------------------------------------------------------
3249
3250 m_volume->set_nxc(m_vnxp/2);
3251 m_volume->set_complex(true);
3252 m_volume->set_ri(true);
3253 m_volume->set_fftpad(true);
3254 m_volume->set_attr("npad", m_npad);
3255 m_volume->set_array_offsets(0,1,1);
3256}
Dict params
This is the dictionary the stores the parameters of the object.
Definition: emobject.h:953

References m_npad, m_vnxp, m_vnyp, m_vnzp, m_volume, and EMAN::FactoryBase::params.

Referenced by setup().

◆ buildNormVolume()

void nn4Reconstructor::buildNormVolume ( )
private

Definition at line 3258 of file reconstructor.cpp.

3258 {
3259
3260 m_wptr = params["weight"];
3261
3262 if( m_wptr->get_xsize() != m_vnxc+1 &&
3263 m_wptr->get_ysize() != m_vnyp &&
3264 m_wptr->get_zsize() != m_vnzp ) {
3265 m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
3266 m_wptr->to_zero();
3267 }
3268 m_wptr->set_array_offsets(0,1,1);
3269}

References m_vnxc, m_vnyp, m_vnzp, m_wptr, and EMAN::FactoryBase::params.

Referenced by setup().

◆ finish()

EMData * nn4Reconstructor::finish ( bool  doift = true)
virtual

Finish reconstruction and return the complete model.

Parameters
doiftA 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 3354 of file reconstructor.cpp.

3354 {
3355
3356 if( m_ndim == 3 ) {
3357 m_volume->symplane0(m_wptr);
3358 } else {
3359 for( int i=1; i <= m_vnyp; ++i ) {
3360
3361 if( (*m_wptr)(0, i, 1)==0.0 ) {
3362 int j = m_vnyp + 1 - i;
3363 (*m_wptr)(0, i, 1) = (*m_wptr)(0, j, 1);
3364 (*m_volume)(0, i, 1) = (*m_volume)(0, j, 1);
3365 (*m_volume)(1, i, 1) = (*m_volume)(1, j, 1);
3366 }
3367 }
3368 }
3369
3370
3371 int box = 7;
3372 int kc = (box-1)/2;
3373 vector< float > pow_a( m_ndim*kc+1, 1.0 );
3374 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
3375 pow_a.back()=0.0;
3376
3377 float alpha = 0.0;
3378 if( m_ndim==3) {
3379 int vol = box*box*box;
3380 float max = max3d( kc, pow_a );
3381 alpha = ( 1.0f - 1.0f/(float)vol ) / max;
3382 } else {
3383 int ara = box*box;
3384 float max = max2d( kc, pow_a );
3385 alpha = ( 1.0f - 1.0f/(float)ara ) / max;
3386 }
3387 int ix,iy,iz;
3388 for (iz = 1; iz <= m_vnzp; iz++) {
3389 for (iy = 1; iy <= m_vnyp; iy++) {
3390 for (ix = 0; ix <= m_vnxc; ix++) {
3391 if ( (*m_wptr)(ix,iy,iz) > 0) {//(*v) should be treated as complex!!
3392 float tmp = (-2*((ix+iy+iz)%2)+1)/((*m_wptr)(ix,iy,iz)+m_osnr);
3393 if( m_weighting == ESTIMATE && false) { // HERE
3394 int cx = ix;
3395 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
3396 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
3397 float sum = 0.0;
3398 for( int ii = -kc; ii <= kc; ++ii ) {
3399 int nbrcx = cx + ii;
3400 if( nbrcx >= m_vnxc ) continue;
3401 for( int jj= -kc; jj <= kc; ++jj ) {
3402 int nbrcy = cy + jj;
3403 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
3404
3405 int kcz = (m_ndim==3) ? kc : 0;
3406 for( int kk = -kcz; kk <= kcz; ++kk ) {
3407 int nbrcz = cz + kk;
3408 if( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
3409 if( nbrcx < 0 ) {
3410 nbrcx = -nbrcx;
3411 nbrcy = -nbrcy;
3412 nbrcz = -nbrcz;
3413 }
3414 int nbrix = nbrcx;
3415 int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
3416 int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
3417 if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
3418 int c = m_ndim*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
3419 sum = sum + pow_a[c];
3420 }
3421 }
3422 }
3423 }
3424 float wght = 1.0f / ( 1.0f - alpha * sum );
3425 tmp = tmp * wght;
3426 }
3427//cout<<" mvol "<<ix<<" "<<iy<<" "<<iz<<" "<<(*m_volume)(2*ix,iy,iz)<<" "<<(*m_volume)(2*ix+1,iy,iz)<<" "<<tmp<<" "<<m_osnr<<endl;
3428 (*m_volume)(2*ix,iy,iz) *= tmp;
3429 (*m_volume)(2*ix+1,iy,iz) *= tmp;
3430 }
3431 }
3432 }
3433 }
3434
3435 //if(m_ndim==2) printImage( m_volume );
3436
3437 // back fft
3438 m_volume->do_ift_inplace();
3439
3440 // EMData* win = m_volume->window_center(m_vnx);
3441 int npad = m_volume->get_attr("npad");
3442 m_volume->depad();
3443 circumfnn( m_volume, npad );
3444 m_volume->set_array_offsets( 0, 0, 0 );
3445
3446 return 0;
3447}
float max2d(int kc, const vector< float > &pow_a)
float max3d(int kc, const vector< float > &pow_a)
@ ESTIMATE
void circumfnn(EMData *win, int npad)

References circumfnn(), ESTIMATE, m_ndim, m_osnr, m_vnxc, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, max2d(), and max3d().

◆ get_desc()

virtual string EMAN::nn4Reconstructor::get_desc ( ) const
inlinevirtual

Get a clear, concise description of this class.

Returns
a clear, concise description of this class

Implements EMAN::FactoryBase.

Definition at line 1040 of file reconstructor.h.

1041 {
1042 return "Direct Fourier inversion routine";
1043 }

◆ get_name()

virtual string EMAN::nn4Reconstructor::get_name ( ) const
inlinevirtual

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

1036 {
1037 return NAME;
1038 }
static const string NAME

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::nn4Reconstructor::get_param_types ( ) const
inlinevirtual
Returns
a TypeDict defining and describing the feasible parameters of this class

Implements EMAN::FactoryBase.

Definition at line 1050 of file reconstructor.h.

1051 {
1052 TypeDict d;
1053 d.put("size", EMObject::INT);
1054 d.put("npad", EMObject::INT);
1055 d.put("sign", EMObject::INT);
1056 d.put("ndim", EMObject::INT);
1057 d.put("snr", EMObject::FLOAT);
1058 d.put("symmetry", EMObject::STRING);
1059 d.put("snr", EMObject::FLOAT);
1060 d.put("fftvol", EMObject::EMDATA);
1061 d.put("weight", EMObject::EMDATA);
1062 d.put("weighting", EMObject::INT);
1063 return d;
1064 }

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

◆ insert_padfft_slice()

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

Definition at line 3343 of file reconstructor.cpp.

3344{
3345 Assert( padfft != NULL );
3346
3347 vector<Transform> tsym = t.get_sym_proj(m_symmetry);
3348 for (unsigned int isym=0; isym < tsym.size(); isym++) m_volume->nn( m_wptr, padfft, tsym[isym], weight);
3349
3350 return 0;
3351}
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42

References Assert, EMAN::Transform::get_sym_proj(), m_symmetry, m_volume, and m_wptr.

Referenced by insert_slice().

◆ insert_slice()

int nn4Reconstructor::insert_slice ( const EMData *const  slice,
const Transform euler,
const float  weight 
)
virtual

Insert an image slice to the reconstructor.

To insert multiple image slices, call this function multiple times.

Parameters
sliceImage slice.
eulerEuler angle of this image slice.
weightA 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 3286 of file reconstructor.cpp.

3286 {
3287 // sanity checks
3288 if (!slice) {
3289 LOGERR("try to insert NULL slice");
3290 return 1;
3291 }
3292
3293 int padffted= slice->get_attr_default( "padffted", 0 );
3294 if( m_ndim==3 ) {
3295 if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx) ) {
3296 // FIXME: Why doesn't this throw an exception?
3297 LOGERR("Tried to insert a slice that is the wrong size.");
3298 return 1;
3299 }
3300 } else {
3301 Assert( m_ndim==2 );
3302 if( slice->get_ysize() !=1 ) {
3303 LOGERR( "for 2D reconstruction, a line is excepted" );
3304 return 1;
3305 }
3306 }
3307 if( weight > 0.0f ) {
3308
3309 EMData* padfft = padfft_slice( slice, t, m_npad );
3310
3311 if( m_ndim==3 ) {
3312 insert_padfft_slice( padfft, t, weight );
3313 } else {
3314 float alpha = padfft->get_attr( "alpha" );
3315 alpha = alpha/180.0f*M_PI;
3316 for(int i=0; i < m_vnxc+1; ++i ) {
3317 float xnew = i*cos(alpha);
3318 float ynew = -i*sin(alpha);
3319 float btqr = padfft->get_value_at( 2*i, 0, 0 );
3320 float btqi = padfft->get_value_at( 2*i+1, 0, 0 );
3321 if( xnew < 0.0 ) {
3322 xnew *= -1;
3323 ynew *= -1;
3324 btqi *= -1;
3325 }
3326
3327 int ixn = int(xnew+0.5+m_vnxp) - m_vnxp;
3328 int iyn = int(ynew+0.5+m_vnyp) - m_vnyp;
3329
3330 if(iyn < 0 ) iyn += m_vnyp;
3331
3332 (*m_volume)( 2*ixn, iyn+1, 1 ) += btqr * weight;
3333 (*m_volume)( 2*ixn+1, iyn+1, 1 ) += btqi * weight;
3334 (*m_wptr)(ixn,iyn+1, 1) += weight;
3335 }
3336
3337 }
3338 checked_delete( padfft );
3339 }
3340 return 0;
3341}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
int insert_padfft_slice(EMData *padded, const Transform &trans, float mult=1)
#define LOGERR
Definition: log.h:51
EMData * padfft_slice(const EMData *const slice, const Transform &t, int npad)
Direct Fourier inversion Reconstructor.
void checked_delete(T *&x)

References Assert, checked_delete(), insert_padfft_slice(), LOGERR, m_ndim, m_npad, m_vnx, m_vnxc, m_vnxp, m_vnyp, and EMAN::padfft_slice().

◆ load_default_settings()

void EMAN::nn4Reconstructor::load_default_settings ( )
inlineprivate

Definition at line 1088 of file reconstructor.h.

1089 {
1090 //params["use_weights"] = false;
1091 }

Referenced by nn4Reconstructor().

◆ NEW()

static Reconstructor * EMAN::nn4Reconstructor::NEW ( )
inlinestatic

Definition at line 1045 of file reconstructor.h.

1046 {
1047 return new nn4Reconstructor();
1048 }

References nn4Reconstructor().

◆ setup() [1/2]

void nn4Reconstructor::setup ( )
virtual

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 3187 of file reconstructor.cpp.

3188{
3189
3190 int size = params["size"];
3191 int npad = params["npad"];
3192
3193 string symmetry;
3194 if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str();
3195 else symmetry = "c1";
3196
3197 if( params.has_key("ndim") ) m_ndim = params["ndim"];
3198 else m_ndim = 3;
3199
3200 if( params.has_key( "snr" ) ) m_osnr = 1.0f/float( params["snr"] );
3201 else m_osnr = 0.0;
3202
3203 setup( symmetry, size, npad );
3204}
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511

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

Referenced by nn4Reconstructor(), and setup().

◆ setup() [2/2]

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

Definition at line 3206 of file reconstructor.cpp.

3207{
3209 m_wghta = 0.2f;
3210
3211 m_symmetry = symmetry;
3212 m_npad = npad;
3214
3215 m_vnx = size;
3216 m_vny = size;
3217 m_vnz = (m_ndim==3) ? size : 1;
3218
3219 m_vnxp = size*npad;
3220 m_vnyp = size*npad;
3221 m_vnzp = (m_ndim==3) ? size*npad : 1;
3222
3223 m_vnxc = m_vnxp/2;
3224 m_vnyc = m_vnyp/2;
3225 m_vnzc = (m_ndim==3) ? m_vnzp/2 : 1;
3226
3229
3230}
static int get_nsym(const string &sym)
get the number of symmetries associated with the given symmetry name
Definition: transform.cpp:1570

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.

Member Data Documentation

◆ m_ndim

int EMAN::nn4Reconstructor::m_ndim
private

Definition at line 1080 of file reconstructor.h.

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

◆ m_npad

int EMAN::nn4Reconstructor::m_npad
private

Definition at line 1078 of file reconstructor.h.

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

◆ m_nsym

int EMAN::nn4Reconstructor::m_nsym
private

Definition at line 1079 of file reconstructor.h.

Referenced by setup().

◆ m_osnr

float EMAN::nn4Reconstructor::m_osnr
private

Definition at line 1087 of file reconstructor.h.

Referenced by finish(), and setup().

◆ m_symmetry

string EMAN::nn4Reconstructor::m_symmetry
private

Definition at line 1075 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

◆ m_vnx

int EMAN::nn4Reconstructor::m_vnx
private

Definition at line 1077 of file reconstructor.h.

Referenced by insert_slice(), and setup().

◆ m_vnxc

int EMAN::nn4Reconstructor::m_vnxc
private

Definition at line 1082 of file reconstructor.h.

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

◆ m_vnxp

int EMAN::nn4Reconstructor::m_vnxp
private

Definition at line 1081 of file reconstructor.h.

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

◆ m_vny

int EMAN::nn4Reconstructor::m_vny
private

Definition at line 1077 of file reconstructor.h.

Referenced by setup().

◆ m_vnyc

int EMAN::nn4Reconstructor::m_vnyc
private

Definition at line 1082 of file reconstructor.h.

Referenced by finish(), and setup().

◆ m_vnyp

int EMAN::nn4Reconstructor::m_vnyp
private

Definition at line 1081 of file reconstructor.h.

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

◆ m_vnz

int EMAN::nn4Reconstructor::m_vnz
private

Definition at line 1077 of file reconstructor.h.

Referenced by setup().

◆ m_vnzc

int EMAN::nn4Reconstructor::m_vnzc
private

Definition at line 1082 of file reconstructor.h.

Referenced by finish(), and setup().

◆ m_vnzp

int EMAN::nn4Reconstructor::m_vnzp
private

Definition at line 1081 of file reconstructor.h.

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

◆ m_volume

EMData* EMAN::nn4Reconstructor::m_volume
private

Definition at line 1073 of file reconstructor.h.

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

◆ m_weighting

int EMAN::nn4Reconstructor::m_weighting
private

Definition at line 1076 of file reconstructor.h.

Referenced by finish(), and setup().

◆ m_wghta

float EMAN::nn4Reconstructor::m_wghta
private

Definition at line 1085 of file reconstructor.h.

Referenced by finish(), and setup().

◆ m_wghtb

float EMAN::nn4Reconstructor::m_wghtb
private

Definition at line 1086 of file reconstructor.h.

◆ m_wptr

EMData* EMAN::nn4Reconstructor::m_wptr
private

Definition at line 1074 of file reconstructor.h.

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

◆ NAME

const string nn4Reconstructor::NAME = "nn4"
static

Definition at line 1070 of file reconstructor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: