summaryrefslogtreecommitdiffstats
path: root/include/astra/DataProjector.h
blob: 15a540f08dd21300cead81659915167e8c7b1652 (plain)
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
-----------------------------------------------------------------------
Copyright: 2010-2018, imec Vision Lab, University of Antwerp
           2014-2018, CWI, Amsterdam

Contact: astra@astra-toolbox.com
Website: http://www.astra-toolbox.com/

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/>.

-----------------------------------------------------------------------
*/

#ifndef _INC_ASTRA_DATAPROJECTOR
#define _INC_ASTRA_DATAPROJECTOR

#include "Projector2D.h"

#include "TypeList.h"

#include "ProjectorTypelist.h"

#include "DataProjectorPolicies.h"

namespace astra
{


/**
 * Interface class for the Data Projector. The sole purpose of this class is to force child classes to implement a series of methods
 */
class CDataProjectorInterface {
public:
	CDataProjectorInterface() { }
	virtual ~CDataProjectorInterface() { }
	virtual void project() = 0;
	virtual void projectSingleProjection(int _iProjection) = 0;
	virtual void projectSingleRay(int _iProjection, int _iDetector) = 0;
//	virtual void projectSingleVoxel(int _iRow, int _iCol) = 0;
//	virtual void projectAllVoxels() = 0;
};

/**
 * Templated Data Projector Class. In this class a specific projector and policies are combined.
 */
template <typename Projector, typename Policy>
class CDataProjector: public CDataProjectorInterface {

private:

	Projector* m_pProjector;
	Policy m_pPolicy;

public:

	CDataProjector() {};

	CDataProjector(Projector* _p, Policy _a);
	~CDataProjector();

	virtual void project();

	virtual void projectSingleProjection(int _iProjection);

	virtual void projectSingleRay(int _iProjection, int _iDetector);

//	virtual void projectSingleVoxel(int _iRow, int _iCol);

//	virtual void projectAllVoxels();
};

//----------------------------------------------------------------------------------------
/**
 * Constructor
*/
template <typename Projector, typename Policy>
CDataProjector<Projector,Policy>::CDataProjector(Projector* _p, Policy _a) 
{ 
	m_pProjector = _p;
	m_pPolicy = _a; 
}

//----------------------------------------------------------------------------------------
/**
 * Destructor
*/
template <typename Projector, typename Policy>
CDataProjector<Projector,Policy>::~CDataProjector() 
{ 
	// does nothing
}

//----------------------------------------------------------------------------------------
/**
 * Compute projection using the algorithm specific to the projector type
*/
template <typename Projector, typename Policy>
void CDataProjector<Projector,Policy>::project() 
{ 
	m_pProjector->project(m_pPolicy);
}

//----------------------------------------------------------------------------------------
/**
 * Compute just one projection using the algorithm specific to the projector type
*/
template <typename Projector, typename Policy>
void CDataProjector<Projector,Policy>::projectSingleProjection(int _iProjection) 
{ 
	m_pProjector->projectSingleProjection(_iProjection, m_pPolicy);
}

//----------------------------------------------------------------------------------------
/**
 * Compute projection of one ray using the algorithm specific to the projector type
*/
template <typename Projector, typename Policy>
void CDataProjector<Projector,Policy>::projectSingleRay(int _iProjection, int _iDetector)
{ 
	m_pProjector->projectSingleRay(_iProjection, _iDetector, m_pPolicy);
}

//----------------------------------------------------------------------------------------
//template <typename Projector, typename Policy>
//void CDataProjector<Projector,Policy>::projectSingleVoxel(int _iRow, int _iCol) 
//{ 
//	m_pProjector->projectSingleVoxel(_iRow, _iCol, m_pPolicy);
//}

//----------------------------------------------------------------------------------------
//template <typename Projector, typename Policy>
//void CDataProjector<Projector,Policy>::projectAllVoxels() 
//{ 
//	m_pProjector->projectAllVoxels(m_pPolicy);
//}
//----------------------------------------------------------------------------------------




//-----------------------------------------------------------------------------------------
// Create a new datainterface from the projector TypeList
namespace typelist {
	template <class TList> 
	struct CreateDataProjector { 
		template <class U, typename Policy>
		 static void find (U& functor, CProjector2D* _pProjector, const Policy& _pPolicy) {
			 if (functor(TList::Head::type)) {
				functor.res = new CDataProjector<typename TList::Head, Policy>(static_cast<typename TList::Head*>(_pProjector), _pPolicy);
			 }
			 CreateDataProjector<typename TList::Tail>::find(functor, _pProjector, _pPolicy); 
		 }
	}; 
	template <> 
	struct CreateDataProjector<NullType> {
		template <class U, typename Policy> 
		static void find(U& functor, CProjector2D* _pProjector, const Policy& _pPolicy) {}
	}; 

