#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. | |||||||
float * | transform (const EMData *const image, const Transform &t) const | ||||||
Static Public Member Functions | |||||||
static Processor * | NEW () | ||||||
Static Public Attributes | |||||||
static const string | NAME = "xform" | ||||||
Private Member Functions | |||||||
void | assert_valid_aspect (const EMData *const image) const |
transform | The Transform object that will be applied to the image |
Definition at line 1511 of file processor.h.
void TransformProcessor::assert_valid_aspect | ( | const EMData *const | image | ) | const [private] |
Definition at line 8535 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().
08535 { 08536 int ndim = image->get_ndim(); 08537 if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D"); 08538 08539 if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation"); 08540 }
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 1542 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 1514 of file processor.h.
References NAME.
01515 { 01516 return NAME; 01517 }
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 1535 of file processor.h.
References EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.
01536 { 01537 TypeDict d; 01538 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" ); 01539 return d; 01540 }
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 8574 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().
08574 { 08575 ENTERFUNC; 08576 08577 assert_valid_aspect(image); 08578 08579 Transform* t = params["transform"]; 08580 08581 EMData* p = 0; 08582 #ifdef EMAN2_USING_CUDA 08583 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08584 //cout << "using CUDA xform" << endl; 08585 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08586 float * m = new float[12]; 08587 Transform inv = t->inverse(); 08588 inv.copy_matrix_into_array(m); 08589 image->bindcudaarrayA(true); 08590 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08591 image->unbindcudaarryA(); 08592 delete [] m; 08593 p->update(); 08594 } 08595 #endif 08596 08597 if ( p == 0 ) { 08598 float* des_data = transform(image,*t); 08599 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08600 } 08601 08602 // all_translation += transform.get_trans(); 08603 08604 float scale = t->get_scale(); 08605 if (scale != 1.0) { 08606 p->scale_pixel(1.0f/scale); 08607 // update_emdata_attributes(p,image->get_attr_dict(),scale); 08608 } 08609 08610 if(t) {delete t; t=0;} 08611 EXITFUNC; 08612 return p; 08613 }
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 8615 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().
08615 { 08616 ENTERFUNC; 08617 08618 assert_valid_aspect(image); 08619 08620 Transform* t = params["transform"]; 08621 08622 // all_translation += transform.get_trans(); 08623 bool use_cpu = true; 08624 08625 #ifdef EMAN2_USING_CUDA 08626 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08627 //cout << "CUDA xform inplace" << endl; 08628 image->bindcudaarrayA(false); 08629 float * m = new float[12]; 08630 Transform inv = t->inverse(); 08631 inv.copy_matrix_into_array(m); 08632 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08633 image->unbindcudaarryA(); 08634 delete [] m; 08635 use_cpu = false; 08636 image->update(); 08637 } 08638 #endif 08639 if ( use_cpu ) { 08640 float* des_data = transform(image,*t); 08641 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08642 image->update(); 08643 } 08644 float scale = t->get_scale(); 08645 if (scale != 1.0f) { 08646 image->scale_pixel(1.0f/scale); 08647 // update_emdata_attributes(image,image->get_attr_dict(),scale); 08648 } 08649 08650 if(t) {delete t; t=0;} 08651 08652 EXITFUNC; 08653 }
Definition at line 8413 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().
08413 { 08414 08415 ENTERFUNC; 08416 08417 Transform inv = t.inverse(); 08418 int nx = image->get_xsize(); 08419 int ny = image->get_ysize(); 08420 int nz = image->get_zsize(); 08421 int nxy = nx*ny; 08422 08423 const float * const src_data = image->get_const_data(); 08424 float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float)); 08425 08426 if (nz == 1) { 08427 Vec2f offset(nx/2,ny/2); 08428 for (int j = 0; j < ny; j++) { 08429 for (int i = 0; i < nx; i++) { 08430 Vec2f coord(i-nx/2,j-ny/2); 08431 Vec2f soln = inv*coord; 08432 soln += offset; 08433 08434 float x2 = soln[0]; 08435 float y2 = soln[1]; 08436 08437 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) { 08438 des_data[i + j * nx] = 0; // It may be tempting to set this value to the 08439 // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it. 08440 } 08441 else { 08442 int ii = Util::fast_floor(x2); 08443 int jj = Util::fast_floor(y2); 08444 int k0 = ii + jj * nx; 08445 int k1 = k0 + 1; 08446 int k2 = k0 + nx; 08447 int k3 = k0 + nx + 1; 08448 08449 if (ii == nx - 1) { 08450 k1--; 08451 k3--; 08452 } 08453 if (jj == ny - 1) { 08454 k2 -= nx; 08455 k3 -= nx; 08456 } 08457 08458 float t = x2 - ii; 08459 float u = y2 - jj; 08460 08461 des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); 08462 } 08463 } 08464 } 08465 } 08466 else { 08467 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7; 08468 Vec3f offset(nx/2,ny/2,nz/2); 08469 float x2, y2, z2, tuvx, tuvy, tuvz; 08470 int ix, iy, iz; 08471 for (int k = 0; k < nz; ++k) { 08472 for (int j = 0; j < ny; ++j) { 08473 for (int i = 0; i < nx; ++i,++l) { 08474 Vec3f coord(i-nx/2,j-ny/2,k-nz/2); 08475 Vec3f soln = inv*coord; 08476 soln += offset; 08477 08478 x2 = soln[0]; 08479 y2 = soln[1]; 08480 z2 = soln[2]; 08481 08482 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) { 08483 des_data[l] = 0; 08484 } 08485 else { 08486 ix = Util::fast_floor(x2); 08487 iy = Util::fast_floor(y2); 08488 iz = Util::fast_floor(z2); 08489 tuvx = x2-ix; 08490 tuvy = y2-iy; 08491 tuvz = z2-iz; 08492 ii = ix + iy * nx + iz * nxy; 08493 08494 k0 = ii; 08495 k1 = k0 + 1; 08496 k2 = k0 + nx; 08497 k3 = k0 + nx+1; 08498 k4 = k0 + nxy; 08499 k5 = k1 + nxy; 08500 k6 = k2 + nxy; 08501 k7 = k3 + nxy; 08502 08503 if (ix == nx - 1) { 08504 k1--; 08505 k3--; 08506 k5--; 08507 k7--; 08508 } 08509 if (iy == ny - 1) { 08510 k2 -= nx; 08511 k3 -= nx; 08512 k6 -= nx; 08513 k7 -= nx; 08514 } 08515 if (iz == nz - 1) { 08516 k4 -= nxy; 08517 k5 -= nxy; 08518 k6 -= nxy; 08519 k7 -= nxy; 08520 } 08521 08522 des_data[l] = Util::trilinear_interpolate(src_data[k0], 08523 src_data[k1], src_data[k2], src_data[k3], src_data[k4], 08524 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz); 08525 } 08526 } 08527 } 08528 } 08529 } 08530 08531 EXITFUNC; 08532 return des_data; 08533 }
const string TransformProcessor::NAME = "xform" [static] |