EMAN::StandardProjector Class Reference
[a function or class that is CUDA enabled]

Fast real-space 3D projection. More...

#include <projector.h>

Inheritance diagram for EMAN::StandardProjector:

Inheritance graph
[legend]
Collaboration diagram for EMAN::StandardProjector:

Collaboration graph
[legend]
List of all members.

Public Member Functions

TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
EMDataproject3d (EMData *image) const
 Project an 3D image into a 2D image.
EMDatabackproject3d (EMData *image) const
 Back-project a 2D image into a 3D image.
string get_name () const
 Get the projector's name.
string get_desc () const

Static Public Member Functions

static ProjectorNEW ()

Static Public Attributes

static const string NAME = "standard"

Detailed Description

Fast real-space 3D projection.

Parameters:
Transform object used for projection

Definition at line 304 of file projector.h.


Member Function Documentation

EMData * StandardProjector::backproject3d ( EMData image  )  const [virtual]

Back-project a 2D image into a 3D image.

Returns:
A 3D image from the backprojection.

Implements EMAN::Projector.

Definition at line 2083 of file projector.cpp.

02084 {
02085    // no implementation yet
02086    EMData *ret = new EMData();
02087    return ret;
02088 }

string EMAN::StandardProjector::get_desc (  )  const [inline, virtual]

Implements EMAN::Projector.

Definition at line 323 of file projector.h.

00324                 {
00325                         return "Simple real-space projection. Most accurate.";
00326                 }

string EMAN::StandardProjector::get_name (  )  const [inline, virtual]

Get the projector's name.

Each projector is indentified by unique name.

Returns:
The projector's name.

Implements EMAN::Projector.

Definition at line 318 of file projector.h.

References NAME.

00319                 {
00320                         return NAME;
00321                 }

TypeDict EMAN::StandardProjector::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::Projector.

Definition at line 307 of file projector.h.

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

00308                 {
00309                         TypeDict d;
00310                         d.put("transform", EMObject::TRANSFORM, "Transform object used for projection");
00311                         return d;
00312                 }

static Projector* EMAN::StandardProjector::NEW (  )  [inline, static]

Definition at line 328 of file projector.h.

00329                 {
00330                         return new StandardProjector();
00331                 }

EMData * StandardProjector::project3d ( EMData image  )  const [virtual]

Project an 3D image into a 2D image.

Returns:
A 2D image from the projection.

Implements EMAN::Projector.

Definition at line 872 of file projector.cpp.

