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();
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();
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;
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 );
124 hdr.
setProperty(
"bits_allocated", (
int) (
sizeof( T ) * 8 ) );
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 & )
169 std::unique_ptr<AffineTransformation3d> m2s = stom.
inverse();
173 short( rint( fabs( df[1] ) ) ),
174 short( rint( fabs( df[2] ) ) ), thing.
dimT() );
178 int16_t( rint( incf[1] ) ),
179 int16_t( rint( incf[2] ) ), 0 );
182 std::vector<int16_t> datashort;
185 datashort.insert( datashort.end(), dx, 0 );
186 std::vector<T> data( dx );
191 if( write4d || thing.
dimT() == 1 )
198 _os.open( name.c_str(), std::ios::out | std::ios::binary );
199 _os.unsetf( std::ios::skipws );
201 for ( f=0; f < tdims[3]; f++)
202 for ( z=0;z<tdims[2];z++)
204 for ( y=0;y<tdims[1];y++)
207 d0 =
Point4d( int16_t( rint( d0f[0] ) ), int16_t( rint( d0f[1] ) ),
208 int16_t( rint( d0f[2] ) ), f );
211 for( x=0; x < dx; ++x, d0+=inc )
212 datashort[ x ] = (int16_t) rint( thing( d0 ) / scale );
213 itemWs.
write( _os, &datashort[0] , dx );
215 else if( inc ==
Point4d( 1, 0, 0, 0 ) )
216 itemW.
write( _os, &thing( d0 ) , dx );
219 for( x=0; x < dx; ++x, d0+=inc )
220 data[ x ] = thing( d0 );
221 itemW.
write( _os, &data[0] , dx );
231 int f, nt = thing.
dimT();
232 std::vector<std::string> fnames;
233 std::string dname, bname;
238 fnames.reserve( nt );
239 for( f=0; f<nt; ++f )
241 sprintf( sequence,
"%04d", f );
242 fnames.push_back( bname + std::string( sequence ) +
".img" );
247 for( f=0; f < nt; ++f )
249 std::string name = dname + fnames[f];
251 hdr.
write( f == 0,
false );
253 _os.open( name.c_str(), std::ios::out | std::ios::binary );
254 _os.unsetf( std::ios::skipws );
256 for (
int z=0;z<tdims[2];z++)
257 for (
int y=0;y<tdims[1];y++)
260 d0 =
Point4d( int16_t( rint( d0f[0] ) ), int16_t( rint( d0f[1] ) ),
261 int16_t( rint( d0f[2] ) ), f );
264 for( x=0; x < dx; ++x, d0+=inc )
265 datashort[ x ] = (int16_t) rint( thing( d0 ) / scale );
266 itemWs.
write( _os, &datashort[0] , dx );
268 else if( inc ==
Point4d( 1, 0, 0, 0 ) )
269 itemW.
write( _os, &thing( d0 ) , dx );
272 for( x=0; x < dx; ++x, d0+=inc )
273 data[ x ] = thing( d0 );
274 itemW.
write( _os, &data[0] , dx );
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.