EMAN2
polardata.cpp
Go to the documentation of this file.
1/*
2 * Author: Grant Tang, 02/06/2006 (gtang@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#include <new>
33#include <cmath>
34#include "emdata.h"
35#include "polardata.h"
36#include "exception"
37#include "util.h"
38
39#ifdef DEBUG
40 #include <iostream>
41 using std::cout;
42 using std::endl;
43#endif
44
45#ifdef WIN32
46 #ifndef M_PI
47 #define M_PI 3.14159265358979323846f
48 #endif //M_PI
49#endif //WIN32
50
51using namespace EMAN;
52using std::bad_alloc;
53
54
55void UnevenMatrix::alloc_data()
56{
57 if( desc_data.size() == 0 ) {
58 LOGERR("No data space need to be allocated for UnevenMatrix, check you desc_data...");
59 throw InvalidValueException((float)desc_data.size(), "desc_data size == 0");
60 }
61
62 int size = 0; //total number of float need to be stored in data block
63 map< int, Xdim >::const_iterator iter;
64 int y = 0;
65 for( iter = desc_data.begin(); iter != desc_data.end(); ++iter ) {
66 y = (*iter).first;
67 size += get_xsize(y);
68 }
69
70 this->tot_size = size;
71 try {
72 this->data = new float[size];
73 }
74 catch( bad_alloc exception ) {
75 LOGERR("memory allocation for UnevenMatrix failed");
76 }
77 catch(...) {
78 LOGERR("Unknown error in memory allocation for UnevenMatrix");
79 }
80}
81
82PolarData::PolarData(EMData * , int , int , string )
83{
84// int nsam = image->get_xsize();
85// int nrow = image->get_ysize();
86
87
88// int nring = numr.size()/3;
89
90}
91/*
92EMData* PolarData::calc_ccf(EMData * em)
93{
94 em = 0;
95}
96*/
97/* I had to block this section, it is in conflict with my python code PAP
98vector<int> PolarData::Numrinit(int first_ring, int last_ring, int skip, string mode)
99{
100 float dpi;
101 if(mode == "f" || mode == "F") {
102 dpi = 2 * M_PI;
103 }
104 else {
105 dpi = M_PI;
106 }
107
108 vector<int> numr;
109 int lcirc = 1;
110 int jp = 0;
111 int ip = 0;
112 for(int k=first_ring; k<=last_ring; ++k) {
113 numr.push_back(k);
114 jp = int(dpi * k + 0.99999999);
115 ip = (int)pow(2, (double)log2(jp));
116 if ( k+skip <= last_ring && jp > ip+std::floor((double)ip/2) ) {
117#ifdef _WIN32
118 ip = _cpp_min(MAXFFT, 2*ip);
119#else
120 ip = std::min<int>(MAXFFT, 2*ip);
121#endif //_WIN32
122 }
123 if ( k+skip > last_ring && jp > ip+std::floor((double)ip/5) ) {
124#ifdef _WIN32
125 ip = _cpp_min(MAXFFT, 2*ip);
126#else
127 ip = std::min<int>(MAXFFT, 2*ip);
128#endif
129 }
130
131 numr.push_back(lcirc);
132 numr.push_back(ip);
133 lcirc += ip;
134 }
135
136 --lcirc;
137 return numr;
138}
139
140int PolarData::log2(int n)
141{
142 int m = 1;
143 int k = -1;
144 int i;
145 while ( m <= n) {
146 i = m;
147 ++k;
148 m = 2*i;
149 }
150
151 return k;
152}
153
154vector<float> PolarData::ringwe( vector<int> numr, string mode )
155{
156 float dpi;
157 if(mode == "f" || mode == "F") {
158 dpi = 2 * M_PI;
159 }
160 else {
161 dpi = M_PI;
162 }
163
164 vector<float> wr;
165 int nring = numr.size()/3;
166 wr.resize(nring);
167 float maxrin = (float)numr[numr.size()-1];
168 for(int i=0; i<nring; ++i) {
169 wr[i] = (numr[i*3]*dpi)*maxrin / (float)(numr[2+i*3]);
170 }
171
172 return wr;
173}
174*/
175#ifdef DEBUG
176int PolarData::test_init_desc_data()
177{
178 desc_data[0] = Xdim(0, 10);
179 desc_data[3] = Xdim(20, 30);
180 desc_data[6] = Xdim(3, 5);
181 desc_data[10] = Xdim(2, 12);
182 //desc_data[10] = Xdim(22, 12); //error test
183
184 cout << "allocation of data success" << endl;
185
186 //int j = 10;
187 //cout << "log2(10) = " << log2(j) << endl;
188
189 return 0;
190}
191#endif //DEBUG
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
float * data
store all data in one dimension float array for cache efficiency, we calculate the offset for x,...
Definition: polardata.h:123
int tot_size
the total size of the data
Definition: polardata.h:129
map< int, Xdim > desc_data
describe for each y, the x dimension's size and range
Definition: polardata.h:126
int get_xsize(int y)
get the x dim size for a given y
Definition: polardata.h:66
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define LOGERR
Definition: log.h:51
E2Exception class.
Definition: aligner.h:40
#define y(i, j)
Definition: projector.cpp:1516