#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 1466 of file processor.h.
void TransformProcessor::assert_valid_aspect | ( | const EMData *const | image | ) | const [private] |
Definition at line 8463 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().
08463 { 08464 int ndim = image->get_ndim(); 08465 if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D"); 08466 08467 if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation"); 08468 }
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 1497 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 1469 of file processor.h.
References NAME.
01470 { 01471 return NAME; 01472 }
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 1490 of file processor.h.
References EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.
01491 { 01492 TypeDict d; 01493 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" ); 01494 return d; 01495 }
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 8502 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, transform(), and EMAN::EMData::update().
08502 { 08503 ENTERFUNC; 08504 08505 assert_valid_aspect(image); 08506 08507 Transform* t = params["transform"]; 08508 08509 EMData* p = 0; 08510 #ifdef EMAN2_USING_CUDA 08511 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08512 //cout << "using CUDA xform" << endl; 08513 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08514 float * m = new float[12]; 08515 Transform inv = t->inverse(); 08516 inv.copy_matrix_into_array(m); 08517 image->bindcudaarrayA(true); 08518 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08519 image->unbindcudaarryA(); 08520 delete [] m; 08521 p->update(); 08522 } 08523 #endif 08524 08525 if ( p == 0 ) { 08526 float* des_data = transform(image,*t); 08527 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08528 } 08529 08530 // all_translation += transform.get_trans(); 08531 08532 float scale = t->get_scale(); 08533 if (scale != 1.0) { 08534 p->scale_pixel(1.0f/scale); 08535 // update_emdata_attributes(p,image->get_attr_dict(),scale); 08536 } 08537 08538 if(t) {delete t; t=0;} 08539 EXITFUNC; 08540 return p; 08541 }
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 8543 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().
08543 { 08544 ENTERFUNC; 08545 08546 assert_valid_aspect(image); 08547 08548 Transform* t = params["transform"]; 08549 08550 // all_translation += transform.get_trans(); 08551 bool use_cpu = true; 08552 08553 #ifdef EMAN2_USING_CUDA 08554 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08555 //cout << "CUDA xform inplace" << endl; 08556 image->bindcudaarrayA(false); 08557 float * m = new float[12]; 08558 Transform inv = t->inverse(); 08559 inv.copy_matrix_into_array(m); 08560 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08561 image->unbindcudaarryA(); 08562 delete [] m; 08563 use_cpu = false; 08564 image->update(); 08565 } 08566 #endif 08567 if ( use_cpu ) { 08568 float* des_data = transform(image,*t); 08569 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08570 image->update(); 08571 } 08572 float scale = t->get_scale(); 08573 if (scale != 1.0f) { 08574 image->scale_pixel(1.0f/scale); 08575 // update_emdata_attributes(image,image->get_attr_dict(),scale); 08576 } 08577 08578 if(t) {delete t; t=0;} 08579 08580 EXITFUNC; 08581 }
float * TransformProcessor::transform | ( | const EMData *const | image, | |
const Transform & | t | |||
) | const [private] |
Definition at line 8341 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().
08341 { 08342 08343 ENTERFUNC; 08344 08345 Transform inv = t.inverse(); 08346 int nx = image->get_xsize(); 08347 int ny = image->get_ysize(); 08348 int nz = image->get_zsize(); 08349 int nxy = nx*ny; 08350 08351 const float * const src_data = image->get_const_data(); 08352 float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float)); 08353 08354 if (nz == 1) { 08355 Vec2f offset(nx/2,ny/2); 08356 for (int j = 0; j < ny; j++) { 08357 for (int i = 0; i < nx; i++) { 08358 Vec2f coord(i-nx/2,j-ny/2); 08359 Vec2f soln = inv*coord; 08360 soln += offset; 08361 08362 float x2 = soln[0]; 08363 float y2 = soln[1]; 08364 08365 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) { 08366 des_data[i + j * nx] = 0; // It may be tempting to set this value to the 08367 // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it. 08368 } 08369 else { 08370 int ii = Util::fast_floor(x2); 08371 int jj = Util::fast_floor(y2); 08372 int k0 = ii + jj * nx; 08373 int k1 = k0 + 1; 08374 int k2 = k0 + nx; 08375 int k3 = k0 + nx + 1; 08376 08377 if (ii == nx - 1) { 08378 k1--; 08379 k3--; 08380 } 08381 if (jj == ny - 1) { 08382 k2 -= nx; 08383 k3 -= nx; 08384 } 08385 08386 float t = x2 - ii; 08387 float u = y2 - jj; 08388 08389 des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); 08390 } 08391 } 08392 } 08393 } 08394 else { 08395 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7; 08396 Vec3f offset(nx/2,ny/2,nz/2); 08397 float x2, y2, z2, tuvx, tuvy, tuvz; 08398 int ix, iy, iz; 08399 for (int k = 0; k < nz; ++k) { 08400 for (int j = 0; j < ny; ++j) { 08401 for (int i = 0; i < nx; ++i,++l) { 08402 Vec3f coord(i-nx/2,j-ny/2,k-nz/2); 08403 Vec3f soln = inv*coord; 08404 soln += offset; 08405 08406 x2 = soln[0]; 08407 y2 = soln[1]; 08408 z2 = soln[2]; 08409 08410 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) { 08411 des_data[l] = 0; 08412 } 08413 else { 08414 ix = Util::fast_floor(x2); 08415 iy = Util::fast_floor(y2); 08416 iz = Util::fast_floor(z2); 08417 tuvx = x2-ix; 08418 tuvy = y2-iy; 08419 tuvz = z2-iz; 08420 ii = ix + iy * nx + iz * nxy; 08421 08422 k0 = ii; 08423 k1 = k0 + 1; 08424 k2 = k0 + nx; 08425 k3 = k0 + nx+1; 08426 k4 = k0 + nxy; 08427 k5 = k1 + nxy; 08428 k6 = k2 + nxy; 08429 k7 = k3 + nxy; 08430 08431 if (ix == nx - 1) { 08432 k1--; 08433 k3--; 08434 k5--; 08435 k7--; 08436 } 08437 if (iy == ny - 1) { 08438 k2 -= nx; 08439 k3 -= nx; 08440 k6 -= nx; 08441 k7 -= nx; 08442 } 08443 if (iz == nz - 1) { 08444 k4 -= nxy; 08445 k5 -= nxy; 08446 k6 -= nxy; 08447 k7 -= nxy; 08448 } 08449 08450 des_data[l] = Util::trilinear_interpolate(src_data[k0], 08451 src_data[k1], src_data[k2], src_data[k3], src_data[k4], 08452 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz); 08453 } 08454 } 08455 } 08456 } 08457 } 08458 08459 EXITFUNC; 08460 return des_data; 08461 }
const string TransformProcessor::NAME = "xform" [static] |