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 1412 of file processor.h.


Member Function Documentation

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

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

08349                                                                             {
08350         int ndim = image->get_ndim();
08351         if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D");
08352 
08353         if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation");
08354 }

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 1443 of file processor.h.

01444                         {
01445                                 return "The image is transformed using Transform parameter.";
01446                         }

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 1415 of file processor.h.

References NAME.

01416                         {
01417                                 return NAME;
01418                         }

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 1436 of file processor.h.

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

01437                         {
01438                                 TypeDict d;
01439                                 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" );
01440                                 return d;
01441                         }

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

Definition at line 1419 of file processor.h.

01420                         {
01421                                 return new TransformProcessor();
01422                         }

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 8388 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, and transform().

08388                                                              {
08389         ENTERFUNC;
08390 
08391         assert_valid_aspect(image);
08392 
08393         Transform* t = params["transform"];
08394 
08395         EMData* p  = 0;
08396 #ifdef EMAN2_USING_CUDA
08397         if(image->isrodataongpu()){     
08398                 //cout << "using CUDA xform" << endl;
08399                 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 
08400                 float * m = new float[12];
08401                 Transform inv = t->inverse();
08402                 inv.copy_matrix_into_array(m);
08403                 image->bindcudaarrayA(true);
08404                 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize()));
08405                 image->unbindcudaarryA();
08406                 delete [] m;
08407         }
08408 #endif
08409 
08410         if ( p == 0 ) {
08411                 float* des_data = transform(image,*t);
08412                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08413         }
08414 
08415         //      all_translation += transform.get_trans();
08416 
08417         float scale = t->get_scale();
08418         if (scale != 1.0) {
08419                 p->scale_pixel(1.0f/scale);
08420 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08421         }
08422 
08423         if(t) {delete t; t=0;}
08424         EXITFUNC;
08425         return p;
08426 }

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 8428 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().

08428                                                       {
08429         ENTERFUNC;
08430 
08431         assert_valid_aspect(image);
08432 
08433         Transform* t = params["transform"];
08434 
08435         //      all_translation += transform.get_trans();
08436         bool use_cpu = true;
08437         
08438 #ifdef EMAN2_USING_CUDA
08439         if(image->isrodataongpu()){
08440                 image->bindcudaarrayA(false);   
08441                 float * m = new float[12];
08442                 Transform inv = t->inverse();
08443                 inv.copy_matrix_into_array(m);  
08444                 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize()));
08445                 image->unbindcudaarryA();
08446                 delete [] m;
08447                 use_cpu = false;
08448         }
08449 #endif
08450         if ( use_cpu ) {
08451                 float* des_data = transform(image,*t);
08452                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08453                 image->update();
08454         }
08455         float scale = t->get_scale();
08456         if (scale != 1.0f) {
08457                 image->scale_pixel(1.0f/scale);
08458 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08459         }
08460 
08461         if(t) {delete t; t=0;}
08462 
08463         EXITFUNC;
08464 }

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

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

08227                                                                                         {
08228 
08229         ENTERFUNC;
08230 
08231         Transform inv = t.inverse();
08232         int nx = image->get_xsize();
08233         int ny = image->get_ysize();
08234         int nz = image->get_zsize();
08235         int nxy = nx*ny;
08236 
08237         const float * const src_data = image->get_const_data();
08238         float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float));
08239 
08240         if (nz == 1) {
08241                 Vec2f offset(nx/2,ny/2);
08242                 for (int j = 0; j < ny; j++) {
08243                         for (int i = 0; i < nx; i++) {
08244                                 Vec2f coord(i-nx/2,j-ny/2);
08245                                 Vec2f soln = inv*coord;
08246                                 soln += offset;
08247 
08248                                 float x2 = soln[0];
08249                                 float y2 = soln[1];
08250 
08251                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
08252                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
08253                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
08254                                 }
08255                                 else {
08256                                         int ii = Util::fast_floor(x2);
08257                                         int jj = Util::fast_floor(y2);
08258                                         int k0 = ii + jj * nx;
08259                                         int k1 = k0 + 1;
08260                                         int k2 = k0 + nx;
08261                                         int k3 = k0 + nx + 1;
08262 
08263                                         if (ii == nx - 1) {
08264                                                 k1--;
08265                                                 k3--;
08266                                         }
08267                                         if (jj == ny - 1) {
08268                                                 k2 -= nx;
08269                                                 k3 -= nx;
08270                                         }
08271 
08272                                         float t = x2 - ii;
08273                                         float u = y2 - jj;
08274 
08275                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u);
08276                                 }
08277                         }
08278                 }
08279         }
08280         else {
08281                 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
08282                 Vec3f offset(nx/2,ny/2,nz/2);
08283                 float x2, y2, z2, tuvx, tuvy, tuvz;
08284                 int ix, iy, iz;
08285                 for (int k = 0; k < nz; ++k) {
08286                         for (int j = 0; j < ny; ++j) {
08287                                 for (int i = 0; i < nx; ++i,++l) {
08288                                         Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
08289                                         Vec3f soln = inv*coord;
08290                                         soln += offset;
08291 
08292                                         x2 = soln[0];
08293                                         y2 = soln[1];
08294                                         z2 = soln[2];
08295 
08296                                         if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx  || y2 >= ny  || z2>= nz ) {
08297                                                 des_data[l] = 0;
08298                                         }
08299                                         else {
08300                                                 ix = Util::fast_floor(x2);
08301                                                 iy = Util::fast_floor(y2);
08302                                                 iz = Util::fast_floor(z2);
08303                                                 tuvx = x2-ix;
08304                                                 tuvy = y2-iy;
08305                                                 tuvz = z2-iz;
08306                                                 ii = ix + iy * nx + iz * nxy;
08307 
08308                                                 k0 = ii;
08309                                                 k1 = k0 + 1;
08310                                                 k2 = k0 + nx;
08311                                                 k3 = k0 + nx+1;
08312                                                 k4 = k0 + nxy;
08313                                                 k5 = k1 + nxy;
08314                                                 k6 = k2 + nxy;
08315                                                 k7 = k3 + nxy;
08316 
08317                                                 if (ix == nx - 1) {
08318                                                         k1--;
08319                                                         k3--;
08320                                                         k5--;
08321                                                         k7--;
08322                                                 }
08323                                                 if (iy == ny - 1) {
08324                                                         k2 -= nx;
08325                                                         k3 -= nx;
08326                                                         k6 -= nx;
08327                                                         k7 -= nx;
08328                                                 }
08329                                                 if (iz == nz - 1) {
08330                                                         k4 -= nxy;
08331                                                         k5 -= nxy;
08332                                                         k6 -= nxy;
08333                                                         k7 -= nxy;
08334                                                 }
08335 
08336                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
08337                                                                 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
08338                                                                 src_data[k5], src_data[k6],     src_data[k7], tuvx, tuvy, tuvz);
08339                                         }
08340                                 }
08341                         }
08342                 }
08343         }
08344 
08345         EXITFUNC;
08346         return des_data;
08347 }


Member Data Documentation

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

Definition at line 1448 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:03 2011 for EMAN2 by  doxygen 1.4.7