#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 4157 of file reconstructor.cpp. 04158 : m_bin_file( filename + ".bin" ), 04159 m_txt_file( filename + ".txt" ) 04160 { 04161 m_npad = npad; 04162 m_ctf = ctf; 04163 }
|
|
Definition at line 4165 of file reconstructor.cpp. 04166 { 04167 }
|
|
Definition at line 4169 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(). 04170 { 04171 if( m_bin_of == NULL ) { 04172 m_bin_of = shared_ptr<ofstream>( new ofstream(m_bin_file.c_str(), std::ios::out|std::ios::binary) ); 04173 m_txt_of = shared_ptr<ofstream>( new ofstream(m_txt_file.c_str()) ); 04174 } 04175 04176 04177 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 04178 04179 int nx = padfft->get_xsize(); 04180 int ny = padfft->get_ysize(); 04181 int n2 = ny / 2; 04182 int n = ny; 04183 04184 float voltage=0.0f, pixel=0.0f, Cs=0.0f, ampcont=0.0f, bfactor=0.0f, defocus=0.0f; 04185 04186 if( m_ctf ) { 04187 Ctf* ctf = emdata->get_attr( "ctf" ); 04188 Dict params = ctf->to_dict(); 04189 voltage = params["voltage"]; 04190 pixel = params["apix"]; 04191 Cs = params["cs"]; 04192 ampcont = params["ampcont"]; 04193 bfactor = params["bfactor"]; 04194 defocus = params["defocus"]; 04195 if(ctf) {delete ctf; ctf=0;} 04196 } 04197 04198 vector<point_t> points; 04199 for( int j=-ny/2+1; j <= ny/2; j++ ) { 04200 int jp = (j>=0) ? j+1 : ny+j+1; 04201 for( int i=0; i <= n2; ++i ) { 04202 int r2 = i*i + j*j; 04203 if( (r2<ny*ny/4) && !( (i==0) && (j<0) ) ) { 04204 float ctf; 04205 if( m_ctf ) { 04206 float ak = std::sqrt( r2/float(ny*ny) )/pixel; 04207 ctf = Util::tf( defocus, ak, voltage, Cs, ampcont, bfactor, 1); 04208 } else { 04209 ctf = 1.0; 04210 } 04211 04212 float xnew = i*tf[0][0] + j*tf[1][0]; 04213 float ynew = i*tf[0][1] + j*tf[1][1]; 04214 float znew = i*tf[0][2] + j*tf[1][2]; 04215 std::complex<float> btq; 04216 if (xnew < 0.) { 04217 xnew = -xnew; 04218 ynew = -ynew; 04219 znew = -znew; 04220 btq = conj(padfft->cmplx(i,jp-1)); 04221 } else { 04222 btq = padfft->cmplx(i,jp-1); 04223 } 04224 04225 int ixn = int(xnew + 0.5 + n) - n; 04226 int iyn = int(ynew + 0.5 + n) - n; 04227 int izn = int(znew + 0.5 + n) - n; 04228 if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) { 04229 int ixf, iyf, izf; 04230 if (ixn >= 0) { 04231 int iza, iya; 04232 if (izn >= 0) 04233 iza = izn + 1; 04234 else 04235 iza = n + izn + 1; 04236 04237 if (iyn >= 0) 04238 iya = iyn + 1; 04239 else 04240 iya = n + iyn + 1; 04241 04242 ixf = ixn; 04243 iyf = iya; 04244 izf = iza; 04245 } else { 04246 int izt, iyt; 04247 if (izn > 0) 04248 izt = n - izn + 1; 04249 else 04250 izt = -izn + 1; 04251 04252 if (iyn > 0) 04253 iyt = n - iyn + 1; 04254 else 04255 iyt = -iyn + 1; 04256 04257 ixf = -ixn; 04258 iyf = iyt; 04259 izf = izt; 04260 } 04261 04262 04263 int pos2 = ixf + (iyf-1)*nx/2 + (izf-1)*ny*nx/2; 04264 float ctfv1 = btq.real() * ctf; 04265 float ctfv2 = btq.imag() * ctf; 04266 float ctf2 = ctf*ctf; 04267 04268 point_t p; 04269 p.pos2 = pos2; 04270 p.real = ctfv1; 04271 p.imag = ctfv2; 04272 p.ctf2 = ctf2; 04273 04274 points.push_back( p ); 04275 } 04276 } 04277 } 04278 } 04279 04280 04281 int npoint = points.size(); 04282 std::istream::off_type offset = (m_offsets.size()==0) ? 0 : m_offsets.back(); 04283 offset += npoint*sizeof(point_t); 04284 m_offsets.push_back( offset ); 04285 04286 *m_txt_of << m_offsets.back() << std::endl; 04287 m_bin_of->write( (char*)(&points[0]), sizeof(point_t)*npoint ); 04288 checked_delete( padfft ); 04289 }
|
|
Definition at line 4361 of file reconstructor.cpp. References Assert, EMAN::EMData::get_data(), EMAN::EMData::imag(), m_offsets, m_points, and EMAN::EMData::real(). 04362 { 04363 float* vdata = fftvol->get_data(); 04364 float* wdata = wgtvol->get_data(); 04365 04366 int npoint = m_offsets[0]/sizeof(point_t); 04367 // Assert( int(mults.size())==nprj ); 04368 Assert( int(m_points.size())== (pend - pbegin)*npoint ); 04369 04370 for( int iprj=pbegin; iprj < pend; ++iprj ) { 04371 int m = mults[iprj]; 04372 if( m==0 ) continue; 04373 04374 int ipt = (iprj-pbegin)*npoint; 04375 for( int i=0; i < npoint; ++i ) { 04376 int pos2 = m_points[ipt].pos2; 04377 int pos1 = pos2*2; 04378 04379 wdata[pos2] += m_points[ipt].ctf2*m; 04380 vdata[pos1] += m_points[ipt].real*m; 04381 vdata[pos1+1] += m_points[ipt].imag*m; 04382 ++ipt; 04383 } 04384 } 04385 }
|
|
Definition at line 4291 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(). 04292 { 04293 if( m_offsets.size()==0 ) { 04294 ifstream is( m_txt_file.c_str() ); 04295 std::istream::off_type off; 04296 while( is >> off ) { 04297 m_offsets.push_back( off ); 04298 } 04299 04300 m_bin_if = shared_ptr<std::ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04301 } 04302 04303 Assert( m_bin_if != NULL ); 04304 04305 std::istream::off_type offset = (id==0) ? 0 : m_offsets[id-1]; 04306 Assert( offset >= 0 ); 04307 m_bin_if->seekg( offset, std::ios::beg ); 04308 04309 04310 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) { 04311 std::cout << "bad or fail or eof while fetching id, offset: " << id << " " << offset << std::endl; 04312 throw std::logic_error( "bad happen" ); 04313 } 04314 04315 int bufsize = (m_offsets[id] - offset)/sizeof(float); 04316 if( buf->get_xsize() != bufsize ) { 04317 buf->set_size( bufsize, 1, 1 ); 04318 } 04319 04320 char* data = (char*)(buf->get_data()); 04321 m_bin_if->read( data, sizeof(float)*bufsize ); 04322 buf->update(); 04323 }
|
|
Definition at line 4325 of file reconstructor.cpp. References m_bin_file, m_bin_if, m_offsets, m_points, and m_txt_file. 04326 { 04327 if( m_offsets.size()==0 ) { 04328 ifstream is( m_txt_file.c_str() ); 04329 std::istream::off_type off; 04330 while( is >> off ) { 04331 m_offsets.push_back( off ); 04332 } 04333 } 04334 04335 if( m_bin_if==NULL ) { 04336 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04337 } 04338 04339 04340 int npoint = m_offsets[0]/sizeof(point_t); 04341 std::ios::off_type prjsize = m_offsets[0]; 04342 04343 try { 04344 m_points.resize(nprj * npoint); 04345 } 04346 catch( std::exception& e ) { 04347 std::cout << "Error: " << e.what() << std::endl; 04348 } 04349 04350 int ip = 0; 04351 for( int i=0; i < nprj; ++i ) { 04352 m_bin_if->read( (char*)(&m_points[ip]), prjsize ); 04353 if( m_bin_if->bad() || m_bin_if->fail() || m_bin_if->eof() ) { 04354 std::cout << "Error: file hander bad or fail or eof" << std::endl; 04355 return; 04356 } 04357 ip += npoint; 04358 } 04359 }
|
|
Definition at line 4387 of file reconstructor.cpp. References m_bin_file, and m_bin_if. 04388 { 04389 m_bin_if = shared_ptr< ifstream>( new ifstream(m_bin_file.c_str(), std::ios::in|std::ios::binary) ); 04390 }
|
|
Definition at line 1326 of file reconstructor.h. Referenced by add_image(), get_image(), read(), and restart(). |
|
Definition at line 1331 of file reconstructor.h. Referenced by get_image(), read(), and restart(). |
|
Definition at line 1329 of file reconstructor.h. Referenced by add_image(). |
|
Definition at line 1324 of file reconstructor.h. Referenced by newfile_store(). |
|
Definition at line 1322 of file reconstructor.h. Referenced by add_image(), and newfile_store(). |
|
Definition at line 1332 of file reconstructor.h. Referenced by add_image(), add_tovol(), get_image(), and read(). |
|
Definition at line 1334 of file reconstructor.h. Referenced by add_tovol(), and read(). |
|
Definition at line 1327 of file reconstructor.h. Referenced by add_image(), get_image(), and read(). |
|
Definition at line 1330 of file reconstructor.h. Referenced by add_image(). |