34#ifndef CARTODATA_VOLUME_VOLUMEPROXY_D_H
35#define CARTODATA_VOLUME_VOLUMEPROXY_D_H
45 template <
typename T >
64 template <
typename T >
69 if(
_size.size() < 4 )
72 _size.insert( _size.end(), 4 - _size.size(), 1 );
74 header().addBuiltinProperty(
"volume_dimension",
_size );
82 template <
typename T >
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" );
109 template <
typename T >
115 template <
typename T >
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] );
140 template <
typename T >
144 size_t i, n =
_size.size();
145 std::vector<float> voxelsize( n, 1. );
149 vso =
header().getProperty(
"voxel_size" );
150 if( vso->size() < n )
155 voxelsize[i] = float( vso->getArrayItem(i)->getScalar() );
157 catch( std::exception & )
161 catch( std::exception & )
170 template <
typename T>
173 std::vector<float> vs( 4 );
182 template <
typename T>
185 header().setProperty(
"voxel_size", vs );
189 template <
typename T >
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" );
206 Object it = other->objectIterator();
207 while( it->isValid() )
209 if( forbidden.find( it->key() ) == forbidden.end() )
214 catch( std::exception & e )
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;
224 if( !err_msg.empty() )
225 throw std::runtime_error( err_msg );
void setProperty(const std::string &, const T &)
void addBuiltinProperty(const std::string &, T &)
VolumeProxy is the base class for volumes.
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.)