EMAN::TransformProcessor Class Reference
[a function or class that is CUDA enabled]

Transform the image using a Transform object. More...

#include <processor.h>

Inheritance diagram for EMAN::TransformProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::TransformProcessor:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual string get_name () const
 Get the processor's name.
virtual void process_inplace (EMData *image)
 
Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

virtual EMDataprocess (const EMData *const image)
 
Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

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 ProcessorNEW ()

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

Detailed Description

Transform the image using a Transform object.

Author:
David Woolford
Date:
September 2008
Parameters:
transform The Transform object that will be applied to the image

Definition at line 1538 of file processor.h.


Member Function Documentation

void TransformProcessor::assert_valid_aspect ( const EMData *const   image  )  const [private]

Definition at line 8387 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().

08387                                                                             {
08388         int ndim = image->get_ndim();
08389         if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D");
08390 
08391         if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation");
08392 }

virtual string EMAN::TransformProcessor::get_desc (  )  const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 1569 of file processor.h.

01570                         {
01571                                 return "The image is transformed using Transform parameter.";
01572                         }

virtual string EMAN::TransformProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 1541 of file processor.h.

References NAME.

01542                         {
01543                                 return NAME;
01544                         }

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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 1562 of file processor.h.

References EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.

01563                         {
01564                                 TypeDict d;
01565                                 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" );
01566                                 return d;
01567                         }

static Processor* EMAN::TransformProcessor::NEW (  )  [inline, static]

Definition at line 1545 of file processor.h.

01546                         {
01547                                 return new TransformProcessor();
01548                         }

EMData * TransformProcessor::process ( const EMData *const   image  )  [virtual]

Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

Reimplemented from EMAN::Processor.

Definition at line 8426 of file processor.cpp.

