/usr/include/minc_1_simple_rw.h is in libminc-dev 2.3.00-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | /* ----------------------------- MNI Header -----------------------------------
@NAME :
@DESCRIPTION: Simplified whole file in a memory MINC access library, using minc_1_rw interface
@COPYRIGHT :
Copyright 2007 Vladimir Fonov, McConnell Brain Imaging Centre,
Montreal Neurological Institute, McGill University.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies. The author and McGill University
make no representations about the suitability of this
software for any purpose. It is provided "as is" without
express or implied warranty.
---------------------------------------------------------------------------- */
#ifndef MINC_1_SIMPLE_RW_H
#define MINC_1_SIMPLE_RW_H
#include "minc_1_simple.h"
#include "minc_io_simple_volume.h"
#include "minc_io_fixed_vector.h"
#include "minc_io_4d_volume.h"
namespace minc
{
template<class T> void load_simple_volume(minc_1_reader& rw,simple_volume<T>& vol)
{
if(rw.ndim(1)<=0||rw.ndim(2)<=0||rw.ndim(3)<=0||rw.ndim(4)>0)
REPORT_ERROR("Need 3D minc file");
vol.resize(rw.ndim(1),rw.ndim(2),rw.ndim(3));
if(typeid(T)==typeid(unsigned char))
{
rw.setup_read_byte();
load_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(int))
{
rw.setup_read_int();
load_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(fixed_vec<3,float>))
{
rw.setup_read_float();
load_standard_volume<float>(rw,(float*)vol.c_buf());
}
else if(typeid(T)==typeid(float))
{
rw.setup_read_float();
load_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(fixed_vec<3,double>))
{
rw.setup_read_double();
load_standard_volume<double>(rw,(double*)vol.c_buf());
}
else if(typeid(T)==typeid(double))
{
rw.setup_read_double();
load_standard_volume(rw,vol.c_buf());
} else
REPORT_ERROR("Data type not supported for minc io");
//set coordinate transfer parameters
for(int i=0;i<3;i++)
{
vol.step()[i]=rw.nspacing(i+1);
vol.start()[i]=rw.nstart(i+1);
if(rw.have_dir_cos(i+1))
{
for(int j=0;j<3;j++)
vol.direction_cosines(i)[j]=rw.ndir_cos(i+1,j);
} else {
for(int j=0;j<3;j++)
vol.direction_cosines(i)[j]=(i==j?1.0:0.0); //identity
}
}
}
template<class T> void save_simple_volume(minc_1_writer& rw,const simple_volume<T>& vol)
{
if(typeid(T)==typeid(unsigned char))
{
rw.setup_write_byte();
save_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(int))
{
rw.setup_write_int();
save_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(fixed_vec<3,float>))
{
rw.setup_write_float();
save_standard_volume<float>(rw,(float*)vol.c_buf());
}
else if(typeid(T)==typeid(float))
{
rw.setup_write_float();
save_standard_volume(rw,vol.c_buf());
}
else if(typeid(T)==typeid(fixed_vec<3,double>))
{
rw.setup_write_double();
save_standard_volume<double>(rw,(double*)vol.c_buf());
}
else if(typeid(T)==typeid(double))
{
rw.setup_write_double();
save_standard_volume(rw,vol.c_buf());
}
else
REPORT_ERROR("Data type not supported for minc io");
}
template<class T> void load_4d_volume(minc_1_reader& rw,simple_4d_volume<T>& vol)
{
//if(rw.ndim(1)<=0||rw.ndim(2)<=0||rw.ndim(3)<=0||rw.ndim(4)<=0)
// REPORT_ERROR("Need 4D minc file");
vol.resize(rw.ndim(1),rw.ndim(2),rw.ndim(3),rw.ndim(4)>0?rw.ndim(4):1); //always assume 4 dimensions
if(typeid(T)==typeid(unsigned char))
rw.setup_read_byte();
else if(typeid(T)==typeid(int))
rw.setup_read_int();
else if(typeid(T)==typeid(fixed_vec<3,float>))
rw.setup_read_float();
else if(typeid(T)==typeid(float))
rw.setup_read_float();
else if(typeid(T)==typeid(fixed_vec<3,double>))
rw.setup_read_double();
else if(typeid(T)==typeid(double))
rw.setup_read_double();
else
REPORT_ERROR("Data type not supported for minc io");
std::vector<size_t> strides(MAX_VAR_DIMS,0);
size_t str=1;
for(size_t i=0;i<5;i++) //T is a special case
{
if(rw.map_space(i)<0) continue;
strides[rw.map_space(i)]=str;
str*=rw.ndim(i);
}
if(rw.map_space(4)>=0)
strides[rw.map_space(4)]=0; //t dimension
minc_input_iterator<T> in(rw);
for(in.begin();!in.last();in.next())
{
size_t address=0;
size_t slice=0;
for(int i=0;i<rw.dim_no();i++)
{
if(strides[i]>0)
address+=in.cur()[i]*strides[i];
else //
slice=in.cur()[i];
}
vol.frame(slice).c_buf()[address]=in.value();
}
//set coordinate transfer parameters
for(int i=0;i<3;i++)
{
vol.step()[i]=rw.nspacing(i+1);
vol.start()[i]=rw.nstart(i+1);
if(rw.have_dir_cos(i+1))
{
for(int j=0;j<3;j++)
vol.direction_cosines(i)[j]=rw.ndir_cos(i+1,j);
} else {
for(int j=0;j<3;j++)
vol.direction_cosines(i)[j]=(i==j?1.0:0.0); //identity
}
}
if(rw.ndim(4)>0)
{
vol.t_start()=rw.nstart(4);//T
vol.t_step()=rw.nspacing(4);//T
} else {
vol.t_start()=0;//T
vol.t_step()=0;//T
}
}
template<class T> void save_4d_volume(minc_1_writer& rw,const simple_4d_volume<T>& vol)
{
if(typeid(T)==typeid(unsigned char))
rw.setup_write_byte();
else if(typeid(T)==typeid(int))
rw.setup_write_int();
else if(typeid(T)==typeid(fixed_vec<3,float>))
rw.setup_write_float();
else if(typeid(T)==typeid(float))
rw.setup_write_float();
else if(typeid(T)==typeid(fixed_vec<3,double>))
rw.setup_write_double();
else if(typeid(T)==typeid(double))
rw.setup_write_double();
else
REPORT_ERROR("Data type not supported for minc io");
std::vector<size_t> strides(MAX_VAR_DIMS,0);
size_t str=1;
for(size_t i=0;i<4;i++)//T is a special
{
if(rw.map_space(i)<0) continue;
strides[rw.map_space(i)]=str;
str*=rw.ndim(i);
}
if(rw.map_space(4)>=0)
strides[rw.map_space(4)]=0; //t dimension
minc_output_iterator<T> out(rw);
for(out.begin();!out.last();out.next())
{
size_t address=0;
size_t slice=0;
for(int i=0;i<rw.dim_no();i++)
{
if(strides[i]>0)
address+=out.cur()[i]*strides[i];
else //
slice=out.cur()[i];
}
out.value(vol.frame(slice).c_buf()[address]);
}
}
bool is_same(minc_1_reader& one,minc_1_reader& two,bool verbose=true);
template<class T> void load_minc_file(const char *file,simple_4d_volume<T>& vol)
{
minc_1_reader rdr;
rdr.open(file);
load_4d_volume(rdr,vol);
}
template<class T> void generate_info(const simple_4d_volume<T>& vol,minc_info& info)
{
bool have_time=vol.frames()>1||vol.t_step()!=0.0; //assume that it is 3D file otherwise
bool is_vector=false;
if(typeid(T)==typeid(fixed_vec<3,float>)) {
is_vector=true;
}
info.resize(3+(is_vector?1:0)+(have_time?1:0));
if(is_vector)
{
info[0].dim=dim_info::DIM_VEC;
info[0].length=3;
info[0].step=1;
}
for(int i=0;i<3;i++)
{
int ii=i+(is_vector?1:0);
info[ii].dim=dim_info::dimensions( dim_info::DIM_X+i);
info[ii].length=vol.dim(i);
info[ii].step =vol.step()[i];
info[ii].start =vol.start()[i];
info[ii].have_dir_cos=true;
for(int j=0;j<3;j++)
info[ii].dir_cos[j]=vol.direction_cosines(i)[j];
}
if(have_time)
{
info[3+(is_vector?1:0)].dim=dim_info::DIM_TIME;
info[3+(is_vector?1:0)].step=vol.t_step();
info[3+(is_vector?1:0)].start=vol.t_start();
info[3+(is_vector?1:0)].length=vol.frames();
}
}
template<class T> void save_minc_file(const char *file,const simple_4d_volume<T>& vol,
const char* history=NULL,const minc_1_reader* original=NULL,
nc_type datatype=NC_NAT,bool is_signed=false)
{
minc_1_writer wrt;
//convert parameters to info
if(typeid(T)==typeid(unsigned char))
{
if(datatype==NC_NAT) datatype=NC_BYTE;
} else if(typeid(T)==typeid(int)) {
if(datatype==NC_NAT) datatype=NC_INT;
is_signed=true;
} else if(typeid(T)==typeid(unsigned int)) {
if(datatype==NC_NAT) datatype=NC_INT;
is_signed=false;
} else if(typeid(T)==typeid(float)) {
if(datatype==NC_NAT) datatype=NC_FLOAT;
is_signed=true;
} else if(typeid(T)==typeid(fixed_vec<3,float>)) {
if(datatype==NC_NAT) datatype=NC_FLOAT;
is_signed=true;
} else if(typeid(T)==typeid(double)) {
if(datatype==NC_NAT) datatype=NC_DOUBLE;
is_signed=true;
} else if(typeid(T)==typeid(fixed_vec<3,double>)) {
if(datatype==NC_NAT) datatype=NC_DOUBLE;
is_signed=true;
} else
REPORT_ERROR("Unsupported data type!");
minc_info info;
generate_info<T>(vol,info);
wrt.open(file,info,2,datatype,is_signed);
if(original)
{
wrt.copy_headers(*original);
}
if(history)
wrt.append_history(history);
save_4d_volume(wrt,vol);
}
}
#endif //MINC_1_SIMPLE_RW_H
|