#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 | |
Processor * | NEW () |
Static Public Attributes | |
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.
|
Definition at line 8550 of file processor.cpp. References EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), ImageDimensionException, and InvalidParameterException. Referenced by process(), and process_inplace(). 08550 { 08551 int ndim = image->get_ndim(); 08552 if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D"); 08553 08554 if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation"); 08555 }
|
|
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. 01543 { 01544 return "The image is transformed using Transform parameter."; 01545 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 1514 of file processor.h. 01515 {
01516 return NAME;
01517 }
|
|
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(). 01536 { 01537 TypeDict d; 01538 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" ); 01539 return d; 01540 }
|
|
Definition at line 1518 of file processor.h. 01519 { 01520 return new TransformProcessor(); 01521 }
|
|
Reimplemented from EMAN::Processor. Definition at line 8589 of file processor.cpp. References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), emdata_transform_cuda(), EMAN::EMData::get_attr_dict(), EMAN::Transform::get_scale(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Transform::inverse(), EMAN::EMData::scale_pixel(), t, transform(), and EMAN::EMData::update(). 08589 { 08590 ENTERFUNC; 08591 08592 assert_valid_aspect(image); 08593 08594 Transform* t = params["transform"]; 08595 08596 EMData* p = 0; 08597 #ifdef EMAN2_USING_CUDA 08598 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08599 //cout << "using CUDA xform" << endl; 08600 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08601 float * m = new float[12]; 08602 Transform inv = t->inverse(); 08603 inv.copy_matrix_into_array(m); 08604 image->bindcudaarrayA(true); 08605 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08606 image->unbindcudaarryA(); 08607 delete [] m; 08608 p->update(); 08609 } 08610 #endif 08611 08612 if ( p == 0 ) { 08613 float* des_data = transform(image,*t); 08614 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08615 } 08616 08617 // all_translation += transform.get_trans(); 08618 08619 float scale = t->get_scale(); 08620 if (scale != 1.0) { 08621 p->scale_pixel(1.0f/scale); 08622 // update_emdata_attributes(p,image->get_attr_dict(),scale); 08623 } 08624 08625 if(t) {delete t; t=0;} 08626 EXITFUNC; 08627 return p; 08628 }
|
|
Implements EMAN::Processor. Definition at line 8630 of file processor.cpp. References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), emdata_transform_cuda(), EMAN::Transform::get_scale(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Transform::inverse(), EMAN::EMData::scale_pixel(), EMAN::EMData::set_data(), t, transform(), and EMAN::EMData::update(). 08630 { 08631 ENTERFUNC; 08632 08633 assert_valid_aspect(image); 08634 08635 Transform* t = params["transform"]; 08636 08637 // all_translation += transform.get_trans(); 08638 bool use_cpu = true; 08639 08640 #ifdef EMAN2_USING_CUDA 08641 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08642 //cout << "CUDA xform inplace" << endl; 08643 image->bindcudaarrayA(false); 08644 float * m = new float[12]; 08645 Transform inv = t->inverse(); 08646 inv.copy_matrix_into_array(m); 08647 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08648 image->unbindcudaarryA(); 08649 delete [] m; 08650 use_cpu = false; 08651 image->update(); 08652 } 08653 #endif 08654 if ( use_cpu ) { 08655 float* des_data = transform(image,*t); 08656 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08657 image->update(); 08658 } 08659 float scale = t->get_scale(); 08660 if (scale != 1.0f) { 08661 image->scale_pixel(1.0f/scale); 08662 // update_emdata_attributes(image,image->get_attr_dict(),scale); 08663 } 08664 08665 if(t) {delete t; t=0;} 08666 08667 EXITFUNC; 08668 }
|
|
Definition at line 8428 of file processor.cpp. References EMAN::Util::bilinear_interpolate(), EMAN::EMUtil::em_malloc(), EMAN::Util::fast_floor(), EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Transform::inverse(), nx, ny, t, EMAN::Util::trilinear_interpolate(), EMAN::Vec2f, and EMAN::Vec3f. Referenced by EMAN::ScaleAligner::align(), EMAN::ScaleAlignerABS::align_using_base(), process(), and process_inplace(). 08428 { 08429 08430 ENTERFUNC; 08431 08432 Transform inv = t.inverse(); 08433 int nx = image->get_xsize(); 08434 int ny = image->get_ysize(); 08435 int nz = image->get_zsize(); 08436 int nxy = nx*ny; 08437 08438 const float * const src_data = image->get_const_data(); 08439 float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float)); 08440 08441 if (nz == 1) { 08442 Vec2f offset(nx/2,ny/2); 08443 for (int j = 0; j < ny; j++) { 08444 for (int i = 0; i < nx; i++) { 08445 Vec2f coord(i-nx/2,j-ny/2); 08446 Vec2f soln = inv*coord; 08447 soln += offset; 08448 08449 float x2 = soln[0]; 08450 float y2 = soln[1]; 08451 08452 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) { 08453 des_data[i + j * nx] = 0; // It may be tempting to set this value to the 08454 // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it. 08455 } 08456 else { 08457 int ii = Util::fast_floor(x2); 08458 int jj = Util::fast_floor(y2); 08459 int k0 = ii + jj * nx; 08460 int k1 = k0 + 1; 08461 int k2 = k0 + nx; 08462 int k3 = k0 + nx + 1; 08463 08464 if (ii == nx - 1) { 08465 k1--; 08466 k3--; 08467 } 08468 if (jj == ny - 1) { 08469 k2 -= nx; 08470 k3 -= nx; 08471 } 08472 08473 float t = x2 - ii; 08474 float u = y2 - jj; 08475 08476 des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); 08477 } 08478 } 08479 } 08480 } 08481 else { 08482 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7; 08483 Vec3f offset(nx/2,ny/2,nz/2); 08484 float x2, y2, z2, tuvx, tuvy, tuvz; 08485 int ix, iy, iz; 08486 for (int k = 0; k < nz; ++k) { 08487 for (int j = 0; j < ny; ++j) { 08488 for (int i = 0; i < nx; ++i,++l) { 08489 Vec3f coord(i-nx/2,j-ny/2,k-nz/2); 08490 Vec3f soln = inv*coord; 08491 soln += offset; 08492 08493 x2 = soln[0]; 08494 y2 = soln[1]; 08495 z2 = soln[2]; 08496 08497 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) { 08498 des_data[l] = 0; 08499 } 08500 else { 08501 ix = Util::fast_floor(x2); 08502 iy = Util::fast_floor(y2); 08503 iz = Util::fast_floor(z2); 08504 tuvx = x2-ix; 08505 tuvy = y2-iy; 08506 tuvz = z2-iz; 08507 ii = ix + iy * nx + iz * nxy; 08508 08509 k0 = ii; 08510 k1 = k0 + 1; 08511 k2 = k0 + nx; 08512 k3 = k0 + nx+1; 08513 k4 = k0 + nxy; 08514 k5 = k1 + nxy; 08515 k6 = k2 + nxy; 08516 k7 = k3 + nxy; 08517 08518 if (ix == nx - 1) { 08519 k1--; 08520 k3--; 08521 k5--; 08522 k7--; 08523 } 08524 if (iy == ny - 1) { 08525 k2 -= nx; 08526 k3 -= nx; 08527 k6 -= nx; 08528 k7 -= nx; 08529 } 08530 if (iz == nz - 1) { 08531 k4 -= nxy; 08532 k5 -= nxy; 08533 k6 -= nxy; 08534 k7 -= nxy; 08535 } 08536 08537 des_data[l] = Util::trilinear_interpolate(src_data[k0], 08538 src_data[k1], src_data[k2], src_data[k3], src_data[k4], 08539 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz); 08540 } 08541 } 08542 } 08543 } 08544 } 08545 08546 EXITFUNC; 08547 return des_data; 08548 }
|
|
Definition at line 86 of file processor.cpp. |