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:

[legend]
Collaboration diagram for EMAN::TransformProcessor:
[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.

Static Public Member Functions

ProcessorNEW ()

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

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


Member Function Documentation

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

Definition at line 8249 of file processor.cpp.

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

Referenced by process(), and process_inplace().

08249                                                                             {
08250         int ndim = image->get_ndim();
08251         if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D");
08252 
08253         if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation");
08254 }

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

01530                         {
01531                                 return "The image is transformed using Transform parameter.";
01532                         }

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

01502                         {
01503                                 return NAME;
01504                         }

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

References EMAN::TypeDict::put().

01523                         {
01524                                 TypeDict d;
01525                                 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" );
01526                                 return d;
01527                         }

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

Definition at line 1505 of file processor.h.

01506                         {
01507                                 return new TransformProcessor();
01508                         }

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 8288 of file processor.cpp.

References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), EMDataForCuda::data, 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(), EMDataForCuda::nx, EMDataForCuda::ny, EMDataForCuda::nz, EMAN::EMData::scale_pixel(), t, and transform().

08288                                                              {
08289         ENTERFUNC;
08290 
08291         assert_valid_aspect(image);
08292 
08293         Transform* t = params["transform"];
08294 
08295         EMData* p  = 0;
08296 #ifdef EMAN2_USING_CUDA
08297         if (image->gpu_operation_preferred()) {
08298 //              cout << "cuda transform" << endl;
08299                 float * m = new float[12];
08300                 Transform inv = t->inverse();
08301                 inv.copy_matrix_into_array(m);
08302                 image->bind_cuda_texture();
08303                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08304                 image->unbind_cuda_texture();
08305                 delete [] m;
08306                 if (tmp == 0) throw;
08307 
08308                 p = new EMData();
08309                 p->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08310                 free(tmp);
08311         }
08312 #endif
08313         if ( p == 0 ) {
08314                 float* des_data = transform(image,*t);
08315                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08316         }
08317 
08318         //      all_translation += transform.get_trans();
08319 
08320         float scale = t->get_scale();
08321         if (scale != 1.0) {
08322                 p->scale_pixel(1.0f/scale);
08323 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08324         }
08325 
08326         if(t) {delete t; t=0;}
08327         EXITFUNC;
08328         return p;
08329 }

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 8331 of file processor.cpp.

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

08331                                                       {
08332         ENTERFUNC;
08333 
08334         assert_valid_aspect(image);
08335 
08336         Transform* t = params["transform"];
08337 
08338         //      all_translation += transform.get_trans();
08339         bool use_cpu = true;
08340 #ifdef EMAN2_USING_CUDA
08341         if (image->gpu_operation_preferred()) {
08342                 use_cpu = false;
08343                 float * m = new float[12];
08344                 Transform inv = t->inverse();
08345                 inv.copy_matrix_into_array(m);
08346                 image->bind_cuda_texture();
08347                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08348                 image->unbind_cuda_texture();
08349                 delete [] m;
08350                 if (tmp == 0) throw;
08351                 image->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08352                 free(tmp);
08353         }
08354 #endif
08355         if ( use_cpu ) {
08356                 float* des_data = transform(image,*t);
08357                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08358                 image->update();
08359         }
08360         float scale = t->get_scale();
08361         if (scale != 1.0) {
08362                 image->scale_pixel(1.0f/scale);
08363 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08364         }
08365 
08366         if(t) {delete t; t=0;}
08367 
08368         EXITFUNC;
08369 }

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

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

08127                                                                                         {
08128 
08129         ENTERFUNC;
08130 
08131         Transform inv = t.inverse();
08132         int nx = image->get_xsize();
08133         int ny = image->get_ysize();
08134         int nz = image->get_zsize();
08135         int nxy = nx*ny;
08136 
08137         const float * const src_data = image->get_const_data();
08138         float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float));
08139 
08140         if (nz == 1) {
08141                 Vec2f offset(nx/2,ny/2);
08142                 for (int j = 0; j < ny; j++) {
08143                         for (int i = 0; i < nx; i++) {
08144                                 Vec2f coord(i-nx/2,j-ny/2);
08145                                 Vec2f soln = inv*coord;
08146                                 soln += offset;
08147 
08148                                 float x2 = soln[0];
08149                                 float y2 = soln[1];
08150 
08151                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
08152                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
08153                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
08154                                 }
08155                                 else {
08156                                         int ii = Util::fast_floor(x2);
08157                                         int jj = Util::fast_floor(y2);
08158                                         int k0 = ii + jj * nx;
08159                                         int k1 = k0 + 1;
08160                                         int k2 = k0 + nx;
08161                                         int k3 = k0 + nx + 1;
08162 
08163                                         if (ii == nx - 1) {
08164                                                 k1--;
08165                                                 k3--;
08166                                         }
08167                                         if (jj == ny - 1) {
08168                                                 k2 -= nx;
08169                                                 k3 -= nx;
08170                                         }
08171 
08172                                         float t = x2 - ii;
08173                                         float u = y2 - jj;
08174 
08175                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u);
08176                                 }
08177                         }
08178                 }
08179         }
08180         else {
08181                 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
08182                 Vec3f offset(nx/2,ny/2,nz/2);
08183                 float x2, y2, z2, tuvx, tuvy, tuvz;
08184                 int ix, iy, iz;
08185                 for (int k = 0; k < nz; ++k) {
08186                         for (int j = 0; j < ny; ++j) {
08187                                 for (int i = 0; i < nx; ++i,++l) {
08188                                         Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
08189                                         Vec3f soln = inv*coord;
08190                                         soln += offset;
08191 
08192                                         x2 = soln[0];
08193                                         y2 = soln[1];
08194                                         z2 = soln[2];
08195 
08196                                         if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx  || y2 >= ny  || z2>= nz ) {
08197                                                 des_data[l] = 0;
08198                                         }
08199                                         else {
08200                                                 ix = Util::fast_floor(x2);
08201                                                 iy = Util::fast_floor(y2);
08202                                                 iz = Util::fast_floor(z2);
08203                                                 tuvx = x2-ix;
08204                                                 tuvy = y2-iy;
08205                                                 tuvz = z2-iz;
08206                                                 ii = ix + iy * nx + iz * nxy;
08207 
08208                                                 k0 = ii;
08209                                                 k1 = k0 + 1;
08210                                                 k2 = k0 + nx;
08211                                                 k3 = k0 + nx+1;
08212                                                 k4 = k0 + nxy;
08213                                                 k5 = k1 + nxy;
08214                                                 k6 = k2 + nxy;
08215                                                 k7 = k3 + nxy;
08216 
08217                                                 if (ix == nx - 1) {
08218                                                         k1--;
08219                                                         k3--;
08220                                                         k5--;
08221                                                         k7--;
08222                                                 }
08223                                                 if (iy == ny - 1) {
08224                                                         k2 -= nx;
08225                                                         k3 -= nx;
08226                                                         k6 -= nx;
08227                                                         k7 -= nx;
08228                                                 }
08229                                                 if (iz == nz - 1) {
08230                                                         k4 -= nxy;
08231                                                         k5 -= nxy;
08232                                                         k6 -= nxy;
08233                                                         k7 -= nxy;
08234                                                 }
08235 
08236                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
08237                                                                 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
08238                                                                 src_data[k5], src_data[k6],     src_data[k7], tuvx, tuvy, tuvz);
08239                                         }
08240                                 }
08241                         }
08242                 }
08243         }
08244 
08245         EXITFUNC;
08246         return des_data;
08247 }


Member Data Documentation

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

Definition at line 88 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:20 2010 for EMAN2 by  doxygen 1.3.9.1