References EMAN::Util::bilinear_interpolate(), EMAN::Transform::copy_matrix_into_array(), EMAN::Util::fast_floor(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, EMAN::Transform::inverse(), EMAN::Util::linear_interpolate(), NullPointerException, nx, ny, EMAN::Projector::params, proj, EMAN::EMData::set_attr(), standard_project(), t, EMAN::Util::trilinear_interpolate(), EMAN::EMData::update(), v, x, and y.

00873 {
00874         Transform* t3d = params["transform"];
00875         if ( t3d == NULL ) throw NullPointerException("The transform object containing the angles(required for projection), was not specified");
00876 //      Dict p = t3d->get_rotation();
00877         if ( image->get_ndim() == 3 )
00878         {
00879 
00880 #ifdef EMAN2_USING_CUDA
00881                 if(EMData::usecuda == 1) {
00882                         if(!image->isrodataongpu()) image->copy_to_cudaro();
00883                         //cout << "CUDA PROJ" << endl;
00884                         Transform* t3d = params["transform"];
00885                         if ( t3d == NULL ) throw NullPointerException("The transform object containing the angles(required for projection), was not specified");
00886                         float * m = new float[12];
00887                         t3d->copy_matrix_into_array(m);
00888                         image->bindcudaarrayA(true);
00889                         //EMData* e = new EMData(0,0,image->get_xsize(),image->get_ysize(),1);
00890                         EMData *e = new EMData();
00891                         e->set_size_cuda(image->get_xsize(), image->get_ysize(), 1);
00892                         e->rw_alloc();
00893                         standard_project(m,e->getcudarwdata(), e->get_xsize(), e->get_ysize());
00894                         image->unbindcudaarryA();
00895                         delete [] m;
00896                 
00897                         e->update();
00898                         e->set_attr("xform.projection",t3d);
00899                         e->set_attr("apix_x",(float)image->get_attr("apix_x"));
00900                         e->set_attr("apix_y",(float)image->get_attr("apix_y"));
00901                         e->set_attr("apix_z",(float)image->get_attr("apix_z"));
00902                         //e_>copy_from_device();
00903                         if(t3d) {delete t3d; t3d=0;}
00904                         return e;
00905                 }
00906 #endif
00907                 int nx = image->get_xsize();
00908                 int ny = image->get_ysize();
00909                 int nz = image->get_zsize();
00910 
00911 //              Transform3D r(Transform3D::EMAN, az, alt, phi);
00912                 Transform r = t3d->inverse(); // The inverse is taken here because we are rotating the coordinate system, not the image
00913                 int xy = nx * ny;
00914 
00915                 EMData *proj = new EMData();
00916                 proj->set_size(nx, ny, 1);
00917 
00918                 Vec3i offset(nx/2,ny/2,nz/2);
00919 
00920                 float *sdata = image->get_data();
00921                 float *ddata = proj->get_data();
00922                 for (int k = -nz / 2; k < nz - nz / 2; k++) {
00923                         int l = 0;
00924                         for (int j = -ny / 2; j < ny - ny / 2; j++) {
00925                                 ddata[l]=0;
00926                                 for (int i = -nx / 2; i < nx - nx / 2; i++,l++) {
00927 
00928                                         Vec3f coord(i,j,k);
00929                                         Vec3f soln = r*coord;
00930                                         soln += offset;
00931 
00935 //                                      printf(" ");
00936 
00937                                         float x2 = soln[0];
00938                                         float y2 = soln[1];
00939                                         float z2 = soln[2];
00940 
00941                                         float x = (float)Util::fast_floor(x2);
00942                                         float y = (float)Util::fast_floor(y2);
00943                                         float z = (float)Util::fast_floor(z2);
00944 
00945                                         float t = x2 - x;
00946                                         float u = y2 - y;
00947                                         float v = z2 - z;
00948 
00949                                         size_t ii = (size_t) ((size_t)x + (size_t)y * nx + (size_t)z * xy);
00950 // 
00951                                         if (x2 < 0 || y2 < 0 || z2 < 0 ) continue;
00952                                         if      (x2 > (nx-1) || y2  > (ny-1) || z2 > (nz-1) ) continue;
00953 
00954                                         if (x2 < (nx - 1) && y2 < (ny - 1) && z2 < (nz - 1)) {
00955                                                 ddata[l] +=
00956                                                                 Util::trilinear_interpolate(sdata[ii], sdata[ii + 1], sdata[ii + nx],
00957                                                                 sdata[ii + nx + 1], sdata[ii + xy],     sdata[ii + xy + 1], sdata[ii + xy + nx],
00958                                                                 sdata[ii + xy + nx + 1], t, u, v);
00959                                         }
00960                                         else if ( x2 == (nx - 1) && y2 == (ny - 1) && z2 == (nz - 1) ) {
00961                                                 ddata[l] += sdata[ii];
00962                                         }
00963                                         else if ( x2 == (nx - 1) && y2 == (ny - 1) ) {
00964                                                 ddata[l] +=     Util::linear_interpolate(sdata[ii], sdata[ii + xy],v);
00965                                         }
00966                                         else if ( x2 == (nx - 1) && z2 == (nz - 1) ) {
00967                                                 ddata[l] += Util::linear_interpolate(sdata[ii], sdata[ii + nx],u);
00968                                         }
00969                                         else if ( y2 == (ny - 1) && z2 == (nz - 1) ) {
00970                                                 ddata[l] += Util::linear_interpolate(sdata[ii], sdata[ii + 1],t);
00971                                         }
00972                                         else if ( x2 == (nx - 1) ) {
00973                                                 ddata[l] += Util::bilinear_interpolate(sdata[ii], sdata[ii + nx], sdata[ii + xy], sdata[ii + xy + nx],u,v);
00974                                         }
00975                                         else if ( y2 == (ny - 1) ) {
00976                                                 ddata[l] += Util::bilinear_interpolate(sdata[ii], sdata[ii + 1], sdata[ii + xy], sdata[ii + xy + 1],t,v);
00977                                         }
00978                                         else if ( z2 == (nz - 1) ) {
00979                                                 ddata[l] += Util::bilinear_interpolate(sdata[ii], sdata[ii + 1], sdata[ii + nx], sdata[ii + nx + 1],t,u);
00980                                         }
00981                                 }
00982                         }
00983                 }
00984                 proj->update();
00985                 proj->set_attr("xform.projection",t3d);
00986                 proj->set_attr("apix_x",(float)image->get_attr("apix_x"));
00987                 proj->set_attr("apix_y",(float)image->get_attr("apix_y"));
00988                 proj->set_attr("apix_z",(float)image->get_attr("apix_z"));
00989                 
00990                 if(t3d) {delete t3d; t3d=0;}
00991                 return proj;
00992         }
00993         else if ( image->get_ndim() == 2 ) {
00994 
00995                 Transform r = t3d->inverse(); // The inverse is taken here because we are rotating the coordinate system, not the image
00996 
00997                 int nx = image->get_xsize();
00998                 int ny = image->get_ysize();
00999 
01000                 EMData *proj = new EMData();
01001                 proj->set_size(nx, 1, 1);
01002                 proj->to_zero();
01003 
01004                 float *sdata = image->get_data();
01005                 float *ddata = proj->get_data();
01006 
01007                 Vec2f offset(nx/2,ny/2);
01008                 for (int j = -ny / 2; j < ny - ny / 2; j++) { // j represents a column of pixels in the direction of the angle
01009                         int l = 0;
01010                         for (int i = -nx / 2; i < nx - nx / 2; i++,l++) {
01011 
01012                                 Vec2f coord(i,j);
01013                                 Vec2f soln = r*coord;
01014                                 soln += offset;
01015 
01016                                 float x2 = soln[0];
01017                                 float y2 = soln[1];
01018 
01019                                 float x = (float)Util::fast_floor(x2);
01020                                 float y = (float)Util::fast_floor(y2);
01021 
01022                                 int ii = (int) (x + y * nx);
01023                                 float u = x2 - x;
01024                                 float v = y2 - y;
01025 
01026                                 if (x2 < 0 || y2 < 0 ) continue;
01027                                 if      (x2 > (nx-1) || y2  > (ny-1) ) continue;
01028 
01029                                 if (  x2 < (nx - 1) && y2 < (ny - 1) ) {
01030                                         ddata[l] += Util::bilinear_interpolate(sdata[ii], sdata[ii + 1], sdata[ii + nx],sdata[ii + nx + 1], u, v);
01031                                 }
01032                                 else if (x2 == (nx-1) && y2 == (ny-1) ) {
01033                                         ddata[l] += sdata[ii];
01034                                 }
01035                                 else if (x2 == (nx-1) ) {
01036                                         ddata[l] += Util::linear_interpolate(sdata[ii],sdata[ii + nx], v);
01037                                 }
01038                                 else if (y2 == (ny-1) ) {
01039                                         ddata[l] += Util::linear_interpolate(sdata[ii],sdata[ii + 1], u);
01040                                 }
01041                         }
01042                 }
01043                 proj->set_attr("xform.projection",t3d);
01044                 proj->update();
01045                 if(t3d) {delete t3d; t3d=0;}
01046                 return proj;
01047         }
01048         else throw ImageDimensionException("Standard projection works only for 2D and 3D images");
01049 }


Member Data Documentation

const string StandardProjector::NAME = "standard" [static]

Definition at line 333 of file projector.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:49:52 2011 for EMAN2 by  doxygen 1.4.7