#include <reconstructor.h>
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_t > | m_points |
Definition at line 1095 of file reconstructor.h.
newfile_store::newfile_store | ( | const string & | prefix, | |
int | npad, | |||
bool | ctf | |||
) |
Definition at line 3276 of file reconstructor.cpp.
03277 : m_bin_file( filename + ".bin" ), 03278 m_txt_file( filename + ".txt" ) 03279 { 03280 m_npad = npad; 03281 m_ctf = ctf; 03282 }
newfile_store::~newfile_store | ( | ) | [virtual] |
Definition at line 3288 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().
03289 { 03290 if( m_bin_of == NULL ) 03291 { 03292 m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) ); 03293 m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) ); 03294 } 03295 03296 03297 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 03298 03299 int nx = padfft->get_xsize(); 03300 int ny = padfft->get_ysize(); 03301 int n2 = ny / 2; 03302 int n = ny; 03303 03304 float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f; 03305 03306 if( m_ctf ) 03307 { 03308 Ctf* ctf = emdata->get_attr( "ctf" ); 03309 Dict params = ctf->to_dict(); 03310 voltage = params["voltage"]; 03311 pixel = params["apix"]; 03312 Cs = params["cs"]; 03313 ampcont = params["ampcont"]; 03314 bfactor = params["bfactor"]; 03315 defocus = params["defocus"]; 03316 if(ctf) {delete ctf; ctf=0;} 03317 } 03318 03319 vector<point_t> points; 03320 for( int j=-ny/2+1; j <= ny/2; j++ ) 03321 { 03322 int jp = (j>=0) ? j+1 : ny+j+1; 03323 for( int i=0; i <= n2; ++i ) 03324 { 03325 int r2 = i*i + j*j; 03326 if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) 03327 { 03328 float ctf; 03329 if( m_ctf ) 03330 { 03331 float ak = std::sqrt( r2/float(ny*ny) )/pixel; 03332 ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1); 03333 } 03334 else 03335 { 03336 ctf = 1.0; 03337 } 03338 03339 float xnew = i*tf[0][0] + j*tf[1][0]; 03340 float ynew = i*tf[0][1] + j*tf[1][1]; 03341 float znew = i*tf[0][2] + j*tf[1][2]; 03342 std::complex<float> btq; 03343 if (xnew < 0.) 03344 { 03345 xnew = -xnew; 03346 ynew = -ynew; 03347 znew = -znew; 03348 btq = conj(padfft->cmplx(i,jp-1)); 03349 } 03350 else 03351 { 03352 btq = padfft->cmplx(i,jp-1); 03353 } 03354 03355 int ixn = int(xnew + 0.5 + n) - n; 03356 int iyn = int(ynew + 0.5 + n) - n; 03357 int izn = int(znew + 0.5 + n) - n; 03358 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) 03359 { 03360 int ixf, iyf, izf; 03361 if (ixn >= 0) 03362 { 03363 int iza, iya; 03364 if (izn >= 0) 03365 iza = izn + 1; 03366 else 03367 iza = n + izn + 1; 03368 03369 if (iyn >= 0) 03370 iya = iyn + 1; 03371 else 03372 iya = n + iyn + 1; 03373 03374 ixf = ixn; 03375 iyf = iya; 03376 izf = iza; 03377 } 03378 else 03379 { 03380 int izt, iyt; 03381 if (izn > 0) 03382 izt = n - izn + 1; 03383 else 03384 izt = -izn + 1; 03385 03386 if (iyn > 0) 03387 iyt = n - iyn + 1; 03388 else 03389 iyt = -iyn + 1; 03390 03391 ixf = -ixn; 03392 iyf = iyt; 03393 izf = izt; 03394 } 03395 03396 03397 int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2; 03398 float ctfv1 = btq.real() * ctf; 03399 float ctfv2 = btq.imag() * ctf; 03400 float ctf2 = ctf*ctf; 03401 03402 point_t p; 03403 p.pos2 = pos2; 03404 p.real = ctfv1; 03405 p.imag = ctfv2; 03406 p.ctf2 = ctf2; 03407 03408 points.push_back( p ); 03409 } 03410 } 03411 } 03412 } 03413 03414 03415 int npoint = points.size(); 03416 std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back(); 03417 offset += npoint*sizeof(point_t); 03418 m_offsets.push_back( offset ); 03419 03420 *m_txt_of << m_offsets.back() << std::endl; 03421 m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint ); 03422 checked_delete( padfft ); 03423 }
void newfile_store::add_tovol | ( | EMData * | fftvol, | |
EMData * | wgtvol, | |||
const vector< int > & | mults, | |||
int | pbegin, | |||
int | pend | |||
) |
Definition at line 3506 of file reconstructor.cpp.
References Assert, EMAN::EMData::get_data(), m_offsets, and m_points.
03507 { 03508 float* vdata = fftvol->get_data(); 03509 float* wdata = wgtvol->get_data(); 03510 03511 int npoint = m_offsets[0]/sizeof(point_t); 03512 // Assert( int(mults.size())==nprj ); 03513 Assert( int(m_points.size())== (pend - pbegin)*npoint ); 03514 03515 for( int iprj=pbegin; iprj < pend; ++iprj ) 03516 { 03517 int m = mults[iprj]; 03518 if( m==0 ) continue; 03519 03520 int ipt = (iprj-pbegin)*npoint; 03521 for( int i=0; i < npoint; ++i ) 03522 { 03523 int pos2 = m_points[ipt].pos2; 03524 int pos1 = pos2*2; 03525 03526 wdata[pos2] += m_points[ipt].ctf2*m; 03527 vdata[pos1] += m_points[ipt].real*m; 03528 vdata[pos1+1]+= m_points[ipt].imag*m; 03529 ++ipt; 03530 } 03531 } 03532 }
void newfile_store::get_image | ( | int | id, | |
EMData * | buf | |||
) |
Definition at line 3425 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().
03426 { 03427 if( m_offsets.size()==0 ) 03428 { 03429 ifstream is( m_txt_file.c_str() ); 03430 std::istream::off_type off; 03431 while( is >> off ) 03432 { 03433 m_offsets.push_back( off ); 03434 } 03435 03436 m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 03437 } 03438 03439 Assert( m_bin_if != NULL ); 03440 03441 std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1]; 03442 Assert( offset >= 0 ); 03443 m_bin_if->seekg( offset, std::ios::beg ); 03444 03445 03446 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) 03447 { 03448 std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl; 03449 throw std::logic_error( "bad happen" ); 03450 } 03451 03452 int bufsize = (m_offsets[id] - offset)/sizeof(float); 03453 if( buf->get_xsize() != bufsize ) 03454 { 03455 buf->set_size( bufsize, 1, 1 ); 03456 } 03457 03458 char* data = (char*)(buf->get_data()); 03459 m_bin_if->read( data, sizeof(float)*bufsize ); 03460 buf->update(); 03461 }
void newfile_store::read | ( | int | nprj | ) |
Definition at line 3463 of file reconstructor.cpp.
References in, m_bin_file, m_bin_if, m_offsets, m_points, and m_txt_file.
03464 { 03465 if( m_offsets.size()==0 ) 03466 { 03467 ifstream is( m_txt_file.c_str() ); 03468 std::istream::off_type off; 03469 while( is >> off ) 03470 { 03471 m_offsets.push_back( off ); 03472 } 03473 } 03474 03475 if( m_bin_if==NULL ) 03476 { 03477 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 03478 } 03479 03480 03481 int npoint = m_offsets[0]/sizeof(point_t); 03482 std::ios::off_type prjsize = m_offsets[0]; 03483 03484 try 03485 { 03486 m_points.resize(nprj * npoint); 03487 } 03488 catch( std::exception& e ) 03489 { 03490 std::cout << "Error: " << e.what() << std::endl; 03491 } 03492 03493 int ip = 0; 03494 for( int i=0; i < nprj; ++i ) 03495 { 03496 m_bin_if->read( (char*)(&m_points[ip]), prjsize ); 03497 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) 03498 { 03499 std::cout << "Error: file hander bad or fail or eof" << std::endl; 03500 return; 03501 } 03502 ip += npoint; 03503 } 03504 }
void newfile_store::restart | ( | ) |
Definition at line 3534 of file reconstructor.cpp.
References in, m_bin_file, and m_bin_if.
03535 { 03536 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 03537 }
string EMAN::newfile_store::m_bin_file [private] |
Definition at line 1117 of file reconstructor.h.
Referenced by add_image(), get_image(), read(), and restart().
shared_ptr<std::ifstream> EMAN::newfile_store::m_bin_if [private] |
shared_ptr<std::ofstream> EMAN::newfile_store::m_bin_of [private] |
bool EMAN::newfile_store::m_ctf [private] |
int EMAN::newfile_store::m_npad [private] |
vector< std::istream::off_type > EMAN::newfile_store::m_offsets [private] |
Definition at line 1123 of file reconstructor.h.
Referenced by add_image(), add_tovol(), get_image(), and read().
vector< point_t > EMAN::newfile_store::m_points [private] |
string EMAN::newfile_store::m_txt_file [private] |
Definition at line 1118 of file reconstructor.h.
Referenced by add_image(), get_image(), and read().
shared_ptr<std::ofstream> EMAN::newfile_store::m_txt_of [private] |