aimsalgo  5.1.2
Neuroimaging image processing
topology.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 
35 #ifndef AIMS_TOPOLOGY_TOPOLOGY_H
36 #define AIMS_TOPOLOGY_TOPOLOGY_H
37 
39 #include <aims/topology/topoBase.h>
40 
41 
42 template< class T >
43 class Topology : public TopologyBase
44 {
45 public:
46 
48 
49  void fillNeighborhood( const Point3d&, int );
50  void fillNeighborhood( const Point3d&, int, int );
51  void fillNeighborhoodComplement( const Point3d&, int );
52 
53 private:
54 
55  void init( const carto::rc_ptr<carto::Volume< T > >& );
56 
58 };
59 
60 
61 template< class T > inline
63  : TopologyBase()
64 {
65  init( d );
66 }
67 
68 
69 template< class T > inline
71 {
72  if ( d->getBorders()[0] == 0 || d->getBorders()[1] == 0
73  || d->getBorders()[2] == 0 )
74  {
75  int dx = d->getSizeX(), dy = d->getSizeY(), dz = d->getSizeZ();
76  int x, y, z;
77 
78  _data = carto::VolumeRef< T >( dx, dy, dz, 1, 1 );
79  _data.setVoxelSize( d->getVoxelSize() );
80 
81  for ( z=0; z<dz; z++ )
82  for ( y=0; y<dy; y++ )
83  for ( x=0; x<dx; x++ )
84  _data( x, y, z ) = d->at( x, y, z );
85  }
86  else _data = d;
87 
88  _data.fillBorder( (T)0 );
89 }
90 
91 
92 template< class T > inline
93 void Topology< T >::fillNeighborhood( const Point3d& pt, int label )
94 {
95  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.getSizeX()-1 &&
96  pt[1] < _data.getSizeY()-1 && pt[2] < _data.getSizeZ()-1 )
97  {
98  Point3d dep;
99 
100  myX[ 0 ] = 0;
101 
102  int *xptr = myX + 1;
103  for ( int i=1; i<27; i++ )
104  {
105  dep = pt + connex26.deplacement( i );
106  *xptr++ = ( _data( dep ) == (T)label );
107  }
108  }
109  else _cstar = _cbar = 0;
110 }
111 
112 
113 template< class T > inline
114 void Topology< T >::fillNeighborhood( const Point3d& pt, int lb1, int lb2 )
115 {
116  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.getSizeX()-1 &&
117  pt[1] < _data.getSizeY()-1 && pt[2] < _data.getSizeZ()-1 )
118  {
119  Point3d dep;
120  T temp;
121 
122  myX[ 0 ] = 0;
123 
124  int *xptr = myX + 1;
125  for ( int i=1; i<27; i++ )
126  {
127  dep = pt + connex26.deplacement( i );
128  temp = _data( dep );
129  *xptr++ = ( temp == (T)lb1 ) || ( temp == (T)lb2 );
130  }
131  }
132  else _cstar = _cbar = 0;
133 }
134 
135 
136 template< class T > inline
138 {
139  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.getSizeX()-1 &&
140  pt[1] < _data.getSizeY()-1 && pt[2] < _data.getSizeZ()-1 )
141  {
142  Point3d dep;
143 
144  myX[ 0 ] = 0;
145 
146  int *xptr = myX + 1;
147  for ( int i=1; i<27; i++ )
148  {
149  dep = pt + connex26.deplacement( i );
150  *xptr++ = ( _data( dep ) != (T)label );
151  }
152  }
153  else _cstar = _cbar = 0;
154 }
155 
156 #endif
void fillNeighborhoodComplement(const Point3d &, int)
Definition: topology.h:137
Topology(const carto::rc_ptr< carto::Volume< T > > &)
Definition: topology.h:62
void fillNeighborhood(const Point3d &, int)
Definition: topology.h:93