References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), EMDataForCuda::data, emdata_transform_cuda(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_attr_dict(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMDataForCuda::nx, EMDataForCuda::ny, EMDataForCuda::nz, EMAN::Processor::params, EMAN::EMData::scale_pixel(), t, and transform().

08426                                                              {
08427         ENTERFUNC;
08428 
08429         assert_valid_aspect(image);
08430 
08431         Transform* t = params["transform"];
08432 
08433         EMData* p  = 0;
08434 #ifdef EMAN2_USING_CUDA
08435         if (image->gpu_operation_preferred()) {
08436 //              cout << "cuda transform" << endl;
08437                 float * m = new float[12];
08438                 Transform inv = t->inverse();
08439                 inv.copy_matrix_into_array(m);
08440                 image->bind_cuda_texture();
08441                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08442                 image->unbind_cuda_texture();
08443                 delete [] m;
08444                 if (tmp == 0) throw;
08445 
08446                 p = new EMData();
08447                 p->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08448                 free(tmp);
08449         }
08450 #endif
08451         if ( p == 0 ) {
08452                 float* des_data = transform(image,*t);
08453                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08454         }
08455 
08456         //      all_translation += transform.get_trans();
08457 
08458         float scale = t->get_scale();
08459         if (scale != 1.0) {
08460                 p->scale_pixel(1.0f/scale);
08461 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08462         }
08463 
08464         if(t) {delete t; t=0;}
08465         EXITFUNC;
08466         return p;
08467 }

void TransformProcessor::process_inplace ( EMData image  )  [virtual]

Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

Implements EMAN::Processor.

Definition at line 8469 of file processor.cpp.

References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), EMDataForCuda::data, emdata_transform_cuda(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMDataForCuda::nx, EMDataForCuda::ny, EMDataForCuda::nz, EMAN::Processor::params, EMAN::EMData::scale_pixel(), EMAN::EMData::set_data(), t, transform(), and EMAN::EMData::update().

08469                                                       {
08470         ENTERFUNC;
08471 
08472         assert_valid_aspect(image);
08473 
08474         Transform* t = params["transform"];
08475 
08476         //      all_translation += transform.get_trans();
08477         bool use_cpu = true;
08478 #ifdef EMAN2_USING_CUDA
08479         if (image->gpu_operation_preferred()) {
08480                 use_cpu = false;
08481                 float * m = new float[12];
08482                 Transform inv = t->inverse();
08483                 inv.copy_matrix_into_array(m);
08484                 image->bind_cuda_texture();
08485                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08486                 image->unbind_cuda_texture();
08487                 delete [] m;
08488                 if (tmp == 0) throw;
08489                 image->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08490                 free(tmp);
08491         }
08492 #endif
08493         if ( use_cpu ) {
08494                 float* des_data = transform(image,*t);
08495                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08496                 image->update();
08497         }
08498         float scale = t->get_scale();
08499         if (scale != 1.0) {
08500                 image->scale_pixel(1.0f/scale);
08501 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08502         }
08503 
08504         if(t) {delete t; t=0;}
08505 
08506         EXITFUNC;
08507 }

float * TransformProcessor::transform ( const EMData *const   image,
const Transform t 
) const [private]

Definition at line 8265 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().

08265                                                                                         {
08266 
08267         ENTERFUNC;
08268 
08269         Transform inv = t.inverse();
08270         int nx = image->get_xsize();
08271         int ny = image->get_ysize();
08272         int nz = image->get_zsize();
08273         int nxy = nx*ny;
08274 
08275         const float * const src_data = image->get_const_data();
08276         float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float));
08277 
08278         if (nz == 1) {
08279                 Vec2f offset(nx/2,ny/2);
08280                 for (int j = 0; j < ny; j++) {
08281                         for (int i = 0; i < nx; i++) {
08282                                 Vec2f coord(i-nx/2,j-ny/2);
08283                                 Vec2f soln = inv*coord;
08284                                 soln += offset;
08285 
08286                                 float x2 = soln[0];
08287                                 float y2 = soln[1];
08288 
08289                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
08290                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
08291                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
08292                                 }
08293                                 else {
08294                                         int ii = Util::fast_floor(x2);
08295                                         int jj = Util::fast_floor(y2);
08296                                         int k0 = ii + jj * nx;
08297                                         int k1 = k0 + 1;
08298                                         int k2 = k0 + nx;
08299                                         int k3 = k0 + nx + 1;
08300 
08301                                         if (ii == nx - 1) {
08302                                                 k1--;
08303                                                 k3--;
08304                                         }
08305                                         if (jj == ny - 1) {
08306                                                 k2 -= nx;
08307                                                 k3 -= nx;
08308                                         }
08309 
08310                                         float t = x2 - ii;
08311                                         float u = y2 - jj;
08312 
08313                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u);
08314                                 }
08315                         }
08316                 }
08317         }
08318         else {
08319                 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
08320                 Vec3f offset(nx/2,ny/2,nz/2);
08321                 float x2, y2, z2, tuvx, tuvy, tuvz;
08322                 int ix, iy, iz;
08323                 for (int k = 0; k < nz; ++k) {
08324                         for (int j = 0; j < ny; ++j) {
08325                                 for (int i = 0; i < nx; ++i,++l) {
08326                                         Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
08327                                         Vec3f soln = inv*coord;
08328                                         soln += offset;
08329 
08330                                         x2 = soln[0];
08331                                         y2 = soln[1];
08332                                         z2 = soln[2];
08333 
08334                                         if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx  || y2 >= ny  || z2>= nz ) {
08335                                                 des_data[l] = 0;
08336                                         }
08337                                         else {
08338                                                 ix = Util::fast_floor(x2);
08339                                                 iy = Util::fast_floor(y2);
08340                                                 iz = Util::fast_floor(z2);
08341                                                 tuvx = x2-ix;
08342                                                 tuvy = y2-iy;
08343                                                 tuvz = z2-iz;
08344                                                 ii = ix + iy * nx + iz * nxy;
08345 
08346                                                 k0 = ii;
08347                                                 k1 = k0 + 1;
08348                                                 k2 = k0 + nx;
08349                                                 k3 = k0 + nx+1;
08350                                                 k4 = k0 + nxy;
08351                                                 k5 = k1 + nxy;
08352                                                 k6 = k2 + nxy;
08353                                                 k7 = k3 + nxy;
08354 
08355                                                 if (ix == nx - 1) {
08356                                                         k1--;
08357                                                         k3--;
08358                                                         k5--;
08359                                                         k7--;
08360                                                 }
08361                                                 if (iy == ny - 1) {
08362                                                         k2 -= nx;
08363                                                         k3 -= nx;
08364                                                         k6 -= nx;
08365                                                         k7 -= nx;
08366                                                 }
08367                                                 if (iz == nz - 1) {
08368                                                         k4 -= nxy;
08369                                                         k5 -= nxy;
08370                                                         k6 -= nxy;
08371                                                         k7 -= nxy;
08372                                                 }
08373 
08374                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
08375                                                                 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
08376                                                                 src_data[k5], src_data[k6],     src_data[k7], tuvx, tuvy, tuvz);
08377                                         }
08378                                 }
08379                         }
08380                 }
08381         }
08382 
08383         EXITFUNC;
08384         return des_data;
08385 }


Member Data Documentation

const string TransformProcessor::NAME = "xform" [static]

Definition at line 1574 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 12:43:10 2010 for EMAN2 by  doxygen 1.4.7