aimsalgo  5.0.5
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 
38 #include <aims/data/data.h>
39 #include <aims/topology/topoBase.h>
40 
41 
42 template< class T >
43 class Topology : public TopologyBase
44 {
45 public:
46 
47  Topology( const AimsData< T >& );
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 AimsData< T >& );
56 
57  AimsData< T > _data;
58 };
59 
60 
61 template< class T > inline
63 {
64  init( d );
65 }
66 
67 
68 template< class T > inline
69 void Topology< T >::init( const AimsData< T >& d )
70 {
71  if ( d.borderWidth() == 0 )
72  {
73  int dx = d.dimX(), dy = d.dimY(), dz = d.dimZ();
74  int x, y, z;
75 
76  _data = AimsData< T >( dx, dy, dz, 1, 1 );
77  _data.setSizeXYZT( d.sizeX(), d.sizeY(), d.sizeZ() );
78 
79  for ( z=0; z<dz; z++ )
80  for ( y=0; y<dy; y++ )
81  for ( x=0; x<dx; x++ )
82  _data( x, y, z ) = d( x, y, z );
83  }
84  else _data = d;
85 
86  _data.fillBorder( (T)0 );
87 }
88 
89 
90 template< class T > inline
91 void Topology< T >::fillNeighborhood( const Point3d& pt, int label )
92 {
93  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.dimX()-1 &&
94  pt[1] < _data.dimY()-1 && pt[2] < _data.dimZ()-1 )
95  {
96  Point3d dep;
97 
98  myX[ 0 ] = 0;
99 
100  int *xptr = myX + 1;
101  for ( int i=1; i<27; i++ )
102  {
103  dep = pt + connex26.deplacement( i );
104  *xptr++ = ( _data( dep ) == (T)label );
105  }
106  }
107  else _cstar = _cbar = 0;
108 }
109 
110 
111 template< class T > inline
112 void Topology< T >::fillNeighborhood( const Point3d& pt, int lb1, int lb2 )
113 {
114  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.dimX()-1 &&
115  pt[1] < _data.dimY()-1 && pt[2] < _data.dimZ()-1 )
116  {
117  Point3d dep;
118  T temp;
119 
120  myX[ 0 ] = 0;
121 
122  int *xptr = myX + 1;
123  for ( int i=1; i<27; i++ )
124  {
125  dep = pt + connex26.deplacement( i );
126  temp = _data( dep );
127  *xptr++ = ( temp == (T)lb1 ) || ( temp == (T)lb2 );
128  }
129  }
130  else _cstar = _cbar = 0;
131 }
132 
133 
134 template< class T > inline
136 {
137  if ( pt[0] > 0 && pt[1] > 0 && pt[2] > 0 && pt[0] < _data.dimX()-1 &&
138  pt[1] < _data.dimY()-1 && pt[2] < _data.dimZ()-1 )
139  {
140  Point3d dep;
141 
142  myX[ 0 ] = 0;
143 
144  int *xptr = myX + 1;
145  for ( int i=1; i<27; i++ )
146  {
147  dep = pt + connex26.deplacement( i );
148  *xptr++ = ( _data( dep ) != (T)label );
149  }
150  }
151  else _cstar = _cbar = 0;
152 }
153 
154 #endif
void fillNeighborhoodComplement(const Point3d &, int)
Definition: topology.h:135
int dimZ() const
Connectivity26 connex26
Definition: topoBase.h:65
float sizeZ() const
int dimY() const
int myX[27]
Definition: topoBase.h:70
int _cstar
Definition: topoBase.h:72
float sizeX() const
Topology(const AimsData< T > &)
Definition: topology.h:62
float sizeY() const
void fillNeighborhood(const Point3d &, int)
Definition: topology.h:91
const Point3d & deplacement(int i) const
Definition: relation.h:49
int dimX() const
int borderWidth() const