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