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


Member Function Documentation

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

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

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

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.

References NAME.

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(), and EMAN::EMObject::TRANSFORM.

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

static 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 8319 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::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::Processor::params, EMAN::EMData::scale_pixel(), t, and transform().

08319                                                              {
08320         ENTERFUNC;
08321 
08322         assert_valid_aspect(image);
08323 
08324         Transform* t = params["transform"];
08325 
08326         EMData* p  = 0;
08327 #ifdef EMAN2_USING_CUDA
08328         if (image->gpu_operation_preferred()) {
08329 //              cout << "cuda transform" << endl;
08330                 float * m = new float[12];
08331                 Transform inv = t->inverse();
08332                 inv.copy_matrix_into_array(m);
08333                 image->bind_cuda_texture();
08334                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08335                 image->unbind_cuda_texture();
08336                 delete [] m;
08337                 if (tmp == 0) throw;
08338 
08339                 p = new EMData();
08340                 p->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08341                 free(tmp);
08342         }
08343 #endif
08344         if ( p == 0 ) {
08345                 float* des_data = transform(image,*t);
08346                 p = new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
08347         }
08348 
08349         //      all_translation += transform.get_trans();
08350 
08351         float scale = t->get_scale();
08352         if (scale != 1.0) {
08353                 p->scale_pixel(1.0f/scale);
08354 //              update_emdata_attributes(p,image->get_attr_dict(),scale);
08355         }
08356 
08357         if(t) {delete t; t=0;}
08358         EXITFUNC;
08359         return p;
08360 }

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

References assert_valid_aspect(), EMAN::Transform::copy_matrix_into_array(), EMDataForCuda::data, emdata_transform_cuda(), ENTERFUNC, EXITFUNC, 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::Processor::params, EMAN::EMData::scale_pixel(), EMAN::EMData::set_data(), t, transform(), and EMAN::EMData::update().

08362                                                       {
08363         ENTERFUNC;
08364 
08365         assert_valid_aspect(image);
08366 
08367         Transform* t = params["transform"];
08368 
08369         //      all_translation += transform.get_trans();
08370         bool use_cpu = true;
08371 #ifdef EMAN2_USING_CUDA
08372         if (image->gpu_operation_preferred()) {
08373                 use_cpu = false;
08374                 float * m = new float[12];
08375                 Transform inv = t->inverse();
08376                 inv.copy_matrix_into_array(m);
08377                 image->bind_cuda_texture();
08378                 EMDataForCuda* tmp = emdata_transform_cuda(m,image->get_xsize(),image->get_ysize(),image->get_zsize());
08379                 image->unbind_cuda_texture();
08380                 delete [] m;
08381                 if (tmp == 0) throw;
08382                 image->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz);
08383                 free(tmp);
08384         }
08385 #endif
08386         if ( use_cpu ) {
08387                 float* des_data = transform(image,*t);
08388                 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
08389                 image->update();
08390         }
08391         float scale = t->get_scale();
08392         if (scale != 1.0) {
08393                 image->scale_pixel(1.0f/scale);
08394 //              update_emdata_attributes(image,image->get_attr_dict(),scale);
08395         }
08396 
08397         if(t) {delete t; t=0;}
08398 
08399         EXITFUNC;
08400 }

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

Definition at line 8158 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(), EMAN::Transform::inverse(), and EMAN::Util::trilinear_interpolate().

Referenced by process(), and process_inplace().

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


Member Data Documentation

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

Definition at line 1534 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:37:00 2010 for EMAN2 by  doxygen 1.4.4