#include <processor.h>
Inheritance diagram for EMAN::TransformProcessor:
Public Member Functions | |||||||
virtual string | get_name () const | ||||||
Get the processor's name. | |||||||
virtual void | process_inplace (EMData *image) | ||||||
| |||||||
virtual EMData * | process (const EMData *const image) | ||||||
| |||||||
virtual TypeDict | get_param_types () const | ||||||
Get processor parameter information in a dictionary. | |||||||
virtual string | get_desc () const | ||||||
Get the descrition of this specific processor. | |||||||
Static Public Member Functions | |||||||
static Processor * | NEW () | ||||||
Static Public Attributes | |||||||
static const string | NAME = "xform" | ||||||
Private Member Functions | |||||||
float * | transform (const EMData *const image, const Transform &t) const | ||||||
void | assert_valid_aspect (const EMData *const image) const |
transform | The Transform object that will be applied to the image |
Definition at line 1316 of file processor.h.
void TransformProcessor::assert_valid_aspect | ( | const EMData *const | image | ) | const [private] |
Definition at line 8352 of file processor.cpp.
References EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, and EMAN::Processor::params.
Referenced by process(), and process_inplace().
08352 { 08353 int ndim = image->get_ndim(); 08354 if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D"); 08355 08356 if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation"); 08357 }
virtual string EMAN::TransformProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 1347 of file processor.h.
virtual string EMAN::TransformProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 1319 of file processor.h.
References NAME.
01320 { 01321 return NAME; 01322 }
virtual TypeDict EMAN::TransformProcessor::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor.
Definition at line 1340 of file processor.h.
References EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.
01341 { 01342 TypeDict d; 01343 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" ); 01344 return d; 01345 }
static Processor* EMAN::TransformProcessor::NEW | ( | ) | [inline, static] |
ImageDimensionException | if the image is not 2D or 3D | |
InvalidParameterException | if the Transform parameter is not specified |
Reimplemented from EMAN::Processor.
Definition at line 8391 of file processor.cpp.
References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), emdata_transform_cuda(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_attr_dict(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Processor::params, EMAN::EMData::scale_pixel(), t, and transform().
08391 { 08392 ENTERFUNC; 08393 08394 assert_valid_aspect(image); 08395 08396 Transform* t = params["transform"]; 08397 08398 EMData* p = 0; 08399 #ifdef EMAN2_USING_CUDA 08400 if(image->isrodataongpu()){ 08401 //cout << "using CUDA xform" << endl; 08402 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08403 float * m = new float[12]; 08404 Transform inv = t->inverse(); 08405 inv.copy_matrix_into_array(m); 08406 image->bindcudaarrayA(true); 08407 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08408 image->unbindcudaarryA(); 08409 delete [] m; 08410 } 08411 #endif 08412 08413 if ( p == 0 ) { 08414 float* des_data = transform(image,*t); 08415 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08416 } 08417 08418 // all_translation += transform.get_trans(); 08419 08420 float scale = t->get_scale(); 08421 if (scale != 1.0) { 08422 p->scale_pixel(1.0f/scale); 08423 // update_emdata_attributes(p,image->get_attr_dict(),scale); 08424 } 08425 08426 if(t) {delete t; t=0;} 08427 EXITFUNC; 08428 return p; 08429 }
void TransformProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
ImageDimensionException | if the image is not 2D or 3D | |
InvalidParameterException | if the Transform parameter is not specified |
Implements EMAN::Processor.
Definition at line 8431 of file processor.cpp.
References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), emdata_transform_cuda(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Processor::params, EMAN::EMData::scale_pixel(), EMAN::EMData::set_data(), t, transform(), and EMAN::EMData::update().
08431 { 08432 ENTERFUNC; 08433 08434 assert_valid_aspect(image); 08435 08436 Transform* t = params["transform"]; 08437 08438 // all_translation += transform.get_trans(); 08439 bool use_cpu = true; 08440 08441 #ifdef EMAN2_USING_CUDA 08442 if(image->isrodataongpu()){ 08443 image->bindcudaarrayA(false); 08444 float * m = new float[12]; 08445 Transform inv = t->inverse(); 08446 inv.copy_matrix_into_array(m); 08447 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08448 image->unbindcudaarryA(); 08449 delete [] m; 08450 use_cpu = false; 08451 } 08452 #endif 08453 if ( use_cpu ) { 08454 float* des_data = transform(image,*t); 08455 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08456 image->update(); 08457 } 08458 float scale = t->get_scale(); 08459 if (scale != 1.0f) { 08460 image->scale_pixel(1.0f/scale); 08461 // update_emdata_attributes(image,image->get_attr_dict(),scale); 08462 } 08463 08464 if(t) {delete t; t=0;} 08465 08466 EXITFUNC; 08467 }
float * TransformProcessor::transform | ( | const EMData *const | image, | |
const Transform & | t | |||
) | const [private] |
Definition at line 8230 of file processor.cpp.
References EMAN::Util::bilinear_interpolate(), EMAN::EMUtil::em_malloc(), ENTERFUNC, EXITFUNC, EMAN::Util::fast_floor(), EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), t, and EMAN::Util::trilinear_interpolate().
Referenced by process(), and process_inplace().
08230 { 08231 08232 ENTERFUNC; 08233 08234 Transform inv = t.inverse(); 08235 int nx = image->get_xsize(); 08236 int ny = image->get_ysize(); 08237 int nz = image->get_zsize(); 08238 int nxy = nx*ny; 08239 08240 const float * const src_data = image->get_const_data(); 08241 float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float)); 08242 08243 if (nz == 1) { 08244 Vec2f offset(nx/2,ny/2); 08245 for (int j = 0; j < ny; j++) { 08246 for (int i = 0; i < nx; i++) { 08247 Vec2f coord(i-nx/2,j-ny/2); 08248 Vec2f soln = inv*coord; 08249 soln += offset; 08250 08251 float x2 = soln[0]; 08252 float y2 = soln[1]; 08253 08254 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) { 08255 des_data[i + j * nx] = 0; // It may be tempting to set this value to the 08256 // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it. 08257 } 08258 else { 08259 int ii = Util::fast_floor(x2); 08260 int jj = Util::fast_floor(y2); 08261 int k0 = ii + jj * nx; 08262 int k1 = k0 + 1; 08263 int k2 = k0 + nx; 08264 int k3 = k0 + nx + 1; 08265 08266 if (ii == nx - 1) { 08267 k1--; 08268 k3--; 08269 } 08270 if (jj == ny - 1) { 08271 k2 -= nx; 08272 k3 -= nx; 08273 } 08274 08275 float t = x2 - ii; 08276 float u = y2 - jj; 08277 08278 des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); 08279 } 08280 } 08281 } 08282 } 08283 else { 08284 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7; 08285 Vec3f offset(nx/2,ny/2,nz/2); 08286 float x2, y2, z2, tuvx, tuvy, tuvz; 08287 int ix, iy, iz; 08288 for (int k = 0; k < nz; ++k) { 08289 for (int j = 0; j < ny; ++j) { 08290 for (int i = 0; i < nx; ++i,++l) { 08291 Vec3f coord(i-nx/2,j-ny/2,k-nz/2); 08292 Vec3f soln = inv*coord; 08293 soln += offset; 08294 08295 x2 = soln[0]; 08296 y2 = soln[1]; 08297 z2 = soln[2]; 08298 08299 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) { 08300 des_data[l] = 0; 08301 } 08302 else { 08303 ix = Util::fast_floor(x2); 08304 iy = Util::fast_floor(y2); 08305 iz = Util::fast_floor(z2); 08306 tuvx = x2-ix; 08307 tuvy = y2-iy; 08308 tuvz = z2-iz; 08309 ii = ix + iy * nx + iz * nxy; 08310 08311 k0 = ii; 08312 k1 = k0 + 1; 08313 k2 = k0 + nx; 08314 k3 = k0 + nx+1; 08315 k4 = k0 + nxy; 08316 k5 = k1 + nxy; 08317 k6 = k2 + nxy; 08318 k7 = k3 + nxy; 08319 08320 if (ix == nx - 1) { 08321 k1--; 08322 k3--; 08323 k5--; 08324 k7--; 08325 } 08326 if (iy == ny - 1) { 08327 k2 -= nx; 08328 k3 -= nx; 08329 k6 -= nx; 08330 k7 -= nx; 08331 } 08332 if (iz == nz - 1) { 08333 k4 -= nxy; 08334 k5 -= nxy; 08335 k6 -= nxy; 08336 k7 -= nxy; 08337 } 08338 08339 des_data[l] = Util::trilinear_interpolate(src_data[k0], 08340 src_data[k1], src_data[k2], src_data[k3], src_data[k4], 08341 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz); 08342 } 08343 } 08344 } 08345 } 08346 } 08347 08348 EXITFUNC; 08349 return des_data; 08350 }
const string TransformProcessor::NAME = "xform" [static] |