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

#include <reconstructor.h>

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

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

Constructor & Destructor Documentation

◆ newfile_store()

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

Definition at line 6298 of file reconstructor.cpp.

6299 : m_bin_file( filename + ".bin" ),
6300 m_txt_file( filename + ".txt" )
6301{
6302 m_npad = npad;
6303 m_ctf = ctf;
6304}

References m_ctf, and m_npad.

◆ ~newfile_store()

newfile_store::~newfile_store ( )
virtual

Definition at line 6306 of file reconstructor.cpp.

6307{
6308}

Member Function Documentation

◆ add_image()

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

Definition at line 6310 of file reconstructor.cpp.

6311{
6312 if( m_bin_of == NULL ) {
6313 m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) );
6314 m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) );
6315 }
6316
6317
6318 EMData* padfft = padfft_slice( emdata, tf, m_npad );
6319
6320 int nx = padfft->get_xsize();
6321 int ny = padfft->get_ysize();
6322 int n2 = ny / 2;
6323 int n = ny;
6324
6325 float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f;
6326
6327 if( m_ctf ) {
6328 Ctf* ctf = emdata->get_attr( "ctf" );
6329 Dict params = ctf->to_dict();
6330 voltage = params["voltage"];
6331 pixel = params["apix"];
6332 Cs = params["cs"];
6333 ampcont = params["ampcont"];
6334 bfactor = params["bfactor"];
6335 defocus = params["defocus"];
6336 if(ctf) {delete ctf; ctf=0;}
6337 }
6338
6339 vector<point_t> points;
6340 for( int j=-ny/2+1; j <= ny/2; j++ ) {
6341 int jp = (j>=0) ? j+1 : ny+j+1;
6342 for( int i=0; i <= n2; ++i ) {
6343 int r2 = i*i + j*j;
6344 if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) {
6345 float ctf;
6346 if( m_ctf ) {
6347 float ak = std::sqrt( r2/float(ny*ny) )/pixel;
6348 ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1);
6349 } else {
6350 ctf = 1.0;
6351 }
6352
6353 float xnew = i*tf[0][0] + j*tf[1][0];
6354 float ynew = i*tf[0][1] + j*tf[1][1];
6355 float znew = i*tf[0][2] + j*tf[1][2];
6356 std::complex<float> btq;
6357 if (xnew < 0.) {
6358 xnew = -xnew;
6359 ynew = -ynew;
6360 znew = -znew;
6361 btq = conj(padfft->cmplx(i,jp-1));
6362 } else {
6363 btq = padfft->cmplx(i,jp-1);
6364 }
6365
6366 int ixn = int(xnew + 0.5 + n) - n;
6367 int iyn = int(ynew + 0.5 + n) - n;
6368 int izn = int(znew + 0.5 + n) - n;
6369 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) {
6370 int ixf, iyf, izf;
6371 if (ixn >= 0) {
6372 int iza, iya;
6373 if (izn >= 0)
6374 iza = izn + 1;
6375 else
6376 iza = n + izn + 1;
6377
6378 if (iyn >= 0)
6379 iya = iyn + 1;
6380 else
6381 iya = n + iyn + 1;
6382
6383 ixf = ixn;
6384 iyf = iya;
6385 izf = iza;
6386 } else {
6387 int izt, iyt;
6388 if (izn > 0)
6389 izt = n - izn + 1;
6390 else
6391 izt = -izn + 1;
6392
6393 if (iyn > 0)
6394 iyt = n - iyn + 1;
6395 else
6396 iyt = -iyn + 1;
6397
6398 ixf = -ixn;
6399 iyf = iyt;
6400 izf = izt;
6401 }
6402
6403
6404 int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2;
6405 float ctfv1 = btq.real() * ctf;
6406 float ctfv2 = btq.imag() * ctf;
6407 float ctf2 = ctf*ctf;
6408
6409 point_t p;
6410 p.pos2 = pos2;
6411 p.real = ctfv1;
6412 p.imag = ctfv2;
6413 p.ctf2 = ctf2;
6414
6415 points.push_back( p );
6416 }
6417 }
6418 }
6419 }
6420
6421
6422 int npoint = points.size();
6423 std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back();
6424 offset += npoint*sizeof(point_t);
6425 m_offsets.push_back( offset );
6426
6427 *m_txt_of << m_offsets.back() << std::endl;
6428 m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint );
6429 checked_delete( padfft );
6430}
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual Dict to_dict() const =0
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
shared_ptr< std::ofstream > m_txt_of
vector< std::istream::off_type > m_offsets
shared_ptr< std::ofstream > m_bin_of
EMData * sqrt() const
return square root of current image
EMData * padfft_slice(const EMData *const slice, const Transform &t, int npad)
Direct Fourier inversion Reconstructor.
void checked_delete(T *&x)

