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

EMAN::newfile_store Class Reference

#include <reconstructor.h>

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


Constructor & Destructor Documentation

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

Definition at line 3397 of file reconstructor.cpp.

References m_ctf, and m_npad.

03398     : m_bin_file( filename + ".bin" ),
03399       m_txt_file( filename + ".txt" )
03400 {
03401     m_npad = npad;
03402     m_ctf = ctf;
03403 }

newfile_store::~newfile_store  )  [virtual]
 

Definition at line 3405 of file reconstructor.cpp.

03406 {
03407 }


Member Function Documentation

void newfile_store::add_image EMData data,
const Transform tf
 

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

03410 {
03411     if( m_bin_of == NULL )
03412     {
03413         m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) );
03414         m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) );
03415     }
03416 
03417 
03418     EMData* padfft = padfft_slice( emdata, tf, m_npad );
03419 
03420     int nx = padfft->get_xsize();
03421     int ny = padfft->get_ysize();
03422     int n2 = ny / 2;
03423     int n = ny;
03424 
03425     float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f;
03426 
03427     if( m_ctf )
03428     {
03429         Ctf* ctf = emdata->get_attr( "ctf" );
03430         Dict params = ctf->to_dict();
03431         voltage = params["voltage"];
03432         pixel   = params["apix"];
03433         Cs      = params["cs"];
03434         ampcont = params["ampcont"];
03435         bfactor = params["bfactor"];
03436         defocus = params["defocus"];
03437         if(ctf) {delete ctf; ctf=0;}
03438     }
03439 
03440     vector<point_t> points;
03441     for( int j=-ny/2+1; j <= ny/2; j++ )
03442     {
03443         int jp = (j>=0) ? j+1 : ny+j+1;
03444         for( int i=0; i <= n2; ++i )
03445         {
03446             int r2 = i*i + j*j;
03447             if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) )
03448             {
03449                 float ctf;
03450                 if( m_ctf )
03451                 {
03452                     float ak = std::sqrt( r2/float(ny*ny) )/pixel;
03453                     ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1);
03454                 }
03455                 else
03456                 {
03457                     ctf = 1.0;
03458                 }
03459 
03460                 float xnew = i*tf[0][0] + j*tf[1][0];
03461                 float ynew = i*tf[0][1] + j*tf[1][1];
03462                 float znew = i*tf[0][2] + j*tf[1][2];
03463                 std::complex<float> btq;
03464                 if (xnew < 0.)
03465                 {
03466                     xnew = -xnew;
03467                     ynew = -ynew;
03468                     znew = -znew;
03469                     btq = conj(padfft->cmplx(i,jp-1));
03470                 }
03471                 else
03472                 {
03473                     btq = padfft->cmplx(i,jp-1);
03474                 }
03475 
03476                 int ixn = int(xnew + 0.5 + n) - n;
03477                 int iyn = int(ynew + 0.5 + n) - n;
03478                 int izn = int(znew + 0.5 + n) - n;
03479                 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2))
03480                 {
03481                     int ixf, iyf, izf;
03482                     if (ixn >= 0)
03483                     {
03484                         int iza, iya;
03485                         if (izn >= 0)
03486                             iza = izn + 1;
03487                         else
03488                             iza = n + izn + 1;
03489 
03490                         if (iyn >= 0)
03491                             iya = iyn + 1;
03492                         else
03493                             iya = n + iyn + 1;
03494 
03495                         ixf = ixn;
03496                         iyf = iya;
03497                         izf = iza;
03498                     }
03499                     else
03500                     {
03501                         int izt, iyt;
03502                         if (izn > 0)
03503                             izt = n - izn + 1;
03504                         else
03505                             izt = -izn + 1;
03506 
03507                         if (iyn > 0)
03508                             iyt = n - iyn + 1;
03509                         else
03510                             iyt = -iyn + 1;
03511 
03512                         ixf = -ixn;
03513                         iyf = iyt;
03514                         izf = izt;
03515                     }
03516 
03517 
03518                     int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2;
03519                     float ctfv1 = btq.real() * ctf;
03520                     float ctfv2 = btq.imag() * ctf;
03521                     float ctf2 = ctf*ctf;
03522 
03523                     point_t p;
03524                     p.pos2 = pos2;
03525                     p.real = ctfv1;
03526                     p.imag = ctfv2;
03527                     p.ctf2 = ctf2;
03528 
03529                     points.push_back( p );
03530                 }
03531             }
03532         }
03533     }
03534 
03535 
03536     int npoint = points.size();
03537     std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back();
03538     offset += npoint*sizeof(point_t);
03539     m_offsets.push_back( offset );
03540 
03541     *m_txt_of << m_offsets.back() << std::endl;
03542     m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint );
03543     checked_delete( padfft );
03544 }

