aimsdata 6.0.0
Neuroimaging data handling
fill_d.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#include <aims/roi/fill.h>
36#include <set>
37
38
39namespace aims
40{
41
42 template <typename T>
43 void floodFill( carto::Volume<T> & vol, const Point3d & pos, T value,
44 Connectivity::Type connectivity, T tolerence, bool verbose )
45 {
46 typedef Point3d Pt;
47 typedef std::list<Pt> Pset;
48
49 std::vector<int> size = vol.getSize(), bsize = vol.getSize();
50 bsize[0] += 2;
51 bsize[1] += 2;
52 bsize[2] += 2;
53 carto::VolumeRef<int16_t> bdone( bsize );
54 std::vector<int> bpos( 3, 1 );
55 carto::VolumeRef<int16_t> done( bdone, bpos, size );
56 bdone.fill( 1 );
57 done.fill( 0 );
58
59 T initVal = vol.at( pos );
60 T minVal = initVal - tolerence;
61 T maxVal = initVal + tolerence;
62 std::cout << "minVal: " << minVal << ", maxVal: " << maxVal << std::endl;
63 Pset front1, front2;
64 Pset *front = &front1, *next_front = &front2;
65 next_front->push_back( pos );
66 Connectivity c( &vol( 0, 1 ) - &vol( 0 ), &vol( 0, 0, 1 ) - &vol( 0 ),
67 connectivity );
68 int i, n = c.nbNeighbors();
69
70 done.at( pos ) = 1;
71 Connectivity c2( &done( 0, 1 ) - &done( 0 ), &done( 0, 0, 1 ) - &done( 0 ),
72 connectivity );
73
74 while( !next_front->empty() )
75 {
76 if( verbose )
77 std::cout << "front size: " << next_front->size() << std::endl;
78 // swap fronts
79 Pset * t = front;
80 front = next_front;
81 next_front = t;
82 next_front->clear();
83 Pset::const_iterator ip, ep = front->end();
84
85 for( ip=front->begin(); ip!=ep; ++ip )
86 {
87 const Pt & p = *ip;
88 T* pp = &vol.at( p );
89 *pp = value;
90 int16_t *pd = &done.at( p );
91 for( i=0; i<n; ++i )
92 {
93 int16_t *ppd = pd + c2.offset( i );
94 const T & val = *( pp + c.offset( i ) );
95 if( *ppd == 0 && val >= minVal && val <= maxVal )
96 {
97 next_front->push_back( p + c.xyzOffset( i ) );
98 *ppd = 1;
99 }
100 }
101 }
102 }
103 }
104
105}
106
Topology of a data container.
const Point3d & xyzOffset(int n) const
Get the X/Y/Z offsets of the nth element.
int nbNeighbors() const
Get the number of neighbors for that connectivity.
int offset(int n) const
Get the linear offset of the nth element.
Type
The different kinds of connectivity.
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
void fill(const T &value)
const T & at(long x, long y=0, long z=0, long t=0) const
The class for EcatSino data write operation.
void floodFill(carto::Volume< T > &vol, const Point3d &pos, T value, Connectivity::Type connectivity=Connectivity::CONNECTIVITY_18_XYZ, T tolerence=0, bool verbose=false)
Definition fill_d.h:43
AimsVector< int16_t, 3 > Point3d