cartodata 6.0.0
volumeproxy_d.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#ifndef CARTODATA_VOLUME_VOLUMEPROXY_D_H
35#define CARTODATA_VOLUME_VOLUMEPROXY_D_H
36
37
39
40
41namespace carto
42{
43
44
45 template < typename T >
46 VolumeProxy< T >::VolumeProxy( int sizeX, int sizeY, int sizeZ, int sizeT )
47 : Headered(),
48 _size( 4 )
49 {
50 _size[0] = sizeX;
51 _size[1] = sizeY;
52 _size[2] = sizeZ;
53 _size[3] = sizeT;
54
55 header().addBuiltinProperty( "volume_dimension", _size );
56 header().addBuiltinProperty( "sizeX", _size[0] );
57 header().addBuiltinProperty( "sizeY", _size[1] );
58 header().addBuiltinProperty( "sizeZ", _size[2] );
59 header().addBuiltinProperty( "sizeT", _size[3] );
60
61 }
62
63
64 template < typename T >
65 VolumeProxy< T >::VolumeProxy( const std::vector<int> & size )
66 : Headered(),
67 _size( size )
68 {
69 if( _size.size() < 4 )
70 {
71 _size.reserve( 4 );
72 _size.insert( _size.end(), 4 - _size.size(), 1 );
73 }
74 header().addBuiltinProperty( "volume_dimension", _size );
75 header().addBuiltinProperty( "sizeX", _size[0] );
76 header().addBuiltinProperty( "sizeY", _size[1] );
77 header().addBuiltinProperty( "sizeZ", _size[2] );
78 header().addBuiltinProperty( "sizeT", _size[3] );
79 }
80
81
82 template < typename T >
84 : RCObject(),
85 Headered( other ),
86 _size( other._size )
87 {
88
89 if( header().hasProperty( "volume_dimension" ) )
90 header().removeProperty( "volume_dimension" );
91 if( header().hasProperty( "sizeX" ) )
92 header().removeProperty( "sizeX" );
93 if( header().hasProperty( "sizeY" ) )
94 header().removeProperty( "sizeY" );
95 if( header().hasProperty( "sizeZ" ) )
96 header().removeProperty( "sizeZ" );
97 if( header().hasProperty( "sizeT" ) )
98 header().removeProperty( "sizeT" );
99
100 header().addBuiltinProperty( "volume_dimension", _size );
101 header().addBuiltinProperty( "sizeX", _size[0] );
102 header().addBuiltinProperty( "sizeY", _size[1] );
103 header().addBuiltinProperty( "sizeZ", _size[2] );
104 header().addBuiltinProperty( "sizeT", _size[3] );
105
106 }
107
108
109 template < typename T >
113
114
115 template < typename T >
118 {
119
120 if( this == &other )
121 return *this;
122
123 this->Headered::operator=( other );
124 _size = other._size;
125
126 if( header().hasProperty( "sizeX" ) )
127 header().changeBuiltinProperty( "sizeX", _size[0] );
128 if( header().hasProperty( "sizeY" ) )
129 header().changeBuiltinProperty( "sizeY", _size[1] );
130 if( header().hasProperty( "sizeZ" ) )
131 header().changeBuiltinProperty( "sizeZ", _size[2] );
132 if( header().hasProperty( "sizeT" ) )
133 header().changeBuiltinProperty( "sizeT", _size[3] );
134
135 return *this;
136
137 }
138
139
140 template < typename T >
141 std::vector<float> VolumeProxy< T >::getVoxelSize() const
142 {
143
144 size_t i, n = _size.size();
145 std::vector<float> voxelsize( n, 1. );
146 carto::Object vso;
147 try
148 {
149 vso = header().getProperty( "voxel_size" );
150 if( vso->size() < n )
151 n = vso->size();
152 for( i=0; i<n; ++i )
153 try
154 {
155 voxelsize[i] = float( vso->getArrayItem(i)->getScalar() );
156 }
157 catch( std::exception & )
158 {
159 }
160 }
161 catch( std::exception & )
162 {
163 }
164
165 return voxelsize;
166
167 }
168
169
170 template < typename T>
171 void VolumeProxy<T>::setVoxelSize( float vx, float vy, float vz, float vt )
172 {
173 std::vector<float> vs( 4 );
174 vs[0] = vx;
175 vs[1] = vy;
176 vs[2] = vz;
177 vs[3] = vt;
178 setVoxelSize( vs );
179 }
180
181
182 template < typename T>
183 void VolumeProxy<T>::setVoxelSize( const std::vector<float> & vs )
184 {
185 header().setProperty( "voxel_size", vs );
186 }
187
188
189 template < typename T >
191 bool stopOnError )
192 {
193 if( other.isNull() )
194 return;
195
196 std::set<std::string> forbidden;
197 forbidden.insert( "sizeX" );
198 forbidden.insert( "sizeY" );
199 forbidden.insert( "sizeZ" );
200 forbidden.insert( "sizeT" );
201 forbidden.insert( "volume_dimension" );
202
203 PropertySet & hdr = header();
204 std::string err_msg;
205
206 Object it = other->objectIterator();
207 while( it->isValid() )
208 {
209 if( forbidden.find( it->key() ) == forbidden.end() )
210 try
211 {
212 hdr.setProperty( it->key(), it->currentValue() );
213 }
214 catch( std::exception & e )
215 {
216 std::cerr << "header property " << it->key() << " could not be copied: probably the destination already exists as a builtin with a different type.\n";
217 std::cerr << "error message: " << e.what() << std::endl;
218 if( stopOnError )
219 throw;
220 err_msg = e.what();
221 }
222 it->next();
223 }
224 if( !err_msg.empty() )
225 throw std::runtime_error( err_msg );
226 }
227
228}
229
230#endif
const PropertySet & header() const
Headered & operator=(const Headered &other)
void setProperty(const std::string &, const T &)
void addBuiltinProperty(const std::string &, T &)
VolumeProxy is the base class for volumes.
Definition volumeproxy.h:50
VolumeProxy(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1)
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
std::vector< float > getVoxelSize() const
get the voxel size from the header, with 4 values defaulting to 1.mm if not present
virtual void copyHeaderFrom(const PropertySet &other, bool stopOnError=true)
copy properties from other to this, avoiding forbidden properties like size.
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
std::vector< int > _size
Definition volumeproxy.h:84
bool isNull() const