#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 | |
Processor * | NEW () |
Static Public Attributes | |
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 1412 of file processor.h.
|
Definition at line 8377 of file processor.cpp. References EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), ImageDimensionException, and InvalidParameterException. Referenced by process(), and process_inplace(). 08377 { 08378 int ndim = image->get_ndim(); 08379 if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D"); 08380 08381 if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation"); 08382 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 1443 of file processor.h. 01444 { 01445 return "The image is transformed using Transform parameter."; 01446 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 1415 of file processor.h. 01416 {
01417 return NAME;
01418 }
|
|
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 1436 of file processor.h. References EMAN::TypeDict::put(). 01437 { 01438 TypeDict d; 01439 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" ); 01440 return d; 01441 }
|
|
Definition at line 1419 of file processor.h. 01420 { 01421 return new TransformProcessor(); 01422 }
|
|
Reimplemented from EMAN::Processor. Definition at line 8416 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(). 08416 { 08417 ENTERFUNC; 08418 08419 assert_valid_aspect(image); 08420 08421 Transform* t = params["transform"]; 08422 08423 EMData* p = 0; 08424 #ifdef EMAN2_USING_CUDA 08425 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08426 //cout << "using CUDA xform" << endl; 08427 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08428 float * m = new float[12]; 08429 Transform inv = t->inverse(); 08430 inv.copy_matrix_into_array(m); 08431 image->bindcudaarrayA(true); 08432 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08433 image->unbindcudaarryA(); 08434 delete [] m; 08435 p->update(); 08436 } 08437 #endif 08438 08439 if ( p == 0 ) { 08440 float* des_data = transform(image,*t); 08441 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 08442 } 08443 08444 // all_translation += transform.get_trans(); 08445 08446 float scale = t->get_scale(); 08447 if (scale != 1.0) { 08448 p->scale_pixel(1.0f/scale); 08449 // update_emdata_attributes(p,image->get_attr_dict(),scale); 08450 } 08451 08452 if(t) {delete t; t=0;} 08453 EXITFUNC; 08454 return p; 08455 }
|
|
Implements EMAN::Processor. Definition at line 8457 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(). 08457 { 08458 ENTERFUNC; 08459 08460 assert_valid_aspect(image); 08461 08462 Transform* t = params["transform"]; 08463 08464 // all_translation += transform.get_trans(); 08465 bool use_cpu = true; 08466 08467 #ifdef EMAN2_USING_CUDA 08468 if(EMData::usecuda == 1 && image->isrodataongpu()){ 08469 //cout << "CUDA xform inplace" << endl; 08470 image->bindcudaarrayA(false); 08471 float * m = new float[12]; 08472 Transform inv = t->inverse(); 08473 inv.copy_matrix_into_array(m); 08474 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize())); 08475 image->unbindcudaarryA(); 08476 delete [] m; 08477 use_cpu = false; 08478 image->update(); 08479 } 08480 #endif 08481 if ( use_cpu ) { 08482 float* des_data = transform(image,*t); 08483 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize()); 08484 image->update(); 08485 } 08486 float scale = t->get_scale(); 08487 if (scale != 1.0f) { 08488 image->scale_pixel(1.0f/scale); 08489 // update_emdata_attributes(image,image->get_attr_dict(),scale); 08490 } 08491 08492 if(t) {delete t; t=0;} 08493 08494 EXITFUNC; 08495 }
|
|
Definition at line 8255 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 process(), and process_inplace(). 08255 { 08256 08257 ENTERFUNC; 08258 08259 Transform inv = t.inverse(); 08260 int nx = image->get_xsize(); 08261 int ny = image->get_ysize(); 08262 int nz = image->get_zsize(); 08263 int nxy = nx*ny; 08264 08265 const float * const src_data = image->get_const_data(); 08266 float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float)); 08267 08268 if (nz == 1) { 08269 Vec2f offset(nx/2,ny/2); 08270 for (int j = 0; j < ny; j++) { 08271 for (int i = 0; i < nx; i++) { 08272 Vec2f coord(i-nx/2,j-ny/2); 08273 Vec2f soln = inv*coord; 08274 soln += offset; 08275 08276 float x2 = soln[0]; 08277 float y2 = soln[1]; 08278 08279 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) { 08280 des_data[i + j * nx] = 0; // It may be tempting to set this value to the 08281 // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it. 08282 } 08283 else { 08284 int ii = Util::fast_floor(x2); 08285 int jj = Util::fast_floor(y2); 08286 int k0 = ii + jj * nx; 08287 int k1 = k0 + 1; 08288 int k2 = k0 + nx; 08289 int k3 = k0 + nx + 1; 08290 08291 if (ii == nx - 1) { 08292 k1--; 08293 k3--; 08294 } 08295 if (jj == ny - 1) { 08296 k2 -= nx; 08297 k3 -= nx; 08298 } 08299 08300 float t = x2 - ii; 08301 float u = y2 - jj; 08302 08303 des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); 08304 } 08305 } 08306 } 08307 } 08308 else { 08309 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7; 08310 Vec3f offset(nx/2,ny/2,nz/2); 08311 float x2, y2, z2, tuvx, tuvy, tuvz; 08312 int ix, iy, iz; 08313 for (int k = 0; k < nz; ++k) { 08314 for (int j = 0; j < ny; ++j) { 08315 for (int i = 0; i < nx; ++i,++l) { 08316 Vec3f coord(i-nx/2,j-ny/2,k-nz/2); 08317 Vec3f soln = inv*coord; 08318 soln += offset; 08319 08320 x2 = soln[0]; 08321 y2 = soln[1]; 08322 z2 = soln[2]; 08323 08324 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) { 08325 des_data[l] = 0; 08326 } 08327 else { 08328 ix = Util::fast_floor(x2); 08329 iy = Util::fast_floor(y2); 08330 iz = Util::fast_floor(z2); 08331 tuvx = x2-ix; 08332 tuvy = y2-iy; 08333 tuvz = z2-iz; 08334 ii = ix + iy * nx + iz * nxy; 08335 08336 k0 = ii; 08337 k1 = k0 + 1; 08338 k2 = k0 + nx; 08339 k3 = k0 + nx+1; 08340 k4 = k0 + nxy; 08341 k5 = k1 + nxy; 08342 k6 = k2 + nxy; 08343 k7 = k3 + nxy; 08344 08345 if (ix == nx - 1) { 08346 k1--; 08347 k3--; 08348 k5--; 08349 k7--; 08350 } 08351 if (iy == ny - 1) { 08352 k2 -= nx; 08353 k3 -= nx; 08354 k6 -= nx; 08355 k7 -= nx; 08356 } 08357 if (iz == nz - 1) { 08358 k4 -= nxy; 08359 k5 -= nxy; 08360 k6 -= nxy; 08361 k7 -= nxy; 08362 } 08363 08364 des_data[l] = Util::trilinear_interpolate(src_data[k0], 08365 src_data[k1], src_data[k2], src_data[k3], src_data[k4], 08366 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz); 08367 } 08368 } 08369 } 08370 } 08371 } 08372 08373 EXITFUNC; 08374 return des_data; 08375 }
|
|
Definition at line 91 of file processor.cpp. |