Commit 007afeb2 authored by Edward Vigmond's avatar Edward Vigmond
Browse files

Closer to working vector data

parent cda52d2f
......@@ -224,12 +224,13 @@ const char *Header_Type[] =
"double_complex", "rgba", "structure", "pointer", "list","int","uint",
"vec3f","vec3d","vec4f","vec4d"
};
//* size of the stored data, not the variable type
unsigned short Data_Size[] =
{
0, sizeof(Byte), sizeof(char), sizeof(short), sizeof(long), sizeof(float),
sizeof(double), 0, 0, 0, 0, sizeof(void *), 0, sizeof(int), sizeof(UInt),
sizeof(IGB_Vec3_f), sizeof(IGB_Vec3_d), sizeof(IGB_Vec4_f),
sizeof(IGB_Vec4_d)
3*sizeof(float), 3*sizeof(double), 4*sizeof(float), 4*sizeof(double)
};
long unsigned
......@@ -871,32 +872,11 @@ int IGBheader::read()
} else if ( ! strcmp( pt_1, "type" ) ) {
if ( ! strcmp( pt_2, "byte" ) ) {
v_type = IGB_BYTE ;
} else if ( ! strcmp( pt_2, "char" ) ) {
v_type = IGB_CHAR ;
} else if ( ! strcmp( pt_2, "short" ) ) {
v_type = IGB_SHORT ;
} else if ( ! strcmp( pt_2, "long" ) ) {
v_type = IGB_LONG ;
} else if ( ! strcmp( pt_2, "float" ) ) {
v_type = IGB_FLOAT ;
} else if ( ! strcmp( pt_2, "double" ) ) {
v_type = IGB_DOUBLE ;
} else if ( ! strcmp( pt_2, "complex" ) ) {
v_type = IGB_COMPLEX ;
} else if ( ! strcmp( pt_2, "double_complex" ) ) {
v_type = IGB_D_COMPLEX ;
} else if ( ! strcmp( pt_2, "rgba" ) ) {
v_type = IGB_RGBA ;
} else if ( ! strcmp( pt_2, "structure" ) ) {
v_type = IGB_STRUCTURE ;
} else if ( ! strcmp( pt_2, "int" ) ) {
v_type = IGB_INT;
} else if ( ! strcmp( pt_2, "uint" ) ) {
v_type = IGB_UINT;
}
bool_type = VRAI;
for( int htype=IGB_MIN_TYPE; htype<=IGB_MAX_TYPE; htype++ )
if ( !strcmp( pt_2, Header_Type[htype] ) ) {
v_type = htype;
}
bool_type = VRAI;
} else if ( ! strcmp( pt_1, "taille" ) ) {
v_taille = atoi( pt_2 ) ;
......@@ -1275,6 +1255,18 @@ const char *IGBheader::systemestr( void )
}
void IGBheader::systeme( const char* s )
{
int i;
for ( i=0; i<N_SYSTEMES; i++ )
if ( !strncmp( Header_Systeme[i], s, strlen(s) ) )
break;
if ( i<N_SYSTEMES )
v_systeme = Header_Systeme_No[i];
}
void IGBheader::type( char *datatype )
{
int tn=IGB_MIN_TYPE;
......
......@@ -9,7 +9,6 @@
#include <cstring>
#include <cctype>
#include<assert.h>
#include "VecData.h"
#define NALLOC 100
......@@ -119,6 +118,9 @@ class IGB_Vec {
T d[M];
T& operator[](const int indx){return d[indx];}
operator float (void) {return sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);}
IGB_Vec<T,M>(void){}
IGB_Vec<T,M>(double &f){ for(int i=0; i<M; i++ )d[i]=*(&f+i);}
IGB_Vec<T,M>& operator=(float *f){memcpy(d,f,M*sizeof(int));return *this;}
};
typedef IGB_Vec<float,3> IGB_Vec3_f;
typedef IGB_Vec<float,4> IGB_Vec4_f;
......@@ -251,6 +253,7 @@ class IGBheader
inline void trame( int a ){ v_trame = a; bool_trame = true;}
const char* systemestr(void);
inline int systeme( void ){ return v_systeme; }
void systeme( const char* s );
inline unsigned int lut(void){ return v_lut; }
inline unsigned int lut( bool &set ){ set=bool_x; return v_x; }
inline void lut( unsigned int a ){ v_lut = a; bool_lut = true; }
......@@ -384,7 +387,6 @@ template<class T>
T IGB_convert_buffer_datum( IGBheader *h, void *buf, int a )
{
T datum;
T* dp = &datum;
switch ( h->type() ) {
case IGB_BYTE:
......@@ -411,28 +413,8 @@ T IGB_convert_buffer_datum( IGBheader *h, void *buf, int a )
case IGB_UINT:
datum = ((unsigned int *)buf)[a];
break;
case IGB_RGBA:
memcpy( &datum, ((unsigned char *)buf)+4*a, 4*sizeof(char) );
break;
case IGB_VEC3_f:
datum = ((IGB_Vec3_f *)buf)[a];
for( int i=0; i<3; i++ ) *(dp+i) = h->from_raw(*(dp+i));
return datum;
break;
case IGB_VEC4_f:
datum = ((IGB_Vec4_f *)buf)[a];
for( int i=0; i<4; i++ ) *(dp+i) = h->from_raw(*(dp+i));
return datum;
break;
case IGB_VEC3_d:
datum = ((IGB_Vec3_d *)buf)[a];
for( int i=0; i<3; i++ ) *(dp+i) = h->from_raw(*(dp+i));
return datum;
break;
case IGB_VEC4_d:
datum = ((IGB_Vec4_d *)buf)[a];
for( int i=0; i<4; i++ ) *(dp+i) = h->from_raw(*(dp+i));
return datum;
case IGB_VEC3_f:
datum = ((float *)buf)[a];
break;
default:
memset(&datum,0,sizeof(datum));
......@@ -440,4 +422,5 @@ T IGB_convert_buffer_datum( IGBheader *h, void *buf, int a )
return h->from_raw(datum);
}
#endif //IGBheader_h
......@@ -3,7 +3,8 @@ HOSTMACHINE := $(shell uname)
FLTK_INC := $(shell fltk-config --use-gl --cxxflags)
FLTK_LD_FLAGS := $(shell fltk-config --use-gl --ldflags)
COMMON_LIBS = -lpng -lpthread -ltcmalloc_minimal -lpthread -lm -lz
#COMMON_LIBS = -lpng -lpthread -ltcmalloc_minimal -lm -lz
COMMON_LIBS = -lpng -lpthread -lm -lz
COMMON_INC = -I. -O0 -g -DOBJ_CLASS -D_REENTRANT
ifeq ($(HOSTMACHINE),Linux)
......
......@@ -290,7 +290,7 @@ int Model::add_surface_from_tri( const char *fn )
_surface[numSurf-1]->num(ntri);
for ( int i=0; i<ntri; i++ ) {
_surface[numSurf-1]->ele(i) = new Triangle( &pt );
int *nl = new int[3];
int nl[3];
if ( gzgets(in,buff,bufsize) == Z_NULL ||
sscanf(buff, "%d %d %d", nl, nl+1, nl+2 ) < 3 ) {
numSurf--;
......
......@@ -14,18 +14,24 @@ using namespace std;
const float vecsize = 0.1; // relative length of maximum vector by default
const float REL_MIN_VEC_SIZE = 100.;
template<class T, class S>
void read_IGB_vec_data( S* vdata, S* sdata, int ntr, IGBheader& h )
template< class S>
void read_IGB_vec_data( S* vdata, S* sdata, IGBheader& h )
{
T* vd = new T[h.slice_sz()];
int nf = 3+(sdata!=NULL);
S* vd;
if( nf==4 ) vd = new S[h.slice_sz()*nf];
for( int i=0; i<h.t(); i++ ){
read_IGB_data( sdata, ntr, &h );
for( int j=0; j<h.slice_sz(); j++ ) {
for( int k=0; k<3; k++ )
vdata[3*j+k+i*h.slice_sz()] = vd[j][k];
if( ntr==4 )
sdata[j+i*h.slice_sz()] = vd[j][3];
if( nf==3 )
read_IGB_data( vdata+nf*h.slice_sz(), nf, &h );
else {
read_IGB_data( vd, nf, &h );
for( int j=0; j<h.slice_sz(); j++ ) {
for( int k=0; k<3; k++ )
vdata[3*j+k+i*h.slice_sz()] = vd[j*4+k];
sdata[j+i*h.slice_sz()] = vd[j*4+3];
}
}
}
......@@ -105,27 +111,11 @@ VecData::VecData(const GLfloat *pt_offset, char* vptfile):_length(1),maxmag(0.),
IGBheader h(in);
if( !h.read() ) { // IGB file
vdata = (float *)realloc( vdata, 3*h.t()*h.slice_sz()*sizeof(float) );
int ntr = 3;
if( h.type() == IGB_VEC4_f || h.type() == IGB_VEC4_d ) { // scalar data
sdata = (float *)realloc( sdata, h.t()*h.slice_sz()*sizeof(float) );
ntr = 4;
}
void *vd = new char[h.slice_sz()*h.data_size()];
switch( h.type() ) {
case IGB_VEC3_f:
read_IGB_vec_data<IGB_Vec3_f>( vdata, sdata, ntr, h );
break;
case IGB_VEC3_d:
read_IGB_vec_data<IGB_Vec4_f>( vdata, sdata, ntr, h );
break;
case IGB_VEC4_f:
read_IGB_vec_data<IGB_Vec3_d>( vdata, sdata, ntr, h );
break;
case IGB_VEC4_d:
read_IGB_vec_data<IGB_Vec4_d>( vdata, sdata, ntr, h );
break;
}
read_IGB_vec_data( vdata, sdata, h );
} else { // text file
gzrewind(in);
// determine if scalar data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment