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.

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


Member Function Documentation

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

Definition at line 8285 of file processor.cpp.

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

Referenced by process(), and process_inplace().

08285                                                                             {
08286         int ndim = image->get_ndim();
08287         if (ndim != 2 && ndim != 3) throw ImageDimensionException("Transforming an EMData only works if it's 2D or 3D");
08288 
08289         if (! params.has_key("transform") ) throw InvalidParameterException("You must specify a Transform in order to perform this operation");
08290 }

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

01320                         {
01321                                 return "The image is transformed using Transform parameter.";
01322                         }

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

01292                         {
01293                                 return NAME;
01294                         }

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

References EMAN::TypeDict::put().

01313                         {
01314                                 TypeDict d;
01315                                 d.put("transform", EMObject::TRANSFORM, "The Transform object that will be applied to the image" );
01316                                 return d;
01317                         }

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

Definition at line 1295 of file processor.h.

01296                         {
01297                                 return new TransformProcessor();
01298                         }

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

08324                                                              {
08325         ENTERFUNC;
08326 
08327         assert_valid_aspect(image);
08328 
08329         Transform* t = params["transform"];
08330 
08331         EMData* p  = 0;
08332         
08333 #ifdef EMAN2_USING_CUDA
08334         if (image->gpu_operation_preferred()) {
08335         
08336                 //cout << "using CUDA" << endl;
08337                 float * m = new float[12];
08338                 Transform inv = t->inverse();
08339                 inv.copy_matrix_into_array(m);
08340                 image->bind_cuda_texture();
08341                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08342                 //printf("CUDA ptr = %d\n", tmp->data);
08343                 //size_t num_bytes = tmp->nx*tmp->ny*tmp->nz*sizeof(float);
08344                 //float * rdata;
08345                 //rdata = (float*) malloc(num_bytes);
08346                 //cudaError_t error = cudaMemcpy(rdata,tmp->data,num_bytes,cudaMemcpyDeviceToHost);
08347                 //if (error != cudaSuccess ){cout << "CUDA FAILED!!! " << error << endl;}
08348                 //cout << error << endl;
08349                 image->unbind_cuda_texture();
08350                 delete [] m;
08351                 if (tmp == 0) throw;
08352 
08353                 p = new EMData();
08354         
08355                 p->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08356                 free(tmp);
08357         }
08358 #endif
08359         if ( p == 0 ) {
08360                 float* des_data = transform(image,*t);
08361                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08362         }
08363 
08364         //      all_translation += transform.get_trans();
08365 
08366         float scale = t->get_scale();
08367         if (scale != 1.0) {
08368                 p->scale_pixel(1.0f/scale);
08369 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08370         }
08371 
08372         if(t) {delete t; t=0;}
08373         EXITFUNC;
08374         return p;
08375 }

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

08377                                                       {
08378         ENTERFUNC;
08379 
08380         assert_valid_aspect(image);
08381 
08382         Transform* t = params["transform"];
08383 
08384         //      all_translation += transform.get_trans();
08385         bool use_cpu = true;
08386 #ifdef EMAN2_USING_CUDA
08387         if (image->gpu_operation_preferred()) {
08388                 use_cpu = false;
08389                 float * m = new float[12];
08390                 Transform inv = t->inverse();
08391                 inv.copy_matrix_into_array(m);
08392                 image->bind_cuda_texture();
08393                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08394                 image->unbind_cuda_texture();
08395                 delete [] m;
08396                 if (tmp == 0) throw;
08397                 image->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08398                 free(tmp);
08399         }
08400 #endif
08401         if ( use_cpu ) {
08402                 float* des_data = transform(image,*t);
08403                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08404                 image->update();
08405         }
08406         float scale = t->get_scale();
08407         if (scale != 1.0) {
08408                 image->scale_pixel(1.0f/scale);
08409 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08410         }
08411 
08412         if(t) {delete t; t=0;}
08413 
08414         EXITFUNC;
08415 }

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

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

