ForEachUnaryVoxelFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * ATTENTION: This source file has been automatically generated using the code
20  * generator mirtkForEachVoxelFunction.py! This generator is
21  * invoked during CMake configuration of the build system when this
22  * source file is missing from the project.
23  *
24  * DO NOT modify this file manually. Instead, modify the code
25  * generator, remove any existing mirtkForEach*VoxelFunction.h
26  * header file from the include/ directory and then re-run CMake.
27  * This will invoke the code generator to re-generate the source files.
28  */
29 
30 #ifndef MIRTK_ForEachUnaryVoxelFunction_H
31 #define MIRTK_ForEachUnaryVoxelFunction_H
32 
33 #include "mirtk/Stream.h"
34 #include "mirtk/VoxelFunction.h"
35 
36 
37 namespace mirtk {
38 
39 
40 inline void _foreachunaryvoxelfunction_must_not_be_reduction()
41 {
42  cerr << "(Parallel)ForEachVoxel(If): Voxel reductions must be passed by reference!"
43  " Pass voxel functor object(s) as last argument(s) instead of first." << endl;
44  exit(1);
45 }
46 
47 
48 // =============================================================================
49 // 1 const image
50 // =============================================================================
51 
52 // -----------------------------------------------------------------------------
53 /**
54  * ForEachVoxel body for voxel function of 1 const image
55  */
56 template <class T1, class VoxelFunc>
58 {
59  const GenericImage<T1> &im1;
60 
61  /// Constructor
63  VoxelFunc &vf)
64  :
65  ForEachVoxelBody<VoxelFunc>(vf, im1.Attributes()), im1(im1)
66  {}
67 
68  /// Copy constructor
70  :
71  ForEachVoxelBody<VoxelFunc>(o), im1(o.im1)
72  {}
73 
74  /// Split constructor
76  :
77  ForEachVoxelBody<VoxelFunc>(o, s), im1(o.im1)
78  {}
79 
80  /// Process entire image
81  void operator ()(const ImageAttributes &attr) const
82  {
83  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels();
84 
85  const int T = (attr._dt ? attr._t : 1);
86 
87  for (int l = 0; l < T; ++l)
88  for (int k = 0; k < attr._z; ++k)
89  for (int j = 0; j < attr._y; ++j)
90  for (int i = 0; i < attr._x; ++i, ++p1) {
91  // const_cast such that voxel functions need only implement
92  // non-const operator() which is required for parallel_reduce
93  const_cast<UnaryForEachVoxelBody_Const *>(this)->_VoxelFunc(i, j, k, l, p1);
94  }
95  }
96 
97  /// Process image region using linear index
98  void operator ()(const blocked_range<int> &re) const
99  {
100  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels() + re.begin();
101 
102  for (int idx = re.begin(); idx < re.end(); ++idx, p1 += 1) {
103  // const_cast such that voxel functions need only implement
104  // non-const operator() which is required for parallel_reduce
105  const_cast<UnaryForEachVoxelBody_Const *>(this)->_VoxelFunc(im1, idx, p1);
106  }
107  }
108 
109  /// Process 2D image region
110  void operator ()(const blocked_range2d<int> &re) const
111  {
112  const int bi = re.cols().begin();
113  const int bj = re.rows().begin();
114  const int ei = re.cols().end();
115  const int ej = re.rows().end();
116 
117  const int s1 = im1.GetX() - (ei - bi);
118 
119  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, this->_k, this->_l);
120 
121  for (int j = bj; j < ej; ++j, p1 += s1)
122  for (int i = bi; i < ei; ++i, p1 += 1) {
123  // const_cast such that voxel functions need only implement
124  // non-const operator() which is required for parallel_reduce
125  const_cast<UnaryForEachVoxelBody_Const *>(this)->_VoxelFunc(i, j, this->_k, this->_l, p1);
126  }
127  }
128 
129  /// Process 3D image region
130  void operator ()(const blocked_range3d<int> &re) const
131  {
132  const int bi = re.cols ().begin();
133  const int bj = re.rows ().begin();
134  const int bk = re.pages().begin();
135  const int ei = re.cols ().end();
136  const int ej = re.rows ().end();
137  const int ek = re.pages().end();
138 
139  const int s1 = im1.GetX() - (ei - bi);
140  const int s2 = (im1.GetY() - (ej - bj)) * im1.GetX();
141 
142  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, bk, this->_l);
143 
144  for (int k = bk; k < ek; ++k, p1 += s2)
145  for (int j = bj; j < ej; ++j, p1 += s1)
146  for (int i = bi; i < ei; ++i, p1 += 1) {
147  // const_cast such that voxel functions need only implement
148  // non-const operator() which is required for parallel_reduce
149  const_cast<UnaryForEachVoxelBody_Const *>(this)->_VoxelFunc(i, j, k, this->_l, p1);
150  }
151  }
152 };
153 
154 // -----------------------------------------------------------------------------
155 /**
156  * ForEachVoxel body for inside and outside unary voxel function of 1 const image
157  */
158 template <class T1,
159  class VoxelFunc, class OutsideFunc = NaryVoxelFunction::NOP,
160  class Domain = ForEachVoxelDomain::Foreground>
161 struct UnaryForEachVoxelIfBody_Const : public ForEachVoxelIfBody<VoxelFunc, OutsideFunc>
162 {
163  const GenericImage<T1> &im1;
164 
165  /// Constructor
167  VoxelFunc &vf, OutsideFunc &of)
168  :
169  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(vf, of, im1.Attributes()), im1(im1)
170  {}
171 
172  /// Copy constructor
174  :
175  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(o), im1(o.im1)
176  {}
177 
178  /// Split constructor
180  :
181  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(o, s), im1(o.im1)
182  {}
183 
184  /// Process entire image
185  void operator ()(const ImageAttributes &attr) const
186  {
187  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels();
188 
189  const int T = (attr._dt ? attr._t : 1);
190 
191  for (int l = 0; l < T; ++l)
192  for (int k = 0; k < attr._z; ++k)
193  for (int j = 0; j < attr._y; ++j)
194  for (int i = 0; i < attr._x; ++i, ++p1) {
195  if (Domain::IsInside(im1, i, j, k, l, p1)) {
196  // const_cast such that voxel functions need only implement
197  // non-const operator() which is required for parallel_reduce
198  const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_VoxelFunc (i, j, k, l, p1);
199  } else const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_OutsideFunc(i, j, k, l, p1);
200  }
201  }
202 
203  /// Process image region using linear index
204  void operator ()(const blocked_range<int> &re) const
205  {
206  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels() + re.begin();
207 
208  for (int idx = re.begin(); idx < re.end(); ++idx, p1 += 1) {
209  if (Domain::IsInside(im1, idx, p1)) {
210  // const_cast such that voxel functions need only implement
211  // non-const operator() which is required for parallel_reduce
212  const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_VoxelFunc (im1, idx, p1);
213  } else const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_OutsideFunc(im1, idx, p1);
214  }
215  }
216 
217  /// Process 2D image region
218  void operator ()(const blocked_range2d<int> &re) const
219  {
220  const int bi = re.cols().begin();
221  const int bj = re.rows().begin();
222  const int ei = re.cols().end();
223  const int ej = re.rows().end();
224 
225  const int s1 = im1.GetX() - (ei - bi);
226 
227  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, this->_k, this->_l);
228 
229  for (int j = bj; j < ej; ++j, p1 += s1)
230  for (int i = bi; i < ei; ++i, p1 += 1) {
231  if (Domain::IsInside(im1, i, j, this->_k, this->_l, p1)) {
232  // const_cast such that voxel functions need only implement
233  // non-const operator() which is required for parallel_reduce
234  const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_VoxelFunc (i, j, this->_k, this->_l, p1);
235  } else const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_OutsideFunc(i, j, this->_k, this->_l, p1);
236  }
237  }
238 
239  /// Process 3D image region
240  void operator ()(const blocked_range3d<int> &re) const
241  {
242  const int bi = re.cols ().begin();
243  const int bj = re.rows ().begin();
244  const int bk = re.pages().begin();
245  const int ei = re.cols ().end();
246  const int ej = re.rows ().end();
247  const int ek = re.pages().end();
248 
249  const int s1 = im1.GetX() - (ei - bi);
250  const int s2 = (im1.GetY() - (ej - bj)) * im1.GetX();
251 
252  const T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, bk, this->_l);
253 
254  for (int k = bk; k < ek; ++k, p1 += s2)
255  for (int j = bj; j < ej; ++j, p1 += s1)
256  for (int i = bi; i < ei; ++i, p1 += 1) {
257  if (Domain::IsInside(im1, i, j, k, this->_l, p1)) {
258  // const_cast such that voxel functions need only implement
259  // non-const operator() which is required for parallel_reduce
260  const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_VoxelFunc (i, j, k, this->_l, p1);
261  } else const_cast<UnaryForEachVoxelIfBody_Const *>(this)->_OutsideFunc(i, j, k, this->_l, p1);
262  }
263  }
264 };
265 
266 // -----------------------------------------------------------------------------
267 // ForEachVoxel
268 // -----------------------------------------------------------------------------
269 
270 //
271 // Image arguments by pointer
272 //
273 
274 // -----------------------------------------------------------------------------
275 template <class T1, class VoxelFunc>
276 void ForEachScalar(const GenericImage<T1> *im1, VoxelFunc &vf)
277 {
280  body(re);
281  vf.join(body._VoxelFunc);
282 }
283 
284 // -----------------------------------------------------------------------------
285 template <class T1, class VoxelFunc>
286 void ForEachScalar(VoxelFunc vf, const GenericImage<T1> *im1)
287 {
288  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
289  ForEachScalar(*im1, vf);
290 }
291 
292 // -----------------------------------------------------------------------------
293 template <class T1, class VoxelFunc>
294 void ForEachVoxel(const GenericImage<T1> *im1, VoxelFunc &vf)
295 {
296  if (im1->GetTSize()) {
297  ForEachScalar(*im1, vf);
298  } else {
300  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
301  body(re);
302  vf.join(body._VoxelFunc);
303  }
304 }
305 
306 // -----------------------------------------------------------------------------
307 template <class T1, class VoxelFunc>
308 void ForEachVoxel(VoxelFunc vf, const GenericImage<T1> *im1)
309 {
310  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
311  ForEachVoxel(*im1, vf);
312 }
313 
314 // -----------------------------------------------------------------------------
315 template <class T1, class VoxelFunc>
316 void ForEachVoxel(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf)
317 {
319  body(attr);
320  vf.join(body._VoxelFunc);
321 }
322 
323 // -----------------------------------------------------------------------------
324 template <class T1, class VoxelFunc>
325 void ForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> *im1)
326 {
327  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
328  ForEachVoxel(attr, *im1, vf);
329 }
330 
331 // -----------------------------------------------------------------------------
332 template <class T1, class VoxelFunc>
333 void ForEachVoxel(const blocked_range<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
334 {
336  body(re);
337  vf.join(body._VoxelFunc);
338 }
339 
340 // -----------------------------------------------------------------------------
341 template <class T1, class VoxelFunc>
342 void ForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> *im1)
343 {
344  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
345  ForEachVoxel(re, *im1, vf);
346 }
347 
348 // -----------------------------------------------------------------------------
349 template <class T1, class VoxelFunc>
350 void ForEachVoxel(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
351 {
353  body(re);
354  vf.join(body._VoxelFunc);
355 }
356 
357 // -----------------------------------------------------------------------------
358 template <class T1, class VoxelFunc>
359 void ForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
360 {
361  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
362  ForEachVoxel(re, *im1, vf);
363 }
364 
365 // -----------------------------------------------------------------------------
366 template <class T1, class VoxelFunc>
367 void ForEachVoxel(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
368 {
370  body(re);
371  vf.join(body._VoxelFunc);
372 }
373 
374 // -----------------------------------------------------------------------------
375 template <class T1, class VoxelFunc>
376 void ForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
377 {
378  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
379  ForEachVoxel(re, *im1, vf);
380 }
381 
382 //
383 // Image arguments by reference
384 //
385 
386 // -----------------------------------------------------------------------------
387 template <class T1, class VoxelFunc>
388 void ForEachScalar(const GenericImage<T1> &im1, VoxelFunc &vf)
389 {
392  body(re);
393  vf.join(body._VoxelFunc);
394 }
395 
396 // -----------------------------------------------------------------------------
397 template <class T1, class VoxelFunc>
398 void ForEachScalar(VoxelFunc vf, const GenericImage<T1> &im1)
399 {
400  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
401  ForEachScalar(im1, vf);
402 }
403 
404 // -----------------------------------------------------------------------------
405 template <class T1, class VoxelFunc>
406 void ForEachVoxel(const GenericImage<T1> &im1, VoxelFunc &vf)
407 {
408  if (im1.GetTSize()) {
409  ForEachScalar(im1, vf);
410  } else {
412  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
413  body(re);
414  vf.join(body._VoxelFunc);
415  }
416 }
417 
418 // -----------------------------------------------------------------------------
419 template <class T1, class VoxelFunc>
420 void ForEachVoxel(VoxelFunc vf, const GenericImage<T1> &im1)
421 {
422  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
423  ForEachVoxel(im1, vf);
424 }
425 
426 // -----------------------------------------------------------------------------
427 template <class T1, class VoxelFunc>
428 void ForEachVoxel(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf)
429 {
431  body(attr);
432  vf.join(body._VoxelFunc);
433 }
434 
435 // -----------------------------------------------------------------------------
436 template <class T1, class VoxelFunc>
437 void ForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> &im1)
438 {
439  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
440  ForEachVoxel(attr, im1, vf);
441 }
442 
443 // -----------------------------------------------------------------------------
444 template <class T1, class VoxelFunc>
445 void ForEachVoxel(const blocked_range<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
446 {
448  body(re);
449  vf.join(body._VoxelFunc);
450 }
451 
452 // -----------------------------------------------------------------------------
453 template <class T1, class VoxelFunc>
454 void ForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> &im1)
455 {
456  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
457  ForEachVoxel(re, im1, vf);
458 }
459 
460 // -----------------------------------------------------------------------------
461 template <class T1, class VoxelFunc>
462 void ForEachVoxel(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
463 {
465  body(re);
466  vf.join(body._VoxelFunc);
467 }
468 
469 // -----------------------------------------------------------------------------
470 template <class T1, class VoxelFunc>
471 void ForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
472 {
473  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
474  ForEachVoxel(re, im1, vf);
475 }
476 
477 // -----------------------------------------------------------------------------
478 template <class T1, class VoxelFunc>
479 void ForEachVoxel(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
480 {
482  body(re);
483  vf.join(body._VoxelFunc);
484 }
485 
486 // -----------------------------------------------------------------------------
487 template <class T1, class VoxelFunc>
488 void ForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
489 {
490  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
491  ForEachVoxel(re, im1, vf);
492 }
493 
494 // -----------------------------------------------------------------------------
495 // ForEachVoxelIf
496 // -----------------------------------------------------------------------------
497 
498 //
499 // Image arguments by pointer
500 //
501 
502 // -----------------------------------------------------------------------------
503 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
504 void ForEachScalarIf(const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
505 {
508  body(re);
509  vf.join(body._VoxelFunc);
510  of.join(body._OutsideFunc);
511 }
512 
513 // -----------------------------------------------------------------------------
514 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
515 void ForEachScalarIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> *im1)
516 {
517  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
518  ForEachScalarIf<Domain>(*im1, vf, of);
519 }
520 
521 // -----------------------------------------------------------------------------
522 template <class Domain, class T1, class VoxelFunc>
523 void ForEachScalarIf(const GenericImage<T1> *im1, VoxelFunc &vf)
524 {
526  ForEachScalarIf<Domain>(*im1, vf, of);
527 }
528 
529 // -----------------------------------------------------------------------------
530 template <class Domain, class T1, class VoxelFunc>
531 void ForEachScalarIf(VoxelFunc vf, const GenericImage<T1> *im1)
532 {
533  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
534  ForEachScalarIf<Domain>(*im1, vf);
535 }
536 
537 // -----------------------------------------------------------------------------
538 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
539 void ForEachVoxelIf(const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
540 {
541  if (im1->GetTSize()) {
542  ForEachScalarIf<Domain>(*im1, vf, of);
543  } else {
545  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
546  body(re);
547  vf.join(body._VoxelFunc);
548  of.join(body._OutsideFunc);
549  }
550 }
551 
552 // -----------------------------------------------------------------------------
553 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
554 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> *im1)
555 {
556  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
557  ForEachVoxelIf<Domain>(*im1, vf, of);
558 }
559 
560 // -----------------------------------------------------------------------------
561 template <class Domain, class T1, class VoxelFunc>
562 void ForEachVoxelIf(const GenericImage<T1> *im1, VoxelFunc &vf)
563 {
565  ForEachVoxelIf<Domain>(*im1, vf, of);
566 }
567 
568 // -----------------------------------------------------------------------------
569 template <class Domain, class T1, class VoxelFunc>
570 void ForEachVoxelIf(VoxelFunc vf, const GenericImage<T1> *im1)
571 {
572  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
573  ForEachVoxelIf<Domain>(*im1, vf);
574 }
575 
576 // -----------------------------------------------------------------------------
577 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
578 void ForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
579 {
581  body(attr);
582  vf.join(body._VoxelFunc);
583  of.join(body._OutsideFunc);
584 }
585 
586 // -----------------------------------------------------------------------------
587 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
588 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, const GenericImage<T1> *im1)
589 {
590  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
591  ForEachVoxelIf<Domain>(attr, *im1, vf, of);
592 }
593 
594 // -----------------------------------------------------------------------------
595 template <class Domain, class T1, class VoxelFunc>
596 void ForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf)
597 {
599  ForEachVoxelIf<Domain>(attr, *im1, vf, of);
600 }
601 
602 // -----------------------------------------------------------------------------
603 template <class Domain, class T1, class VoxelFunc>
604 void ForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> *im1)
605 {
606  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
607  ForEachVoxelIf<Domain>(attr, *im1, vf);
608 }
609 
610 // -----------------------------------------------------------------------------
611 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
612 void ForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
613 {
615  body(re);
616  vf.join(body._VoxelFunc);
617  of.join(body._OutsideFunc);
618 }
619 
620 // -----------------------------------------------------------------------------
621 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
622 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, const GenericImage<T1> *im1)
623 {
624  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
625  ForEachVoxelIf<Domain>(re, *im1, vf, of);
626 }
627 
628 // -----------------------------------------------------------------------------
629 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
630 void ForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
631 {
633  body(re);
634  vf.join(body._VoxelFunc);
635  of.join(body._OutsideFunc);
636 }
637 
638 // -----------------------------------------------------------------------------
639 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
640 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
641 {
642  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
643  ForEachVoxelIf<Domain>(re, *im1, vf, of);
644 }
645 
646 // -----------------------------------------------------------------------------
647 template <class Domain, class T1, class VoxelFunc>
648 void ForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
649 {
651  ForEachVoxelIf<Domain>(re, *im1, vf, of);
652 }
653 
654 // -----------------------------------------------------------------------------
655 template <class Domain, class T1, class VoxelFunc>
656 void ForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
657 {
658  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
659  ForEachVoxelIf<Domain>(re, *im1, vf);
660 }
661 
662 // -----------------------------------------------------------------------------
663 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
664 void ForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
665 {
667  body(re);
668  vf.join(body._VoxelFunc);
669  of.join(body._OutsideFunc);
670 }
671 
672 // -----------------------------------------------------------------------------
673 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
674 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
675 {
676  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
677  ForEachVoxelIf<Domain>(*im1, vf, of);
678 }
679 
680 // -----------------------------------------------------------------------------
681 template <class Domain, class T1, class VoxelFunc>
682 void ForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
683 {
685  ForEachVoxelIf<Domain>(re, *im1, vf, of);
686 }
687 
688 // -----------------------------------------------------------------------------
689 template <class Domain, class T1, class VoxelFunc>
690 void ForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
691 {
692  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
693  ForEachVoxelIf<Domain>(re, *im1, vf);
694 }
695 
696 //
697 // Image arguments by reference
698 //
699 
700 // -----------------------------------------------------------------------------
701 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
702 void ForEachScalarIf(const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
703 {
706  body(re);
707  vf.join(body._VoxelFunc);
708  of.join(body._OutsideFunc);
709 }
710 
711 // -----------------------------------------------------------------------------
712 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
713 void ForEachScalarIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> &im1)
714 {
715  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
716  ForEachScalarIf<Domain>(im1, vf, of);
717 }
718 
719 // -----------------------------------------------------------------------------
720 template <class Domain, class T1, class VoxelFunc>
721 void ForEachScalarIf(const GenericImage<T1> &im1, VoxelFunc &vf)
722 {
724  ForEachScalarIf<Domain>(im1, vf, of);
725 }
726 
727 // -----------------------------------------------------------------------------
728 template <class Domain, class T1, class VoxelFunc>
729 void ForEachScalarIf(VoxelFunc vf, const GenericImage<T1> &im1)
730 {
731  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
732  ForEachScalarIf<Domain>(im1, vf);
733 }
734 
735 // -----------------------------------------------------------------------------
736 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
737 void ForEachVoxelIf(const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
738 {
739  if (im1.GetTSize()) {
740  ForEachVoxelIf<Domain>(im1, vf, of);
741  } else {
743  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
744  body(re);
745  vf.join(body._VoxelFunc);
746  of.join(body._OutsideFunc);
747  }
748 }
749 
750 // -----------------------------------------------------------------------------
751 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
752 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> &im1)
753 {
754  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
755  ForEachVoxelIf<Domain>(im1, vf, of);
756 }
757 
758 // -----------------------------------------------------------------------------
759 template <class Domain, class T1, class VoxelFunc>
760 void ForEachVoxelIf(const GenericImage<T1> &im1, VoxelFunc &vf)
761 {
763  ForEachVoxelIf<Domain>(im1, vf, of);
764 }
765 
766 // -----------------------------------------------------------------------------
767 template <class Domain, class T1, class VoxelFunc>
768 void ForEachVoxelIf(VoxelFunc vf, const GenericImage<T1> &im1)
769 {
770  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
771  ForEachVoxelIf<Domain>(im1, vf);
772 }
773 
774 // -----------------------------------------------------------------------------
775 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
776 void ForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
777 {
779  body(attr);
780  vf.join(body._VoxelFunc);
781  of.join(body._OutsideFunc);
782 }
783 
784 // -----------------------------------------------------------------------------
785 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
786 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, const GenericImage<T1> &im1)
787 {
788  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
789  ForEachVoxelIf<Domain>(attr, im1, vf, of);
790 }
791 
792 // -----------------------------------------------------------------------------
793 template <class Domain, class T1, class VoxelFunc>
794 void ForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf)
795 {
797  ForEachVoxelIf<Domain>(attr, im1, vf, of);
798 }
799 
800 // -----------------------------------------------------------------------------
801 template <class Domain, class T1, class VoxelFunc>
802 void ForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> &im1)
803 {
804  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
805  ForEachVoxelIf<Domain>(attr, im1, vf);
806 }
807 
808 // -----------------------------------------------------------------------------
809 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
810 void ForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
811 {
813  body(re);
814  vf.join(body._VoxelFunc);
815  of.join(body._OutsideFunc);
816 }
817 
818 // -----------------------------------------------------------------------------
819 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
820 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, const GenericImage<T1> &im1)
821 {
822  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
823  ForEachVoxelIf<Domain>(re, im1, vf, of);
824 }
825 
826 // -----------------------------------------------------------------------------
827 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
828 void ForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
829 {
831  body(re);
832  vf.join(body._VoxelFunc);
833  of.join(body._OutsideFunc);
834 }
835 
836 // -----------------------------------------------------------------------------
837 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
838 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
839 {
840  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
841  ForEachVoxelIf<Domain>(re, im1, vf, of);
842 }
843 
844 // -----------------------------------------------------------------------------
845 template <class Domain, class T1, class VoxelFunc>
846 void ForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
847 {
849  ForEachVoxelIf<Domain>(re, im1, vf, of);
850 }
851 
852 // -----------------------------------------------------------------------------
853 template <class Domain, class T1, class VoxelFunc>
854 void ForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
855 {
856  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
857  ForEachVoxelIf<Domain>(re, im1, vf);
858 }
859 
860 // -----------------------------------------------------------------------------
861 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
862 void ForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
863 {
865  body(re);
866  vf.join(body._VoxelFunc);
867  of.join(body._OutsideFunc);
868 }
869 
870 // -----------------------------------------------------------------------------
871 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
872 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
873 {
874  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
875  ForEachVoxelIf<Domain>(re, im1, vf, of);
876 }
877 
878 // -----------------------------------------------------------------------------
879 template <class Domain, class T1, class VoxelFunc>
880 void ForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
881 {
883  ForEachVoxelIf<Domain>(re, im1, vf, of);
884 }
885 
886 // -----------------------------------------------------------------------------
887 template <class Domain, class T1, class VoxelFunc>
888 void ForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
889 {
890  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
891  ForEachVoxelIf<Domain>(re, im1, vf);
892 }
893 
894 // -----------------------------------------------------------------------------
895 // ParallelForEachVoxel
896 // -----------------------------------------------------------------------------
897 
898 //
899 // Image arguments by pointer
900 //
901 
902 // -----------------------------------------------------------------------------
903 template <class T1, class VoxelFunc>
904 void ParallelForEachScalar(const GenericImage<T1> *im1, VoxelFunc &vf)
905 {
908  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
909  else parallel_for (re, body);
910 }
911 
912 // -----------------------------------------------------------------------------
913 template <class T1, class VoxelFunc>
914 void ParallelForEachScalar(VoxelFunc vf, const GenericImage<T1> *im1)
915 {
916  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
917  ParallelForEachScalar(*im1, vf);
918 }
919 
920 // -----------------------------------------------------------------------------
921 template <class T1, class VoxelFunc>
922 void ParallelForEachVoxel(const GenericImage<T1> *im1, VoxelFunc &vf)
923 {
924  if (im1->GetTSize()) {
925  ParallelForEachScalar(*im1, vf);
926  } else {
928  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
929  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
930  else parallel_for (re, body);
931  }
932 }
933 
934 // -----------------------------------------------------------------------------
935 template <class T1, class VoxelFunc>
936 void ParallelForEachVoxel(VoxelFunc vf, const GenericImage<T1> *im1)
937 {
938  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
939  ParallelForEachVoxel(*im1, vf);
940 }
941 
942 // -----------------------------------------------------------------------------
943 template <class T1, class VoxelFunc>
944 void ParallelForEachVoxel(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf)
945 {
947  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
948  if (VoxelFunc::IsReduction()) {
949  if (attr._dt) {
950  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
951  } else {
952  parallel_reduce(re, body);
953  }
954  vf.join(body._VoxelFunc);
955  } else {
956  if (attr._dt) {
957  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
958  } else {
959  parallel_for(re, body);
960  }
961  }
962 }
963 
964 // -----------------------------------------------------------------------------
965 template <class T1, class VoxelFunc>
966 void ParallelForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> *im1)
967 {
968  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
969  ParallelForEachVoxel(attr, *im1, vf);
970 }
971 
972 // -----------------------------------------------------------------------------
973 template <class T1, class VoxelFunc>
974 void ParallelForEachVoxel(const blocked_range<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
975 {
977  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
978  else parallel_for (re, body);
979 }
980 
981 // -----------------------------------------------------------------------------
982 template <class T1, class VoxelFunc>
983 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> *im1)
984 {
985  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
986  ParallelForEachVoxel(re, *im1, vf);
987 }
988 
989 // -----------------------------------------------------------------------------
990 template <class T1, class VoxelFunc>
991 void ParallelForEachVoxel(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
992 {
994  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
995  else parallel_for (re, body);
996 }
997 
998 // -----------------------------------------------------------------------------
999 template <class T1, class VoxelFunc>
1000 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
1001 {
1002  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1003  ParallelForEachVoxel(re, *im1, vf);
1004 }
1005 
1006 // -----------------------------------------------------------------------------
1007 template <class T1, class VoxelFunc>
1008 void ParallelForEachVoxel(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
1009 {
1011  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1012  else parallel_for (re, body);
1013 }
1014 
1015 // -----------------------------------------------------------------------------
1016 template <class T1, class VoxelFunc>
1017 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
1018 {
1019  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1020  ParallelForEachVoxel(re, *im1, vf);
1021 }
1022 
1023 //
1024 // Image arguments by reference
1025 //
1026 
1027 // -----------------------------------------------------------------------------
1028 template <class T1, class VoxelFunc>
1029 void ParallelForEachScalar(const GenericImage<T1> &im1, VoxelFunc &vf)
1030 {
1033  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1034  else parallel_for (re, body);
1035 }
1036 
1037 // -----------------------------------------------------------------------------
1038 template <class T1, class VoxelFunc>
1039 void ParallelForEachScalar(VoxelFunc vf, const GenericImage<T1> &im1)
1040 {
1041  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1042  ParallelForEachScalar(im1, vf);
1043 }
1044 
1045 // -----------------------------------------------------------------------------
1046 template <class T1, class VoxelFunc>
1047 void ParallelForEachVoxel(const GenericImage<T1> &im1, VoxelFunc &vf)
1048 {
1049  if (im1.GetTSize()) {
1050  ParallelForEachScalar(im1, vf);
1051  } else {
1053  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
1054  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1055  else parallel_for (re, body);
1056  }
1057 }
1058 
1059 // -----------------------------------------------------------------------------
1060 template <class T1, class VoxelFunc>
1061 void ParallelForEachVoxel(VoxelFunc vf, const GenericImage<T1> &im1)
1062 {
1063  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1064  ParallelForEachVoxel(im1, vf);
1065 }
1066 
1067 // -----------------------------------------------------------------------------
1068 template <class T1, class VoxelFunc>
1069 void ParallelForEachVoxel(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf)
1070 {
1072  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
1073  if (VoxelFunc::IsReduction()) {
1074  if (attr._dt) {
1075  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
1076  } else {
1077  parallel_reduce(re, body);
1078  }
1079  vf.join(body._VoxelFunc);
1080  } else {
1081  if (attr._dt) {
1082  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
1083  } else {
1084  parallel_for(re, body);
1085  }
1086  }
1087 }
1088 
1089 // -----------------------------------------------------------------------------
1090 template <class T1, class VoxelFunc>
1091 void ParallelForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> &im1)
1092 {
1093  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1094  ParallelForEachVoxel(attr, im1, vf);
1095 }
1096 
1097 // -----------------------------------------------------------------------------
1098 template <class T1, class VoxelFunc>
1099 void ParallelForEachVoxel(const blocked_range<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1100 {
1102  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1103  else parallel_for (re, body);
1104 }
1105 
1106 // -----------------------------------------------------------------------------
1107 template <class T1, class VoxelFunc>
1108 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> &im1)
1109 {
1110  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1111  ParallelForEachVoxel(re, im1, vf);
1112 }
1113 
1114 // -----------------------------------------------------------------------------
1115 template <class T1, class VoxelFunc>
1116 void ParallelForEachVoxel(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1117 {
1119  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1120  else parallel_for (re, body);
1121 }
1122 
1123 // -----------------------------------------------------------------------------
1124 template <class T1, class VoxelFunc>
1125 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
1126 {
1127  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1128  ParallelForEachVoxel(re, im1, vf);
1129 }
1130 
1131 // -----------------------------------------------------------------------------
1132 template <class T1, class VoxelFunc>
1133 void ParallelForEachVoxel(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1134 {
1136  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
1137  else parallel_for (re, body);
1138 }
1139 
1140 // -----------------------------------------------------------------------------
1141 template <class T1, class VoxelFunc>
1142 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
1143 {
1144  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1145  ParallelForEachVoxel(re, im1, vf);
1146 }
1147 
1148 // -----------------------------------------------------------------------------
1149 // ParallelForEachVoxelIf
1150 // -----------------------------------------------------------------------------
1151 
1152 //
1153 // Image arguments by pointer
1154 //
1155 
1156 // -----------------------------------------------------------------------------
1157 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1158 void ParallelForEachScalarIf(const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1159 {
1161  blocked_range<int> re(0, im1->GetNumberOfVoxels());
1162  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1163  parallel_reduce(re, body);
1164  vf.join(body._VoxelFunc);
1165  of.join(body._OutsideFunc);
1166  } else {
1167  parallel_for(re, body);
1168  }
1169 }
1170 
1171 // -----------------------------------------------------------------------------
1172 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1173 void ParallelForEachScalarIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> *im1)
1174 {
1175  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1176  ParallelForEachScalarIf<Domain>(*im1, vf, of);
1177 }
1178 
1179 // -----------------------------------------------------------------------------
1180 template <class Domain, class T1, class VoxelFunc>
1181 void ParallelForEachScalarIf(const GenericImage<T1> *im1, VoxelFunc &vf)
1182 {
1184  ParallelForEachScalarIf<Domain>(*im1, vf, of);
1185 }
1186 
1187 // -----------------------------------------------------------------------------
1188 template <class Domain, class T1, class VoxelFunc>
1189 void ParallelForEachScalarIf(VoxelFunc vf, const GenericImage<T1> *im1)
1190 {
1191  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1192  ParallelForEachScalarIf<Domain>(*im1, vf);
1193 }
1194 
1195 // -----------------------------------------------------------------------------
1196 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1197 void ParallelForEachVoxelIf(const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1198 {
1199  if (im1->GetTSize()) {
1200  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
1201  } else {
1203  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
1204  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1205  parallel_reduce(re, body);
1206  vf.join(body._VoxelFunc);
1207  of.join(body._OutsideFunc);
1208  } else {
1209  parallel_for(re, body);
1210  }
1211  }
1212 }
1213 
1214 // -----------------------------------------------------------------------------
1215 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1216 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> *im1)
1217 {
1218  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1219  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
1220 }
1221 
1222 // -----------------------------------------------------------------------------
1223 template <class Domain, class T1, class VoxelFunc>
1224 void ParallelForEachVoxelIf(const GenericImage<T1> *im1, VoxelFunc &vf)
1225 {
1227  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
1228 }
1229 
1230 // -----------------------------------------------------------------------------
1231 template <class Domain, class T1, class VoxelFunc>
1232 void ParallelForEachVoxelIf(VoxelFunc vf, const GenericImage<T1> *im1)
1233 {
1234  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1235  ParallelForEachVoxelIf<Domain>(*im1, vf);
1236 }
1237 
1238 // -----------------------------------------------------------------------------
1239 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1240 void ParallelForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1241 {
1243  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
1244  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1245  if (attr._dt) {
1246  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
1247  } else {
1248  parallel_reduce(re, body);
1249  }
1250  vf.join(body._VoxelFunc);
1251  of.join(body._OutsideFunc);
1252  } else {
1253  if (attr._dt) {
1254  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
1255  } else {
1256  parallel_for(re, body);
1257  }
1258  }
1259 }
1260 
1261 // -----------------------------------------------------------------------------
1262 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1263 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, const GenericImage<T1> *im1)
1264 {
1265  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1266  ParallelForEachVoxelIf<Domain>(attr, *im1, vf, of);
1267 }
1268 
1269 // -----------------------------------------------------------------------------
1270 template <class Domain, class T1, class VoxelFunc>
1271 void ParallelForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> *im1, VoxelFunc &vf)
1272 {
1274  ParallelForEachVoxelIf<Domain>(attr, *im1, vf, of);
1275 }
1276 
1277 // -----------------------------------------------------------------------------
1278 template <class Domain, class T1, class VoxelFunc>
1279 void ParallelForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> *im1)
1280 {
1281  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1282  ParallelForEachVoxelIf<Domain>(attr, *im1, vf);
1283 }
1284 
1285 // -----------------------------------------------------------------------------
1286 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1287 void ParallelForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1288 {
1290  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1291  parallel_reduce(re, body);
1292  vf.join(body._VoxelFunc);
1293  of.join(body._OutsideFunc);
1294  } else {
1295  parallel_for(re, body);
1296  }
1297 }
1298 
1299 // -----------------------------------------------------------------------------
1300 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1301 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, const GenericImage<T1> *im1)
1302 {
1303  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1304  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1305 }
1306 
1307 // -----------------------------------------------------------------------------
1308 template <class Domain, class T1, class VoxelFunc>
1309 void ParallelForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
1310 {
1312  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1313 }
1314 
1315 // -----------------------------------------------------------------------------
1316 template <class Domain, class T1, class VoxelFunc>
1317 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> *im1)
1318 {
1319  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1320  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
1321 }
1322 
1323 // -----------------------------------------------------------------------------
1324 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1325 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1326 {
1328  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1329  parallel_reduce(re, body);
1330  vf.join(body._VoxelFunc);
1331  of.join(body._OutsideFunc);
1332  } else {
1333  parallel_for(re, body);
1334  }
1335 }
1336 
1337 // -----------------------------------------------------------------------------
1338 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1339 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
1340 {
1341  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1342  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1343 }
1344 
1345 // -----------------------------------------------------------------------------
1346 template <class Domain, class T1, class VoxelFunc>
1347 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
1348 {
1350  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1351 }
1352 
1353 // -----------------------------------------------------------------------------
1354 template <class Domain, class T1, class VoxelFunc>
1355 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> *im1)
1356 {
1357  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1358  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
1359 }
1360 
1361 // -----------------------------------------------------------------------------
1362 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1363 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
1364 {
1366  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1367  parallel_reduce(re, body);
1368  vf.join(body._VoxelFunc);
1369  of.join(body._OutsideFunc);
1370  } else {
1371  parallel_for(re, body);
1372  }
1373 }
1374 
1375 // -----------------------------------------------------------------------------
1376 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1377 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
1378 {
1379  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1380  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1381 }
1382 
1383 // -----------------------------------------------------------------------------
1384 template <class Domain, class T1, class VoxelFunc>
1385 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> *im1, VoxelFunc &vf)
1386 {
1388  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
1389 }
1390 
1391 // -----------------------------------------------------------------------------
1392 template <class Domain, class T1, class VoxelFunc>
1393 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> *im1)
1394 {
1395  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1396  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
1397 }
1398 
1399 //
1400 // Image arguments by reference
1401 //
1402 
1403 // -----------------------------------------------------------------------------
1404 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1405 void ParallelForEachScalarIf(const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1406 {
1409  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1410  parallel_reduce(re, body);
1411  vf.join(body._VoxelFunc);
1412  of.join(body._OutsideFunc);
1413  } else {
1414  parallel_for(re, body);
1415  }
1416 }
1417 
1418 // -----------------------------------------------------------------------------
1419 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1420 void ParallelForEachScalarIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> &im1)
1421 {
1422  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1423  ParallelForEachScalarIf<Domain>(im1, vf, of);
1424 }
1425 
1426 // -----------------------------------------------------------------------------
1427 template <class Domain, class T1, class VoxelFunc>
1428 void ParallelForEachScalarIf(const GenericImage<T1> &im1, VoxelFunc &vf)
1429 {
1431  ParallelForEachScalarIf<Domain>(im1, vf, of);
1432 }
1433 
1434 // -----------------------------------------------------------------------------
1435 template <class Domain, class T1, class VoxelFunc>
1436 void ParallelForEachScalarIf(VoxelFunc vf, const GenericImage<T1> &im1)
1437 {
1438  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1439  ParallelForEachScalarIf<Domain>(im1, vf);
1440 }
1441 
1442 // -----------------------------------------------------------------------------
1443 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1444 void ParallelForEachVoxelIf(const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1445 {
1446  if (im1.GetTSize()) {
1447  ParallelForEachVoxelIf<Domain>(im1, vf, of);
1448  } else {
1450  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
1451  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1452  parallel_reduce(re, body);
1453  vf.join(body._VoxelFunc);
1454  of.join(body._OutsideFunc);
1455  } else {
1456  parallel_for(re, body);
1457  }
1458  }
1459 }
1460 
1461 // -----------------------------------------------------------------------------
1462 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1463 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const GenericImage<T1> &im1)
1464 {
1465  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1466  ParallelForEachVoxelIf<Domain>(im1, vf, of);
1467 }
1468 
1469 // -----------------------------------------------------------------------------
1470 template <class Domain, class T1, class VoxelFunc>
1471 void ParallelForEachVoxelIf(const GenericImage<T1> &im1, VoxelFunc &vf)
1472 {
1474  ParallelForEachVoxelIf<Domain>(im1, vf, of);
1475 }
1476 
1477 // -----------------------------------------------------------------------------
1478 template <class Domain, class T1, class VoxelFunc>
1479 void ParallelForEachVoxelIf(VoxelFunc vf, const GenericImage<T1> &im1)
1480 {
1481  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1482  ParallelForEachVoxelIf<Domain>(im1, vf);
1483 }
1484 
1485 // -----------------------------------------------------------------------------
1486 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1487 void ParallelForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1488 {
1490  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
1491  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1492  if (attr._dt) {
1493  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
1494  } else {
1495  parallel_reduce(re, body);
1496  }
1497  vf.join(body._VoxelFunc);
1498  of.join(body._OutsideFunc);
1499  } else {
1500  if (attr._dt) {
1501  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
1502  } else {
1503  parallel_for(re, body);
1504  }
1505  }
1506 }
1507 
1508 // -----------------------------------------------------------------------------
1509 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1510 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, const GenericImage<T1> &im1)
1511 {
1512  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1513  ParallelForEachVoxelIf<Domain>(attr, im1, vf, of);
1514 }
1515 
1516 // -----------------------------------------------------------------------------
1517 template <class Domain, class T1, class VoxelFunc>
1518 void ParallelForEachVoxelIf(const ImageAttributes &attr, const GenericImage<T1> &im1, VoxelFunc &vf)
1519 {
1521  ParallelForEachVoxelIf<Domain>(attr, im1, vf, of);
1522 }
1523 
1524 // -----------------------------------------------------------------------------
1525 template <class Domain, class T1, class VoxelFunc>
1526 void ParallelForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, const GenericImage<T1> &im1)
1527 {
1528  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1529  ParallelForEachVoxelIf<Domain>(attr, im1, vf);
1530 }
1531 
1532 // -----------------------------------------------------------------------------
1533 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1534 void ParallelForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1535 {
1537  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1538  parallel_reduce(re, body);
1539  vf.join(body._VoxelFunc);
1540  of.join(body._OutsideFunc);
1541  } else {
1542  parallel_for(re, body);
1543  }
1544 }
1545 
1546 // -----------------------------------------------------------------------------
1547 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1548 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, const GenericImage<T1> &im1)
1549 {
1550  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1551  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1552 }
1553 
1554 // -----------------------------------------------------------------------------
1555 template <class Domain, class T1, class VoxelFunc>
1556 void ParallelForEachVoxelIf(const blocked_range<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1557 {
1559  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1560 }
1561 
1562 // -----------------------------------------------------------------------------
1563 template <class Domain, class T1, class VoxelFunc>
1564 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range<int> &re, const GenericImage<T1> &im1)
1565 {
1566  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1567  ParallelForEachVoxelIf<Domain>(re, im1, vf);
1568 }
1569 
1570 // -----------------------------------------------------------------------------
1571 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1572 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1573 {
1575  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1576  parallel_reduce(re, body);
1577  vf.join(body._VoxelFunc);
1578  of.join(body._OutsideFunc);
1579  } else {
1580  parallel_for(re, body);
1581  }
1582 }
1583 
1584 // -----------------------------------------------------------------------------
1585 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1586 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
1587 {
1588  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1589  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1590 }
1591 
1592 // -----------------------------------------------------------------------------
1593 template <class Domain, class T1, class VoxelFunc>
1594 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1595 {
1597  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1598 }
1599 
1600 // -----------------------------------------------------------------------------
1601 template <class Domain, class T1, class VoxelFunc>
1602 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, const GenericImage<T1> &im1)
1603 {
1604  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1605  ParallelForEachVoxelIf<Domain>(re, im1, vf);
1606 }
1607 
1608 // -----------------------------------------------------------------------------
1609 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1610 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
1611 {
1613  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
1614  parallel_reduce(re, body);
1615  vf.join(body._VoxelFunc);
1616  of.join(body._OutsideFunc);
1617  } else {
1618  parallel_for(re, body);
1619  }
1620 }
1621 
1622 // -----------------------------------------------------------------------------
1623 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
1624 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
1625 {
1626  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1627  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1628 }
1629 
1630 // -----------------------------------------------------------------------------
1631 template <class Domain, class T1, class VoxelFunc>
1632 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, const GenericImage<T1> &im1, VoxelFunc &vf)
1633 {
1635  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
1636 }
1637 
1638 // -----------------------------------------------------------------------------
1639 template <class Domain, class T1, class VoxelFunc>
1640 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, const GenericImage<T1> &im1)
1641 {
1642  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1643  ParallelForEachVoxelIf<Domain>(re, im1, vf);
1644 }
1645 
1646 // =============================================================================
1647 // 1 non-const image
1648 // =============================================================================
1649 
1650 // -----------------------------------------------------------------------------
1651 /**
1652  * ForEachVoxel body for voxel function of 1 non-const image
1653  */
1654 template <class T1, class VoxelFunc>
1655 struct UnaryForEachVoxelBody : public ForEachVoxelBody<VoxelFunc>
1656 {
1657  GenericImage<T1> &im1;
1658 
1659  /// Constructor
1661  VoxelFunc &vf)
1662  :
1663  ForEachVoxelBody<VoxelFunc>(vf, im1.Attributes()), im1(im1)
1664  {}
1665 
1666  /// Copy constructor
1668  :
1669  ForEachVoxelBody<VoxelFunc>(o), im1(o.im1)
1670  {}
1671 
1672  /// Split constructor
1674  :
1675  ForEachVoxelBody<VoxelFunc>(o, s), im1(o.im1)
1676  {}
1677 
1678  /// Process entire image
1679  void operator ()(const ImageAttributes &attr) const
1680  {
1681  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels();
1682 
1683  const int T = (attr._dt ? attr._t : 1);
1684 
1685  for (int l = 0; l < T; ++l)
1686  for (int k = 0; k < attr._z; ++k)
1687  for (int j = 0; j < attr._y; ++j)
1688  for (int i = 0; i < attr._x; ++i, ++p1) {
1689  // const_cast such that voxel functions need only implement
1690  // non-const operator() which is required for parallel_reduce
1691  const_cast<UnaryForEachVoxelBody *>(this)->_VoxelFunc(i, j, k, l, p1);
1692  }
1693  }
1694 
1695  /// Process image region using linear index
1696  void operator ()(const blocked_range<int> &re) const
1697  {
1698  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels() + re.begin();
1699 
1700  for (int idx = re.begin(); idx < re.end(); ++idx, p1 += 1) {
1701  // const_cast such that voxel functions need only implement
1702  // non-const operator() which is required for parallel_reduce
1703  const_cast<UnaryForEachVoxelBody *>(this)->_VoxelFunc(im1, idx, p1);
1704  }
1705  }
1706 
1707  /// Process 2D image region
1708  void operator ()(const blocked_range2d<int> &re) const
1709  {
1710  const int bi = re.cols().begin();
1711  const int bj = re.rows().begin();
1712  const int ei = re.cols().end();
1713  const int ej = re.rows().end();
1714 
1715  const int s1 = im1.GetX() - (ei - bi);
1716 
1717  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, this->_k, this->_l);
1718 
1719  for (int j = bj; j < ej; ++j, p1 += s1)
1720  for (int i = bi; i < ei; ++i, p1 += 1) {
1721  // const_cast such that voxel functions need only implement
1722  // non-const operator() which is required for parallel_reduce
1723  const_cast<UnaryForEachVoxelBody *>(this)->_VoxelFunc(i, j, this->_k, this->_l, p1);
1724  }
1725  }
1726 
1727  /// Process 3D image region
1728  void operator ()(const blocked_range3d<int> &re) const
1729  {
1730  const int bi = re.cols ().begin();
1731  const int bj = re.rows ().begin();
1732  const int bk = re.pages().begin();
1733  const int ei = re.cols ().end();
1734  const int ej = re.rows ().end();
1735  const int ek = re.pages().end();
1736 
1737  const int s1 = im1.GetX() - (ei - bi);
1738  const int s2 = (im1.GetY() - (ej - bj)) * im1.GetX();
1739 
1740  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, bk, this->_l);
1741 
1742  for (int k = bk; k < ek; ++k, p1 += s2)
1743  for (int j = bj; j < ej; ++j, p1 += s1)
1744  for (int i = bi; i < ei; ++i, p1 += 1) {
1745  // const_cast such that voxel functions need only implement
1746  // non-const operator() which is required for parallel_reduce
1747  const_cast<UnaryForEachVoxelBody *>(this)->_VoxelFunc(i, j, k, this->_l, p1);
1748  }
1749  }
1750 };
1751 
1752 // -----------------------------------------------------------------------------
1753 /**
1754  * ForEachVoxel body for inside and outside unary voxel function of 1 non-const image
1755  */
1756 template <class T1,
1757  class VoxelFunc, class OutsideFunc = NaryVoxelFunction::NOP,
1758  class Domain = ForEachVoxelDomain::Foreground>
1759 struct UnaryForEachVoxelIfBody : public ForEachVoxelIfBody<VoxelFunc, OutsideFunc>
1760 {
1761  GenericImage<T1> &im1;
1762 
1763  /// Constructor
1765  VoxelFunc &vf, OutsideFunc &of)
1766  :
1767  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(vf, of, im1.Attributes()), im1(im1)
1768  {}
1769 
1770  /// Copy constructor
1772  :
1773  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(o), im1(o.im1)
1774  {}
1775 
1776  /// Split constructor
1778  :
1779  ForEachVoxelIfBody<VoxelFunc, OutsideFunc>(o, s), im1(o.im1)
1780  {}
1781 
1782  /// Process entire image
1783  void operator ()(const ImageAttributes &attr) const
1784  {
1785  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels();
1786 
1787  const int T = (attr._dt ? attr._t : 1);
1788 
1789  for (int l = 0; l < T; ++l)
1790  for (int k = 0; k < attr._z; ++k)
1791  for (int j = 0; j < attr._y; ++j)
1792  for (int i = 0; i < attr._x; ++i, ++p1) {
1793  if (Domain::IsInside(im1, i, j, k, l, p1)) {
1794  // const_cast such that voxel functions need only implement
1795  // non-const operator() which is required for parallel_reduce
1796  const_cast<UnaryForEachVoxelIfBody *>(this)->_VoxelFunc (i, j, k, l, p1);
1797  } else const_cast<UnaryForEachVoxelIfBody *>(this)->_OutsideFunc(i, j, k, l, p1);
1798  }
1799  }
1800 
1801  /// Process image region using linear index
1802  void operator ()(const blocked_range<int> &re) const
1803  {
1804  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels() + re.begin();
1805 
1806  for (int idx = re.begin(); idx < re.end(); ++idx, p1 += 1) {
1807  if (Domain::IsInside(im1, idx, p1)) {
1808  // const_cast such that voxel functions need only implement
1809  // non-const operator() which is required for parallel_reduce
1810  const_cast<UnaryForEachVoxelIfBody *>(this)->_VoxelFunc (im1, idx, p1);
1811  } else const_cast<UnaryForEachVoxelIfBody *>(this)->_OutsideFunc(im1, idx, p1);
1812  }
1813  }
1814 
1815  /// Process 2D image region
1816  void operator ()(const blocked_range2d<int> &re) const
1817  {
1818  const int bi = re.cols().begin();
1819  const int bj = re.rows().begin();
1820  const int ei = re.cols().end();
1821  const int ej = re.rows().end();
1822 
1823  const int s1 = im1.GetX() - (ei - bi);
1824 
1825  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, this->_k, this->_l);
1826 
1827  for (int j = bj; j < ej; ++j, p1 += s1)
1828  for (int i = bi; i < ei; ++i, p1 += 1) {
1829  if (Domain::IsInside(im1, i, j, this->_k, this->_l, p1)) {
1830  // const_cast such that voxel functions need only implement
1831  // non-const operator() which is required for parallel_reduce
1832  const_cast<UnaryForEachVoxelIfBody *>(this)->_VoxelFunc (i, j, this->_k, this->_l, p1);
1833  } else const_cast<UnaryForEachVoxelIfBody *>(this)->_OutsideFunc(i, j, this->_k, this->_l, p1);
1834  }
1835  }
1836 
1837  /// Process 3D image region
1838  void operator ()(const blocked_range3d<int> &re) const
1839  {
1840  const int bi = re.cols ().begin();
1841  const int bj = re.rows ().begin();
1842  const int bk = re.pages().begin();
1843  const int ei = re.cols ().end();
1844  const int ej = re.rows ().end();
1845  const int ek = re.pages().end();
1846 
1847  const int s1 = im1.GetX() - (ei - bi);
1848  const int s2 = (im1.GetY() - (ej - bj)) * im1.GetX();
1849 
1850  T1 *p1 = im1.IsEmpty() ? NULL : im1.GetPointerToVoxels(bi, bj, bk, this->_l);
1851 
1852  for (int k = bk; k < ek; ++k, p1 += s2)
1853  for (int j = bj; j < ej; ++j, p1 += s1)
1854  for (int i = bi; i < ei; ++i, p1 += 1) {
1855  if (Domain::IsInside(im1, i, j, k, this->_l, p1)) {
1856  // const_cast such that voxel functions need only implement
1857  // non-const operator() which is required for parallel_reduce
1858  const_cast<UnaryForEachVoxelIfBody *>(this)->_VoxelFunc (i, j, k, this->_l, p1);
1859  } else const_cast<UnaryForEachVoxelIfBody *>(this)->_OutsideFunc(i, j, k, this->_l, p1);
1860  }
1861  }
1862 };
1863 
1864 // -----------------------------------------------------------------------------
1865 // ForEachVoxel
1866 // -----------------------------------------------------------------------------
1867 
1868 //
1869 // Image arguments by pointer
1870 //
1871 
1872 // -----------------------------------------------------------------------------
1873 template <class T1, class VoxelFunc>
1874 void ForEachScalar(GenericImage<T1> *im1, VoxelFunc &vf)
1875 {
1876  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1877  blocked_range<int> re(0, im1->GetNumberOfVoxels());
1878  body(re);
1879  vf.join(body._VoxelFunc);
1880 }
1881 
1882 // -----------------------------------------------------------------------------
1883 template <class T1, class VoxelFunc>
1884 void ForEachScalar(VoxelFunc vf, GenericImage<T1> *im1)
1885 {
1886  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1887  ForEachScalar(*im1, vf);
1888 }
1889 
1890 // -----------------------------------------------------------------------------
1891 template <class T1, class VoxelFunc>
1892 void ForEachVoxel(GenericImage<T1> *im1, VoxelFunc &vf)
1893 {
1894  if (im1->GetTSize()) {
1895  ForEachScalar(*im1, vf);
1896  } else {
1897  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1898  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
1899  body(re);
1900  vf.join(body._VoxelFunc);
1901  }
1902 }
1903 
1904 // -----------------------------------------------------------------------------
1905 template <class T1, class VoxelFunc>
1906 void ForEachVoxel(VoxelFunc vf, GenericImage<T1> *im1)
1907 {
1908  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1909  ForEachVoxel(*im1, vf);
1910 }
1911 
1912 // -----------------------------------------------------------------------------
1913 template <class T1, class VoxelFunc>
1914 void ForEachVoxel(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf)
1915 {
1916  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1917  body(attr);
1918  vf.join(body._VoxelFunc);
1919 }
1920 
1921 // -----------------------------------------------------------------------------
1922 template <class T1, class VoxelFunc>
1923 void ForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> *im1)
1924 {
1925  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1926  ForEachVoxel(attr, *im1, vf);
1927 }
1928 
1929 // -----------------------------------------------------------------------------
1930 template <class T1, class VoxelFunc>
1931 void ForEachVoxel(const blocked_range<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
1932 {
1933  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1934  body(re);
1935  vf.join(body._VoxelFunc);
1936 }
1937 
1938 // -----------------------------------------------------------------------------
1939 template <class T1, class VoxelFunc>
1940 void ForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> *im1)
1941 {
1942  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1943  ForEachVoxel(re, *im1, vf);
1944 }
1945 
1946 // -----------------------------------------------------------------------------
1947 template <class T1, class VoxelFunc>
1948 void ForEachVoxel(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
1949 {
1950  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1951  body(re);
1952  vf.join(body._VoxelFunc);
1953 }
1954 
1955 // -----------------------------------------------------------------------------
1956 template <class T1, class VoxelFunc>
1957 void ForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> *im1)
1958 {
1959  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1960  ForEachVoxel(re, *im1, vf);
1961 }
1962 
1963 // -----------------------------------------------------------------------------
1964 template <class T1, class VoxelFunc>
1965 void ForEachVoxel(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
1966 {
1967  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
1968  body(re);
1969  vf.join(body._VoxelFunc);
1970 }
1971 
1972 // -----------------------------------------------------------------------------
1973 template <class T1, class VoxelFunc>
1974 void ForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> *im1)
1975 {
1976  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1977  ForEachVoxel(re, *im1, vf);
1978 }
1979 
1980 //
1981 // Image arguments by reference
1982 //
1983 
1984 // -----------------------------------------------------------------------------
1985 template <class T1, class VoxelFunc>
1986 void ForEachScalar(GenericImage<T1> &im1, VoxelFunc &vf)
1987 {
1990  body(re);
1991  vf.join(body._VoxelFunc);
1992 }
1993 
1994 // -----------------------------------------------------------------------------
1995 template <class T1, class VoxelFunc>
1996 void ForEachScalar(VoxelFunc vf, GenericImage<T1> &im1)
1997 {
1998  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
1999  ForEachScalar(im1, vf);
2000 }
2001 
2002 // -----------------------------------------------------------------------------
2003 template <class T1, class VoxelFunc>
2004 void ForEachVoxel(GenericImage<T1> &im1, VoxelFunc &vf)
2005 {
2006  if (im1.GetTSize()) {
2007  ForEachScalar(im1, vf);
2008  } else {
2010  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
2011  body(re);
2012  vf.join(body._VoxelFunc);
2013  }
2014 }
2015 
2016 // -----------------------------------------------------------------------------
2017 template <class T1, class VoxelFunc>
2018 void ForEachVoxel(VoxelFunc vf, GenericImage<T1> &im1)
2019 {
2020  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2021  ForEachVoxel(im1, vf);
2022 }
2023 
2024 // -----------------------------------------------------------------------------
2025 template <class T1, class VoxelFunc>
2026 void ForEachVoxel(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf)
2027 {
2029  body(attr);
2030  vf.join(body._VoxelFunc);
2031 }
2032 
2033 // -----------------------------------------------------------------------------
2034 template <class T1, class VoxelFunc>
2035 void ForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> &im1)
2036 {
2037  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2038  ForEachVoxel(attr, im1, vf);
2039 }
2040 
2041 // -----------------------------------------------------------------------------
2042 template <class T1, class VoxelFunc>
2043 void ForEachVoxel(const blocked_range<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2044 {
2046  body(re);
2047  vf.join(body._VoxelFunc);
2048 }
2049 
2050 // -----------------------------------------------------------------------------
2051 template <class T1, class VoxelFunc>
2052 void ForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> &im1)
2053 {
2054  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2055  ForEachVoxel(re, im1, vf);
2056 }
2057 
2058 // -----------------------------------------------------------------------------
2059 template <class T1, class VoxelFunc>
2060 void ForEachVoxel(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2061 {
2063  body(re);
2064  vf.join(body._VoxelFunc);
2065 }
2066 
2067 // -----------------------------------------------------------------------------
2068 template <class T1, class VoxelFunc>
2069 void ForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> &im1)
2070 {
2071  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2072  ForEachVoxel(re, im1, vf);
2073 }
2074 
2075 // -----------------------------------------------------------------------------
2076 template <class T1, class VoxelFunc>
2077 void ForEachVoxel(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2078 {
2080  body(re);
2081  vf.join(body._VoxelFunc);
2082 }
2083 
2084 // -----------------------------------------------------------------------------
2085 template <class T1, class VoxelFunc>
2086 void ForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> &im1)
2087 {
2088  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2089  ForEachVoxel(re, im1, vf);
2090 }
2091 
2092 // -----------------------------------------------------------------------------
2093 // ForEachVoxelIf
2094 // -----------------------------------------------------------------------------
2095 
2096 //
2097 // Image arguments by pointer
2098 //
2099 
2100 // -----------------------------------------------------------------------------
2101 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2102 void ForEachScalarIf(GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2103 {
2105  blocked_range<int> re(0, im1->GetNumberOfVoxels());
2106  body(re);
2107  vf.join(body._VoxelFunc);
2108  of.join(body._OutsideFunc);
2109 }
2110 
2111 // -----------------------------------------------------------------------------
2112 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2113 void ForEachScalarIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> *im1)
2114 {
2115  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2116  ForEachScalarIf<Domain>(*im1, vf, of);
2117 }
2118 
2119 // -----------------------------------------------------------------------------
2120 template <class Domain, class T1, class VoxelFunc>
2121 void ForEachScalarIf(GenericImage<T1> *im1, VoxelFunc &vf)
2122 {
2124  ForEachScalarIf<Domain>(*im1, vf, of);
2125 }
2126 
2127 // -----------------------------------------------------------------------------
2128 template <class Domain, class T1, class VoxelFunc>
2129 void ForEachScalarIf(VoxelFunc vf, GenericImage<T1> *im1)
2130 {
2131  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2132  ForEachScalarIf<Domain>(*im1, vf);
2133 }
2134 
2135 // -----------------------------------------------------------------------------
2136 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2137 void ForEachVoxelIf(GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2138 {
2139  if (im1->GetTSize()) {
2140  ForEachScalarIf<Domain>(*im1, vf, of);
2141  } else {
2143  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
2144  body(re);
2145  vf.join(body._VoxelFunc);
2146  of.join(body._OutsideFunc);
2147  }
2148 }
2149 
2150 // -----------------------------------------------------------------------------
2151 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2152 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> *im1)
2153 {
2154  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2155  ForEachVoxelIf<Domain>(*im1, vf, of);
2156 }
2157 
2158 // -----------------------------------------------------------------------------
2159 template <class Domain, class T1, class VoxelFunc>
2160 void ForEachVoxelIf(GenericImage<T1> *im1, VoxelFunc &vf)
2161 {
2163  ForEachVoxelIf<Domain>(*im1, vf, of);
2164 }
2165 
2166 // -----------------------------------------------------------------------------
2167 template <class Domain, class T1, class VoxelFunc>
2168 void ForEachVoxelIf(VoxelFunc vf, GenericImage<T1> *im1)
2169 {
2170  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2171  ForEachVoxelIf<Domain>(*im1, vf);
2172 }
2173 
2174 // -----------------------------------------------------------------------------
2175 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2176 void ForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2177 {
2179  body(attr);
2180  vf.join(body._VoxelFunc);
2181  of.join(body._OutsideFunc);
2182 }
2183 
2184 // -----------------------------------------------------------------------------
2185 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2186 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, GenericImage<T1> *im1)
2187 {
2188  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2189  ForEachVoxelIf<Domain>(attr, *im1, vf, of);
2190 }
2191 
2192 // -----------------------------------------------------------------------------
2193 template <class Domain, class T1, class VoxelFunc>
2194 void ForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf)
2195 {
2197  ForEachVoxelIf<Domain>(attr, *im1, vf, of);
2198 }
2199 
2200 // -----------------------------------------------------------------------------
2201 template <class Domain, class T1, class VoxelFunc>
2202 void ForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> *im1)
2203 {
2204  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2205  ForEachVoxelIf<Domain>(attr, *im1, vf);
2206 }
2207 
2208 // -----------------------------------------------------------------------------
2209 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2210 void ForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2211 {
2213  body(re);
2214  vf.join(body._VoxelFunc);
2215  of.join(body._OutsideFunc);
2216 }
2217 
2218 // -----------------------------------------------------------------------------
2219 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2220 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, GenericImage<T1> *im1)
2221 {
2222  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2223  ForEachVoxelIf<Domain>(re, *im1, vf, of);
2224 }
2225 
2226 // -----------------------------------------------------------------------------
2227 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2228 void ForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2229 {
2231  body(re);
2232  vf.join(body._VoxelFunc);
2233  of.join(body._OutsideFunc);
2234 }
2235 
2236 // -----------------------------------------------------------------------------
2237 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2238 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, GenericImage<T1> *im1)
2239 {
2240  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2241  ForEachVoxelIf<Domain>(re, *im1, vf, of);
2242 }
2243 
2244 // -----------------------------------------------------------------------------
2245 template <class Domain, class T1, class VoxelFunc>
2246 void ForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2247 {
2249  ForEachVoxelIf<Domain>(re, *im1, vf, of);
2250 }
2251 
2252 // -----------------------------------------------------------------------------
2253 template <class Domain, class T1, class VoxelFunc>
2254 void ForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> *im1)
2255 {
2256  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2257  ForEachVoxelIf<Domain>(re, *im1, vf);
2258 }
2259 
2260 // -----------------------------------------------------------------------------
2261 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2262 void ForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2263 {
2265  body(re);
2266  vf.join(body._VoxelFunc);
2267  of.join(body._OutsideFunc);
2268 }
2269 
2270 // -----------------------------------------------------------------------------
2271 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2272 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, GenericImage<T1> *im1)
2273 {
2274  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2275  ForEachVoxelIf<Domain>(*im1, vf, of);
2276 }
2277 
2278 // -----------------------------------------------------------------------------
2279 template <class Domain, class T1, class VoxelFunc>
2280 void ForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2281 {
2283  ForEachVoxelIf<Domain>(re, *im1, vf, of);
2284 }
2285 
2286 // -----------------------------------------------------------------------------
2287 template <class Domain, class T1, class VoxelFunc>
2288 void ForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> *im1)
2289 {
2290  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2291  ForEachVoxelIf<Domain>(re, *im1, vf);
2292 }
2293 
2294 //
2295 // Image arguments by reference
2296 //
2297 
2298 // -----------------------------------------------------------------------------
2299 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2300 void ForEachScalarIf(GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2301 {
2304  body(re);
2305  vf.join(body._VoxelFunc);
2306  of.join(body._OutsideFunc);
2307 }
2308 
2309 // -----------------------------------------------------------------------------
2310 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2311 void ForEachScalarIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> &im1)
2312 {
2313  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2314  ForEachScalarIf<Domain>(im1, vf, of);
2315 }
2316 
2317 // -----------------------------------------------------------------------------
2318 template <class Domain, class T1, class VoxelFunc>
2319 void ForEachScalarIf(GenericImage<T1> &im1, VoxelFunc &vf)
2320 {
2322  ForEachScalarIf<Domain>(im1, vf, of);
2323 }
2324 
2325 // -----------------------------------------------------------------------------
2326 template <class Domain, class T1, class VoxelFunc>
2327 void ForEachScalarIf(VoxelFunc vf, GenericImage<T1> &im1)
2328 {
2329  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2330  ForEachScalarIf<Domain>(im1, vf);
2331 }
2332 
2333 // -----------------------------------------------------------------------------
2334 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2335 void ForEachVoxelIf(GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2336 {
2337  if (im1.GetTSize()) {
2338  ForEachVoxelIf<Domain>(im1, vf, of);
2339  } else {
2341  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
2342  body(re);
2343  vf.join(body._VoxelFunc);
2344  of.join(body._OutsideFunc);
2345  }
2346 }
2347 
2348 // -----------------------------------------------------------------------------
2349 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2350 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> &im1)
2351 {
2352  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2353  ForEachVoxelIf<Domain>(im1, vf, of);
2354 }
2355 
2356 // -----------------------------------------------------------------------------
2357 template <class Domain, class T1, class VoxelFunc>
2358 void ForEachVoxelIf(GenericImage<T1> &im1, VoxelFunc &vf)
2359 {
2361  ForEachVoxelIf<Domain>(im1, vf, of);
2362 }
2363 
2364 // -----------------------------------------------------------------------------
2365 template <class Domain, class T1, class VoxelFunc>
2366 void ForEachVoxelIf(VoxelFunc vf, GenericImage<T1> &im1)
2367 {
2368  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2369  ForEachVoxelIf<Domain>(im1, vf);
2370 }
2371 
2372 // -----------------------------------------------------------------------------
2373 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2374 void ForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2375 {
2377  body(attr);
2378  vf.join(body._VoxelFunc);
2379  of.join(body._OutsideFunc);
2380 }
2381 
2382 // -----------------------------------------------------------------------------
2383 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2384 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, GenericImage<T1> &im1)
2385 {
2386  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2387  ForEachVoxelIf<Domain>(attr, im1, vf, of);
2388 }
2389 
2390 // -----------------------------------------------------------------------------
2391 template <class Domain, class T1, class VoxelFunc>
2392 void ForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf)
2393 {
2395  ForEachVoxelIf<Domain>(attr, im1, vf, of);
2396 }
2397 
2398 // -----------------------------------------------------------------------------
2399 template <class Domain, class T1, class VoxelFunc>
2400 void ForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> &im1)
2401 {
2402  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2403  ForEachVoxelIf<Domain>(attr, im1, vf);
2404 }
2405 
2406 // -----------------------------------------------------------------------------
2407 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2408 void ForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2409 {
2411  body(re);
2412  vf.join(body._VoxelFunc);
2413  of.join(body._OutsideFunc);
2414 }
2415 
2416 // -----------------------------------------------------------------------------
2417 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2418 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, GenericImage<T1> &im1)
2419 {
2420  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2421  ForEachVoxelIf<Domain>(re, im1, vf, of);
2422 }
2423 
2424 // -----------------------------------------------------------------------------
2425 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2426 void ForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2427 {
2429  body(re);
2430  vf.join(body._VoxelFunc);
2431  of.join(body._OutsideFunc);
2432 }
2433 
2434 // -----------------------------------------------------------------------------
2435 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2436 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, GenericImage<T1> &im1)
2437 {
2438  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2439  ForEachVoxelIf<Domain>(re, im1, vf, of);
2440 }
2441 
2442 // -----------------------------------------------------------------------------
2443 template <class Domain, class T1, class VoxelFunc>
2444 void ForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2445 {
2447  ForEachVoxelIf<Domain>(re, im1, vf, of);
2448 }
2449 
2450 // -----------------------------------------------------------------------------
2451 template <class Domain, class T1, class VoxelFunc>
2452 void ForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> &im1)
2453 {
2454  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2455  ForEachVoxelIf<Domain>(re, im1, vf);
2456 }
2457 
2458 // -----------------------------------------------------------------------------
2459 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2460 void ForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
2461 {
2463  body(re);
2464  vf.join(body._VoxelFunc);
2465  of.join(body._OutsideFunc);
2466 }
2467 
2468 // -----------------------------------------------------------------------------
2469 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2470 void ForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, GenericImage<T1> &im1)
2471 {
2472  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2473  ForEachVoxelIf<Domain>(re, im1, vf, of);
2474 }
2475 
2476 // -----------------------------------------------------------------------------
2477 template <class Domain, class T1, class VoxelFunc>
2478 void ForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2479 {
2481  ForEachVoxelIf<Domain>(re, im1, vf, of);
2482 }
2483 
2484 // -----------------------------------------------------------------------------
2485 template <class Domain, class T1, class VoxelFunc>
2486 void ForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> &im1)
2487 {
2488  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2489  ForEachVoxelIf<Domain>(re, im1, vf);
2490 }
2491 
2492 // -----------------------------------------------------------------------------
2493 // ParallelForEachVoxel
2494 // -----------------------------------------------------------------------------
2495 
2496 //
2497 // Image arguments by pointer
2498 //
2499 
2500 // -----------------------------------------------------------------------------
2501 template <class T1, class VoxelFunc>
2502 void ParallelForEachScalar(GenericImage<T1> *im1, VoxelFunc &vf)
2503 {
2504  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2505  blocked_range<int> re(0, im1->GetNumberOfVoxels());
2506  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2507  else parallel_for (re, body);
2508 }
2509 
2510 // -----------------------------------------------------------------------------
2511 template <class T1, class VoxelFunc>
2512 void ParallelForEachScalar(VoxelFunc vf, GenericImage<T1> *im1)
2513 {
2514  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2515  ParallelForEachScalar(*im1, vf);
2516 }
2517 
2518 // -----------------------------------------------------------------------------
2519 template <class T1, class VoxelFunc>
2520 void ParallelForEachVoxel(GenericImage<T1> *im1, VoxelFunc &vf)
2521 {
2522  if (im1->GetTSize()) {
2523  ParallelForEachScalar(*im1, vf);
2524  } else {
2525  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2526  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
2527  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2528  else parallel_for (re, body);
2529  }
2530 }
2531 
2532 // -----------------------------------------------------------------------------
2533 template <class T1, class VoxelFunc>
2534 void ParallelForEachVoxel(VoxelFunc vf, GenericImage<T1> *im1)
2535 {
2536  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2537  ParallelForEachVoxel(*im1, vf);
2538 }
2539 
2540 // -----------------------------------------------------------------------------
2541 template <class T1, class VoxelFunc>
2542 void ParallelForEachVoxel(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf)
2543 {
2544  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2545  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
2546  if (VoxelFunc::IsReduction()) {
2547  if (attr._dt) {
2548  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
2549  } else {
2550  parallel_reduce(re, body);
2551  }
2552  vf.join(body._VoxelFunc);
2553  } else {
2554  if (attr._dt) {
2555  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
2556  } else {
2557  parallel_for(re, body);
2558  }
2559  }
2560 }
2561 
2562 // -----------------------------------------------------------------------------
2563 template <class T1, class VoxelFunc>
2564 void ParallelForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> *im1)
2565 {
2566  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2567  ParallelForEachVoxel(attr, *im1, vf);
2568 }
2569 
2570 // -----------------------------------------------------------------------------
2571 template <class T1, class VoxelFunc>
2572 void ParallelForEachVoxel(const blocked_range<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2573 {
2574  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2575  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2576  else parallel_for (re, body);
2577 }
2578 
2579 // -----------------------------------------------------------------------------
2580 template <class T1, class VoxelFunc>
2581 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> *im1)
2582 {
2583  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2584  ParallelForEachVoxel(re, *im1, vf);
2585 }
2586 
2587 // -----------------------------------------------------------------------------
2588 template <class T1, class VoxelFunc>
2589 void ParallelForEachVoxel(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2590 {
2591  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2592  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2593  else parallel_for (re, body);
2594 }
2595 
2596 // -----------------------------------------------------------------------------
2597 template <class T1, class VoxelFunc>
2598 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> *im1)
2599 {
2600  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2601  ParallelForEachVoxel(re, *im1, vf);
2602 }
2603 
2604 // -----------------------------------------------------------------------------
2605 template <class T1, class VoxelFunc>
2606 void ParallelForEachVoxel(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2607 {
2608  UnaryForEachVoxelBody<T1, VoxelFunc> body(*im1, vf);
2609  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2610  else parallel_for (re, body);
2611 }
2612 
2613 // -----------------------------------------------------------------------------
2614 template <class T1, class VoxelFunc>
2615 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> *im1)
2616 {
2617  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2618  ParallelForEachVoxel(re, *im1, vf);
2619 }
2620 
2621 //
2622 // Image arguments by reference
2623 //
2624 
2625 // -----------------------------------------------------------------------------
2626 template <class T1, class VoxelFunc>
2627 void ParallelForEachScalar(GenericImage<T1> &im1, VoxelFunc &vf)
2628 {
2631  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2632  else parallel_for (re, body);
2633 }
2634 
2635 // -----------------------------------------------------------------------------
2636 template <class T1, class VoxelFunc>
2637 void ParallelForEachScalar(VoxelFunc vf, GenericImage<T1> &im1)
2638 {
2639  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2640  ParallelForEachScalar(im1, vf);
2641 }
2642 
2643 // -----------------------------------------------------------------------------
2644 template <class T1, class VoxelFunc>
2645 void ParallelForEachVoxel(GenericImage<T1> &im1, VoxelFunc &vf)
2646 {
2647  if (im1.GetTSize()) {
2648  ParallelForEachScalar(im1, vf);
2649  } else {
2651  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
2652  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2653  else parallel_for (re, body);
2654  }
2655 }
2656 
2657 // -----------------------------------------------------------------------------
2658 template <class T1, class VoxelFunc>
2659 void ParallelForEachVoxel(VoxelFunc vf, GenericImage<T1> &im1)
2660 {
2661  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2662  ParallelForEachVoxel(im1, vf);
2663 }
2664 
2665 // -----------------------------------------------------------------------------
2666 template <class T1, class VoxelFunc>
2667 void ParallelForEachVoxel(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf)
2668 {
2670  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
2671  if (VoxelFunc::IsReduction()) {
2672  if (attr._dt) {
2673  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
2674  } else {
2675  parallel_reduce(re, body);
2676  }
2677  vf.join(body._VoxelFunc);
2678  } else {
2679  if (attr._dt) {
2680  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
2681  } else {
2682  parallel_for(re, body);
2683  }
2684  }
2685 }
2686 
2687 // -----------------------------------------------------------------------------
2688 template <class T1, class VoxelFunc>
2689 void ParallelForEachVoxel(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> &im1)
2690 {
2691  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2692  ParallelForEachVoxel(attr, im1, vf);
2693 }
2694 
2695 // -----------------------------------------------------------------------------
2696 template <class T1, class VoxelFunc>
2697 void ParallelForEachVoxel(const blocked_range<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2698 {
2700  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2701  else parallel_for (re, body);
2702 }
2703 
2704 // -----------------------------------------------------------------------------
2705 template <class T1, class VoxelFunc>
2706 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> &im1)
2707 {
2708  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2709  ParallelForEachVoxel(re, im1, vf);
2710 }
2711 
2712 // -----------------------------------------------------------------------------
2713 template <class T1, class VoxelFunc>
2714 void ParallelForEachVoxel(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2715 {
2717  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2718  else parallel_for (re, body);
2719 }
2720 
2721 // -----------------------------------------------------------------------------
2722 template <class T1, class VoxelFunc>
2723 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> &im1)
2724 {
2725  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2726  ParallelForEachVoxel(re, im1, vf);
2727 }
2728 
2729 // -----------------------------------------------------------------------------
2730 template <class T1, class VoxelFunc>
2731 void ParallelForEachVoxel(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
2732 {
2734  if (VoxelFunc::IsReduction()) { parallel_reduce(re, body); vf.join(body._VoxelFunc); }
2735  else parallel_for (re, body);
2736 }
2737 
2738 // -----------------------------------------------------------------------------
2739 template <class T1, class VoxelFunc>
2740 void ParallelForEachVoxel(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> &im1)
2741 {
2742  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2743  ParallelForEachVoxel(re, im1, vf);
2744 }
2745 
2746 // -----------------------------------------------------------------------------
2747 // ParallelForEachVoxelIf
2748 // -----------------------------------------------------------------------------
2749 
2750 //
2751 // Image arguments by pointer
2752 //
2753 
2754 // -----------------------------------------------------------------------------
2755 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2756 void ParallelForEachScalarIf(GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2757 {
2759  blocked_range<int> re(0, im1->GetNumberOfVoxels());
2760  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2761  parallel_reduce(re, body);
2762  vf.join(body._VoxelFunc);
2763  of.join(body._OutsideFunc);
2764  } else {
2765  parallel_for(re, body);
2766  }
2767 }
2768 
2769 // -----------------------------------------------------------------------------
2770 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2771 void ParallelForEachScalarIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> *im1)
2772 {
2773  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2774  ParallelForEachScalarIf<Domain>(*im1, vf, of);
2775 }
2776 
2777 // -----------------------------------------------------------------------------
2778 template <class Domain, class T1, class VoxelFunc>
2779 void ParallelForEachScalarIf(GenericImage<T1> *im1, VoxelFunc &vf)
2780 {
2782  ParallelForEachScalarIf<Domain>(*im1, vf, of);
2783 }
2784 
2785 // -----------------------------------------------------------------------------
2786 template <class Domain, class T1, class VoxelFunc>
2787 void ParallelForEachScalarIf(VoxelFunc vf, GenericImage<T1> *im1)
2788 {
2789  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2790  ParallelForEachScalarIf<Domain>(*im1, vf);
2791 }
2792 
2793 // -----------------------------------------------------------------------------
2794 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2795 void ParallelForEachVoxelIf(GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2796 {
2797  if (im1->GetTSize()) {
2798  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
2799  } else {
2801  blocked_range<int> re(0, im1->GetNumberOfVoxels() / im1->GetT());
2802  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2803  parallel_reduce(re, body);
2804  vf.join(body._VoxelFunc);
2805  of.join(body._OutsideFunc);
2806  } else {
2807  parallel_for(re, body);
2808  }
2809  }
2810 }
2811 
2812 // -----------------------------------------------------------------------------
2813 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2814 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> *im1)
2815 {
2816  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2817  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
2818 }
2819 
2820 // -----------------------------------------------------------------------------
2821 template <class Domain, class T1, class VoxelFunc>
2822 void ParallelForEachVoxelIf(GenericImage<T1> *im1, VoxelFunc &vf)
2823 {
2825  ParallelForEachVoxelIf<Domain>(*im1, vf, of);
2826 }
2827 
2828 // -----------------------------------------------------------------------------
2829 template <class Domain, class T1, class VoxelFunc>
2830 void ParallelForEachVoxelIf(VoxelFunc vf, GenericImage<T1> *im1)
2831 {
2832  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2833  ParallelForEachVoxelIf<Domain>(*im1, vf);
2834 }
2835 
2836 // -----------------------------------------------------------------------------
2837 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2838 void ParallelForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2839 {
2841  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
2842  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2843  if (attr._dt) {
2844  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
2845  } else {
2846  parallel_reduce(re, body);
2847  }
2848  vf.join(body._VoxelFunc);
2849  of.join(body._OutsideFunc);
2850  } else {
2851  if (attr._dt) {
2852  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
2853  } else {
2854  parallel_for(re, body);
2855  }
2856  }
2857 }
2858 
2859 // -----------------------------------------------------------------------------
2860 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2861 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, GenericImage<T1> *im1)
2862 {
2863  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2864  ParallelForEachVoxelIf<Domain>(attr, *im1, vf, of);
2865 }
2866 
2867 // -----------------------------------------------------------------------------
2868 template <class Domain, class T1, class VoxelFunc>
2869 void ParallelForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> *im1, VoxelFunc &vf)
2870 {
2872  ParallelForEachVoxelIf<Domain>(attr, *im1, vf, of);
2873 }
2874 
2875 // -----------------------------------------------------------------------------
2876 template <class Domain, class T1, class VoxelFunc>
2877 void ParallelForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> *im1)
2878 {
2879  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2880  ParallelForEachVoxelIf<Domain>(attr, *im1, vf);
2881 }
2882 
2883 // -----------------------------------------------------------------------------
2884 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2885 void ParallelForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2886 {
2888  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2889  parallel_reduce(re, body);
2890  vf.join(body._VoxelFunc);
2891  of.join(body._OutsideFunc);
2892  } else {
2893  parallel_for(re, body);
2894  }
2895 }
2896 
2897 // -----------------------------------------------------------------------------
2898 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2899 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, GenericImage<T1> *im1)
2900 {
2901  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2902  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2903 }
2904 
2905 // -----------------------------------------------------------------------------
2906 template <class Domain, class T1, class VoxelFunc>
2907 void ParallelForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2908 {
2910  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2911 }
2912 
2913 // -----------------------------------------------------------------------------
2914 template <class Domain, class T1, class VoxelFunc>
2915 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> *im1)
2916 {
2917  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2918  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
2919 }
2920 
2921 // -----------------------------------------------------------------------------
2922 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2923 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2924 {
2926  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2927  parallel_reduce(re, body);
2928  vf.join(body._VoxelFunc);
2929  of.join(body._OutsideFunc);
2930  } else {
2931  parallel_for(re, body);
2932  }
2933 }
2934 
2935 // -----------------------------------------------------------------------------
2936 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2937 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, GenericImage<T1> *im1)
2938 {
2939  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2940  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2941 }
2942 
2943 // -----------------------------------------------------------------------------
2944 template <class Domain, class T1, class VoxelFunc>
2945 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2946 {
2948  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2949 }
2950 
2951 // -----------------------------------------------------------------------------
2952 template <class Domain, class T1, class VoxelFunc>
2953 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> *im1)
2954 {
2955  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2956  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
2957 }
2958 
2959 // -----------------------------------------------------------------------------
2960 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2961 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf, OutsideFunc &of)
2962 {
2964  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
2965  parallel_reduce(re, body);
2966  vf.join(body._VoxelFunc);
2967  of.join(body._OutsideFunc);
2968  } else {
2969  parallel_for(re, body);
2970  }
2971 }
2972 
2973 // -----------------------------------------------------------------------------
2974 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
2975 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, GenericImage<T1> *im1)
2976 {
2977  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2978  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2979 }
2980 
2981 // -----------------------------------------------------------------------------
2982 template <class Domain, class T1, class VoxelFunc>
2983 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> *im1, VoxelFunc &vf)
2984 {
2986  ParallelForEachVoxelIf<Domain>(re, *im1, vf, of);
2987 }
2988 
2989 // -----------------------------------------------------------------------------
2990 template <class Domain, class T1, class VoxelFunc>
2991 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> *im1)
2992 {
2993  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
2994  ParallelForEachVoxelIf<Domain>(re, *im1, vf);
2995 }
2996 
2997 //
2998 // Image arguments by reference
2999 //
3000 
3001 // -----------------------------------------------------------------------------
3002 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3003 void ParallelForEachScalarIf(GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3004 {
3007  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3008  parallel_reduce(re, body);
3009  vf.join(body._VoxelFunc);
3010  of.join(body._OutsideFunc);
3011  } else {
3012  parallel_for(re, body);
3013  }
3014 }
3015 
3016 // -----------------------------------------------------------------------------
3017 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3018 void ParallelForEachScalarIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> &im1)
3019 {
3020  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3021  ParallelForEachScalarIf<Domain>(im1, vf, of);
3022 }
3023 
3024 // -----------------------------------------------------------------------------
3025 template <class Domain, class T1, class VoxelFunc>
3026 void ParallelForEachScalarIf(GenericImage<T1> &im1, VoxelFunc &vf)
3027 {
3029  ParallelForEachScalarIf<Domain>(im1, vf, of);
3030 }
3031 
3032 // -----------------------------------------------------------------------------
3033 template <class Domain, class T1, class VoxelFunc>
3034 void ParallelForEachScalarIf(VoxelFunc vf, GenericImage<T1> &im1)
3035 {
3036  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3037  ParallelForEachScalarIf<Domain>(im1, vf);
3038 }
3039 
3040 // -----------------------------------------------------------------------------
3041 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3042 void ParallelForEachVoxelIf(GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3043 {
3044  if (im1.GetTSize()) {
3045  ParallelForEachVoxelIf<Domain>(im1, vf, of);
3046  } else {
3048  blocked_range<int> re(0, im1.GetNumberOfVoxels() / im1.GetT());
3049  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3050  parallel_reduce(re, body);
3051  vf.join(body._VoxelFunc);
3052  of.join(body._OutsideFunc);
3053  } else {
3054  parallel_for(re, body);
3055  }
3056  }
3057 }
3058 
3059 // -----------------------------------------------------------------------------
3060 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3061 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, GenericImage<T1> &im1)
3062 {
3063  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3064  ParallelForEachVoxelIf<Domain>(im1, vf, of);
3065 }
3066 
3067 // -----------------------------------------------------------------------------
3068 template <class Domain, class T1, class VoxelFunc>
3069 void ParallelForEachVoxelIf(GenericImage<T1> &im1, VoxelFunc &vf)
3070 {
3072  ParallelForEachVoxelIf<Domain>(im1, vf, of);
3073 }
3074 
3075 // -----------------------------------------------------------------------------
3076 template <class Domain, class T1, class VoxelFunc>
3077 void ParallelForEachVoxelIf(VoxelFunc vf, GenericImage<T1> &im1)
3078 {
3079  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3080  ParallelForEachVoxelIf<Domain>(im1, vf);
3081 }
3082 
3083 // -----------------------------------------------------------------------------
3084 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3085 void ParallelForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3086 {
3088  blocked_range3d<int> re(0, attr._z, 0, attr._y, 0, attr._x);
3089  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3090  if (attr._dt) {
3091  for (body._l = 0; body._l < attr._t; ++body._l) parallel_reduce(re, body);
3092  } else {
3093  parallel_reduce(re, body);
3094  }
3095  vf.join(body._VoxelFunc);
3096  of.join(body._OutsideFunc);
3097  } else {
3098  if (attr._dt) {
3099  for (body._l = 0; body._l < attr._t; ++body._l) parallel_for(re, body);
3100  } else {
3101  parallel_for(re, body);
3102  }
3103  }
3104 }
3105 
3106 // -----------------------------------------------------------------------------
3107 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3108 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const ImageAttributes &attr, GenericImage<T1> &im1)
3109 {
3110  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3111  ParallelForEachVoxelIf<Domain>(attr, im1, vf, of);
3112 }
3113 
3114 // -----------------------------------------------------------------------------
3115 template <class Domain, class T1, class VoxelFunc>
3116 void ParallelForEachVoxelIf(const ImageAttributes &attr, GenericImage<T1> &im1, VoxelFunc &vf)
3117 {
3119  ParallelForEachVoxelIf<Domain>(attr, im1, vf, of);
3120 }
3121 
3122 // -----------------------------------------------------------------------------
3123 template <class Domain, class T1, class VoxelFunc>
3124 void ParallelForEachVoxelIf(VoxelFunc vf, const ImageAttributes &attr, GenericImage<T1> &im1)
3125 {
3126  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3127  ParallelForEachVoxelIf<Domain>(attr, im1, vf);
3128 }
3129 
3130 // -----------------------------------------------------------------------------
3131 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3132 void ParallelForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3133 {
3135  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3136  parallel_reduce(re, body);
3137  vf.join(body._VoxelFunc);
3138  of.join(body._OutsideFunc);
3139  } else {
3140  parallel_for(re, body);
3141  }
3142 }
3143 
3144 // -----------------------------------------------------------------------------
3145 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3146 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range<int> &re, GenericImage<T1> &im1)
3147 {
3148  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3149  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3150 }
3151 
3152 // -----------------------------------------------------------------------------
3153 template <class Domain, class T1, class VoxelFunc>
3154 void ParallelForEachVoxelIf(const blocked_range<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
3155 {
3157  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3158 }
3159 
3160 // -----------------------------------------------------------------------------
3161 template <class Domain, class T1, class VoxelFunc>
3162 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range<int> &re, GenericImage<T1> &im1)
3163 {
3164  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3165  ParallelForEachVoxelIf<Domain>(re, im1, vf);
3166 }
3167 
3168 // -----------------------------------------------------------------------------
3169 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3170 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3171 {
3173  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3174  parallel_reduce(re, body);
3175  vf.join(body._VoxelFunc);
3176  of.join(body._OutsideFunc);
3177  } else {
3178  parallel_for(re, body);
3179  }
3180 }
3181 
3182 // -----------------------------------------------------------------------------
3183 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3184 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range2d<int> &re, GenericImage<T1> &im1)
3185 {
3186  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3187  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3188 }
3189 
3190 // -----------------------------------------------------------------------------
3191 template <class Domain, class T1, class VoxelFunc>
3192 void ParallelForEachVoxelIf(const blocked_range2d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
3193 {
3195  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3196 }
3197 
3198 // -----------------------------------------------------------------------------
3199 template <class Domain, class T1, class VoxelFunc>
3200 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range2d<int> &re, GenericImage<T1> &im1)
3201 {
3202  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3203  ParallelForEachVoxelIf<Domain>(re, im1, vf);
3204 }
3205 
3206 // -----------------------------------------------------------------------------
3207 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3208 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf, OutsideFunc &of)
3209 {
3211  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) {
3212  parallel_reduce(re, body);
3213  vf.join(body._VoxelFunc);
3214  of.join(body._OutsideFunc);
3215  } else {
3216  parallel_for(re, body);
3217  }
3218 }
3219 
3220 // -----------------------------------------------------------------------------
3221 template <class Domain, class T1, class VoxelFunc, class OutsideFunc>
3222 void ParallelForEachVoxelIf(VoxelFunc vf, OutsideFunc of, const blocked_range3d<int> &re, GenericImage<T1> &im1)
3223 {
3224  if (VoxelFunc::IsReduction() || OutsideFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3225  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3226 }
3227 
3228 // -----------------------------------------------------------------------------
3229 template <class Domain, class T1, class VoxelFunc>
3230 void ParallelForEachVoxelIf(const blocked_range3d<int> &re, GenericImage<T1> &im1, VoxelFunc &vf)
3231 {
3233  ParallelForEachVoxelIf<Domain>(re, im1, vf, of);
3234 }
3235 
3236 // -----------------------------------------------------------------------------
3237 template <class Domain, class T1, class VoxelFunc>
3238 void ParallelForEachVoxelIf(VoxelFunc vf, const blocked_range3d<int> &re, GenericImage<T1> &im1)
3239 {
3240  if (VoxelFunc::IsReduction()) _foreachunaryvoxelfunction_must_not_be_reduction();
3241  ParallelForEachVoxelIf<Domain>(re, im1, vf);
3242 }
3243 
3244 
3245 } // namespace mirtk
3246 
3247 #endif
double _dt
Voxel t-dimensions (in ms)
Dummy type used to distinguish split constructor from copy constructor.
Definition: Parallel.h:143
Two-dimensional range.
Definition: Parallel.h:168
UnaryForEachVoxelIfBody(UnaryForEachVoxelIfBody &o, split s)
Split constructor.
bool IsEmpty() const
Whether image is uninitialized.
Definition: BaseImage.h:1283
UnaryForEachVoxelBody_Const(const UnaryForEachVoxelBody_Const &o)
Copy constructor.
int _y
Image y-dimension (in voxels)
UnaryForEachVoxelIfBody_Const(const UnaryForEachVoxelIfBody_Const &o)
Copy constructor.
One-dimensional range.
Definition: Parallel.h:155
VoxelFunc _VoxelFunc
Functor executed for each voxel.
void operator()(const ImageAttributes &attr) const
Process entire image.
UnaryForEachVoxelBody_Const(const GenericImage< T1 > &im1, VoxelFunc &vf)
Constructor.
UnaryForEachVoxelBody(GenericImage< T1 > &im1, VoxelFunc &vf)
Constructor.
UnaryForEachVoxelIfBody_Const(const GenericImage< T1 > &im1, VoxelFunc &vf, OutsideFunc &of)
Constructor.
Definition: IOConfig.h:41
VoxelType * GetPointerToVoxels(int=0, int=0, int=0, int=0)
Definition: GenericImage.h:849
int GetX() const
Returns the number of voxels in the x-direction.
Definition: BaseImage.h:904
int _z
Image z-dimension (in voxels)
int _l
Indices for fixed dimensions.
int _t
Image t-dimension (in voxels)
int GetT() const
Returns the number of voxels in the t-direction.
Definition: BaseImage.h:922
int GetY() const
Returns the number of voxels in the y-direction.
Definition: BaseImage.h:910
Three-dimensional range.
Definition: Parallel.h:197
int GetNumberOfVoxels() const
Definition: BaseImage.h:1741
OutsideFunc _OutsideFunc
Functor executed for each background voxel.
UnaryForEachVoxelIfBody_Const(UnaryForEachVoxelIfBody_Const &o, split s)
Split constructor.
UnaryForEachVoxelBody_Const(UnaryForEachVoxelBody_Const &o, split s)
Split constructor.
double GetTSize() const
Returns the size of a voxel in the t-direction.
Definition: BaseImage.h:970
int _x
Image x-dimension (in voxels)
UnaryForEachVoxelIfBody(GenericImage< T1 > &im1, VoxelFunc &vf, OutsideFunc &of)
Constructor.
UnaryForEachVoxelBody(UnaryForEachVoxelBody &o, split s)
Split constructor.
void parallel_reduce(const Range &range, Body &body)
parallel_reduce dummy template function which executes the body serially
Definition: Parallel.h:238
UnaryForEachVoxelBody(const UnaryForEachVoxelBody &o)
Copy constructor.
void parallel_for(const Range &range, const Body &body)
parallel_for dummy template function which executes the body serially
Definition: Parallel.h:232
UnaryForEachVoxelIfBody(const UnaryForEachVoxelIfBody &o)
Copy constructor.