49 #define IGB_BIG_ENDIAN 666666666
50 #define IGB_LITTLE_ENDIAN 777777777
62 #define IGB_D_COMPLEX 8
64 #define IGB_STRUCTURE 10
65 #define IGB_POINTER 11
77 #define IGB_MIN_TYPE 1
78 #define IGB_MAX_TYPE 22
96 #define IGB_ENDIAN_VAL -1.24e5
97 #define IGB_LITTLE_END_REP 0,48,242,199
100 #define ERR_EOF_IN_HEADER 1
101 #define ERR_LINE_TOO_LONG 2
102 #define ERR_UNPRINTABLE_CHAR 3
103 #define ERR_IGB_SYNTAX 4
104 #define ERR_UNDEFINED_X_Y_TYPE 5
105 #define ERR_SIZE_REDEFINED 6
106 #define ERR_SIZE_NOT_DEFINED 7
107 #define WARN_DIM_INCONSISTENT 256
165 #define HFLT_MIN -65504
166 #define HFLT_MAX 65504
170 #ifndef HEADER_GLOBALS
192 int v_x=0, v_y=0, v_z=1, v_t=1;
195 unsigned long v_systeme=
endian() ;
199 unsigned int v_lut=0 ;
200 unsigned int v_comp=0 ;
202 float v_org_x=1., v_org_y=1., v_org_z=1., v_org_t=0.;
203 float v_inc_x=1., v_inc_y=1., v_inc_z=1., v_inc_t=1.;
204 float v_dim_x, v_dim_y, v_dim_z, v_dim_t ;
205 float *v_vect_z=NULL;
206 char v_unites_x[41]={}, v_unites_y[41]={}, v_unites_z[41]={}, v_unites_t[41]={};
208 char v_unites[41]={};
209 float v_facteur=1., v_zero=0.;
210 char v_struct_desc[41]={};
211 char v_aut_name[41]={};
212 char** v_comment=(
char**)calloc(
NALLOC,
sizeof(
char*));
213 void* v_transparent=NULL;
214 int puts_fcn(FILE *,
char *);
218 bool bool_x=
false, bool_y=
false, bool_z=
false, bool_t=
false;
219 bool bool_type=
false;
220 bool bool_taille=
false;
223 bool bool_trame=
false;
225 bool bool_comp=
false;
226 bool bool_epais=
false;
227 bool bool_org_x=
false, bool_org_y=
false, bool_org_z=
false, bool_org_t=
false;
228 bool bool_inc_x=
false, bool_inc_y=
false, bool_inc_z=
false, bool_inc_t=
false;
229 bool bool_dim_x, bool_dim_y=
false, bool_dim_z=
false, bool_dim_t=
false;
230 bool bool_vect_z=
false;
231 bool bool_unites_x=
false, bool_unites_y=
false, bool_unites_z=
false, bool_unites_t=
false;
232 bool bool_unites=
false;
233 bool bool_facteur=
false, bool_zero=
false;
234 bool bool_struct_desc=
false;
235 bool bool_aut_name=
false;
236 bool bool_comment=
false;
237 bool bool_transparent=
false;
241 IGBheader( FILE *f = NULL,
bool read=
false,
bool quiet=
false );
245 int read(
bool quiet=
false );
249 void swab(
void *,
int nd=-1 );
250 inline double from_raw(
double a ){
return a*v_facteur+v_zero; }
251 inline double to_raw(
double a ){
return (a-v_zero)/v_facteur; }
254 inline char **
comment(
void){
return v_comment;}
256 inline int x(
void){
return v_x; }
257 inline int x(
bool &set ){ set=bool_x;
return v_x; }
258 inline void x(
int a ){ v_x = a; bool_x =
true;}
259 inline int y(
void){
return v_y; }
260 inline int y(
bool &set ){ set=bool_y;
return v_y; }
261 inline void y(
int a ){ v_y = a; bool_y =
true;}
262 inline int z(
void){
return v_z; }
263 inline int z(
bool &set ){ set=bool_z;
return v_z; }
264 inline void z(
int a ){ v_z = a; bool_z =
true;}
265 inline int t(
void){
return v_t; }
266 inline int t(
bool &set ){ set=bool_t;
return v_t; }
267 inline void t(
int a ){ v_t = a; bool_t =
true;}
268 inline int type(
void){
return v_type; }
269 inline int type(
bool &set ){ set=bool_type;
return v_type; }
270 inline void type(
int a ){ v_type = a; bool_type =
true; }
272 inline int taille(
void){
return v_taille; }
273 inline int taille(
bool &set ){ set=bool_taille;
return v_taille; }
274 inline void taille(
int a ){ v_taille = a; bool_taille =
true;}
275 inline int num(
void){
return v_num; }
276 inline int num(
bool &set ){ set=bool_num;
return v_num; }
277 inline void num(
int a ){ v_num = a; bool_num =
true;}
278 inline int bin(
void){
return v_bin; }
279 inline int bin(
bool &set ){ set=bool_bin;
return v_bin; }
280 inline void bin(
int a ){ v_bin = a; bool_bin =
true;}
281 inline int trame(
void){
return v_trame; }
282 inline int trame(
bool &set ){ set=bool_trame;
return v_trame; }
283 inline void trame(
int a ){ v_trame = a; bool_trame =
true;}
285 inline int systeme(
void ){
return v_systeme; }
287 inline unsigned int lut(
void){
return v_lut; }
288 inline unsigned int lut(
bool &set ){ set=bool_x;
return v_x; }
289 inline void lut(
unsigned int a ){ v_lut = a; bool_lut =
true; }
290 inline unsigned int comp(
void){
return v_comp; }
291 inline unsigned int comp(
bool &set ){ set=bool_lut;
return v_lut; }
292 inline void comp(
unsigned int a ){ v_comp = a; bool_comp =
true;}
293 inline float epais(
void){
return v_epais; }
294 inline float epais(
bool &set ){ set=bool_epais;
return v_epais; }
295 inline void epais(
float a ){ v_epais = a; bool_epais =
true;}
296 inline float org_x(
void){
return v_org_x; }
297 inline float org_x(
bool &set ){ set=bool_org_x;
return v_org_x; }
298 inline void org_x(
float a ){ v_org_x = a; bool_org_x =
true; }
299 inline float org_y(
void){
return v_org_y; }
300 inline float org_y(
bool &set ){ set=bool_org_y;
return v_org_y; }
301 inline void org_y(
float a ){ v_org_y = a; bool_org_y =
true; }
302 inline float org_z(
void){
return v_org_z; }
303 inline float org_z(
bool &set ){ set=bool_org_z;
return v_org_z; }
304 inline void org_z(
float a ){ v_org_z = a; bool_org_z =
true;}
305 inline float org_t(
void){
return v_org_t; }
306 inline float org_t(
bool &set ){ set=bool_org_t;
return v_org_t; }
307 inline void org_t(
float a ){ v_org_t = a; bool_org_t =
true;}
308 inline void inc_x(
float a ){ v_inc_x = a; bool_inc_x =
true;}
309 inline float inc_x(
bool &set ){ set=bool_inc_x;
return v_inc_x; }
310 inline float inc_x(
void){
return v_inc_x; }
311 inline void inc_y(
float a ){ v_inc_y = a; bool_inc_y =
true;}
312 inline float inc_y(
bool &set ){ set=bool_inc_y;
return v_inc_y; }
313 inline float inc_y(
void){
return v_inc_y; }
314 inline void inc_z(
float a ){ v_inc_z = a; bool_inc_z =
true;}
315 inline float inc_z(
bool &set ){ set=bool_inc_z;
return v_inc_z; }
316 inline float inc_z(
void){
return v_inc_z; }
317 inline void inc_t(
float a ){ v_inc_t = a; bool_inc_t =
true;}
318 inline float inc_t(
bool &set ){ set=bool_inc_t;
return v_inc_t; }
319 inline float inc_t(
void){
return v_inc_t; }
320 inline void dim_x(
float a ){ v_dim_x = a; bool_dim_x =
true;}
321 inline float dim_x(
bool &set ){ set=bool_dim_x;
return v_dim_x; }
322 inline float dim_x(
void){
return v_dim_x; }
323 inline void dim_y(
float a ){ v_dim_y = a; bool_dim_y =
true;}
324 inline float dim_y(
bool &set ){ set=bool_dim_y;
return v_dim_y; }
325 inline float dim_y(
void){
return v_dim_y; }
326 inline void dim_z(
float a ){ v_dim_z = a; bool_dim_y =
true;}
327 inline float dim_z(
bool &set ){ set=bool_dim_z;
return v_dim_z; }
328 inline float dim_z(
void){
return v_dim_z; }
329 inline void dim_t(
float a ){ v_dim_t = a; bool_dim_t =
true;}
330 inline float dim_t(
bool &set ){ set=bool_dim_t;
return v_dim_t; }
331 inline float dim_t(
void){
return v_dim_t; }
332 inline void facteur(
float a ){ v_facteur = a; bool_facteur =
true; }
333 inline float facteur(
bool &set ){ set=bool_facteur;
return v_facteur; }
334 inline float facteur(
void){
return v_facteur; }
335 inline void zero(
float a ){ v_zero = a; bool_zero =
true; }
336 inline float zero(
bool &set ){ set=bool_zero;
return v_zero; }
337 inline float zero(
void){
return v_zero; }
338 inline void vect_z(
float* a ){ v_vect_z = a; bool_vect_z =
true; }
339 inline float*
vect_z(
bool &set ){ set=bool_vect_z;
return v_vect_z; }
340 inline float*
vect_z(
void){
return v_vect_z; }
341 inline void unites_x(
const char* a ){ strcpy(v_unites_x, a); bool_unites_x =
true; }
342 inline char*
unites_x(
bool &set ){ set=bool_unites_x;
return v_unites_x; }
344 inline void unites_y(
const char* a ){ strcpy(v_unites_y, a); bool_unites_y =
true;}
345 inline char*
unites_y(
bool &set ){ set=bool_unites_y;
return v_unites_y; }
347 inline void unites_z(
const char* a ){ strcpy(v_unites_z,a); bool_unites_z =
true; }
348 inline char*
unites_z(
bool &set ){ set=bool_unites_z;
return v_unites_z; }
350 inline void unites_t(
const char* a ){ strcpy(v_unites_t, a); bool_unites_t =
true; }
351 inline char*
unites_t(
bool &set ){ set=bool_unites_t;
return v_unites_t; }
353 inline void unites(
const char* a ){ strcpy(v_unites, a); bool_unites =
true; }
354 inline char*
unites(
bool &set ){ set=bool_unites;
return v_unites; }
355 inline char*
unites(
void){
return v_unites; }
356 inline void struct_desc(
const char* a ){ strcpy(v_struct_desc, a); bool_struct_desc =
true; }
357 inline char*
struct_desc(
bool &set ){ set=bool_struct_desc;
return v_struct_desc; }
359 inline void aut_name(
const char* a ){ strcpy(v_aut_name, a); bool_aut_name =
true; }
360 inline char*
aut_name(
bool &set ){ set=bool_aut_name;
return v_aut_name; }
362 inline void transparent(
void* a ){ v_transparent=a; bool_transparent =
true; }
363 inline void*
transparent(
bool &set ){ set=bool_transparent;
return v_transparent; }
368 template<
class T>
int read_data( T* dp,
int numt=1,
char *buf=NULL );
369 template<
class T>
void write_data( T* dp,
int numt=1,
char *buf=NULL );
370 template<
class T>
void to_bin(
void *buf, T d );
386 bool alloc_buf =
false;
388 buf =
new char[slicesize];
393 for (
int a=0; a<numprimitive; a++ )
396 fwrite( buf, 1, slicesize, file );
398 if ( alloc_buf )
delete[] buf;
417 bool alloc_buf =
false;
419 buf =
new char[slicesize];
429 #pragma omp parallel for
430 for (
int a=0; a<numprimitive; a++ )
431 dp[a] = convert_buffer_datum<T>( buf, a );
433 if ( alloc_buf )
delete[] buf;
451 datum = ((
unsigned char *)buf)[a];
454 datum = ((
signed char *)buf)[a];
457 datum = ((
short *)buf)[a];
460 datum = ((
long *)buf)[a];
466 datum = ((
float *)buf)[a];
472 datum = ((
double *)buf)[a];
475 datum = ((
int *)buf)[a];
478 datum = ((
unsigned int *)buf)[a];
481 datum = ((
unsigned short *)buf)[a];
487 memset(&datum,0,
sizeof(datum));
498 #define CONVERT_TYPE(D,m,M,B) { const double min_val = static_cast<double>(m); \
499 const double max_val = static_cast<double>(M); \
500 if(datum < min_val) datum = min_val; else if(datum > max_val) datum = max_val; \
501 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[]