EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
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)
 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, float mult=1)

Static Public Member Functions

static ReconstructorNEW ()

Static Public Attributes

static 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

Detailed Description

Definition at line 1143 of file reconstructor.h.


Constructor & Destructor Documentation

nnSSNR_Reconstructor::nnSSNR_Reconstructor ( )

Definition at line 2865 of file reconstructor.cpp.

References m_volume, m_wptr, and m_wptr2.

Referenced by NEW().

{
        m_volume = NULL;
        m_wptr   = NULL;
        m_wptr2  = NULL;
}
nnSSNR_Reconstructor::nnSSNR_Reconstructor ( const string &  symmetry,
int  size,
int  npad 
)

Definition at line 2872 of file reconstructor.cpp.

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

{
        m_volume = NULL;
        m_wptr   = NULL;
        m_wptr2  = NULL;

        setup( symmetry, size, npad );
}
nnSSNR_Reconstructor::~nnSSNR_Reconstructor ( )

Definition at line 2881 of file reconstructor.cpp.

{
        //if( m_delete_volume ) checked_delete(m_volume);

        //if( m_delete_weight ) checked_delete( m_wptr );

        //if( m_delete_weight2 ) checked_delete( m_wptr2 );

        //checked_delete( m_result );
}

Member Function Documentation

void nnSSNR_Reconstructor::buildFFTVolume ( ) [private]
void nnSSNR_Reconstructor::buildNorm2Volume ( ) [private]
void nnSSNR_Reconstructor::buildNormVolume ( ) [private]
EMData * nnSSNR_Reconstructor::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.

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

Reimplemented from EMAN::Reconstructor.

Definition at line 3006 of file reconstructor.cpp.

References abs, EMAN::EMData::cmplx(), ESTIMATE, 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::FactoryBase::params, 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().