	struct functor_find_datainterface {
		functor_find_datainterface() { res = NULL; }
		bool operator() (std::string name) { 
			return strcmp(tofind.c_str(), name.c_str()) == 0;
		} 
		std::string tofind;
		CDataProjectorInterface* res;
	};
}
//-----------------------------------------------------------------------------------------

/**
 * Data Projector Dispatcher - 1 Policy
 */
template <typename Policy>
static CDataProjectorInterface* dispatchDataProjector(CProjector2D* _pProjector, const Policy& _policy)
{
	typelist::functor_find_datainterface finder = typelist::functor_find_datainterface();
	finder.tofind = _pProjector->getType();
	typelist::CreateDataProjector<Projector2DTypeList>::find(finder, _pProjector, _policy);
	return finder.res;
}



/**
 * Data Projector Dispatcher - 2 Policies
 */
template <typename Policy1, typename Policy2>
static CDataProjectorInterface* dispatchDataProjector(CProjector2D* _pProjector, 
													  const Policy1& _policy,
													  const Policy2& _policy2,
													  bool _bUsePolicy1 = true, 
													  bool _bUsePolicy2 = true) 
{
	if (!_bUsePolicy1 && !_bUsePolicy2) {
		return dispatchDataProjector(_pProjector, EmptyPolicy());
	} else if (!_bUsePolicy1) {
		return dispatchDataProjector(_pProjector, _policy2);
	} else if (!_bUsePolicy2) {
		return dispatchDataProjector(_pProjector, _policy);
	} else {
		return dispatchDataProjector(_pProjector, CombinePolicy<Policy1, Policy2>(_policy, _policy2));
	}
	
}

/**
 * Data Projector Dispatcher - 3 Policies
 */

template <typename Policy1, typename Policy2, typename Policy3>
static CDataProjectorInterface* dispatchDataProjector(CProjector2D* _pProjector, 
													  const Policy1& _policy1,
													  const Policy2& _policy2,
													  const Policy3& _policy3,
													  bool _bUsePolicy1 = true, 
													  bool _bUsePolicy2 = true,
													  bool _bUsePolicy3 = true) 
{
	if (!_bUsePolicy1) {
		return dispatchDataProjector(_pProjector, _policy2, _policy3, _bUsePolicy2, _bUsePolicy3);
	} else if (!_bUsePolicy2) {
		return dispatchDataProjector(_pProjector, _policy1, _policy3, _bUsePolicy1, _bUsePolicy3);
	} else if (!_bUsePolicy3) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _bUsePolicy1, _bUsePolicy2);
	} else {
		return dispatchDataProjector(_pProjector, Combine3Policy<Policy1, Policy2, Policy3>(_policy1, _policy2, _policy3));
	}
}

/**
 * Data Projector Dispatcher - 4 Policies
 */
template <typename Policy1, typename Policy2, typename Policy3, typename Policy4>
static CDataProjectorInterface* dispatchDataProjector(CProjector2D* _pProjector, 
													  const Policy1& _policy1,
													  const Policy2& _policy2,
													  const Policy3& _policy3,
													  const Policy4& _policy4,
													  bool _bUsePolicy1 = true, 
													  bool _bUsePolicy2 = true,
													  bool _bUsePolicy3 = true,
													  bool _bUsePolicy4 = true) 
{
	if (!_bUsePolicy1) {
		return dispatchDataProjector(_pProjector, _policy2, _policy3, _policy4, _bUsePolicy2, _bUsePolicy3, _bUsePolicy4);
	} else if (!_bUsePolicy2) {
		return dispatchDataProjector(_pProjector, _policy1, _policy3, _policy4, _bUsePolicy1, _bUsePolicy3, _bUsePolicy4);
	} else if (!_bUsePolicy3) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _policy4, _bUsePolicy1, _bUsePolicy2, _bUsePolicy4);
	} else if (!_bUsePolicy4) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _policy3, _bUsePolicy1, _bUsePolicy2, _bUsePolicy3);
	} else {
		return dispatchDataProjector(_pProjector, Combine4Policy<Policy1, Policy2, Policy3, Policy4>(_policy1, _policy2, _policy3, _policy4));
	}
}

/**
 * Data Projector Dispatcher - 5 Policies
 */
template <typename Policy1, typename Policy2, typename Policy3, typename Policy4, typename Policy5>
static CDataProjectorInterface* dispatchDataProjector(CProjector2D* _pProjector, 
													  const Policy1& _policy1,
													  const Policy2& _policy2,
													  const Policy3& _policy3,
													  const Policy4& _policy4,
													  const Policy5& _policy5,
													  bool _bUsePolicy1 = true, 
													  bool _bUsePolicy2 = true,
													  bool _bUsePolicy3 = true,
													  bool _bUsePolicy4 = true,
													  bool _bUsePolicy5 = true) 
{
	if (!_bUsePolicy1) {
		return dispatchDataProjector(_pProjector, _policy2, _policy3, _policy4, _policy5, _bUsePolicy2, _bUsePolicy3, _bUsePolicy4, _bUsePolicy5);
	} else if (!_bUsePolicy2) {
		return dispatchDataProjector(_pProjector, _policy1, _policy3, _policy4, _policy5, _bUsePolicy1, _bUsePolicy3, _bUsePolicy4, _bUsePolicy5);
	} else if (!_bUsePolicy3) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _policy4, _policy5, _bUsePolicy1, _bUsePolicy2, _bUsePolicy4, _bUsePolicy5);
	} else if (!_bUsePolicy4) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _policy3, _policy5, _bUsePolicy1, _bUsePolicy2, _bUsePolicy3, _bUsePolicy5);
	} else if (!_bUsePolicy5) {
		return dispatchDataProjector(_pProjector, _policy1, _policy2, _policy3, _policy4, _bUsePolicy1, _bUsePolicy2, _bUsePolicy3, _bUsePolicy4);
	} else {
		return dispatchDataProjector(_pProjector, CombinePolicy< Combine4Policy<Policy1, Policy2, Policy3, Policy4>, Policy5>(
														Combine4Policy<Policy1, Policy2, Policy3, Policy4>(_policy1, _policy2, _policy3, _policy4), 
														_policy5)
									);
	}
}




//-----------------------------------------------------------------------------------------
/**
 * Data Projector Project
 */
template <typename Policy>
static void projectData(CProjector2D* _pProjector, const Policy& _policy)
{
	CDataProjectorInterface* dp = dispatchDataProjector(_pProjector, _policy);
	dp->project();
	delete dp;
}




} // namespace astra

#endif