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


Detailed Description

Definition at line 1502 of file reconstructor.h.


Constructor & Destructor Documentation

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

Definition at line 4089 of file reconstructor.cpp.

References m_ctf, and m_npad.

04090     : m_bin_file( filename + ".bin" ),
04091       m_txt_file( filename + ".txt" )
04092 {
04093         m_npad = npad;
04094         m_ctf = ctf;
04095 }

newfile_store::~newfile_store (  )  [virtual]

Definition at line 4097 of file reconstructor.cpp.

04098 {
04099 }


Member Function Documentation

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

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

04102 {
04103         if( m_bin_of == NULL ) {
04104             m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) );
04105             m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) );
04106         }
04107 
04108 
04109         EMData* padfft = padfft_slice( emdata, tf, m_npad );
04110 
04111         int nx = padfft->get_xsize();
04112         int ny = padfft->get_ysize();
04113         int n2 = ny / 2;
04114         int n = ny;
04115 
04116         float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f;
04117 
04118         if( m_ctf ) {
04119                 Ctf* ctf = emdata->get_attr( "ctf" );
04120                 Dict params = ctf->to_dict();
04121                 voltage = params["voltage"];
04122                 pixel   = params["apix"];
04123                 Cs      = params["cs"];
04124                 ampcont = params["ampcont"];
04125                 bfactor = params["bfactor"];
04126                 defocus = params["defocus"];
04127                 if(ctf) {delete ctf; ctf=0;}
04128         }
04129 
04130         vector<point_t> points;
04131         for( int j=-ny/2+1; j <= ny/2; j++ ) {
04132                 int jp = (j>=0) ? j+1 : ny+j+1;
04133                 for( int i=0; i <= n2; ++i ) {
04134                         int r2 = i*i + j*j;
04135                         if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) {
04136                                 float ctf;
04137                                 if( m_ctf ) {
04138                                         float ak = std::sqrt( r2/float(ny*ny) )/pixel;
04139                                         ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1);
04140                                 } else {
04141                                         ctf = 1.0;
04142                                 }
04143 
04144                                 float xnew = i*tf[0][0] + j*tf[1][0];
04145                                 float ynew = i*tf[0][1] + j*tf[1][1];
04146                                 float znew = i*tf[0][2] + j*tf[1][2];
04147                                 std::complex<float> btq;
04148                                 if (xnew < 0.) {
04149                                         xnew = -xnew;
04150                                         ynew = -ynew;
04151                                         znew = -znew;
04152                                         btq = conj(padfft->cmplx(i,jp-1));
04153                                 } else {
04154                                         btq = padfft->cmplx(i,jp-1);
04155                                 }
04156 
04157                                 int ixn = int(xnew + 0.5 + n) - n;
04158                                 int iyn = int(ynew + 0.5 + n) - n;
04159                                 int izn = int(znew + 0.5 + n) - n;
04160                                 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) {
04161                                         int ixf, iyf, izf;
04162                                         if (ixn >= 0) {
04163                                                 int iza, iya;
04164                                                 if (izn >= 0)
04165                                                     iza = izn + 1;
04166                                                 else
04167                                                     iza = n + izn + 1;
04168 
04169                                                 if (iyn >= 0)
04170                                                     iya = iyn + 1;
04171                                                 else
04172                                                     iya = n + iyn + 1;
04173 
04174                                                 ixf = ixn;
04175                                                 iyf = iya;
04176                                                 izf = iza;
04177                                         } else {
04178                                                 int izt, iyt;
04179                                                 if (izn > 0)
04180                                                     izt = n - izn + 1;
04181                                                 else
04182                                                     izt = -izn + 1;
04183 
04184                                                 if (iyn > 0)
04185                                                     iyt = n - iyn + 1;
04186                                                 else
04187                                                     iyt = -iyn + 1;
04188 
04189                                                 ixf = -ixn;
04190                                                 iyf = iyt;
04191                                                 izf = izt;
04192                                         }
04193 
04194 
04195                                         int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2;
04196                                         float ctfv1 = btq.real() * ctf;
04197                                         float ctfv2 = btq.imag() * ctf;
04198                                         float ctf2 = ctf*ctf;
04199 
04200                                         point_t p;
04201                                         p.pos2 = pos2;
04202                                         p.real = ctfv1;
04203                                         p.imag = ctfv2;
04204                                         p.ctf2 = ctf2;
04205 
04206                                         points.push_back( p );
04207                                 }
04208                         }
04209                 }
04210         }
04211 
04212 
04213         int npoint = points.size();
04214         std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back();
04215         offset += npoint*sizeof(point_t);
04216         m_offsets.push_back( offset );
04217 
04218         *m_txt_of << m_offsets.back() << std::endl;
04219         m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint );
04220         checked_delete( padfft );
04221 }

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