References checked_delete(), EMAN::point_t::ctf2, EMAN::point_t::imag, m_bin_file, m_bin_of, m_ctf, m_npad, m_offsets, m_txt_file, m_txt_of, EMAN::padfft_slice(), EMAN::point_t::pos2, EMAN::point_t::real, sqrt(), and EMAN::Ctf::to_dict().

◆ add_tovol()

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

Definition at line 6502 of file reconstructor.cpp.

6503{
6504 float* vdata = fftvol->get_data();
6505 float* wdata = wgtvol->get_data();
6506
6507 int npoint = m_offsets[0]/sizeof(point_t);
6508// Assert( int(mults.size())==nprj );
6509 Assert( int(m_points.size())== (pend - pbegin)*npoint );
6510
6511 for( int iprj=pbegin; iprj < pend; ++iprj ) {
6512 int m = mults[iprj];
6513 if( m==0 ) continue;
6514
6515 int ipt = (iprj-pbegin)*npoint;
6516 for( int i=0; i < npoint; ++i ) {
6517 int pos2 = m_points[ipt].pos2;
6518 int pos1 = pos2*2;
6519
6520 wdata[pos2] += m_points[ipt].ctf2*m;
6521 vdata[pos1] += m_points[ipt].real*m;
6522 vdata[pos1+1] += m_points[ipt].imag*m;
6523 ++ipt;
6524 }
6525 }
6526}
vector< point_t > m_points
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42

References Assert, m_offsets, and m_points.

◆ get_image()

void newfile_store::get_image ( int  id,
EMData buf 
)

Definition at line 6432 of file reconstructor.cpp.

6433{
6434 if( m_offsets.size()==0 ) {
6435 ifstream is( m_txt_file.c_str() );
6436 std::istream::off_type off;
6437 while( is >> off ) {
6438 m_offsets.push_back( off );
6439 }
6440
6441 m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
6442 }
6443
6444 Assert( m_bin_if != NULL );
6445
6446 std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1];
6447 Assert( offset >= 0 );
6448 m_bin_if->seekg( offset, std::ios::beg );
6449
6450
6451 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) {
6452 std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl;
6453 throw std::logic_error( "bad happen" );
6454 }
6455
6456 int bufsize = (m_offsets[id] - offset)/sizeof(float);
6457 if( buf->get_xsize() != bufsize ) {
6458 buf->set_size( bufsize, 1, 1 );
6459 }
6460
6461 char* data = (char*)(buf->get_data());
6462 m_bin_if->read( data, sizeof(float)*bufsize );
6463 buf->update();
6464}
shared_ptr< std::ifstream > m_bin_if

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

◆ read()

void newfile_store::read ( int  nprj)

Definition at line 6466 of file reconstructor.cpp.

6467{
6468 if( m_offsets.size()==0 ) {
6469 ifstream is( m_txt_file.c_str() );
6470 std::istream::off_type off;
6471 while( is >> off ) {
6472 m_offsets.push_back( off );
6473 }
6474 }
6475
6476 if( m_bin_if==NULL ) {
6477 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
6478 }
6479
6480
6481 int npoint = m_offsets[0]/sizeof(point_t);
6482 std::ios::off_type prjsize = m_offsets[0];
6483
6484 try {
6485 m_points.resize(nprj * npoint);
6486 }
6487 catch( std::exception& e ) {
6488 std::cout << "Error: " << e.what() << std::endl;
6489 }
6490
6491 int ip = 0;
6492 for( int i=0; i < nprj; ++i ) {
6493 m_bin_if->read( (char*)(&m_points[ip]), prjsize );
6494 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) {
6495 std::cout << "Error: file hander bad or fail or eof" << std::endl;
6496 return;
6497 }
6498 ip += npoint;
6499 }
6500}

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

◆ restart()

void newfile_store::restart ( )

Definition at line 6528 of file reconstructor.cpp.

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

References m_bin_file, and m_bin_if.

Member Data Documentation

◆ m_bin_file

string EMAN::newfile_store::m_bin_file
private

Definition at line 1767 of file reconstructor.h.

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

◆ m_bin_if

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

Definition at line 1772 of file reconstructor.h.

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

◆ m_bin_of

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

Definition at line 1770 of file reconstructor.h.

Referenced by add_image().

◆ m_ctf

bool EMAN::newfile_store::m_ctf
private

Definition at line 1765 of file reconstructor.h.

Referenced by add_image(), and newfile_store().

◆ m_npad

int EMAN::newfile_store::m_npad
private

Definition at line 1763 of file reconstructor.h.

Referenced by add_image(), and newfile_store().

◆ m_offsets

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

Definition at line 1773 of file reconstructor.h.

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

◆ m_points

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

Definition at line 1775 of file reconstructor.h.

Referenced by add_tovol(), and read().

◆ m_txt_file

string EMAN::newfile_store::m_txt_file
private

Definition at line 1768 of file reconstructor.h.

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

◆ m_txt_of

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

Definition at line 1771 of file reconstructor.h.

Referenced by add_image().


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