{
/*
  I changed the code on 05/15/2008 so it only returns variance.
  Lines commented out are marked by //#
  The version prior to the currect changes is r1.190
  PAP
*/
        int kz, ky;
        //#int iix, iiy, iiz;
        int box = 7;
        int kc = (box-1)/2;
        float alpha = 0.0;
        float argx, argy, argz;
        vector< float > pow_a( 3*kc+1, 1.0 );
        float w = params["w"];
        EMData* SSNR = params["SSNR"];
        //#EMData* vol_ssnr = new EMData();
        //#vol_ssnr->set_size(m_vnxp, m_vnyp, m_vnzp);
        //#vol_ssnr->to_zero();
        //#  new line follow
        EMData* vol_ssnr = params["vol_ssnr"];
        vol_ssnr->set_size(m_vnxp+ 2 - m_vnxp%2, m_vnyp ,m_vnzp);
        vol_ssnr->to_zero();
        if ( m_vnxp % 2 == 0 ) vol_ssnr->set_fftodd(0);
        else                   vol_ssnr->set_fftodd(1);
        vol_ssnr->set_nxc(m_vnxc);
        vol_ssnr->set_complex(true);
        vol_ssnr->set_ri(true);
        vol_ssnr->set_fftpad(false);
        //#

        float dx2 = 1.0f/float(m_vnxc)/float(m_vnxc);
        float dy2 = 1.0f/float(m_vnyc)/float(m_vnyc);
#ifdef _WIN32
        float dz2 = 1.0f/_cpp_max(float(m_vnzc),1.0f)/_cpp_max(float(m_vnzc),1.0f);
        int  inc = Util::round(float(_cpp_max(_cpp_max(m_vnxc,m_vnyc),m_vnzc))/w);
#else
        float dz2 = 1.0f/std::max(float(m_vnzc),1.0f)/std::max(float(m_vnzc),1.0f);
        int  inc = Util::round(float(std::max(std::max(m_vnxc,m_vnyc),m_vnzc))/w);
#endif  //_WIN32
        SSNR->set_size(inc+1,4,1);

        float *nom    = new float[inc+1];
        float *denom  = new float[inc+1];
        int  *nn     = new int[inc+1];
        int  *ka     = new int[inc+1];
        float wght = 1.0f;
        for (int i = 0; i <= inc; i++) {
                nom[i] = 0.0f;
                denom[i] = 0.0f;
                nn[i] = 0;
                ka[i] = 0;
        }

        m_volume->symplane1(m_wptr, m_wptr2);

        if ( m_weighting == ESTIMATE ) {
                int vol = box*box*box;
                for( unsigned int i=1; i < pow_a.size(); ++i ) pow_a[i] = pow_a[i-1] * exp(m_wghta);
                pow_a[3*kc] = 0.0;
                float max = max3d( kc, pow_a );
                alpha = ( 1.0f - 1.0f/(float)vol ) / max;
        }

        for (int iz = 1; iz <= m_vnzp; iz++) {
                if ( iz-1 > m_vnzc ) kz = iz-1-m_vnzp; else kz = iz-1;
                argz = float(kz*kz)*dz2;
                for (int iy = 1; iy <= m_vnyp; iy++) {
                        if ( iy-1 > m_vnyc ) ky = iy-1-m_vnyp; else ky = iy-1;
                        argy = argz + float(ky*ky)*dy2;
                        for (int ix = 0; ix <= m_vnxc; ix++) {
                                float Kn = (*m_wptr)(ix,iy,iz);
                                argx = std::sqrt(argy + float(ix*ix)*dx2);
                                int r = Util::round(float(inc)*argx);
                                if ( r >= 0 && Kn > 4.5f ) {
                                        if ( m_weighting == ESTIMATE ) {
                                                int cx = ix;
                                                int cy = (iy<=m_vnyc) ? iy - 1 : iy - 1 - m_vnyp;
                                                int cz = (iz<=m_vnzc) ? iz - 1 : iz - 1 - m_vnzp;

                                                float sum = 0.0;
                                                for( int ii = -kc; ii <= kc; ++ii ) {
                                                        int nbrcx = cx + ii;
                                                        if( nbrcx >= m_vnxc ) continue;
                                                    for ( int jj= -kc; jj <= kc; ++jj ) {
                                                                int nbrcy = cy + jj;
                                                                if( nbrcy <= -m_vnyc || nbrcy >= m_vnyc ) continue;
                                                                for( int kk = -kc; kk <= kc; ++kk ) {
                                                                        int nbrcz = cz + jj;
                                                                        if ( nbrcz <= -m_vnyc || nbrcz >= m_vnyc ) continue;
                                                                        if( nbrcx < 0 ) {
                                                                                nbrcx = -nbrcx;
                                                                                nbrcy = -nbrcy;
                                                                                nbrcz = -nbrcz;
                                                                        }
                                                                        int nbrix = nbrcx;
                                                                        int nbriy = nbrcy >= 0 ? nbrcy + 1 : nbrcy + 1 + m_vnyp;
                                                                        int nbriz = nbrcz >= 0 ? nbrcz + 1 : nbrcz + 1 + m_vnzp;
                                                                        if( (*m_wptr)( nbrix, nbriy, nbriz ) == 0 ) {
                                                                                int c = 3*kc+1 - std::abs(ii) - std::abs(jj) - std::abs(kk);
                                                                                sum = sum + pow_a[c];
                                                                        }
                                                                }
                                                        }
                                                }
                                                wght = 1.0f / ( 1.0f - alpha * sum );
                                        } // end of ( m_weighting == ESTIMATE )
                                        float nominator = std::norm(m_volume->cmplx(ix,iy,iz)/Kn);
                                        float denominator = ((*m_wptr2)(ix,iy,iz)-nominator)/(Kn-1.0f);
                                        // Skip Friedel related values
                                        if( (ix>0 || (kz>=0 && (ky>=0 || kz!=0)))) {
                                                if ( r <= inc ) {
                                                        nom[r]   += nominator*wght;
                                                        denom[r] += denominator/Kn*wght;
                                                        nn[r]    += 2;
                                                        ka[r]    += int(Kn);
                                                }
/*
#ifdef  _WIN32
                                                //#float  tmp = _cpp_max(nominator/denominator/Kn-1.0f,0.0f);
#else
                                                //#float  tmp = std::max(nominator/denominator/Kn-1.0f,0.0f);
#endif  //_WIN32
                                                //  Create SSNR as a 3D array (-n/2:n/2+n%2-1)
                                                iix = m_vnxc + ix; iiy = m_vnyc + ky; iiz = m_vnzc + kz;
                                                if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
                                                        (*vol_ssnr)(iix, iiy, iiz) = tmp;
                                                // Friedel part
                                                iix = m_vnxc - ix; iiy = m_vnyc - ky; iiz = m_vnzc - kz;
                                                if( iix >= 0 && iix < m_vnxp && iiy >= 0 && iiy < m_vnyp && iiz >= 0 && iiz < m_vnzp )
                                                        (*vol_ssnr)(iix, iiy, iiz) = tmp;
*/

                                        }
                                        (*vol_ssnr)(2*ix, iy-1, iz-1) = nominator*wght;//Kn;//denominator*wght;//
                                        //(*vol_ssnr)(2*ix, iy-1, iz-1) =  real(m_volume->cmplx(ix,iy,iz))*wght/Kn;
                                        //(*vol_ssnr)(2*ix+1, iy-1, iz-1) = imag(m_volume->cmplx(ix,iy,iz))*wght/Kn;
                                } // end of Kn>4.5
                        }
                }
        }

        for (int i = 0; i <= inc; i++)  {
                (*SSNR)(i,0,0) = nom[i];  
                (*SSNR)(i,1,0) = denom[i];    // variance
                (*SSNR)(i,2,0) = static_cast<float>(nn[i]);
                (*SSNR)(i,3,0) = static_cast<float>(ka[i]);
        }
        vol_ssnr->update();
        
        delete[] nom;
        delete[] denom;
        delete[] nn;
        delete[] ka;

        return 0;
}
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 1172 of file reconstructor.h.

                {
                        return "Reconstruction by nearest neighbor with 3D SSNR";
                }
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 1167 of file reconstructor.h.

