34 #ifndef AIMS_IO_SPMW_D_H 35 #define AIMS_IO_SPMW_D_H 58 thing.
sizeT(), _name );
66 std::vector<int> dims(4);
67 dims[0] = thing.
dimX();
68 dims[1] = thing.
dimY();
69 dims[2] = thing.
dimZ();
70 dims[3] = thing.
dimT();
71 hdr.setProperty(
"volume_dimension", dims );
72 std::vector<float> vs(4);
73 vs[0] = thing.
sizeX();
74 vs[1] = thing.
sizeY();
75 vs[2] = thing.
sizeZ();
76 vs[3] = thing.
sizeT();
77 hdr.setProperty(
"voxel_size", vs );
79 if( hdr.hasProperty(
"SPM_data_type" ) )
80 hdr.removeProperty(
"SPM_data_type" );
81 if( hdr.hasProperty(
"disk_data_type" ) )
82 hdr.removeProperty(
"disk_data_type" );
83 if( hdr.hasProperty(
"possible_data_types" ) )
84 hdr.removeProperty(
"possible_data_types" );
88 hdr.setupWriteAttributes( code );
91 T vmin = thing( 0 ), vmax = thing( 0 );
93 float offset = 0, scale = 1;
95 if( code ==
"FLOAT" || code ==
"DOUBLE" )
102 std::cout <<
"16 bit coding possible: scale: " << scale
103 <<
", max error: " << maxm << std::endl;
104 hdr.setProperty(
"disk_data_type",
107 hdr.setProperty(
"scale_factor_applied",
int(0) );
108 hdr.setProperty(
"scale_factor", scale );
111 std::cout <<
"matching interval not found. Not 16 bit codable\n";
115 if( thing( x, y, z, f ) < vmin )
116 vmin = thing( x, y, z, f );
117 if( thing( x, y, z, f ) > vmax )
118 vmax = thing( x, y, z, f );
122 hdr.setProperty(
"bits_allocated", (
int) 16 );
124 hdr.setProperty(
"bits_allocated", (
int) (
sizeof( T ) * 8 ) );
125 hdr.setProperty(
"minimum", (
int) vmin ) ;
126 hdr.setProperty(
"maximum", (
int) vmax ) ;
133 sett.getProperty(
"spm_output_4d_volumes" )->getScalar();
135 catch( std::exception & )
140 hdr.write(
false, write4d );
142 std::vector<float> vstom;
144 if( hdr.getProperty(
"storage_to_memory", vstom ) )
148 std::cout <<
"no storage_to_memory in SPM header\n";
157 radio = (bool) hdr.getProperty(
"spm_radio_convention" )->getScalar();
159 catch( std::exception & )
174 short( rint( fabs( df[1] ) ) ),
175 short( rint( fabs( df[2] ) ) ), thing.
dimT() );
179 int16_t( rint( incf[1] ) ),
180 int16_t( rint( incf[2] ) ), 0 );
183 std::vector<int16_t> datashort;
186 datashort.insert( datashort.end(), dx, 0 );
187 std::vector<T> data( dx );
192 if( write4d || thing.
dimT() == 1 )
194 std::string fname = removeExtension( _name );
195 hdr.setName( fname );
198 std::string name = removeExtension( fname ) +
".img";
199 _os.open( name.c_str(), std::ios::out | std::ios::binary );
200 _os.unsetf( std::ios::skipws );
202 for ( f=0; f < tdims[3]; f++)
203 for ( z=0;z<tdims[2];z++)
205 for ( y=0;y<tdims[1];y++)
208 d0 =
Point4d( int16_t( rint( d0f[0] ) ), int16_t( rint( d0f[1] ) ),
209 int16_t( rint( d0f[2] ) ), f );
212 for( x=0; x < dx; ++x, d0+=inc )
213 datashort[ x ] = (int16_t) rint( thing( d0 ) / scale );
214 itemWs.
write( _os, &datashort[0] , dx );
216 else if( inc ==
Point4d( 1, 0, 0, 0 ) )
217 itemW.
write( _os, &thing( d0 ) , dx );
220 for( x=0; x < dx; ++x, d0+=inc )
221 data[ x ] = thing( d0 );
222 itemW.
write( _os, &data[0] , dx );
233 std::vector<std::string> fnames;
234 std::string dname, bname;
239 fnames.reserve( nt );
240 for( f=0; f<
nt; ++f )
242 sprintf( sequence,
"%04d", f );
243 fnames.push_back( bname + std::string( sequence ) +
".img" );
245 hdr.setProperty(
"series_filenames", fnames );
248 for( f=0; f <
nt; ++f )
250 std::string name = dname + fnames[f];
252 hdr.write( f == 0,
false );
254 _os.open( name.c_str(), std::ios::out | std::ios::binary );
255 _os.unsetf( std::ios::skipws );
257 for (
int z=0;z<tdims[2];z++)
258 for (
int y=0;y<tdims[1];y++)
261 d0 =
Point4d( int16_t( rint( d0f[0] ) ), int16_t( rint( d0f[1] ) ),
262 int16_t( rint( d0f[2] ) ), f );
265 for( x=0; x < dx; ++x, d0+=inc )
266 datashort[ x ] = (int16_t) rint( thing( d0 ) / scale );
267 itemWs.
write( _os, &datashort[0] , dx );
269 else if( inc ==
Point4d( 1, 0, 0, 0 ) )
270 itemW.
write( _os, &thing( d0 ) , dx );
273 for( x=0; x < dx; ++x, d0+=inc )
274 data[ x ] = thing( d0 );
275 itemW.
write( _os, &data[0] , dx );
Default low-levels writers.
static std::string basename(const std::string &)
The class for EcatSino data write operation.
#define ForEach4d(thing, x, y, z, t)
aims::AffineTransformation3d Motion
static std::string dirname(const std::string &)
const aims::Header * header() const
bool canEncodeAsScaledS16(const carto::Volume< T > &vol, float &slope, float &offset, bool enableoffset=true, double *maxerr=0)
Checks if a volume can be encoded as 16 bit signed ints with a scale factor and optionally an offset...
carto::rc_ptr< carto::Volume< T > > volume()
virtual void write(std::ostream &os, const T &item) const
static Settings & settings()
void write(const AimsData< T > &thing)
Write the data with "name" file name to disk.