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