1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
/*
-----------------------------------------------------------------------
Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
2014-2015, CWI, Amsterdam
Contact: astra@uantwerpen.be
Website: http://sf.net/projects/astra-toolbox
This file is part of the ASTRA Toolbox.
The ASTRA Toolbox is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The ASTRA Toolbox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------
$Id$
*/
#include "astra/ParallelBeamBlobKernelProjector2D.h"
#include <cmath>
#include <boost/lexical_cast.hpp>
#include "astra/DataProjectorPolicies.h"
using namespace std;
using namespace astra;
#include "astra/ParallelBeamBlobKernelProjector2D.inl"
// type of the projector, needed to register with CProjectorFactory
std::string CParallelBeamBlobKernelProjector2D::type = "blob";
//----------------------------------------------------------------------------------------
// default constructor
CParallelBeamBlobKernelProjector2D::CParallelBeamBlobKernelProjector2D()
{
_clear();
}
//----------------------------------------------------------------------------------------
// constructor
CParallelBeamBlobKernelProjector2D::CParallelBeamBlobKernelProjector2D(CParallelProjectionGeometry2D* _pProjectionGeometry,
CVolumeGeometry2D* _pReconstructionGeometry,
float32 _fBlobSize,
float32 _fBlobSampleRate,
int _iBlobSampleCount,
float32* _pfBlobValues)
{
_clear();
initialize(_pProjectionGeometry, _pReconstructionGeometry, _fBlobSize, _fBlobSampleRate, _iBlobSampleCount, _pfBlobValues);
}
//----------------------------------------------------------------------------------------
// destructor
CParallelBeamBlobKernelProjector2D::~CParallelBeamBlobKernelProjector2D()
{
clear();
}
//---------------------------------------------------------------------------------------
// Clear - Constructors
void CParallelBeamBlobKernelProjector2D::_clear()
{
CProjector2D::_clear();
m_pfBlobValues = NULL;
m_iBlobSampleCount = 0;
m_fBlobSize = 0;
m_fBlobSampleRate = 0;
m_bIsInitialized = false;
}
//---------------------------------------------------------------------------------------
// Clear - Public
void CParallelBeamBlobKernelProjector2D::clear()
{
CProjector2D::clear();
if (m_pfBlobValues) {
delete[] m_pfBlobValues;
m_pfBlobValues = NULL;
}
m_iBlobSampleCount = 0;
m_fBlobSize = 0;
m_fBlobSampleRate = 0;
m_bIsInitialized = false;
}
//---------------------------------------------------------------------------------------
// Check
bool CParallelBeamBlobKernelProjector2D::_check()
{
// check base class
ASTRA_CONFIG_CHECK(CProjector2D::_check(), "ParallelBeamBlobKernelProjector2D", "Error in Projector2D initialization");
ASTRA_CONFIG_CHECK(dynamic_cast<CParallelProjectionGeometry2D*>(m_pProjectionGeometry) || dynamic_cast<CParallelVecProjectionGeometry2D*>(m_pProjectionGeometry), "ParallelBeamBlobKernelProjector2D", "Unsupported projection geometry");
ASTRA_CONFIG_CHECK(m_iBlobSampleCount > 0, "ParallelBeamBlobKernelProjector2D", "m_iBlobSampleCount should be strictly positive.");
ASTRA_CONFIG_CHECK(m_pfBlobValues, "ParallelBeamBlobKernelProjector2D", "Invalid Volume Geometry Object.");
// success
return true;
}
//---------------------------------------------------------------------------------------
// Initialize, use a Config object
bool CParallelBeamBlobKernelProjector2D::initialize(const Config& _cfg)
{
ASTRA_ASSERT(_cfg.self);
// if already initialized, clear first
if (m_bIsInitialized) {
clear();
}
// initialization of parent class
if (!CProjector2D::initialize(_cfg)) {
return false;
}
// required: Kernel
XMLNode node = _cfg.self.getSingleNode("Kernel");
ASTRA_CONFIG_CHECK(node, "BlobProjector", "No Kernel tag specified.");
{
// Required: KernelSize
XMLNode node2 = node.getSingleNode("KernelSize");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelSize tag specified.");
m_fBlobSize = boost::lexical_cast<float32>(node2.getContent());
// Required: SampleRate
node2 = node.getSingleNode("SampleRate");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleRate tag specified.");
m_fBlobSampleRate = boost::lexical_cast<float32>(node2.getContent());
// Required: SampleCount
node2 = node.getSingleNode("SampleCount");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleCount tag specified.");
m_iBlobSampleCount = boost::lexical_cast<int>(node2.getContent());
// Required: KernelValues
node2 = node.getSingleNode("KernelValues");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelValues tag specified.");
vector<float32> values = node2.getContentNumericalArray();
ASTRA_CONFIG_CHECK(values.size() == (unsigned int)m_iBlobSampleCount, "BlobProjector", "Number of specified values doesn't match SampleCount.");
m_pfBlobValues = new float32[m_iBlobSampleCount];
for (int i = 0; i < m_iBlobSampleCount; i++) {
m_pfBlobValues[i] = values[i];
}
}
// success
m_bIsInitialized = _check();
return m_bIsInitialized;
}
//----------------------------------------------------------------------------------------
// initialize
bool CParallelBeamBlobKernelProjector2D::initialize(CParallelProjectionGeometry2D* _pProjectionGeometry,
CVolumeGeometry2D* _pVolumeGeometry,
float32 _fBlobSize,
float32 _fBlobSampleRate,
int _iBlobSampleCount,
float32* _pfBlobValues)
{
// if already initialized, clear first
if (m_bIsInitialized) {
clear();
}
ASTRA_CONFIG_CHECK(_pProjectionGeometry, "BlobProjector", "Invalid ProjectionGeometry Object");
ASTRA_CONFIG_CHECK(m_pVolumeGeometry, "BlobProjector", "Invalid ProjectionGeometry Object");
m_pProjectionGeometry = _pProjectionGeometry->clone();
m_pVolumeGeometry = _pVolumeGeometry->clone();
m_fBlobSize = _fBlobSize;
m_fBlobSampleRate = _fBlobSampleRate;
m_iBlobSampleCount = _iBlobSampleCount;
m_pfBlobValues = new float32[_iBlobSampleCount];
for (int i = 0; i <_iBlobSampleCount; i++) {
m_pfBlobValues[i] = _pfBlobValues[i];
}
// success
m_bIsInitialized = _check();
return m_bIsInitialized;
}
//----------------------------------------------------------------------------------------
// Get maximum amount of weights on a single ray
int CParallelBeamBlobKernelProjector2D::getProjectionWeightsCount(int _iProjectionIndex)
{
int maxDim = max(m_pVolumeGeometry->getGridRowCount(), m_pVolumeGeometry->getGridColCount());
return (int)(maxDim * 2 * (m_fBlobSize+2) + 1);
}
//----------------------------------------------------------------------------------------
// Single Ray Weights
void CParallelBeamBlobKernelProjector2D::computeSingleRayWeights(int _iProjectionIndex,
int _iDetectorIndex,
SPixelWeight* _pWeightedPixels,
int _iMaxPixelCount,
int& _iStoredPixelCount)
{
ASTRA_ASSERT(m_bIsInitialized);
StorePixelWeightsPolicy p(_pWeightedPixels, _iMaxPixelCount);
projectSingleRay(_iProjectionIndex, _iDetectorIndex, p);
_iStoredPixelCount = p.getStoredPixelCount();
}
//----------------------------------------------------------------------------------------
// Splat a single point
std::vector<SDetector2D> CParallelBeamBlobKernelProjector2D::projectPoint(int _iRow, int _iCol)
{
// float32 x = m_pVolumeGeometry->pixelColToCenterX(_iCol);
// float32 y = m_pVolumeGeometry->pixelRowToCenterY(_iRow);
// std::vector<SDetector2D> res;
// // loop projectors and detectors
// for (int iProjection = 0; iProjection < m_pProjectionGeometry->getProjectionAngleCount(); ++iProjection) {
// // get projection angle
// float32 theta = m_pProjectionGeometry->getProjectionAngle(iProjection);
// if (theta >= 7*PIdiv4) theta -= 2*PI;
// bool inverse = false;
// if (theta >= 3*PIdiv4) {
// theta -= PI;
// inverse = true;
// }
// // calculate distance from the center of the voxel to the ray though the origin
// float32 t = x * cos(theta) + y * sin(theta);
// if (inverse) t *= -1.0f;
// // calculate the offset on the detectorarray (in indices)
// float32 d = m_pProjectionGeometry->detectorOffsetToIndexFloat(t);
// int dmin = (int)ceil(d - m_fBlobSize);
// int dmax = (int)floor(d + m_fBlobSize);
// // add affected detectors to the list
// for (int i = dmin; i <= dmax; ++i) {
// if (d >= 0 && d < m_pProjectionGeometry->getDetectorCount()) {
// SDetector2D det;
// det.m_iAngleIndex = iProjection;
// det.m_iDetectorIndex = i;
// det.m_iIndex = iProjection * getProjectionGeometry()->getDetectorCount() + i;
// res.push_back(det);
// }
// }
// }
// // return result vector
// return res;
return std::vector<SDetector2D>();
}
|