08163                                                                                         {
08164 
08165         ENTERFUNC;
08166 
08167         Transform inv = t.inverse();
08168         int nx = image->get_xsize();
08169         int ny = image->get_ysize();
08170         int nz = image->get_zsize();
08171         int nxy = nx*ny;
08172 
08173         const float * const src_data = image->get_const_data();
08174         float *des_data = (float *) EMUtil::em_malloc(nx*ny*nz* sizeof(float));
08175 
08176         if (nz == 1) {
08177                 Vec2f offset(nx/2,ny/2);
08178                 for (int j = 0; j < ny; j++) {
08179                         for (int i = 0; i < nx; i++) {
08180                                 Vec2f coord(i-nx/2,j-ny/2);
08181                                 Vec2f soln = inv*coord;
08182                                 soln += offset;
08183 
08184                                 float x2 = soln[0];
08185                                 float y2 = soln[1];
08186 
08187                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
08188                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
08189                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
08190                                 }
08191                                 else {
08192                                         int ii = Util::fast_floor(x2);
08193                                         int jj = Util::fast_floor(y2);
08194                                         int k0 = ii + jj * nx;
08195                                         int k1 = k0 + 1;
08196                                         int k2 = k0 + nx;
08197                                         int k3 = k0 + nx + 1;
08198 
08199                                         if (ii == nx - 1) {
08200                                                 k1--;
08201                                                 k3--;
08202                                         }
08203                                         if (jj == ny - 1) {
08204                                                 k2 -= nx;
08205                                                 k3 -= nx;
08206                                         }
08207 
08208                                         float t = x2 - ii;
08209                                         float u = y2 - jj;
08210 
08211                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u);
08212                                 }
08213                         }
08214                 }
08215         }
08216         else {
08217                 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
08218                 Vec3f offset(nx/2,ny/2,nz/2);
08219                 float x2, y2, z2, tuvx, tuvy, tuvz;
08220                 int ix, iy, iz;
08221                 for (int k = 0; k < nz; ++k) {
08222                         for (int j = 0; j < ny; ++j) {
08223                                 for (int i = 0; i < nx; ++i,++l) {
08224                                         Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
08225                                         Vec3f soln = inv*coord;
08226                                         soln += offset;
08227 
08228                                         x2 = soln[0];
08229                                         y2 = soln[1];
08230                                         z2 = soln[2];
08231 
08232                                         if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx  || y2 >= ny  || z2>= nz ) {
08233                                                 des_data[l] = 0;
08234                                         }
08235                                         else {
08236                                                 ix = Util::fast_floor(x2);
08237                                                 iy = Util::fast_floor(y2);
08238                                                 iz = Util::fast_floor(z2);
08239                                                 tuvx = x2-ix;
08240                                                 tuvy = y2-iy;
08241                                                 tuvz = z2-iz;
08242                                                 ii = ix + iy * nx + iz * nxy;
08243 
08244                                                 k0 = ii;
08245                                                 k1 = k0 + 1;
08246                                                 k2 = k0 + nx;
08247                                                 k3 = k0 + nx+1;
08248                                                 k4 = k0 + nxy;
08249                                                 k5 = k1 + nxy;
08250                                                 k6 = k2 + nxy;
08251                                                 k7 = k3 + nxy;
08252 
08253                                                 if (ix == nx - 1) {
08254                                                         k1--;
08255                                                         k3--;
08256                                                         k5--;
08257                                                         k7--;
08258                                                 }
08259                                                 if (iy == ny - 1) {
08260                                                         k2 -= nx;
08261                                                         k3 -= nx;
08262                                                         k6 -= nx;
08263                                                         k7 -= nx;
08264                                                 }
08265                                                 if (iz == nz - 1) {
08266                                                         k4 -= nxy;
08267                                                         k5 -= nxy;
08268                                                         k6 -= nxy;
08269                                                         k7 -= nxy;
08270                                                 }
08271 
08272                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
08273                                                                 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
08274                                                                 src_data[k5], src_data[k6],     src_data[k7], tuvx, tuvy, tuvz);
08275                                         }
08276                                 }
08277                         }
08278                 }
08279         }
08280 
08281         EXITFUNC;
08282         return des_data;
08283 }


Member Data Documentation

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

Definition at line 82 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:47:44 2010 for EMAN2 by  doxygen 1.3.9.1