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

EMAN::nnSSNR_Reconstructor Class Reference

#include <reconstructor.h>

Inheritance diagram for EMAN::nnSSNR_Reconstructor:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 nnSSNR_Reconstructor ()
 nnSSNR_Reconstructor (const string &symmetry, int size, int npad)
 ~nnSSNR_Reconstructor ()
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)
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 = "nnSSNR"

Private Member Functions

void buildFFTVolume ()
void buildNormVolume ()
void buildNorm2Volume ()

Private Attributes

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

Constructor & Destructor Documentation

nnSSNR_Reconstructor::nnSSNR_Reconstructor  ) 
 

Definition at line 2826 of file reconstructor.cpp.

References m_volume, m_wptr, and m_wptr2.

02827 {
02828         m_volume = NULL;
02829         m_wptr   = NULL;
02830         m_wptr2  = NULL;
02831 }

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

Definition at line 2833 of file reconstructor.cpp.

References m_volume, m_wptr, m_wptr2, and setup().

02834 {
02835         m_volume = NULL;
02836         m_wptr   = NULL;
02837         m_wptr2  = NULL;
02838 
02839         setup( symmetry, size, npad );
02840 }

nnSSNR_Reconstructor::~nnSSNR_Reconstructor  ) 
 

Definition at line 2842 of file reconstructor.cpp.

02843 {
02844         //if( m_delete_volume ) checked_delete(m_volume);
02845 
02846         //if( m_delete_weight ) checked_delete( m_wptr );
02847 
02848         //if( m_delete_weight2 ) checked_delete( m_wptr2 );
02849 
02850         //checked_delete( m_result );
02851 }


Member Function Documentation

void nnSSNR_Reconstructor::buildFFTVolume  )  [private]
 

Definition at line 2894 of file reconstructor.cpp.

References m_npad, m_vnxc, 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().

02894                                           {
02895 
02896         m_volume = params["fftvol"]; 
02897         m_volume->set_size(m_vnxp+ 2 - m_vnxp%2,m_vnyp,m_vnzp);
02898         m_volume->to_zero();
02899         if ( m_vnxp % 2 == 0 ) m_volume->set_fftodd(0);
02900         else                   m_volume->set_fftodd(1);
02901 
02902         m_volume->set_nxc(m_vnxc);
02903         m_volume->set_complex(true);
02904         m_volume->set_ri(true);
02905         m_volume->set_fftpad(true);
02906         m_volume->set_attr("npad", m_npad);
02907         m_volume->set_array_offsets(0,1,1);
02908 }

void nnSSNR_Reconstructor::buildNorm2Volume  )  [private]
 

Definition at line 2918 of file reconstructor.cpp.

References m_vnxc, m_vnyp, m_vnzp, m_wptr2, EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::to_zero().

Referenced by setup().

02918                                             {
02919 
02920         m_wptr2 = params["weight2"];
02921         m_wptr2->set_size(m_vnxc+1,m_vnyp,m_vnzp);
02922         m_wptr2->to_zero();
02923         m_wptr2->set_array_offsets(0,1,1);
02924 }

void nnSSNR_Reconstructor::buildNormVolume  )  [private]
 

Definition at line 2910 of file reconstructor.cpp.

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

02910                                            {
02911 
02912         m_wptr = params["weight"];
02913         m_wptr->set_size(m_vnxc+1,m_vnyp,m_vnzp);
02914         m_wptr->to_zero();
02915         m_wptr->set_array_offsets(0,1,1);
02916 }

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

(*SSNR)(i,0,0) = nom[i]/denom[i] - 1;///

Reimplemented from EMAN::Reconstructor.

Definition at line 2969 of file reconstructor.cpp.

