aimsdata 6.0.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 <cartodata/volume/volume.h>
42
51
52
61template <class T,class U>
63{
64 public :
67
72 AimsMerge(merge_t type,T value=0,U label=0);
74 virtual ~AimsMerge() {}
76
79
81 const carto::rc_ptr<carto::Volume<T> > & data,
82 const carto::rc_ptr<carto::Volume<U> > & mask);
84
85 protected :
92};
93
94
95template <class T,class U>
97{
98 _type = type;
99 _value = value;
100 _label = label;
101
102}
103
104
105template <class T,class U> inline
107 const carto::rc_ptr<carto::Volume<T> > & data,
108 const carto::rc_ptr<carto::Volume<U> > & mask )
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;
126 for (it1=res.begin(),it2=mask->begin();it1!=res.end();it1++,it2++)
127 if (*it2==_label) *it1 = (T)_value;
128 break;
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)
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
iterator end()
iterator begin()
VolumeRef< T > deepcopy() const
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