cartodata  4.5.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 
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  _sizeX( sizeX ),
49  _sizeY( sizeY ),
50  _sizeZ( sizeZ ),
51  _sizeT( sizeT )
52  {
53 
54  header().addBuiltinProperty( "sizeX", _sizeX );
55  header().addBuiltinProperty( "sizeY", _sizeY );
56  header().addBuiltinProperty( "sizeZ", _sizeZ );
57  header().addBuiltinProperty( "sizeT", _sizeT );
58 
59  }
60 
61 
62  template < typename T >
64  : RCObject(),
65  Headered( other ),
66  _sizeX( other._sizeX ),
67  _sizeY( other._sizeY ),
68  _sizeZ( other._sizeZ ),
69  _sizeT( other._sizeT )
70  {
71 
72  if( header().hasProperty( "sizeX" ) )
73  header().removeProperty( "sizeX" );
74  if( header().hasProperty( "sizeY" ) )
75  header().removeProperty( "sizeY" );
76  if( header().hasProperty( "sizeZ" ) )
77  header().removeProperty( "sizeZ" );
78  if( header().hasProperty( "sizeT" ) )
79  header().removeProperty( "sizeT" );
80 
81  header().addBuiltinProperty( "sizeX", _sizeX );
82  header().addBuiltinProperty( "sizeY", _sizeY );
83  header().addBuiltinProperty( "sizeZ", _sizeZ );
84  header().addBuiltinProperty( "sizeT", _sizeT );
85 
86  }
87 
88 
89  template < typename T >
91  {
92  }
93 
94 
95  template < typename T >
98  {
99 
100  if( this == &other )
101  return *this;
102 
103  this->Headered::operator=( other );
104  _sizeX = other._sizeX;
105  _sizeY = other._sizeY;
106  _sizeZ = other._sizeZ;
107  _sizeT = other._sizeT;
108 
109  return *this;
110 
111  }
112 
113 
114  template < typename T >
115  std::vector<float> VolumeProxy< T >::getVoxelSize() const
116  {
117 
118  std::vector<float> voxelsize(4, 1.);
119  carto::Object vso;
120  try
121  {
122  vso = header().getProperty( "voxel_size" );
123  if( !vso.isNull() )
124  {
125  carto::Object it = vso->objectIterator();
126  if( it->isValid() )
127  {
128  voxelsize[0] = it->currentValue()->getScalar();
129  it->next();
130  if( it->isValid() )
131  {
132  voxelsize[1] = it->currentValue()->getScalar();
133  it->next();
134  if( it->isValid() )
135  {
136  voxelsize[2] = it->currentValue()->getScalar();
137  it->next();
138  if( it->isValid() )
139  voxelsize[3] = it->currentValue()->getScalar();
140  }
141  }
142  }
143  }
144  }
145  catch( std::exception & )
146  {
147  }
148 
149  return voxelsize;
150 
151  }
152 
153 
154  template < typename T >
156  {
157  if( other.isNull() )
158  return;
159 
160  std::set<std::string> forbidden;
161  forbidden.insert( "sizeX" );
162  forbidden.insert( "sizeY" );
163  forbidden.insert( "sizeZ" );
164  forbidden.insert( "sizeT" );
165  forbidden.insert( "volume_dimension" );
166 
167  PropertySet & hdr = header();
168 
169  Object it = other->objectIterator();
170  while( it->isValid() )
171  {
172  if( forbidden.find( it->key() ) == forbidden.end() )
173  hdr.setProperty( it->key(), it->currentValue() );
174  it->next();
175  }
176  }
177 
178 }
179 
180 #endif
Headered & operator=(const Headered &other)
void addBuiltinProperty(const std::string &, T &)
virtual bool removeProperty(const std::string &)
bool isNull() const
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
Definition: volumeproxy_d.h:97
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
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)
copy properties from other to this, avoiding forbidden properties like size.
Definition: volumeproxy.h:143
virtual double getScalar() const =0
const PropertySet & header() const
void setProperty(const std::string &, const T &)
virtual ~VolumeProxy()
Definition: volumeproxy_d.h:90
virtual Object objectIterator() const =0
virtual Object currentValue() const =0
virtual bool isValid() const =0
virtual std::string key() const =0