References NAME.

                {
                        return NAME;
                }
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 1182 of file reconstructor.h.

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

                {
                        TypeDict d;
                        d.put("size", EMObject::INT);
                        d.put("npad", EMObject::INT);
                        d.put("symmetry", EMObject::STRING);
                        d.put("fftvol", EMObject::EMDATA);
                        d.put("weight", EMObject::EMDATA);
                        d.put("weight2", EMObject::EMDATA);
                        d.put("SSNR", EMObject::EMDATA);
                        d.put("vol_ssnr", EMObject::EMDATA);
                        d.put("w", EMObject::FLOAT);
                        return d;
                }
int nnSSNR_Reconstructor::insert_padfft_slice ( EMData padded,
const Transform trans,
float  mult = 1 
)

Definition at line 2993 of file reconstructor.cpp.

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

Referenced by insert_slice().

{
        Assert( padfft != NULL );
        // insert slice for all symmetry related positions
        for (int isym=0; isym < m_nsym; isym++) {
                Transform tsym = t.get_sym(m_symmetry, isym);
                m_volume->nn_SSNR( m_wptr, m_wptr2, padfft, tsym, weight);
        }
        return 0;
}
int nnSSNR_Reconstructor::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 2966 of file reconstructor.cpp.

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

                                                                                                        {
        // sanity checks
        if (!slice) {
                LOGERR("try to insert NULL slice");
                return 1;
        }
        if( weight > 0.0f )  {
                int padffted=slice->get_attr_default( "padffted", 0 );

                if ( padffted==0 && (slice->get_xsize()!=slice->get_ysize() || slice->get_xsize()!=m_vnx)  ) {
                        // FIXME: Why doesn't this throw an exception?
                        LOGERR("Tried to insert a slice that has wrong size.");
                        return 1;
                }

                EMData* padfft = NULL;

                if( padffted != 0 ) padfft = new EMData(*slice);
                else                padfft = padfft_slice( slice, t, m_npad );

                insert_padfft_slice( padfft, t, weight );

                checked_delete( padfft );
                return 0;
        }
}
static Reconstructor* EMAN::nnSSNR_Reconstructor::NEW ( ) [inline, static]

Definition at line 1177 of file reconstructor.h.

References nnSSNR_Reconstructor().

                {
                        return new nnSSNR_Reconstructor();
                }
void nnSSNR_Reconstructor::setup ( ) [virtual]

Initialize the reconstructor.

Implements EMAN::Reconstructor.

Definition at line 2892 of file reconstructor.cpp.

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

Referenced by nnSSNR_Reconstructor().

{
        int size = params["size"];
        int npad = params["npad"];

        string symmetry;
        if( params.has_key("symmetry") ) symmetry = params["symmetry"].to_str();
        else                             symmetry = "c1";

        setup( symmetry, size, npad );
}
void nnSSNR_Reconstructor::setup ( const string &  symmetry,
int  size,
int  npad 
)

Member Data Documentation

Definition at line 1210 of file reconstructor.h.

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

Definition at line 1211 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1207 of file reconstructor.h.

Referenced by insert_padfft_slice(), and setup().

Definition at line 1209 of file reconstructor.h.

Referenced by insert_slice(), and setup().

Definition at line 1213 of file reconstructor.h.

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

Definition at line 1212 of file reconstructor.h.

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

Definition at line 1209 of file reconstructor.h.

Referenced by setup().

Definition at line 1213 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1212 of file reconstructor.h.

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

Definition at line 1209 of file reconstructor.h.

Referenced by setup().

Definition at line 1213 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1212 of file reconstructor.h.

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

Definition at line 1208 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1217 of file reconstructor.h.

Referenced by finish(), and setup().

Definition at line 1218 of file reconstructor.h.

Referenced by setup().

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

Definition at line 1201 of file reconstructor.h.

Referenced by get_name().


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