Definition at line 4293 of file reconstructor.cpp.

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

04294 {
04295         float* vdata = fftvol->get_data();
04296         float* wdata = wgtvol->get_data();
04297 
04298         int npoint = m_offsets[0]/sizeof(point_t);
04299 //    Assert( int(mults.size())==nprj );
04300         Assert( int(m_points.size())== (pend - pbegin)*npoint );
04301 
04302         for( int iprj=pbegin; iprj < pend; ++iprj ) {
04303                 int m = mults[iprj];
04304                 if( m==0 ) continue;
04305 
04306                 int ipt = (iprj-pbegin)*npoint;
04307                 for( int i=0; i < npoint; ++i )  {
04308                     int pos2 = m_points[ipt].pos2;
04309                     int pos1 = pos2*2;
04310 
04311                     wdata[pos2]   += m_points[ipt].ctf2*m;
04312                     vdata[pos1]   += m_points[ipt].real*m;
04313                     vdata[pos1+1] += m_points[ipt].imag*m;
04314                     ++ipt;
04315                 }
04316         }
04317 }

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

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

04224 {
04225         if( m_offsets.size()==0 ) {
04226                 ifstream is( m_txt_file.c_str() );
04227                 std::istream::off_type off;
04228                 while( is >> off ) {
04229                     m_offsets.push_back( off );
04230                 }
04231 
04232                 m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
04233         }
04234 
04235         Assert( m_bin_if != NULL );
04236 
04237         std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1];
04238         Assert( offset >= 0 );
04239         m_bin_if->seekg( offset, std::ios::beg );
04240 
04241 
04242         if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) {
04243                 std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl;
04244                 throw std::logic_error( "bad happen" );
04245         }
04246 
04247         int bufsize = (m_offsets[id] - offset)/sizeof(float);
04248         if( buf->get_xsize() != bufsize ) {
04249                 buf->set_size( bufsize, 1, 1 );
04250         }
04251 
04252         char* data = (char*)(buf->get_data());
04253         m_bin_if->read( data, sizeof(float)*bufsize );
04254         buf->update();
04255 }

void newfile_store::read ( int  nprj  ) 

Definition at line 4257 of file reconstructor.cpp.

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

04258 {
04259         if( m_offsets.size()==0 ) {
04260             ifstream is( m_txt_file.c_str() );
04261             std::istream::off_type off;
04262             while( is >> off ) {
04263                 m_offsets.push_back( off );
04264             }
04265         }
04266 
04267         if( m_bin_if==NULL ) {
04268             m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) );
04269         }
04270 
04271 
04272         int npoint = m_offsets[0]/sizeof(point_t);
04273         std::ios::off_type prjsize = m_offsets[0];
04274 
04275         try {
04276             m_points.resize(nprj * npoint);
04277         }
04278         catch( std::exception& e ) {
04279             std::cout << "Error: " << e.what() << std::endl;
04280         }
04281 
04282         int ip = 0;
04283         for( int i=0; i < nprj; ++i ) {
04284                 m_bin_if->read( (char*)(&m_points[ip]), prjsize );
04285                 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() )  {
04286                         std::cout << "Error: file hander bad or fail or eof" << std::endl;
04287                         return;
04288                 }
04289                 ip += npoint;
04290         }
04291 }

void newfile_store::restart (  ) 

Definition at line 4319 of file reconstructor.cpp.

References in, m_bin_file, and m_bin_if.

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


Member Data Documentation

string EMAN::newfile_store::m_bin_file [private]

Definition at line 1524 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 1529 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 1527 of file reconstructor.h.

Referenced by add_image().

bool EMAN::newfile_store::m_ctf [private]

Definition at line 1522 of file reconstructor.h.

Referenced by add_image(), and newfile_store().

int EMAN::newfile_store::m_npad [private]

Definition at line 1520 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 1530 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 1532 of file reconstructor.h.

Referenced by add_tovol(), and read().

string EMAN::newfile_store::m_txt_file [private]

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

Referenced by add_image().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:11:17 2012 for EMAN2 by  doxygen 1.4.7