Xmipp  v3.23.11-Nereus
reconstruct_fourier_buffer_data.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef XMIPP_LIBRARIES_DATA_RECONSTRUCT_FOURIER_BUFFER_DATA_H_
27 #define XMIPP_LIBRARIES_DATA_RECONSTRUCT_FOURIER_BUFFER_DATA_H_
28 
31 
43 {
50  int fftSizeX, int fftSizeY, int paddedImgSize,
51  int maxNoOfImages, int noOfSymmetries) :
52  hasFFTs(hasFFTs), hasCTFs(hasCTFs),
53  fftSizeX(fftSizeX), fftSizeY(fftSizeY), paddedImgSize(paddedImgSize),
54  maxNoOfImages(maxNoOfImages),noOfSymmetries(noOfSymmetries), noOfImages(0) {
55  spaces = memoryUtils::page_aligned_alloc<RecFourierProjectionTraverseSpace>(maxNoOfImages * noOfSymmetries, false);
56  if (hasFFTs) {
57  paddedImages = nullptr;
58  FFTs = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages * 2, true); // *2 since it's complex
59  } else {
60  FFTs = nullptr;
61  paddedImages = memoryUtils::page_aligned_alloc<float>(paddedImgSize * paddedImgSize * maxNoOfImages, true);
62  }
63 
64  if (hasCTFs) {
65  CTFs = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages, true);
66  modulators = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages, true);
67  } else {
68  CTFs = modulators = nullptr;
69  }
70  };
71 
73  free(FFTs);
74  free(CTFs);
77  FFTs = CTFs = paddedImages = modulators = nullptr;
78 
79  free(spaces);
80  spaces = nullptr;
81  }
82 
88  }
89 
94  return getPaddedImgSize() * sizeof(float);
95  }
96 
101  return getNoOfElements(FFTs) * sizeof(float);
102  }
103 
109  float* getNthItem(float* array, int itemIndex) {
110  if (array == FFTs) return array + (fftSizeX * fftSizeY * itemIndex * 2); // *2 since it's complex
111  if (array == CTFs) return array + (fftSizeX * fftSizeY * itemIndex);
112  if (array == modulators) return array + (fftSizeX * fftSizeY * itemIndex);
113  if (array == paddedImages) return array + (paddedImgSize * paddedImgSize * itemIndex);
114  return nullptr; // undefined
115  }
116 
121  int getNoOfElements(float* array) {
122  if (array == FFTs) return (fftSizeX * fftSizeY * noOfImages * 2); // *2 since it's complex
123  if (array == CTFs) return (fftSizeX * fftSizeY * noOfImages);
124  if (array == modulators) return (fftSizeX * fftSizeY * noOfImages);
125  if (array == paddedImages) return (paddedImgSize * paddedImgSize * noOfImages);
126  return -1; // undefined
127  }
128 
134  return noOfImages * noOfSymmetries;
135  }
136 
141  int getMaxByteSize(float* array) {
142  if (array == FFTs) return (fftSizeX * fftSizeY * maxNoOfImages * 2 * sizeof(float)); // *2 since it's complex
143  if (array == CTFs) return (fftSizeX * fftSizeY * maxNoOfImages * sizeof(float));
144  if (array == modulators) return (fftSizeX * fftSizeY * maxNoOfImages * sizeof(float));
145  if (array == paddedImages) return (paddedImgSize * paddedImgSize * maxNoOfImages * sizeof(float));
146  return -1; // undefined
147  }
148 
154  if (array == spaces) return (noOfSymmetries * maxNoOfImages * sizeof(RecFourierProjectionTraverseSpace));
155  return -1; // undefined
156  }
157 
158  // holds 'right side of the centered FFT', i.e. only unique values, with high frequencies in the corners
159  float* FFTs;
160  // holds CTF correction for each pixel of FFT
161  float* CTFs;
162  // holds correction for each pixel of FFT
163  float* modulators;
168  float* paddedImages;
169  // holds spaces for each FFT
171 
172  int fftSizeX;
173  int fftSizeY;
174  int paddedImgSize; // paddedImage is squared
175  int noOfImages; // currently stored in buffer
176  int maxNoOfImages; // that can be stored in the buffer
182  bool hasFFTs;
183  bool hasCTFs; // if 'true', CTF correction data are present in 'CTFs' and 'modulators'
184 
190  void invalidate() {
191  hasCTFs = hasFFTs = false;
192  noOfImages = fftSizeX = fftSizeY = paddedImgSize
193  = maxNoOfImages = noOfSymmetries = -1;
194 
195  FFTs = CTFs = paddedImages = modulators = nullptr;
196  spaces = nullptr;
197  }
198 
199 protected:
201 };
202 
203 
204 #endif /* XMIPP_LIBRARIES_DATA_RECONSTRUCT_FOURIER_BUFFER_DATA_H_ */
int getNoOfElements(RecFourierProjectionTraverseSpace *array)
float * getNthItem(float *array, int itemIndex)
RecFourierBufferData(bool hasFFTs, bool hasCTFs, int fftSizeX, int fftSizeY, int paddedImgSize, int maxNoOfImages, int noOfSymmetries)
free((char *) ob)
RecFourierProjectionTraverseSpace * spaces
int getMaxByteSize(RecFourierProjectionTraverseSpace *array)