34 #define IGB_BIG_ENDIAN 666666666
35 #define IGB_LITTLE_ENDIAN 777777777
47 #define IGB_D_COMPLEX 8
49 #define IGB_STRUCTURE 10
50 #define IGB_POINTER 11
62 #define IGB_MIN_TYPE 1
63 #define IGB_MAX_TYPE 22
81 #define IGB_ENDIAN_VAL -1.24e5
82 #define IGB_LITTLE_END_REP 0,48,242,199
85 #define ERR_EOF_IN_HEADER 1
86 #define ERR_LINE_TOO_LONG 2
87 #define ERR_UNPRINTABLE_CHAR 3
88 #define ERR_IGB_SYNTAX 4
89 #define ERR_UNDEFINED_X_Y_TYPE 5
90 #define ERR_SIZE_REDEFINED 6
91 #define ERR_SIZE_NOT_DEFINED 7
92 #define WARN_DIM_INCONSISTENT 256
150 #define HFLT_MIN -65504
151 #define HFLT_MAX 65504
155 #ifndef HEADER_GLOBALS
177 int v_x=0, v_y=0, v_z=1, v_t=1;
180 unsigned long v_systeme=
endian() ;
184 unsigned int v_lut=0 ;
185 unsigned int v_comp=0 ;
187 float v_org_x=1., v_org_y=1., v_org_z=1., v_org_t=0.;
188 float v_inc_x=1., v_inc_y=1., v_inc_z=1., v_inc_t=1.;
189 float v_dim_x, v_dim_y, v_dim_z, v_dim_t ;
190 float *v_vect_z=NULL;
191 char v_unites_x[41]={}, v_unites_y[41]={}, v_unites_z[41]={}, v_unites_t[41]={};
193 char v_unites[41]={};
194 float v_facteur=1., v_zero=0.;
195 char v_struct_desc[41]={};
196 char v_aut_name[41]={};
197 char** v_comment=(
char**)calloc(
NALLOC,
sizeof(
char*));
198 void* v_transparent=NULL;
199 int puts_fcn(FILE *,
char *);
203 bool bool_x=
false, bool_y=
false, bool_z=
false, bool_t=
false;
204 bool bool_type=
false;
205 bool bool_taille=
false;
208 bool bool_trame=
false;
210 bool bool_comp=
false;
211 bool bool_epais=
false;
212 bool bool_org_x=
false, bool_org_y=
false, bool_org_z=
false, bool_org_t=
false;
213 bool bool_inc_x=
false, bool_inc_y=
false, bool_inc_z=
false, bool_inc_t=
false;
214 bool bool_dim_x, bool_dim_y=
false, bool_dim_z=
false, bool_dim_t=
false;
215 bool bool_vect_z=
false;
216 bool bool_unites_x=
false, bool_unites_y=
false, bool_unites_z=
false, bool_unites_t=
false;
217 bool bool_unites=
false;
218 bool bool_facteur=
false, bool_zero=
false;
219 bool bool_struct_desc=
false;
220 bool bool_aut_name=
false;
221 bool bool_comment=
false;
222 bool bool_transparent=
false;
226 IGBheader( FILE *f = NULL,
bool read=
false,
bool quiet=
false );
230 int read(
bool quiet=
false );
234 void swab(
void *,
int nd=-1 );
235 inline double from_raw(
double a ){
return a*v_facteur+v_zero; }
236 inline double to_raw(
double a ){
return (a-v_zero)/v_facteur; }
239 inline char **
comment(
void){
return v_comment;}
241 inline int x(
void){
return v_x; }
242 inline int x(
bool &set ){ set=bool_x;
return v_x; }
243 inline void x(
int a ){ v_x = a; bool_x =
true;}
244 inline int y(
void){
return v_y; }
245 inline int y(
bool &set ){ set=bool_y;
return v_y; }
246 inline void y(
int a ){ v_y = a; bool_y =
true;}
247 inline int z(
void){
return v_z; }
248 inline int z(
bool &set ){ set=bool_z;
return v_z; }
249 inline void z(
int a ){ v_z = a; bool_z =
true;}
250 inline int t(
void){
return v_t; }
251 inline int t(
bool &set ){ set=bool_t;
return v_t; }
252 inline void t(
int a ){ v_t = a; bool_t =
true;}
253 inline int type(
void){
return v_type; }
254 inline int type(
bool &set ){ set=bool_type;
return v_type; }
255 inline void type(
int a ){ v_type = a; bool_type =
true; }
257 inline int taille(
void){
return v_taille; }
258 inline int taille(
bool &set ){ set=bool_taille;
return v_taille; }
259 inline void taille(
int a ){ v_taille = a; bool_taille =
true;}
260 inline int num(
void){
return v_num; }
261 inline int num(
bool &set ){ set=bool_num;
return v_num; }
262 inline void num(
int a ){ v_num = a; bool_num =
true;}
263 inline int bin(
void){
return v_bin; }
264 inline int bin(
bool &set ){ set=bool_bin;
return v_bin; }
265 inline void bin(
int a ){ v_bin = a; bool_bin =
true;}
266 inline int trame(
void){
return v_trame; }
267 inline int trame(
bool &set ){ set=bool_trame;
return v_trame; }
268 inline void trame(
int a ){ v_trame = a; bool_trame =
true;}
270 inline int systeme(
void ){
return v_systeme; }
272 inline unsigned int lut(
void){
return v_lut; }
273 inline unsigned int lut(
bool &set ){ set=bool_x;
return v_x; }
274 inline void lut(
unsigned int a ){ v_lut = a; bool_lut =
true; }
275 inline unsigned int comp(
void){
return v_comp; }
276 inline unsigned int comp(
bool &set ){ set=bool_lut;
return v_lut; }
277 inline void comp(
unsigned int a ){ v_comp = a; bool_comp =
true;}
278 inline float epais(
void){
return v_epais; }
279 inline float epais(
bool &set ){ set=bool_epais;
return v_epais; }
280 inline void epais(
float a ){ v_epais = a; bool_epais =
true;}
281 inline float org_x(
void){
return v_org_x; }
282 inline float org_x(
bool &set ){ set=bool_org_x;
return v_org_x; }
283 inline void org_x(
float a ){ v_org_x = a; bool_org_x =
true; }
284 inline float org_y(
void){
return v_org_y; }
285 inline float org_y(
bool &set ){ set=bool_org_y;
return v_org_y; }
286 inline void org_y(
float a ){ v_org_y = a; bool_org_y =
true; }
287 inline float org_z(
void){
return v_org_z; }
288 inline float org_z(
bool &set ){ set=bool_org_z;
return v_org_z; }
289 inline void org_z(
float a ){ v_org_z = a; bool_org_z =
true;}
290 inline float org_t(
void){
return v_org_t; }
291 inline float org_t(
bool &set ){ set=bool_org_t;
return v_org_t; }
292 inline void org_t(
float a ){ v_org_t = a; bool_org_t =
true;}
293 inline void inc_x(
float a ){ v_inc_x = a; bool_inc_x =
true;}
294 inline float inc_x(
bool &set ){ set=bool_inc_x;
return v_inc_x; }
295 inline float inc_x(
void){
return v_inc_x; }
296 inline void inc_y(
float a ){ v_inc_y = a; bool_inc_y =
true;}
297 inline float inc_y(
bool &set ){ set=bool_inc_y;
return v_inc_y; }
298 inline float inc_y(
void){
return v_inc_y; }
299 inline void inc_z(
float a ){ v_inc_z = a; bool_inc_z =
true;}
300 inline float inc_z(
bool &set ){ set=bool_inc_z;
return v_inc_z; }
301 inline float inc_z(
void){
return v_inc_z; }
302 inline void inc_t(
float a ){ v_inc_t = a; bool_inc_t =
true;}
303 inline float inc_t(
bool &set ){ set=bool_inc_t;
return v_inc_t; }
304 inline float inc_t(
void){
return v_inc_t; }
305 inline void dim_x(
float a ){ v_dim_x = a; bool_dim_x =
true;}
306 inline float dim_x(
bool &set ){ set=bool_dim_x;
return v_dim_x; }
307 inline float dim_x(
void){
return v_dim_x; }
308 inline void dim_y(
float a ){ v_dim_y = a; bool_dim_y =
true;}
309 inline float dim_y(
bool &set ){ set=bool_dim_y;
return v_dim_y; }
310 inline float dim_y(
void){
return v_dim_y; }
311 inline void dim_z(
float a ){ v_dim_z = a; bool_dim_y =
true;}
312 inline float dim_z(
bool &set ){ set=bool_dim_z;
return v_dim_z; }
313 inline float dim_z(
void){
return v_dim_z; }
314 inline void dim_t(
float a ){ v_dim_t = a; bool_dim_t =
true;}
315 inline float dim_t(
bool &set ){ set=bool_dim_t;
return v_dim_t; }
316 inline float dim_t(
void){
return v_dim_t; }
317 inline void facteur(
float a ){ v_facteur = a; bool_facteur =
true; }
318 inline float facteur(
bool &set ){ set=bool_facteur;
return v_facteur; }
319 inline float facteur(
void){
return v_facteur; }
320 inline void zero(
float a ){ v_zero = a; bool_zero =
true; }
321 inline float zero(
bool &set ){ set=bool_zero;
return v_zero; }
322 inline float zero(
void){
return v_zero; }
323 inline void vect_z(
float* a ){ v_vect_z = a; bool_vect_z =
true; }
324 inline float*
vect_z(
bool &set ){ set=bool_vect_z;
return v_vect_z; }
325 inline float*
vect_z(
void){
return v_vect_z; }
326 inline void unites_x(
const char* a ){ strcpy(v_unites_x, a); bool_unites_x =
true; }
327 inline char*
unites_x(
bool &set ){ set=bool_unites_x;
return v_unites_x; }
329 inline void unites_y(
const char* a ){ strcpy(v_unites_y, a); bool_unites_y =
true;}
330 inline char*
unites_y(
bool &set ){ set=bool_unites_y;
return v_unites_y; }
332 inline void unites_z(
const char* a ){ strcpy(v_unites_z,a); bool_unites_z =
true; }
333 inline char*
unites_z(
bool &set ){ set=bool_unites_z;
return v_unites_z; }
335 inline void unites_t(
const char* a ){ strcpy(v_unites_t, a); bool_unites_t =
true; }
336 inline char*
unites_t(
bool &set ){ set=bool_unites_t;
return v_unites_t; }
338 inline void unites(
const char* a ){ strcpy(v_unites, a); bool_unites =
true; }
339 inline char*
unites(
bool &set ){ set=bool_unites;
return v_unites; }
340 inline char*
unites(
void){
return v_unites; }
341 inline void struct_desc(
const char* a ){ strcpy(v_struct_desc, a); bool_struct_desc =
true; }
342 inline char*
struct_desc(
bool &set ){ set=bool_struct_desc;
return v_struct_desc; }
344 inline void aut_name(
const char* a ){ strcpy(v_aut_name, a); bool_aut_name =
true; }
345 inline char*
aut_name(
bool &set ){ set=bool_aut_name;
return v_aut_name; }
347 inline void transparent(
void* a ){ v_transparent=a; bool_transparent =
true; }
348 inline void*
transparent(
bool &set ){ set=bool_transparent;
return v_transparent; }
353 template<
class T>
int read_data( T* dp,
int numt=1,
char *buf=NULL );
354 template<
class T>
void write_data( T* dp,
int numt=1,
char *buf=NULL );
355 template<
class T>
void to_bin(
void *buf, T d );
371 bool alloc_buf =
false;
373 buf =
new char[slicesize];
378 for (
int a=0; a<numprimitive; a++ )
381 fwrite( buf, 1, slicesize, file );
383 if ( alloc_buf )
delete[] buf;
402 bool alloc_buf =
false;
404 buf =
new char[slicesize];
414 #pragma omp parallel for
415 for (
int a=0; a<numprimitive; a++ )
416 dp[a] = convert_buffer_datum<T>( buf, a );
418 if ( alloc_buf )
delete[] buf;
436 datum = ((
unsigned char *)buf)[a];
439 datum = ((
signed char *)buf)[a];
442 datum = ((
short *)buf)[a];
445 datum = ((
long *)buf)[a];
451 datum = ((
float *)buf)[a];
457 datum = ((
double *)buf)[a];
460 datum = ((
int *)buf)[a];
463 datum = ((
unsigned int *)buf)[a];
466 datum = ((
unsigned short *)buf)[a];
472 memset(&datum,0,
sizeof(datum));
483 #define CONVERT_TYPE(D,m,M,B) { const double min_val = static_cast<double>(m); \
484 const double max_val = static_cast<double>(M); \
485 if(datum < min_val) datum = min_val; else if(datum > max_val) datum = max_val; \
486 D a0 = (D)datum; *((D*)(B))=a0;};
const char * Header_Type[]
unsigned short Data_Size[]
int read_IGB_data(T *dp, int numt, IGBheader *h, char *buf=NULL)
long unsigned Header_Systeme_No[]
union opencarp::rgba rgba
struct opencarp::List List
T IGB_convert_buffer_datum(IGBheader *, void *buf, int a)
const char * Header_Systeme[]