aimsdata  5.1.2
Neuroimaging data handling
merge.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  * Merging operators
36  */
37 #ifndef AIMS_UTILITY_MERGE_H
38 #define AIMS_UTILITY_MERGE_H
39 
42 
43 enum merge_t
44 {
50 };
51 
52 
61 template <class T,class U>
62 class AimsMerge
63 {
64  public :
72  AimsMerge(merge_t type,T value=0,U label=0);
74  virtual ~AimsMerge() {}
76 
81  const carto::rc_ptr<carto::Volume<T> > & data,
84 
85  protected :
89  T _value;
91  U _label;
92 };
93 
94 
95 template <class T,class U>
96 AimsMerge<T,U>::AimsMerge(merge_t type,T value,U label)
97 {
98  _type = type;
99  _value = value;
100  _label = label;
101 
102 }
103 
104 
105 template <class T,class U> inline
107  const carto::rc_ptr<carto::Volume<T> > & data,
109 {
110  ASSERT(data->getSizeX() == mask->getSizeX() &&
111  data->getSizeY() == mask->getSizeY() &&
112  data->getSizeZ() == mask->getSizeZ() &&
113  data->getSizeT() == mask->getSizeT() );
114 
116 
117  typename carto::Volume<T>::iterator it1;
119 
120  switch (_type)
121  { case AIMS_MERGE_SAME_VALUES :
122  for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
123  if (*it2) *it1 = (T)*it2;
124  break;
125  case AIMS_MERGE_ONE_TO_ONE :
126  for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
127  if (*it2==_label) *it1 = (T)_value;
128  break;
129  case AIMS_MERGE_ALL_TO_ONE :
130  for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
131  if (*it2) *it1 = (T)_value;
132  break;
134  _value = res.max() + 1;
135  for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
136  if (*it2==_label) *it1 = (T)_value;
137  break;
139  _value = res.max() + 1;
140  for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
141  if (*it2) *it1 = (T)_value;
142  break;
143  }
144  return(res);
145 }
146 
147 
148 #endif
#define ASSERT(EX)
The template class to merge data and byte label data.
Definition: merge.h:63
U _label
Label to consider.
Definition: merge.h:91
AimsMerge(merge_t type, T value=0, U label=0)
The programmer must provide a type of merging.
Definition: merge.h:96
merge_t _type
Merging type.
Definition: merge.h:87
carto::VolumeRef< T > operator()(const carto::rc_ptr< carto::Volume< T > > &data, const carto::rc_ptr< carto::Volume< U > > &mask)
Return the result of the merge of a data and a byte label data.
Definition: merge.h:106
T _value
Merging value.
Definition: merge.h:89
virtual ~AimsMerge()
Destructor does nothing.
Definition: merge.h:74
VolumeRef< T > deepcopy() const
iterator end()
iterator begin()
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
merge_t
Definition: merge.h:44
@ AIMS_MERGE_ONE_TO_MAXP1
Definition: merge.h:48
@ AIMS_MERGE_ONE_TO_ONE
Definition: merge.h:46
@ AIMS_MERGE_ALL_TO_ONE
Definition: merge.h:47
@ AIMS_MERGE_SAME_VALUES
Definition: merge.h:45
@ AIMS_MERGE_ALL_TO_MAXP1
Definition: merge.h:49
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)
mask src object with m.