aimsdata  4.7.0
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 
41 #include <aims/data/data.h>
42 
44 {
50 };
51 
52 
61 template <class T,class U>
63 {
64  public :
72  AimsMerge(merge_t type,T value=0,U label=0);
74  virtual ~AimsMerge() {}
76 
79  inline AimsData<T> operator () (const AimsData<T> &data,
81  const AimsData<U> &mask);
83 
84  protected :
87  merge_t _type;
90  T _value;
92  U _label;
94 };
95 
96 
97 template <class T,class U>
98 AimsMerge<T,U>::AimsMerge(merge_t type,T value,U label)
99 {
100  _type = type;
101  _value = value;
102  _label = label;
103 
104 }
105 
106 
107 template <class T,class U> inline
109  const AimsData<U> &mask)
110 { ASSERT(data.dimX() == mask.dimX() &&
111  data.dimY() == mask.dimY() &&
112  data.dimZ() == mask.dimZ() &&
113  data.dimT() == mask.dimT() );
114 
115  AimsData<T> res = data.clone();
116 
117  typename AimsData<T>::iterator it1;
118  typename AimsData<U>::const_iterator it2;
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.maximum() + 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.maximum() + 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
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)
mask src object with m.
const T * const_iterator
basic constant iterator
int dimZ() const
AimsData< T > operator()(const AimsData< T > &data, const AimsData< U > &mask)
Return the result of the merge of a data and a byte label data.
Definition: merge.h:108
iterator begin()
#define AIMSDATA_API
T * iterator
basic iterator
int dimY() const
The template class to merge data and byte label data.
Definition: merge.h:62
merge_t
Definition: merge.h:43
virtual ~AimsMerge()
Destructor does nothing.
Definition: merge.h:74
AimsData< T > clone() const
U _label
Label to consider.
Definition: merge.h:92
int dimT() const
T _value
Merging value.
Definition: merge.h:90
AimsMerge(merge_t type, T value=0, U label=0)
The programmer must provide a type of merging.
Definition: merge.h:98
iterator end()
#define ASSERT(EX)
int dimX() const