50 #define IGB_BIG_ENDIAN 666666666 51 #define IGB_LITTLE_ENDIAN 777777777 63 #define IGB_D_COMPLEX 8 65 #define IGB_STRUCTURE 10 66 #define IGB_POINTER 11 78 #define IGB_MIN_TYPE 1 79 #define IGB_MAX_TYPE 22 97 #define IGB_ENDIAN_VAL -1.24e5 98 #define IGB_LITTLE_END_REP 0,48,242,199 101 #define ERR_EOF_IN_HEADER 1 102 #define ERR_LINE_TOO_LONG 2 103 #define ERR_UNPRINTABLE_CHAR 3 104 #define ERR_IGB_SYNTAX 4 105 #define ERR_UNDEFINED_X_Y_TYPE 5 106 #define ERR_SIZE_REDEFINED 6 107 #define ERR_SIZE_NOT_DEFINED 7 108 #define WARN_DIM_INCONSISTENT 256 166 #define HFLT_MIN -65504 167 #define HFLT_MAX 65504 171 #ifndef HEADER_GLOBALS 194 int v_x=0, v_y=0, v_z=1, v_t=1;
197 unsigned long v_systeme=endian() ;
201 unsigned int v_lut=0 ;
202 unsigned int v_comp=0 ;
204 float v_org_x=1., v_org_y=1., v_org_z=1., v_org_t=0.;
205 float v_inc_x=1., v_inc_y=1., v_inc_z=1., v_inc_t=1.;
206 float v_dim_x, v_dim_y, v_dim_z, v_dim_t ;
207 float *v_vect_z=NULL;
208 char v_unites_x[41]={}, v_unites_y[41]={}, v_unites_z[41]={}, v_unites_t[41]={};
210 char v_unites[41]={};
211 float v_facteur=1., v_zero=0.;
212 char v_struct_desc[41]={};
213 char v_aut_name[41]={};
214 char** v_comment=(
char**)calloc(
NALLOC,
sizeof(
char*));
215 void* v_transparent=NULL;
216 int puts_fcn(
void *,
char *);
220 bool bool_x=
false, bool_y=
false, bool_z=
false, bool_t=
false;
221 bool bool_type=
false;
222 bool bool_taille=
false;
225 bool bool_trame=
false;
227 bool bool_comp=
false;
228 bool bool_epais=
false;
229 bool bool_org_x=
false, bool_org_y=
false, bool_org_z=
false, bool_org_t=
false;
230 bool bool_inc_x=
false, bool_inc_y=
false, bool_inc_z=
false, bool_inc_t=
false;
231 bool bool_dim_x, bool_dim_y=
false, bool_dim_z=
false, bool_dim_t=
false;
232 bool bool_vect_z=
false;
233 bool bool_unites_x=
false, bool_unites_y=
false, bool_unites_z=
false, bool_unites_t=
false;
234 bool bool_unites=
false;
235 bool bool_facteur=
false, bool_zero=
false;
236 bool bool_struct_desc=
false;
237 bool bool_aut_name=
false;
238 bool bool_comment=
false;
239 bool bool_transparent=
false;
243 IGBheader( gzFile a = NULL,
bool read=
false,
bool quiet=
false );
244 IGBheader( FILE *f,
bool read=
false,
bool quiet=
false );
248 int read(
bool quiet=
false );
249 void fileptr( gzFile f );
250 void fileptr( FILE* f );
252 void close(
void){
if(gzipping)gzclose((gzFile)file);
else fclose((FILE*)file);}
253 void swab(
void *,
int nd=-1 );
254 inline double from_raw(
double a ){
return a*v_facteur+v_zero; }
255 inline double to_raw(
double a ){
return (a-v_zero)/v_facteur; }
257 void comment(
char* );
258 inline char **
comment(
void){
return v_comment;}
260 inline int x(
void){
return v_x; }
261 inline int x(
bool &
set ){
set=bool_x;
return v_x; }
262 inline void x(
int a ){ v_x = a; bool_x =
true;}
263 inline int y(
void){
return v_y; }
264 inline int y(
bool &
set ){
set=bool_y;
return v_y; }
265 inline void y(
int a ){ v_y = a; bool_y =
true;}
266 inline int z(
void){
return v_z; }
267 inline int z(
bool &
set ){
set=bool_z;
return v_z; }
268 inline void z(
int a ){ v_z = a; bool_z =
true;}
269 inline int t(
void){
return v_t; }
270 inline int t(
bool &
set ){
set=bool_t;
return v_t; }
271 inline void t(
int a ){ v_t = a; bool_t =
true;}
272 inline int type(
void){
return v_type; }
273 inline int type(
bool &
set ){
set=bool_type;
return v_type; }
274 inline void type(
int a ){ v_type = a; bool_type =
true; }
276 inline int taille(
void){
return v_taille; }
277 inline int taille(
bool &
set ){
set=bool_taille;
return v_taille; }
278 inline void taille(
int a ){ v_taille = a; bool_taille =
true;}
279 inline int num(
void){
return v_num; }
280 inline int num(
bool &
set ){
set=bool_num;
return v_num; }
281 inline void num(
int a ){ v_num = a; bool_num =
true;}
282 inline int bin(
void){
return v_bin; }
283 inline int bin(
bool &
set ){
set=bool_bin;
return v_bin; }
284 inline void bin(
int a ){ v_bin = a; bool_bin =
true;}
285 inline int trame(
void){
return v_trame; }
286 inline int trame(
bool &
set ){
set=bool_trame;
return v_trame; }
287 inline void trame(
int a ){ v_trame = a; bool_trame =
true;}
288 const char* systemestr(
void);
289 inline int systeme(
void ){
return v_systeme; }
290 void systeme(
const char* s );
291 inline unsigned int lut(
void){
return v_lut; }
292 inline unsigned int lut(
bool &
set ){
set=bool_x;
return v_x; }
293 inline void lut(
unsigned int a ){ v_lut = a; bool_lut =
true; }
294 inline unsigned int comp(
void){
return v_comp; }
295 inline unsigned int comp(
bool &
set ){
set=bool_lut;
return v_lut; }
296 inline void comp(
unsigned int a ){ v_comp = a; bool_comp =
true;}
297 inline float epais(
void){
return v_epais; }
298 inline float epais(
bool &
set ){
set=bool_epais;
return v_epais; }
299 inline void epais(
float a ){ v_epais = a; bool_epais =
true;}
300 inline float org_x(
void){
return v_org_x; }
301 inline float org_x(
bool &
set ){
set=bool_org_x;
return v_org_x; }
302 inline void org_x(
float a ){ v_org_x = a; bool_org_x =
true; }
303 inline float org_y(
void){
return v_org_y; }
304 inline float org_y(
bool &
set ){
set=bool_org_y;
return v_org_y; }
305 inline void org_y(
float a ){ v_org_y = a; bool_org_y =
true; }
306 inline float org_z(
void){
return v_org_z; }
307 inline float org_z(
bool &
set ){
set=bool_org_z;
return v_org_z; }
308 inline void org_z(
float a ){ v_org_z = a; bool_org_z =
true;}
309 inline float org_t(
void){
return v_org_t; }
310 inline float org_t(
bool &
set ){
set=bool_org_t;
return v_org_t; }
311 inline void org_t(
float a ){ v_org_t = a; bool_org_t =
true;}
312 inline void inc_x(
float a ){ v_inc_x = a; bool_inc_x =
true;}
313 inline float inc_x(
bool &
set ){
set=bool_inc_x;
return v_inc_x; }
314 inline float inc_x(
void){
return v_inc_x; }
315 inline void inc_y(
float a ){ v_inc_y = a; bool_inc_y =
true;}
316 inline float inc_y(
bool &
set ){
set=bool_inc_y;
return v_inc_y; }
317 inline float inc_y(
void){
return v_inc_y; }
318 inline void inc_z(
float a ){ v_inc_z = a; bool_inc_z =
true;}
319 inline float inc_z(
bool &
set ){
set=bool_inc_z;
return v_inc_z; }
320 inline float inc_z(
void){
return v_inc_z; }
321 inline void inc_t(
float a ){ v_inc_t = a; bool_inc_t =
true;}
322 inline float inc_t(
bool &
set ){
set=bool_inc_t;
return v_inc_t; }
323 inline float inc_t(
void){
return v_inc_t; }
324 inline void dim_x(
float a ){ v_dim_x = a; bool_dim_x =
true;}
325 inline float dim_x(
bool &
set ){
set=bool_dim_x;
return v_dim_x; }
326 inline float dim_x(
void){
return v_dim_x; }
327 inline void dim_y(
float a ){ v_dim_y = a; bool_dim_y =
true;}
328 inline float dim_y(
bool &
set ){
set=bool_dim_y;
return v_dim_y; }
329 inline float dim_y(
void){
return v_dim_y; }
330 inline void dim_z(
float a ){ v_dim_z = a; bool_dim_y =
true;}
331 inline float dim_z(
bool &
set ){
set=bool_dim_z;
return v_dim_z; }
332 inline float dim_z(
void){
return v_dim_z; }
333 inline void dim_t(
float a ){ v_dim_t = a; bool_dim_t =
true;}
334 inline float dim_t(
bool &
set ){
set=bool_dim_t;
return v_dim_t; }
335 inline float dim_t(
void){
return v_dim_t; }
336 inline void facteur(
float a ){ v_facteur = a; bool_facteur =
true; }
337 inline float facteur(
bool &
set ){
set=bool_facteur;
return v_facteur; }
338 inline float facteur(
void){
return v_facteur; }
339 inline void zero(
float a ){ v_zero = a; bool_zero =
true; }
340 inline float zero(
bool &
set ){
set=bool_zero;
return v_zero; }
341 inline float zero(
void){
return v_zero; }
342 inline void vect_z(
float* a ){ v_vect_z = a; bool_vect_z =
true; }
343 inline float*
vect_z(
bool &
set ){
set=bool_vect_z;
return v_vect_z; }
344 inline float*
vect_z(
void){
return v_vect_z; }
345 inline void unites_x(
const char* a ){ strcpy(v_unites_x, a); bool_unites_x =
true; }
346 inline char*
unites_x(
bool &
set ){
set=bool_unites_x;
return v_unites_x; }
348 inline void unites_y(
const char* a ){ strcpy(v_unites_y, a); bool_unites_y =
true;}
349 inline char*
unites_y(
bool &
set ){
set=bool_unites_y;
return v_unites_y; }
351 inline void unites_z(
const char* a ){ strcpy(v_unites_z,a); bool_unites_z =
true; }
352 inline char*
unites_z(
bool &
set ){
set=bool_unites_z;
return v_unites_z; }
354 inline void unites_t(
const char* a ){ strcpy(v_unites_t, a); bool_unites_t =
true; }
355 inline char*
unites_t(
bool &
set ){
set=bool_unites_t;
return v_unites_t; }
357 inline void unites(
const char* a ){ strcpy(v_unites, a); bool_unites =
true; }
358 inline char*
unites(
bool &
set ){
set=bool_unites;
return v_unites; }
359 inline char*
unites(
void){
return v_unites; }
360 inline void struct_desc(
const char* a ){ strcpy(v_struct_desc, a); bool_struct_desc =
true; }
361 inline char*
struct_desc(
bool &
set ){
set=bool_struct_desc;
return v_struct_desc; }
363 inline void aut_name(
const char* a ){ strcpy(v_aut_name, a); bool_aut_name =
true; }
364 inline char*
aut_name(
bool &
set ){
set=bool_aut_name;
return v_aut_name; }
366 inline void transparent(
void* a ){ v_transparent=a; bool_transparent =
true; }
367 inline void*
transparent(
bool &
set ){
set=bool_transparent;
return v_transparent; }
372 template<
class T>
int read_data( T* dp,
int numt=1,
char *buf=NULL );
373 template<
class T>
void write_data( T* dp,
int numt=1,
char *buf=NULL );
374 template<
class T>
void to_bin(
void *buf, T d );
375 template<
class T> T convert_buffer_datum(
void *buf,
int a );
389 int slicesize = data_size()*slice_sz()*numt;
390 bool alloc_buf =
false;
392 buf =
new char[slicesize];
396 int numprimitive = slice_sz()*num_components();
397 for (
int a=0; a<numprimitive; a++ )
398 to_bin<T>( buf+a*data_size(), dp[a] );
401 gzwrite( (gzFile)file, buf, slicesize );
403 fwrite( buf, 1, slicesize, (FILE*)file );
405 if ( alloc_buf )
delete[] buf;
423 int slicesize = data_size()*slice_sz()*numt;
424 bool alloc_buf =
false;
426 buf =
new char[slicesize];
432 numread = gzread( (gzFile)(file), buf, slicesize )/data_size();
434 numread = fread( buf, slice_sz()*numt, data_size(), (FILE *)(file) );
436 if ( systeme() != endian() ) swab(buf, numread);
438 int numprimitive = numread*num_components();
440 #pragma omp parallel for 441 for (
int a=0; a<numprimitive; a++ )
442 dp[a] = convert_buffer_datum<T>( buf, a );
444 if ( alloc_buf )
delete[] buf;
462 datum = ((
unsigned char *)buf)[a];
465 datum = ((
signed char *)buf)[a];
468 datum = ((
short *)buf)[a];
471 datum = ((
long *)buf)[a];
477 datum = ((
float *)buf)[a];
483 datum = ((
double *)buf)[a];
486 datum = ((
int *)buf)[a];
489 datum = ((
unsigned int *)buf)[a];
492 datum = ((
unsigned short *)buf)[a];
498 memset(&datum,0,
sizeof(datum));
500 return datum=from_raw(datum);
509 #define CONVERT_TYPE(D,m,M,B) { if(datum<m)datum=m;else if(datum>M)datum=M; \ 510 D a0 = (D)datum; *((D*)(B))=a0;}; 521 double datum=to_raw(d);
int read_IGB_data(T *dp, int numt, IGBheader *h, char *buf=NULL)
const char * Header_Systeme[]
T IGB_convert_buffer_datum(IGBheader *, void *buf, int a)
long unsigned Header_Systeme_No[]
union opencarp::rgba rgba
const char * Header_Type[]
struct opencarp::List List
unsigned short Data_Size[]