References abs, EMAN::EMData::cmplx(), m_vnxc, m_vnxp, m_vnyc, m_vnyp, m_vnzc, m_vnzp, m_volume, m_weighting, m_wghta, m_wptr, m_wptr2, max, max3d(), nn(), norm(), EMAN::Util::round(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_nxc(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::symplane1(), EMAN::EMData::to_zero(), and EMAN::EMData::update().

02970 {
02971 /*
02972   I changed the code on 05/15 so it only returns variance.
02973   Lines commented out are marked by //#
02974   The version prior to the currect changes is r1.190
02975   PAP
02976 */
02977         int kz, ky;
02978         //#int iix, iiy, iiz;
02979         int box = 7;
02980         int kc = (box-1)/2;
02981         float alpha = 0.0;
02982         float argx, argy, argz;
02983         vector< float > pow_a( 3*kc+1, 1.0 );
02984         float w = params["w"];
02985         EMData* SSNR = params["SSNR"];
02986         //#EMData* vol_ssnr = new EMData();
02987         //#vol_ssnr->set_size(m_vnxp, m_vnyp, m_vnzp);
02988         //#vol_ssnr->to_zero();
02989         //#  new line follow
02990         EMData* vol_ssnr = params["vol_ssnr"];
02991         vol_ssnr->set_size(m_vnxp+ 2 - m_vnxp%2, m_vnyp ,m_vnzp);
02992         vol_ssnr->to_zero();
02993         if ( m_vnxp % 2 == 0 ) vol_ssnr->set_fftodd(0);
02994         else                   vol_ssnr->set_fftodd(1);
02995         vol_ssnr->set_nxc(m_vnxc);
02996         vol_ssnr->set_complex(true);
02997         vol_ssnr->set_ri(true);
02998         vol_ssnr->set_fftpad(false);
02999         //#
03000 
03001         float dx2 = 1.0f/float(m_vnxc)/float(m_vnxc);
03002         float dy2 = 1.0f/float(m_vnyc)/float(m_vnyc);
03003 #ifdef _WIN32
03004         float dz2 = 1.0f/_cpp_max(float(m_vnzc),1.0f)/_cpp_max(float(m_vnzc),1.0f);
03005         int  inc = Util::round(float(_cpp_max(_cpp_max(m_vnxc,m_vnyc),m_vnzc))/w);
03006 #else
03007         float dz2 = 1.0f/std::max(float(m_vnzc),1.0f)/std::max(float(m_vnzc),1.0f);
03008         int  inc = Util::round(float(std::max(std::max(m_vnxc,m_vnyc),m_vnzc))/w);
03009 #endif  //_WIN32
03010         SSNR->set_size(inc+1,4,1);
03011 
03012         float *nom    = new float[inc+1];
03013         float *denom  = new float[inc+1];
03014         int  *nn     = new int[inc+1];
03015         int  *ka     = new int[inc+1];
03016         float wght = 1.0f;
03017         for (int i = 0; i <= inc; i++) {
03018                 nom[i] = 0.0f;
03019                 denom[i] = 0.0f;
03020                 nn[i] = 0;
03021                 ka[i] = 0;
03022         }
03023 
03024         m_volume->symplane1(m_wptr, m_wptr2);
03025 
03026         if ( m_weighting == ESTIMATE ) {
03027                 int vol = box*box*box;
03028                 for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
03029                 pow_a[3*kc] = 0.0;
03030                 float max = max3d( kc, pow_a );
03031                 alpha = ( 1.0f - 1.0f/(float)vol ) / max;
03032         }
03033 
03034         for (int iz = 1; iz <= m_vnzp; iz++) {
03035                 if ( iz-1 > m_vnzc ) kz = iz-1-m_vnzp; else kz = iz-1;
03036                 argz = float(kz*kz)*dz2;
03037                 for (int iy = 1; iy <= m_vnyp; iy++) {
03038                         if ( iy-1 > m_vnyc ) ky = iy-1-m_vnyp; else ky = iy-1;
03039                         argy = argz + float(ky*ky)*dy2;
03040                         for (int ix = 0; ix <= m_vnxc; ix++) {
03041                                 float Kn = (*m_wptr)(ix,iy,iz);
03042                                 argx = std::sqrt(argy + float(ix*ix)*dx2);
03043                                 int r = Util::round(float(inc)*argx);
03044                                 if ( r >= 0 && Kn > 4.5f ) {
03045                                         if ( m_weighting == ESTIMATE ) {
03046                                                 int cx = ix;
03047                                                 int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
03048                                                 int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;
03049 
03050                                                 float sum = 0.0;
03051                                                 for( int ii = -kc; ii <= kc; ++ii ) {
03052                                                         int nbrcx = cx + ii;
03053                                                         if( nbrcx >= m_vnxc ) continue;
03054                                                     for ( int jj= -kc; jj <= kc; ++jj ) {
03055                                                                 int nbrcy = cy + jj;
03056                                                                 if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
03057                                                                 for( int kk = -kc; kk <= kc; ++kk ) {
03058                                                                         int nbrcz = cz + jj;
03059                                                                         if ( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
03060                                                                         if( nbrcx < 0 ) {
03061                                                                                 nbrcx = -nbrcx;
03062                                                                                 nbrcy = -nbrcy;
03063                                                                                 nbrcz = -nbrcz;
03064                                                                         }
03065                                                                         int nbrix = nbrcx;
03066                                                                         int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
03067                                                                         int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
03068                                                                         if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
03069                                                                                 int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
03070                                                                                 sum = sum + pow_a[c];
03071                                                                         }
03072                                                                 }
03073                                                         }
03074                                                 }
03075                                                 wght = 1.0f / ( 1.0f - alpha * sum );
03076                                         } // end of ( m_weighting == ESTIMATE )
03077                                         float nominator = std::norm(m_volume->cmplx(ix,iy,iz))/Kn;
03078                                         float denominator = ((*m_wptr2)(ix,iy,iz)-nominator)/(Kn-1.0f);
03079                                         // Skip Friedel related values
03080                                         if( (ix>0 || (kz>=0 && (ky>=0 || kz!=0)))) {
03081                                                 if ( r <= inc ) {
03082                                                         nom[r]   += nominator*wght;
03083                                                         denom[r] += denominator/Kn*wght;
03084                                                         nn[r]    += 2;
03085                                                         ka[r]    += int(Kn);
03086                                                 }
03087 /*
03088 #ifdef  _WIN32
03089                                                 //#float  tmp = _cpp_max(nominator/denominator/Kn-1.0f,0.0f);
03090 #else
03091                                                 //#float  tmp = std::max(nominator/denominator/Kn-1.0f,0.0f);
03092 #endif  //_WIN32
03093                                                 //  Create SSNR as a 3D array (-n/2:n/2+n%2-1)
03094                                                 iix = m_vnxc + ix; iiy = m_vnyc + ky; iiz = m_vnzc + kz;
03095                                                 if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
03096                                                         (*vol_ssnr)(iix, iiy, iiz) = tmp;
03097                                                 // Friedel part
03098                                                 iix = m_vnxc - ix; iiy = m_vnyc - ky; iiz = m_vnzc - kz;
03099                                                 if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
03100                                                         (*vol_ssnr)(iix, iiy, iiz) = tmp;
03101 */
03102 
03103                                         }
03104                                         (*vol_ssnr)(2*ix, iy-1, iz-1) = denominator*wght;
03105                                         //(*vol_ssnr)(2*ix, iy-1, iz-1) =  real(m_volume->cmplx(ix,iy,iz))*wght/Kn;
03106                                         //(*vol_ssnr)(2*ix+1, iy-1, iz-1) = imag(m_volume->cmplx(ix,iy,iz))*wght/Kn;
03107                                 } // end of Kn>4.5
03108                         }
03109                 }
03110         }
03111 
03112         for (int i = 0; i <= inc; i++)  {
03113                 (*SSNR)(i,0,0) = nom[i];  
03114                 (*SSNR)(i,1,0) = denom[i];    // variance
03115                 (*SSNR)(i,2,0) = static_cast<float>(nn[i]);
03116                 (*SSNR)(i,3,0) = static_cast<float>(ka[i]);
03117         }
03118         vol_ssnr->update();
03119         
03120         delete[] nom;
03121         delete[] denom;
03122         delete[] nn;
03123         delete[] ka;
03124 
03125         return 0;
03126 }

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

00945                 {
00946                         return "Reconstruction by nearest neighbor with 3D SSNR";
00947                 }

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

00940                 {
00941                         return NAME;
00942                 }

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

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

Implements EMAN::FactoryBase.

Definition at line 954 of file reconstructor.h.

References EMAN::TypeDict::put().

00955                 {
00956                         TypeDict d;
00957                         d.put("size", EMObject::INT);
00958                         d.put("npad", EMObject::INT);
00959                         d.put("symmetry", EMObject::STRING);
00960                         d.put("fftvol", EMObject::EMDATA);
00961                         d.put("weight", EMObject::EMDATA);
00962                         d.put("weight2", EMObject::EMDATA);
00963                         d.put("SSNR", EMObject::EMDATA);
00964                         d.put("vol_ssnr", EMObject::EMDATA);
00965                         d.put("w", EMObject::FLOAT);
00966                         return d;
00967                 }

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

Definition at line 2956 of file reconstructor.cpp.

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

02957 {
02958         Assert( padfft != NULL );
02959         // insert slice for all symmetry related positions
02960         for (int isym=0; isym < m_nsym; isym++) {
02961                 Transform tsym = t.get_sym(m_symmetry, isym);
02962                 m_volume->nn_SSNR( m_wptr, m_wptr2, padfft, tsym, mult);
02963         }
02964         return 0;
02965 }

virtual int EMAN::nnSSNR_Reconstructor::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.

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

Definition at line 949 of file reconstructor.h.

00950                 {
00951                         return new nnSSNR_Reconstructor();
00952                 }

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

Definition at line 2865 of file reconstructor.cpp.

References buildFFTVolume(), buildNorm2Volume(), buildNormVolume(), EMAN::Transform::get_nsym(), 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, m_wghta, and m_wghtb.

02866 {
02867 
02868         m_weighting = ESTIMATE;
02869         m_wghta = 0.2f;
02870         m_wghtb = 0.004f;
02871 
02872         m_symmetry = symmetry;
02873         m_npad = npad;
02874         m_nsym = Transform::get_nsym(m_symmetry);
02875 
02876         m_vnx = size;
02877         m_vny = size;
02878         m_vnz = size;
02879 
02880         m_vnxp = size*npad;
02881         m_vnyp = size*npad;
02882         m_vnzp = size*npad;
02883 
02884         m_vnxc = m_vnxp/2;
02885         m_vnyc = m_vnyp/2;
02886         m_vnzc = m_vnzp/2;
02887 
02888         buildFFTVolume();
02889         buildNormVolume();
02890         buildNorm2Volume();
02891 
02892 }

void nnSSNR_Reconstructor::setup  )  [virtual]
 

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 2853 of file reconstructor.cpp.

References EMAN::Dict::has_key().

Referenced by nnSSNR_Reconstructor().

02854 {
02855         int size = params["size"];
02856         int npad = params["npad"];
02857 
02858         string symmetry;
02859         if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str();
02860         else                             symmetry = "c1";
02861 
02862         setup( symmetry, size, npad );
02863 }


Member Data Documentation

int EMAN::nnSSNR_Reconstructor::m_npad [private]
 

Definition at line 982 of file reconstructor.h.

Referenced by buildFFTVolume(), and setup().

int EMAN::nnSSNR_Reconstructor::m_nsym [private]
 

Definition at line 983 of file reconstructor.h.

Referenced by setup().

string EMAN::nnSSNR_Reconstructor::m_symmetry [private]
 

Definition at line 979 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

int EMAN::nnSSNR_Reconstructor::m_vnx [private]
 

Definition at line 981 of file reconstructor.h.

Referenced by setup().

int EMAN::nnSSNR_Reconstructor::m_vnxc [private]
 

Definition at line 985 of file reconstructor.h.

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

int EMAN::nnSSNR_Reconstructor::m_vnxp [private]
 

Definition at line 984 of file reconstructor.h.

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

int EMAN::nnSSNR_Reconstructor::m_vny [private]
 

Definition at line 981 of file reconstructor.h.

Referenced by setup().

int EMAN::nnSSNR_Reconstructor::m_vnyc [private]
 

Definition at line 985 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nnSSNR_Reconstructor::m_vnyp [private]
 

Definition at line 984 of file reconstructor.h.

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

int EMAN::nnSSNR_Reconstructor::m_vnz [private]
 

Definition at line 981 of file reconstructor.h.

Referenced by setup().

int EMAN::nnSSNR_Reconstructor::m_vnzc [private]
 

Definition at line 985 of file reconstructor.h.

Referenced by finish(), and setup().

int EMAN::nnSSNR_Reconstructor::m_vnzp [private]
 

Definition at line 984 of file reconstructor.h.

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

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

Definition at line 976 of file reconstructor.h.

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

int EMAN::nnSSNR_Reconstructor::m_weighting [private]
 

Definition at line 980 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nnSSNR_Reconstructor::m_wghta [private]
 

Definition at line 989 of file reconstructor.h.

Referenced by finish(), and setup().

float EMAN::nnSSNR_Reconstructor::m_wghtb [private]
 

Definition at line 990 of file reconstructor.h.

Referenced by setup().

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

Definition at line 977 of file reconstructor.h.

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

EMData* EMAN::nnSSNR_Reconstructor::m_wptr2 [private]
 

Definition at line 978 of file reconstructor.h.

Referenced by buildNorm2Volume(), finish(), insert_padfft_slice(), and nnSSNR_Reconstructor().

const string nnSSNR_Reconstructor::NAME = "nnSSNR" [static]
 

Definition at line 83 of file reconstructor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:42 2011 for EMAN2 by  doxygen 1.3.9.1