EMAN2
Public Member Functions | Private Attributes
EMAN::newfile_store Class Reference

#include <reconstructor.h>

Collaboration diagram for EMAN::newfile_store:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 newfile_store (const string &prefix, int npad, bool ctf)
virtual ~newfile_store ()
void add_image (EMData *data, const Transform &tf)
void add_tovol (EMData *fftvol, EMData *wgtvol, const vector< int > &mults, int pbegin, int pend)
void get_image (int id, EMData *buf)
void read (int nprj)
void restart ()

Private Attributes

int m_npad
bool m_ctf
string m_bin_file
string m_txt_file
shared_ptr< std::ofstream > m_bin_of
shared_ptr< std::ofstream > m_txt_of
shared_ptr< std::ifstream > m_bin_if
vector< std::istream::off_type > m_offsets
vector< point_tm_points

Detailed Description

Definition at line 1597 of file reconstructor.h.


Constructor & Destructor Documentation

newfile_store::newfile_store ( const string &  prefix,
int  npad,
bool  ctf 
)

Definition at line 4400 of file reconstructor.cpp.

References m_ctf, and m_npad.

    : m_bin_file( filename + ".bin" ),
      m_txt_file( filename + ".txt" )
{
        m_npad = npad;
        m_ctf = ctf;
}
newfile_store::~newfile_store ( ) [virtual]

Definition at line 4408 of file reconstructor.cpp.

{
}

Member Function Documentation

void newfile_store::add_image ( EMData data,
const Transform tf 
)

Definition at line 4412 of file reconstructor.cpp.

References checked_delete(), EMAN::EMData::cmplx(), EMAN::point_t::ctf2, EMAN::EMData::get_attr(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::point_t::imag, m_bin_file, m_bin_of, m_ctf, m_npad, m_offsets, m_txt_file, m_txt_of, nx, ny, EMAN::padfft_slice(), EMAN::point_t::pos2, EMAN::point_t::real, sqrt(), tf(), and EMAN::Ctf::to_dict().

{
        if( m_bin_of == NULL ) {
            m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) );
            m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) );
        }


        EMData* padfft = padfft_slice( emdata, tf, m_npad );

        int nx = padfft->get_xsize();
        int ny = padfft->get_ysize();
        int n2 = ny / 2;
        int n = ny;

        float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f;

        if( m_ctf ) {
                Ctf* ctf = emdata->get_attr( "ctf" );
                Dict params = ctf->to_dict();
                voltage = params["voltage"];
                pixel   = params["apix"];
                Cs      = params["cs"];
                ampcont = params["ampcont"];
                bfactor = params["bfactor"];
                defocus = params["defocus"];
                if(ctf) {delete ctf; ctf=0;}
        }

        vector<point_t> points;
        for( int j=-ny/2+1; j <= ny/2; j++ ) {
                int jp = (j>=0) ? j+1 : ny+j+1;
                for( int i=0; i <= n2; ++i ) {
                        int r2 = i*i + j*j;
                        if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) {
                                float ctf;
                                if( m_ctf ) {
                                        float ak = std::sqrt( r2/float(ny*ny) )/pixel;
                                        ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1);
                                } else {
                                        ctf = 1.0;
                                }

                                float xnew = i*tf[0][0] + j*tf[1][0];
                                float ynew = i*tf[0][1] + j*tf[1][1];
                                float znew = i*tf[0][2] + j*tf[1][2];
                                std::complex<float> btq;
                                if (xnew < 0.) {
                                        xnew = -xnew;
                                        ynew = -ynew;
                                        znew = -znew;
                                        btq = conj(padfft->cmplx(i,jp-1));
                                } else {
                                        btq = padfft->cmplx(i,jp-1);
                                }

                                int ixn = int(xnew + 0.5 + n) - n;
                                int iyn = int(ynew + 0.5 + n) - n;
                                int izn = int(znew + 0.5 + n) - n;
                                if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) {
                                        int ixf, iyf, izf;
                                        if (ixn >= 0) {
                                                int iza, iya;
                                                if (izn >= 0)
                                                    iza = izn + 1;
                                                else
                                                    iza = n + izn + 1;

                                                if (iyn >= 0)
                                                    iya = iyn + 1;
                                                else
                                                    iya = n + iyn + 1;

                                                ixf = ixn;
                                                iyf = iya;
                                                izf = iza;
                                        } else {
                                                int izt, iyt;
                                                if (izn > 0)
                                                    izt = n - izn + 1;
                                                else
                                                    izt = -izn + 1;

                                                if (iyn > 0)
                                                    iyt = n - iyn + 1;
                                                else
                                                    iyt = -iyn + 1;

                                                ixf = -ixn;
                                                iyf = iyt;
                                                izf = izt;
                                        }


                                        int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2;
                                        float ctfv1 = btq.real() * ctf;
                                        float ctfv2 = btq.imag() * ctf;
                                        float ctf2 = ctf*ctf;

                                        point_t p;
                                        p.pos2 = pos2;
                                        p.real = ctfv1;
                                        p.imag = ctfv2;
                                        p.ctf2 = ctf2;

                                        points.push_back( p );
                                }
                        }
                }
        }


        int npoint = points.size();
        std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back();
        offset += npoint*sizeof(point_t);
        m_offsets.push_back( offset );

        *m_txt_of << m_offsets.back() << std::endl;
        m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint );
        checked_delete( padfft );
}
void newfile_store::add_tovol ( EMData fftvol,
EMData wgtvol,
const vector< int > &  mults,
int  pbegin,
int  pend 
)

