cartodata  5.0.5
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 
41 namespace 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  while( _size.size() < 4 )
70  {
71  _size.reserve( 4 );
72  _size.push_back( 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 >
111  {
112  }
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 >
172  {
173  if( other.isNull() )
174  return;
175 
176  std::set<std::string> forbidden;
177  forbidden.insert( "sizeX" );
178  forbidden.insert( "sizeY" );
179  forbidden.insert( "sizeZ" );
180  forbidden.insert( "sizeT" );
181  forbidden.insert( "volume_dimension" );
182 
183  PropertySet & hdr = header();
184 
185  Object it = other->objectIterator();
186  while( it->isValid() )
187  {
188  if( forbidden.find( it->key() ) == forbidden.end() )
189  hdr.setProperty( it->key(), it->currentValue() );
190  it->next();
191  }
192  }
193 
194 }
195 
196 #endif
Headered & operator=(const Headered &other)
void addBuiltinProperty(const std::string &, T &)
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
virtual bool removeProperty(const std::string &key)
VolumeProxy(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1)
Definition: volumeproxy_d.h:46
VolumeProxy is the base class for volumes.
Definition: volumeproxy.h:49
virtual void copyHeaderFrom(const PropertySet &other)
copy properties from other to this, avoiding forbidden properties like size.
Definition: volumeproxy.h:137
void setProperty(const std::string &, const T &)
virtual ~VolumeProxy()
std::vector< int > _size
Definition: volumeproxy.h:80
void changeBuiltinProperty(const std::string &, T &)
std::vector< float > getVoxelSize() const
get the voxel size from the header, with 4 values defaulting to 1.mm if not present ...
const PropertySet & header() const
bool getProperty(const std::string &, T &) const