#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 1502 of file reconstructor.h.
newfile_store::newfile_store | ( | const string & | prefix, | |
int | npad, | |||
bool | ctf | |||
) |
Definition at line 4087 of file reconstructor.cpp.
04088 : m_bin_file( filename + ".bin" ), 04089 m_txt_file( filename + ".txt" ) 04090 { 04091 m_npad = npad; 04092 m_ctf = ctf; 04093 }
newfile_store::~newfile_store | ( | ) | [virtual] |
Definition at line 4099 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().
04100 { 04101 if( m_bin_of == NULL ) { 04102 m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) ); 04103 m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) ); 04104 } 04105 04106 04107 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 04108 04109 int nx = padfft->get_xsize(); 04110 int ny = padfft->get_ysize(); 04111 int n2 = ny / 2; 04112 int n = ny; 04113 04114 float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f; 04115 04116 if( m_ctf ) { 04117 Ctf* ctf = emdata->get_attr( "ctf" ); 04118 Dict params = ctf->to_dict(); 04119 voltage = params["voltage"]; 04120 pixel = params["apix"]; 04121 Cs = params["cs"]; 04122 ampcont = params["ampcont"]; 04123 bfactor = params["bfactor"]; 04124 defocus = params["defocus"]; 04125 if(ctf) {delete ctf; ctf=0;} 04126 } 04127 04128 vector<point_t> points; 04129 for( int j=-ny/2+1; j <= ny/2; j++ ) { 04130 int jp = (j>=0) ? j+1 : ny+j+1; 04131 for( int i=0; i <= n2; ++i ) { 04132 int r2 = i*i + j*j; 04133 if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) { 04134 float ctf; 04135 if( m_ctf ) { 04136 float ak = std::sqrt( r2/float(ny*ny) )/pixel; 04137 ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1); 04138 } else { 04139 ctf = 1.0; 04140 } 04141 04142 float xnew = i*tf[0][0] + j*tf[1][0]; 04143 float ynew = i*tf[0][1] + j*tf[1][1]; 04144 float znew = i*tf[0][2] + j*tf[1][2]; 04145 std::complex<float> btq; 04146 if (xnew < 0.) { 04147 xnew = -xnew; 04148 ynew = -ynew; 04149 znew = -znew; 04150 btq = conj(padfft->cmplx(i,jp-1)); 04151 } else { 04152 btq = padfft->cmplx(i,jp-1); 04153 } 04154 04155 int ixn = int(xnew + 0.5 + n) - n; 04156 int iyn = int(ynew + 0.5 + n) - n; 04157 int izn = int(znew + 0.5 + n) - n; 04158 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) { 04159 int ixf, iyf, izf; 04160 if (ixn >= 0) { 04161 int iza, iya; 04162 if (izn >= 0) 04163 iza = izn + 1; 04164 else 04165 iza = n + izn + 1; 04166 04167 if (iyn >= 0) 04168 iya = iyn + 1; 04169 else 04170 iya = n + iyn + 1; 04171 04172 ixf = ixn; 04173 iyf = iya; 04174 izf = iza; 04175 } else { 04176 int izt, iyt; 04177 if (izn > 0) 04178 izt = n - izn + 1; 04179 else 04180 izt = -izn + 1; 04181 04182 if (iyn > 0) 04183 iyt = n - iyn + 1; 04184 else 04185 iyt = -iyn + 1; 04186 04187 ixf = -ixn; 04188 iyf = iyt; 04189 izf = izt; 04190 } 04191 04192 04193 int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2; 04194 float ctfv1 = btq.real() * ctf; 04195 float ctfv2 = btq.imag() * ctf; 04196 float ctf2 = ctf*ctf; 04197 04198 point_t p; 04199 p.pos2 = pos2; 04200 p.real = ctfv1; 04201 p.imag = ctfv2; 04202 p.ctf2 = ctf2; 04203 04204 points.push_back( p ); 04205 } 04206 } 04207 } 04208 } 04209 04210 04211 int npoint = points.size(); 04212 std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back(); 04213 offset += npoint*sizeof(point_t); 04214 m_offsets.push_back( offset ); 04215 04216 *m_txt_of << m_offsets.back() << std::endl; 04217 m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint ); 04218 checked_delete( padfft ); 04219 }
void newfile_store::add_tovol | ( | EMData * | fftvol, | |
EMData * | wgtvol, | |||
const vector< int > & | mults, | |||
int | pbegin, | |||
int | pend | |||
) |
Definition at line 4291 of file reconstructor.cpp.
References Assert, EMAN::EMData::get_data(), m_offsets, and m_points.
04292 { 04293 float* vdata = fftvol->get_data(); 04294 float* wdata = wgtvol->get_data(); 04295 04296 int npoint = m_offsets[0]/sizeof(point_t); 04297 // Assert( int(mults.size())==nprj ); 04298 Assert( int(m_points.size())== (pend - pbegin)*npoint ); 04299 04300 for( int iprj=pbegin; iprj < pend; ++iprj ) { 04301 int m = mults[iprj]; 04302 if( m==0 ) continue; 04303 04304 int ipt = (iprj-pbegin)*npoint; 04305 for( int i=0; i < npoint; ++i ) { 04306 int pos2 = m_points[ipt].pos2; 04307 int pos1 = pos2*2; 04308 04309 wdata[pos2] += m_points[ipt].ctf2*m; 04310 vdata[pos1] += m_points[ipt].real*m; 04311 vdata[pos1+1] += m_points[ipt].imag*m; 04312 ++ipt; 04313 } 04314 } 04315 }
void newfile_store::get_image | ( | int | id, | |
EMData * | buf | |||
) |
Definition at line 4221 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().
04222 { 04223 if( m_offsets.size()==0 ) { 04224 ifstream is( m_txt_file.c_str() ); 04225 std::istream::off_type off; 04226 while( is >> off ) { 04227 m_offsets.push_back( off ); 04228 } 04229 04230 m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04231 } 04232 04233 Assert( m_bin_if != NULL ); 04234 04235 std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1]; 04236 Assert( offset >= 0 ); 04237 m_bin_if->seekg( offset, std::ios::beg ); 04238 04239 04240 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) { 04241 std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl; 04242 throw std::logic_error( "bad happen" ); 04243 } 04244 04245 int bufsize = (m_offsets[id] - offset)/sizeof(float); 04246 if( buf->get_xsize() != bufsize ) { 04247 buf->set_size( bufsize, 1, 1 ); 04248 } 04249 04250 char* data = (char*)(buf->get_data()); 04251 m_bin_if->read( data, sizeof(float)*bufsize ); 04252 buf->update(); 04253 }
void newfile_store::read | ( | int | nprj | ) |
Definition at line 4255 of file reconstructor.cpp.
References in, m_bin_file, m_bin_if, m_offsets, m_points, and m_txt_file.
04256 { 04257 if( m_offsets.size()==0 ) { 04258 ifstream is( m_txt_file.c_str() ); 04259 std::istream::off_type off; 04260 while( is >> off ) { 04261 m_offsets.push_back( off ); 04262 } 04263 } 04264 04265 if( m_bin_if==NULL ) { 04266 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04267 } 04268 04269 04270 int npoint = m_offsets[0]/sizeof(point_t); 04271 std::ios::off_type prjsize = m_offsets[0]; 04272 04273 try { 04274 m_points.resize(nprj * npoint); 04275 } 04276 catch( std::exception& e ) { 04277 std::cout << "Error: " << e.what() << std::endl; 04278 } 04279 04280 int ip = 0; 04281 for( int i=0; i < nprj; ++i ) { 04282 m_bin_if->read( (char*)(&m_points[ip]), prjsize ); 04283 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) { 04284 std::cout << "Error: file hander bad or fail or eof" << std::endl; 04285 return; 04286 } 04287 ip += npoint; 04288 } 04289 }
void newfile_store::restart | ( | ) |
Definition at line 4317 of file reconstructor.cpp.
References in, m_bin_file, and m_bin_if.
04318 { 04319 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04320 }
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] |
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 1530 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 1525 of file reconstructor.h.
Referenced by add_image(), get_image(), and read().
shared_ptr<std::ofstream> EMAN::newfile_store::m_txt_of [private] |