Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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)
virtual EMDataprocess (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

ProcessorNEW ()

Static Public Attributes

const string NAME = "xform"

Private Member Functions

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


Member Function Documentation

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

Definition at line 8615 of file processor.cpp.

References EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), ImageDimensionException, and InvalidParameterException.

Referenced by process(), and process_inplace().

08615                                                                             {
08616         int ndim = image->get_ndim();
08617         if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D");
08618 
08619         if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation");
08620 }

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

01543                         {
01544                                 return "The image is transformed using Transform parameter.";
01545                         }

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

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.

Returns:
A dictionary containing the parameter info.

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                         }

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

Definition at line 1518 of file processor.h.

01519                         {
01520                                 return new TransformProcessor();
01521                         }

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

08654                                                              {
08655         ENTERFUNC;
08656 
08657         assert_valid_aspect(image);
08658 
08659         Transform* t = params["transform"];
08660 
08661         EMData* p  = 0;
08662 #ifdef EMAN2_USING_CUDA
08663         if(EMData::usecuda == 1 && image->isrodataongpu()){     
08664                 //cout << "using CUDA xform" << endl;
08665                 p = new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict()); 
08666                 float * m = new float[12];
08667                 Transform inv = t->inverse();
08668                 inv.copy_matrix_into_array(m);
08669                 image->bindcudaarrayA(true);
08670                 p->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize()));
08671                 image->unbindcudaarryA();
08672                 delete [] m;
08673                 p->update();
08674         }
08675 #endif
08676 
08677         if ( p == 0 ) {
08678                 float* des_data = transform(image,*t);
08679                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08680         }
08681 
08682         //      all_translation += transform.get_trans();
08683 
08684         float scale = t->get_scale();
08685         if (scale != 1.0) {
08686                 p->scale_pixel(1.0f/scale);
08687 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08688         }
08689 
08690         if(t) {delete t; t=0;}
08691         EXITFUNC;
08692         return p;
08693 }

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

08695                                                       {
08696         ENTERFUNC;
08697 
08698         assert_valid_aspect(image);
08699 
08700         Transform* t = params["transform"];
08701 
08702         //      all_translation += transform.get_trans();
08703         bool use_cpu = true;
08704         
08705 #ifdef EMAN2_USING_CUDA
08706         if(EMData::usecuda == 1 && image->isrodataongpu()){
08707                 //cout << "CUDA xform inplace" << endl;
08708                 image->bindcudaarrayA(false);   
08709                 float * m = new float[12];
08710                 Transform inv = t->inverse();
08711                 inv.copy_matrix_into_array(m);  
08712                 image->runcuda(emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize()));
08713                 image->unbindcudaarryA();
08714                 delete [] m;
08715                 use_cpu = false;
08716                 image->update();
08717         }
08718 #endif
08719         if ( use_cpu ) {
08720                 float* des_data = transform(image,*t);
08721                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08722                 image->update();
08723         }
08724         float scale = t->get_scale();
08725         if (scale != 1.0f) {
08726                 image->scale_pixel(1.0f/scale);
08727 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08728         }
08729 
08730         if(t) {delete t; t=0;}
08731 
08732         EXITFUNC;
08733 }

float * TransformProcessor::transform const EMData *const   image,
const Transform t
const
 

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

08493                                                                                         {
08494 
08495         ENTERFUNC;
08496 
08497         Transform inv = t.inverse();
08498         int nx = image->get_xsize();
08499         int ny = image->get_ysize();
08500         int nz = image->get_zsize();
08501         int nxy = nx*ny;
08502 
08503         const float * const src_data = image->get_const_data();
08504         float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float));
08505 
08506         if (nz == 1) {
08507                 Vec2f offset(nx/2,ny/2);
08508                 for (int j = 0; j < ny; j++) {
08509                         for (int i = 0; i < nx; i++) {
08510                                 Vec2f coord(i-nx/2,j-ny/2);
08511                                 Vec2f soln = inv*coord;
08512                                 soln += offset;
08513 
08514                                 float x2 = soln[0];
08515                                 float y2 = soln[1];
08516 
08517                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
08518                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
08519                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
08520                                 }
08521                                 else {
08522                                         int ii = Util::fast_floor(x2);
08523                                         int jj = Util::fast_floor(y2);
08524                                         int k0 = ii + jj * nx;
08525                                         int k1 = k0 + 1;
08526                                         int k2 = k0 + nx;
08527                                         int k3 = k0 + nx + 1;
08528 
08529                                         if (ii == nx - 1) {
08530                                                 k1--;
08531                                                 k3--;
08532                                         }
08533                                         if (jj == ny - 1) {
08534                                                 k2 -= nx;
08535                                                 k3 -= nx;
08536                                         }
08537 
08538                                         float t = x2 - ii;
08539                                         float u = y2 - jj;
08540 
08541                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u);
08542                                 }
08543                         }
08544                 }
08545         }
08546         else {
08547                 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
08548                 Vec3f offset(nx/2,ny/2,nz/2);
08549                 float x2, y2, z2, tuvx, tuvy, tuvz;
08550                 int ix, iy, iz;
08551                 for (int k = 0; k < nz; ++k) {
08552                         for (int j = 0; j < ny; ++j) {
08553                                 for (int i = 0; i < nx; ++i,++l) {
08554                                         Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
08555                                         Vec3f soln = inv*coord;
08556                                         soln += offset;
08557 
08558                                         x2 = soln[0];
08559                                         y2 = soln[1];
08560                                         z2 = soln[2];
08561 
08562                                         if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx  || y2 >= ny  || z2>= nz ) {
08563                                                 des_data[l] = 0;
08564                                         }
08565                                         else {
08566                                                 ix = Util::fast_floor(x2);
08567                                                 iy = Util::fast_floor(y2);
08568                                                 iz = Util::fast_floor(z2);
08569                                                 tuvx = x2-ix;
08570                                                 tuvy = y2-iy;
08571                                                 tuvz = z2-iz;
08572                                                 ii = ix + iy * nx + iz * nxy;
08573 
08574                                                 k0 = ii;
08575                                                 k1 = k0 + 1;
08576                                                 k2 = k0 + nx;
08577                                                 k3 = k0 + nx+1;
08578                                                 k4 = k0 + nxy;
08579                                                 k5 = k1 + nxy;
08580                                                 k6 = k2 + nxy;
08581                                                 k7 = k3 + nxy;
08582 
08583                                                 if (ix == nx - 1) {
08584                                                         k1--;
08585                                                         k3--;
08586                                                         k5--;
08587                                                         k7--;
08588                                                 }
08589                                                 if (iy == ny - 1) {
08590                                                         k2 -= nx;
08591                                                         k3 -= nx;
08592                                                         k6 -= nx;
08593                                                         k7 -= nx;
08594                                                 }
08595                                                 if (iz == nz - 1) {
08596                                                         k4 -= nxy;
08597                                                         k5 -= nxy;
08598                                                         k6 -= nxy;
08599                                                         k7 -= nxy;
08600                                                 }
08601 
08602                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
08603                                                                 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
08604                                                                 src_data[k5], src_data[k6],     src_data[k7], tuvx, tuvy, tuvz);
08605                                         }
08606                                 }
08607                         }
08608                 }
08609         }
08610 
08611         EXITFUNC;
08612         return des_data;
08613 }


Member Data Documentation

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

Definition at line 86 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:27 2013 for EMAN2 by  doxygen 1.3.9.1