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