Definition at line 4604 of file reconstructor.cpp.

References Assert, EMAN::EMData::get_data(), m_offsets, and m_points.

{
        float* vdata = fftvol->get_data();
        float* wdata = wgtvol->get_data();

        int npoint = m_offsets[0]/sizeof(point_t);
//    Assert( int(mults.size())==nprj );
        Assert( int(m_points.size())== (pend - pbegin)*npoint );

        for( int iprj=pbegin; iprj < pend; ++iprj ) {
                int m = mults[iprj];
                if( m==0 ) continue;

                int ipt = (iprj-pbegin)*npoint;
                for( int i=0; i < npoint; ++i )  {
                    int pos2 = m_points[ipt].pos2;
                    int pos1 = pos2*2;

                    wdata[pos2]   += m_points[ipt].ctf2*m;
                    vdata[pos1]   += m_points[ipt].real*m;
                    vdata[pos1+1] += m_points[ipt].imag*m;
                    ++ipt;
                }
        }
}
void newfile_store::get_image ( int  id,
EMData buf 
)

Definition at line 4534 of file reconstructor.cpp.

References Assert, data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), in, m_bin_file, m_bin_if, m_offsets, m_txt_file, EMAN::EMData::set_size(), and EMAN::EMData::update().

{
        if( m_offsets.size()==0 ) {
                ifstream is( m_txt_file.c_str() );
                std::istream::off_type off;
                while( is >> off ) {
                    m_offsets.push_back( off );
                }

                m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
        }

        Assert( m_bin_if != NULL );

        std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1];
        Assert( offset >= 0 );
        m_bin_if->seekg( offset, std::ios::beg );


        if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) {
                std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl;
                throw std::logic_error( "bad happen" );
        }

        int bufsize = (m_offsets[id] - offset)/sizeof(float);
        if( buf->get_xsize() != bufsize ) {
                buf->set_size( bufsize, 1, 1 );
        }

        char* data = (char*)(buf->get_data());
        m_bin_if->read( data, sizeof(float)*bufsize );
        buf->update();
}
void newfile_store::read ( int  nprj)

Definition at line 4568 of file reconstructor.cpp.

References in, m_bin_file, m_bin_if, m_offsets, m_points, and m_txt_file.

{
        if( m_offsets.size()==0 ) {
            ifstream is( m_txt_file.c_str() );
            std::istream::off_type off;
            while( is >> off ) {
                m_offsets.push_back( off );
            }
        }

        if( m_bin_if==NULL ) {
            m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
        }


        int npoint = m_offsets[0]/sizeof(point_t);
        std::ios::off_type prjsize = m_offsets[0];

        try {
            m_points.resize(nprj * npoint);
        }
        catch( std::exception& e ) {
            std::cout << "Error: " << e.what() << std::endl;
        }

        int ip = 0;
        for( int i=0; i < nprj; ++i ) {
                m_bin_if->read( (char*)(&m_points[ip]), prjsize );
                if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() )  {
                        std::cout << "Error: file hander bad or fail or eof" << std::endl;
                        return;
                }
                ip += npoint;
        }
}
void newfile_store::restart ( )

Definition at line 4630 of file reconstructor.cpp.

References in, m_bin_file, and m_bin_if.

{
    m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
}

Member Data Documentation

Definition at line 1619 of file reconstructor.h.

Referenced by add_image(), get_image(), read(), and restart().

shared_ptr<std::ifstream> EMAN::newfile_store::m_bin_if [private]

Definition at line 1624 of file reconstructor.h.

Referenced by get_image(), read(), and restart().

shared_ptr<std::ofstream> EMAN::newfile_store::m_bin_of [private]

Definition at line 1622 of file reconstructor.h.

Referenced by add_image().

Definition at line 1617 of file reconstructor.h.

Referenced by add_image(), and newfile_store().

Definition at line 1615 of file reconstructor.h.

Referenced by add_image(), and newfile_store().

vector< std::istream::off_type > EMAN::newfile_store::m_offsets [private]

Definition at line 1625 of file reconstructor.h.

Referenced by add_image(), add_tovol(), get_image(), and read().

Definition at line 1627 of file reconstructor.h.

Referenced by add_tovol(), and read().

Definition at line 1620 of file reconstructor.h.

Referenced by add_image(), get_image(), and read().

shared_ptr<std::ofstream> EMAN::newfile_store::m_txt_of [private]

Definition at line 1623 of file reconstructor.h.

Referenced by add_image().


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