void newfile_store::add_tovol EMData fftvol,
EMData wgtvol,
const vector< int > &  mults,
int  pbegin,
int  pend
 

Definition at line 3627 of file reconstructor.cpp.

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

03628 {
03629     float* vdata = fftvol->get_data();
03630     float* wdata = wgtvol->get_data();
03631 
03632     int npoint = m_offsets[0]/sizeof(point_t);
03633 //    Assert( int(mults.size())==nprj );
03634     Assert( int(m_points.size())== (pend - pbegin)*npoint );
03635 
03636     for( int iprj=pbegin; iprj < pend; ++iprj )
03637     {
03638         int m = mults[iprj];
03639         if( m==0 ) continue;
03640 
03641         int ipt = (iprj-pbegin)*npoint;
03642         for( int i=0; i < npoint; ++i )
03643         {
03644             int pos2 = m_points[ipt].pos2;
03645             int pos1 = pos2*2;
03646 
03647             wdata[pos2] += m_points[ipt].ctf2*m;
03648             vdata[pos1] += m_points[ipt].real*m;
03649             vdata[pos1+1]+= m_points[ipt].imag*m;
03650             ++ipt;
03651         }
03652     }
03653 }

void newfile_store::get_image int  id,
EMData buf
 

Definition at line 3546 of file reconstructor.cpp.

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

03547 {
03548     if( m_offsets.size()==0 )
03549     {
03550         ifstream is( m_txt_file.c_str() );
03551         std::istream::off_type off;
03552         while( is >> off )
03553         {
03554             m_offsets.push_back( off );
03555         }
03556 
03557         m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
03558     }
03559 
03560     Assert( m_bin_if != NULL );
03561 
03562     std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1];
03563     Assert( offset >= 0 );
03564     m_bin_if->seekg( offset, std::ios::beg );
03565 
03566 
03567     if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() )
03568     {
03569         std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl;
03570         throw std::logic_error( "bad happen" );
03571     }
03572 
03573     int bufsize = (m_offsets[id] - offset)/sizeof(float);
03574     if( buf->get_xsize() != bufsize )
03575     {
03576         buf->set_size( bufsize, 1, 1 );
03577     }
03578 
03579     char* data = (char*)(buf->get_data());
03580     m_bin_if->read( data, sizeof(float)*bufsize );
03581     buf->update();
03582 }

void newfile_store::read int  nprj  ) 
 

Definition at line 3584 of file reconstructor.cpp.

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

03585 {
03586     if( m_offsets.size()==0 )
03587     {
03588         ifstream is( m_txt_file.c_str() );
03589         std::istream::off_type off;
03590         while( is >> off )
03591         {
03592             m_offsets.push_back( off );
03593         }
03594     }
03595 
03596     if( m_bin_if==NULL )
03597     {
03598         m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
03599     }
03600 
03601 
03602     int npoint = m_offsets[0]/sizeof(point_t);
03603     std::ios::off_type prjsize = m_offsets[0];
03604 
03605     try
03606     {
03607         m_points.resize(nprj * npoint);
03608     }
03609     catch( std::exception& e )
03610     {
03611         std::cout << "Error: " << e.what() << std::endl;
03612     }
03613 
03614     int ip = 0;
03615     for( int i=0; i < nprj; ++i )
03616     {
03617         m_bin_if->read( (char*)(&m_points[ip]), prjsize );
03618             if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() )
03619         {
03620             std::cout << "Error: file hander bad or fail or eof" << std::endl;
03621             return;
03622         }
03623         ip += npoint;
03624     }
03625 }

void newfile_store::restart  ) 
 

Definition at line 3655 of file reconstructor.cpp.

References m_bin_file, and m_bin_if.

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


Member Data Documentation

string EMAN::newfile_store::m_bin_file [private]
 

Definition at line 1187 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 1192 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 1190 of file reconstructor.h.

Referenced by add_image().

bool EMAN::newfile_store::m_ctf [private]
 

Definition at line 1185 of file reconstructor.h.

Referenced by newfile_store().

int EMAN::newfile_store::m_npad [private]
 

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

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

vector< point_t > EMAN::newfile_store::m_points [private]
 

Definition at line 1195 of file reconstructor.h.

Referenced by add_tovol(), and read().

string EMAN::newfile_store::m_txt_file [private]
 

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

Referenced by add_image().


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:31 2010 for EMAN2 by  doxygen 1.3.9.1