highres-cortex 6.0.4
advection.tcc
Go to the documentation of this file.
1/*
2Copyright CEA (2014, 2017).
3Copyright Université Paris XI (2014).
4
5Contributor: Yann Leprince <yann.leprince@ylep.fr>.
6Contributor: Denis Rivière <denis.riviere@cea.fr>.
7
8This file is part of highres-cortex, a collection of software designed
9to process high-resolution magnetic resonance images of the cerebral
10cortex.
11
12This software is governed by the CeCILL licence under French law and
13abiding by the rules of distribution of free software. You can use,
14modify and/or redistribute the software under the terms of the CeCILL
15licence as circulated by CEA, CNRS and INRIA at the following URL:
16<http://www.cecill.info/>.
17
18As a counterpart to the access to the source code and rights to copy,
19modify and redistribute granted by the licence, users are provided only
20with a limited warranty and the software's author, the holder of the
21economic rights, and the successive licensors have only limited
22liability.
23
24In this respect, the user's attention is drawn to the risks associated
25with loading, using, modifying and/or developing or reproducing the
26software by the user in light of its specific status of scientific
27software, that may mean that it is complicated to manipulate, and that
28also therefore means that it is reserved for developers and experienced
29professionals having in-depth computer knowledge. Users are therefore
30encouraged to load and test the software's suitability as regards their
31requirements in conditions enabling the security of their systems and/or
32data to be ensured and, more generally, to use and operate it in the
33same conditions as regards security.
34
35The fact that you are presently reading this means that you have had
36knowledge of the CeCILL licence and that you accept its terms.
37*/
38
39#include <iostream>
40
41
42namespace
43{
44int debug_output = 0;
45} // end of anonymous namespace
46
47template <class TVisitor>
48bool
49yl::Advection::
50visitor_advection(TVisitor& visitor,
51 const Point3df& start_point) const
52{
53 using std::clog;
54 using std::endl;
55
56 if(m_verbose >= 2) {
57 clog << "yl::Advection::visitor_advection starting at "
58 << start_point << endl;
59 }
60
61 unsigned int iter = 0;
62 Point3df point = start_point;
63 visitor.first(point);
64
65 while(visitor.move_on(point)) {
66 if(iter >= m_max_iter) {
67 if(m_verbose >= 1) {
68 clog << " advection aborted after " << iter
69 << " iterations: too many iterations." << endl;
70 }
71 visitor.abort();
72 return false;
73 }
74
75 if(debug_output >= 3 && m_verbose >= 3) {
76 clog << " iteration " << iter << " at " << point << endl;
77 }
78
79 ++iter;
80 visitor.visit(point);
81
82 // Move along the field
83 Point3df local_field;
84 try {
85 m_vector_field.evaluate(point, local_field);
86 } catch(const Field::UndefinedField&) {
87 if(m_verbose >= 1) {
88 clog << " advection aborted after " << iter
89 << " iterations: vector field is undefined at " << point << endl;
90 }
91
92 visitor.abort();
93 return false;
94 }
95
96 try {
97 move_one_step(point, local_field);
98 } catch(const AbnormalField&) {
99 if(m_verbose >= 1) {
100 clog << " advection aborted after " << iter
101 << " iterations: vector field is abnormal"
102 " (too small, infinite, or NaN) at "
103 << point << endl;
104 }
105
106 visitor.abort();
107 return false;
108 }
109 }
110
111 visitor.finished(start_point);
112
113 if(m_verbose >= 2) {
114 clog << " advection finished after " << iter << " iterations" << endl;
115 }
116 return !visitor.aborted();
117}