00001 00005 /* 00006 * Author: Grant Tang, 02/06/2006 (gtang@bcm.edu) 00007 * Copyright (c) 2000-2006 Baylor College of Medicine 00008 * 00009 * This software is issued under a joint BSD/GNU license. You may use the 00010 * source code in this file under either license. However, note that the 00011 * complete EMAN2 and SPARX software packages have some GPL dependencies, 00012 * so you are responsible for compliance with the licenses of these packages 00013 * if you opt to use BSD licensing. The warranty disclaimer below holds 00014 * in either instance. 00015 * 00016 * This complete copyright notice must be included in any revised version of the 00017 * source code. Additional authorship citations may be added, but existing 00018 * author citations must be preserved. 00019 * 00020 * This program is free software; you can redistribute it and/or modify 00021 * it under the terms of the GNU General Public License as published by 00022 * the Free Software Foundation; either version 2 of the License, or 00023 * (at your option) any later version. 00024 * 00025 * This program is distributed in the hope that it will be useful, 00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00028 * GNU General Public License for more details. 00029 * 00030 * You should have received a copy of the GNU General Public License 00031 * along with this program; if not, write to the Free Software 00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00033 * 00034 * */ 00035 00036 #include <new> 00037 #include <cmath> 00038 #include "emdata.h" 00039 #include "polardata.h" 00040 #include "exception" 00041 #include "util.h" 00042 00043 #ifdef DEBUG 00044 #include <iostream> 00045 using std::cout; 00046 using std::endl; 00047 #endif 00048 00049 #ifdef WIN32 00050 #ifndef M_PI 00051 #define M_PI 3.14159265358979323846f 00052 #endif //M_PI 00053 #endif //WIN32 00054 00055 using namespace EMAN; 00056 using std::bad_alloc; 00057 00058 00059 void UnevenMatrix::alloc_data() 00060 { 00061 if( desc_data.size() == 0 ) { 00062 LOGERR("No data space need to be allocated for UnevenMatrix, check you desc_data..."); 00063 throw InvalidValueException((float)desc_data.size(), "desc_data size == 0"); 00064 } 00065 00066 int size = 0; //total number of float need to be stored in data block 00067 map< int, Xdim >::const_iterator iter; 00068 int y = 0; 00069 for( iter = desc_data.begin(); iter != desc_data.end(); ++iter ) { 00070 y = (*iter).first; 00071 size += get_xsize(y); 00072 } 00073 00074 this->tot_size = size; 00075 try { 00076 this->data = new float[size]; 00077 } 00078 catch( bad_alloc exception ) { 00079 LOGERR("memory allocation for UnevenMatrix failed"); 00080 } 00081 catch(...) { 00082 LOGERR("Unknown error in memory allocation for UnevenMatrix"); 00083 } 00084 } 00085 00086 PolarData::PolarData(EMData * , int , int , string ) 00087 { 00088 // int nsam = image->get_xsize(); 00089 // int nrow = image->get_ysize(); 00090 00091 00092 // int nring = numr.size()/3; 00093 00094 } 00095 /* 00096 EMData* PolarData::calc_ccf(EMData * em) 00097 { 00098 em = 0; 00099 } 00100 */ 00101 /* I had to block this section, it is in conflict with my python code PAP 00102 vector<int> PolarData::Numrinit(int first_ring, int last_ring, int skip, string mode) 00103 { 00104 float dpi; 00105 if(mode == "f" || mode == "F") { 00106 dpi = 2 * M_PI; 00107 } 00108 else { 00109 dpi = M_PI; 00110 } 00111 00112 vector<int> numr; 00113 int lcirc = 1; 00114 int jp = 0; 00115 int ip = 0; 00116 for(int k=first_ring; k<=last_ring; ++k) { 00117 numr.push_back(k); 00118 jp = int(dpi * k + 0.99999999); 00119 ip = (int)pow(2, (double)log2(jp)); 00120 if ( k+skip <= last_ring && jp > ip+std::floor((double)ip/2) ) { 00121 #ifdef _WIN32 00122 ip = _cpp_min(MAXFFT, 2*ip); 00123 #else 00124 ip = std::min<int>(MAXFFT, 2*ip); 00125 #endif //_WIN32 00126 } 00127 if ( k+skip > last_ring && jp > ip+std::floor((double)ip/5) ) { 00128 #ifdef _WIN32 00129 ip = _cpp_min(MAXFFT, 2*ip); 00130 #else 00131 ip = std::min<int>(MAXFFT, 2*ip); 00132 #endif 00133 } 00134 00135 numr.push_back(lcirc); 00136 numr.push_back(ip); 00137 lcirc += ip; 00138 } 00139 00140 --lcirc; 00141 return numr; 00142 } 00143 00144 int PolarData::log2(int n) 00145 { 00146 int m = 1; 00147 int k = -1; 00148 int i; 00149 while ( m <= n) { 00150 i = m; 00151 ++k; 00152 m = 2*i; 00153 } 00154 00155 return k; 00156 } 00157 00158 vector<float> PolarData::ringwe( vector<int> numr, string mode ) 00159 { 00160 float dpi; 00161 if(mode == "f" || mode == "F") { 00162 dpi = 2 * M_PI; 00163 } 00164 else { 00165 dpi = M_PI; 00166 } 00167 00168 vector<float> wr; 00169 int nring = numr.size()/3; 00170 wr.resize(nring); 00171 float maxrin = (float)numr[numr.size()-1]; 00172 for(int i=0; i<nring; ++i) { 00173 wr[i] = (numr[i*3]*dpi)*maxrin / (float)(numr[2+i*3]); 00174 } 00175 00176 return wr; 00177 } 00178 */ 00179 #ifdef DEBUG 00180 int PolarData::test_init_desc_data() 00181 { 00182 desc_data[0] = Xdim(0, 10); 00183 desc_data[3] = Xdim(20, 30); 00184 desc_data[6] = Xdim(3, 5); 00185 desc_data[10] = Xdim(2, 12); 00186 //desc_data[10] = Xdim(22, 12); //error test 00187 00188 cout << "allocation of data success" << endl; 00189 00190 //int j = 10; 00191 //cout << "log2(10) = " << log2(j) << endl; 00192 00193 return 0; 00194 } 00195 #endif //DEBUG