Beispiel #1
0
int get_framerate_strings( QSP_ARG_DECL  Data_Obj *str_dp, PGR_Cam *pgcp )
{
	// Could check format of object here...
	// Should be string table with enough entries to hold the modes
	// Should the strings be rows or multidim pixels?

	int i, n;

	if( OBJ_COLS(str_dp) < pgcp->pc_framerates.num ){
		sprintf(ERROR_STRING,"String object %s has too few columns (%ld) to hold %d framerates",
			OBJ_NAME(str_dp),(long)OBJ_COLS(str_dp),pgcp->pc_framerates.num);
		WARN(ERROR_STRING);
		n = OBJ_COLS(str_dp);
	} else {
		n=pgcp->pc_framerates.num;
	}
		
	for(i=0;i<n;i++){
		const char *src;
		char *dst;

		src = name_for_framerate(pgcp->pc_framerates.framerates[i]);
		dst = OBJ_DATA_PTR(str_dp);
		dst += i * OBJ_PXL_INC(str_dp);
		if( strlen(src)+1 > OBJ_COMPS(str_dp) ){
			sprintf(ERROR_STRING,"String object %s has too few components (%ld) to hold framerate string \"%s\"",
				OBJ_NAME(str_dp),(long)OBJ_COMPS(str_dp),src);
			WARN(ERROR_STRING);
		} else {
			strcpy(dst,src);
		}
	}
	return n;
}
Beispiel #2
0
static void get_data_params(Data_Obj *dp, u_long *np, long *incp)
{
    if( OBJ_COLS(dp)==1 ) {	/* maybe this is a column vector? */
        *np=OBJ_ROWS(dp);
        *incp = OBJ_ROW_INC(dp);
    } else {
        *np=OBJ_COLS(dp);
        *incp = OBJ_PXL_INC(dp);
    }
}
Beispiel #3
0
void assign_polh_var_data(char *varname, Data_Obj *dp, Polh_Output_Type type, int index )
{
	short *rpdp;
	Fmt_Pt fp1;
	Polh_Record_Format *prfp;
	char str[64];
	char *s,*s2;
	int i;

	if( OBJ_COLS(dp) != 1 ){
		sprintf(ERROR_STRING,"assign_polh_var_data:  object %s has %d columns, should be 1",
				OBJ_NAME(dp),OBJ_COLS(dp));
		warn(ERROR_STRING);
		return;
	}

	rpdp = (short *) OBJ_DATA_PTR(dp);
	prfp = &station_info[curr_station_idx].sd_multi_prf;
	format_polh_data(&fp1,rpdp,prfp);
	separator="";	/* no leading tab before the first record */
	if( fmt_one(msg_str,&fp1,type) < 0 )
		return;
	s=msg_str;
	i=index;
	while(i--){
		while( *s!=0 && !isspace(*s) ) s++;	/* skip data */
		while( *s!=0 && isspace(*s) ) s++;	/* skip spaces */
	}
#ifdef CAUTIOUS
	if( *s == 0 ){
		sprintf(ERROR_STRING,"CAUTIOUS:  assign_polh_var_data:  not enough words for index %d",
				index);
		warn(ERROR_STRING);
		sprintf(ERROR_STRING,"formatted string:  %s",msg_str);
		advise(ERROR_STRING);
		return;
	}
#endif /* CAUTIOUS */

	/* we have to do this check in case index is zero, so the check for leading spaces hasn't been
	 * performed above.  This is an issue with  milliseconds, where a leading space may appear
	 * in the string for values less than 100.
	 */
	while( *s!=0 && isspace(*s) ) s++;	/* skip any leading spaces */

	s2 = str;
	while( *s != 0 && !isspace(*s) )
		*s2++ = *s++;
	*s2=0;				/* BUG should check for overflow */

	assign_var(varname,str);

} /* end assign_polh_var_data */
Beispiel #4
0
int cksiz(QSP_ARG_DECL  int argtyp,Data_Obj *src_dp,Data_Obj *dst_dp)
{
	int i;

	/* allow exception for vmaxg, etc.
	 * These functions return two scalars, the max value,
	 * and number of occurrences, PLUS a vector with the
	 * indices of the occurrences.
	 *
	 * But where do we check them?  Do we need to do any checking for them?
	 */
	if( argtyp == V_SCALRET2 )
		return(0);

	for(i=0;i<N_DIMENSIONS;i++){
		if( OBJ_TYPE_DIM(src_dp,i) != OBJ_TYPE_DIM(dst_dp,i) ){

			/* special case for real/cpx fft */
			if( i==1 ){
				if( (argtyp & FWD_FT) && IS_REAL(src_dp) && IS_COMPLEX(dst_dp) ){
					if( OBJ_COLS(dst_dp) == (1+OBJ_COLS(src_dp)/2) )
						continue;
				} else if( (argtyp & INV_FT) && IS_COMPLEX(src_dp) && IS_REAL(dst_dp) ){
					if( OBJ_COLS(src_dp) == (1+OBJ_COLS(dst_dp)/2) )
						continue;
				}
			}

			/* if we get to here, the dimensions don't match... */
			/* if the source dimension is 1, it may be an outer op */
			/* if the destination dimension is 1, it may be a projection op */
			if( OBJ_TYPE_DIM(src_dp,i) == 1 /* && (argtyp&VV_SOURCES) == VV_SOURCES */ ){
				/* vmul, vadd, vsub, vatan2 */
				/* vvm_gt etc also */
				/* don't need VV_SOURCES... */
				continue;
			} else if( OBJ_TYPE_DIM(dst_dp,i) == 1 && CAN_PROJECT(argtyp) ){
				/* vsum, vmaxv, vmainv, etc */
				continue;
			} else {
				/* if we get to here, we're not happy... */
				sprintf(ERROR_STRING,
					"cksiz:  %s count mismatch, %s (%d) & %s (%d)",
					dimension_name[i],
					OBJ_NAME(src_dp),OBJ_TYPE_DIM(src_dp,i),
					OBJ_NAME(dst_dp),OBJ_TYPE_DIM(dst_dp,i));
				WARN(ERROR_STRING);
				return(-1);
			}
		}
	}
	return(0);
} /* end cksiz() */
Beispiel #5
0
void convert_polh_vector(Data_Obj *flt_dp,Data_Obj *polh_dp)
{
	uint32_t i,j;
	short *rpdp;
	float *cvt_p;
	Fmt_Pt fp1;
	int station;

	if( OBJ_PREC(flt_dp) != PREC_SP ){
		sprintf(ERROR_STRING,"convert_polh_data:  object %s has precision %s, should be %s",
				OBJ_NAME(flt_dp),PREC_NAME(OBJ_PREC_PTR(flt_dp)),PREC_NAME(prec_for_code(PREC_SP)));
		warn(ERROR_STRING);
		return;
	}
	if( OBJ_COLS(flt_dp) != OBJ_COLS(polh_dp) ){
		sprintf(ERROR_STRING,"convert_polh_data:  vectors %s (%d) and %s (%d) do not have the same number of columns",
				OBJ_NAME(flt_dp),OBJ_COLS(flt_dp),OBJ_NAME(polh_dp),OBJ_COLS(polh_dp));
		warn(ERROR_STRING);
		return;
	}
	/* BUG should make sure that tdim of flt_dp is correct! */

	/* assume that the object has already been checked for proper dim, type... */

	if( n_active_stations == 2 )
		station=0;
	else if(n_active_stations < 1 ){
		warn("format_polh_vector:  no active stations!?");
		return;
	} else
		station=curr_station_idx;

	rpdp = (short *) OBJ_DATA_PTR(polh_dp);

	for(i=0;i<OBJ_COLS(polh_dp);i++){
		Polh_Record_Format *prfp;

		cvt_p = ((float *) OBJ_DATA_PTR(flt_dp)) + i * OBJ_PXL_INC(flt_dp);

		prfp = &station_info[station].sd_multi_prf;
		format_polh_data(&fp1,rpdp,prfp);
		for(j=0;j<prfp->rf_n_data;j++){
			Polh_Output_Type type;
			type = prfp->rf_output[j];
			convert_chunk(cvt_p,&fp1,type);
			cvt_p += od_tbl[type].od_strings;	/* BUG not the right variable?... */
		}
		rpdp += prfp->rf_n_words;
		if( n_active_stations == 2 )
			station ^= 1;
	}
}
Beispiel #6
0
static int _fft_row_size_ok(QSP_ARG_DECL  Data_Obj *dp, const char * funcname )
{
	if( log_2(OBJ_COLS(dp)) == -1 ){
		sprintf(ERROR_STRING,
	"%s:  number of columns of image %s (%d) is not a power of two for FFT",
			funcname,OBJ_NAME(dp),OBJ_COLS(dp));
		WARN(ERROR_STRING);
		longlist(dp);
		return(-1);
	}

	return(0);
}
Beispiel #7
0
// BUG this assumes contiguity
void unity(Data_Obj *mp)				/**/
{
	dimension_t i,j;
	float *f;

	f=(float *)OBJ_DATA_PTR(mp);
	for(i=0;i<OBJ_COLS(mp);i++){
		for(j=0;j<OBJ_COLS(mp);j++){
			if(i==j) *f++ = 1.0;
			else *f++ = 0.0;
		}
	}
}
Beispiel #8
0
double _add_to_sos(QSP_ARG_DECL  dimension_t x,dimension_t y,Data_Obj *edp,Data_Obj *fdp,int factor)
{
	dimension_t i,j;
	double err,adj;
	incr_t xx,yy;

	/*
	if( the_sos == NO_VALUE )
		the_sos = get_sos(edp,fdp);
	*/

	adj =0.0;
	for(j=0;j<OBJ_ROWS(fdp);j++){
		yy = (incr_t)(y + j) - (incr_t)OBJ_ROWS(fdp)/2;
#ifdef NOWRAP
		if( yy >= 0 && yy < OBJ_ROWS(edp) ){
			for(i=0;i<OBJ_COLS(fdp);i++){
				xx = (incr_t)(x + i) - (incr_t)(OBJ_COLS(fdp)/2);
				if( xx >= 0 && xx < OBJ_COLS(edp) ){
					err = get_ferror(edp,fdp,xx,yy);
					adj += err*err;
				}
			}
		}
#else
		while( yy < 0 ) yy += OBJ_ROWS(edp);
		while( yy >= (incr_t)OBJ_ROWS(edp) ) yy -= OBJ_ROWS(edp);
		for(i=0;i<OBJ_COLS(fdp);i++){
			xx = x + i - OBJ_COLS(fdp)/2;
			while( xx < 0 ) xx += OBJ_COLS(edp);
			while( xx >= (incr_t)OBJ_COLS(edp) ) xx -= OBJ_COLS(edp);
			err = get_ferror(edp,fdp,xx,yy);
			adj += err*err;
		}
#endif /* NOWRAP */
	}
	/* normalize by number of pixels */
	if( factor == 1 )
		adj /= (OBJ_COLS(edp) * OBJ_ROWS(edp));
	else if( factor == -1 )
		adj /= - (OBJ_COLS(edp) * OBJ_ROWS(edp));
#ifdef CAUTIOUS
	else {
		sprintf(ERROR_STRING,"CAUTIOUS:  add_to_sos:  factor (%d) is not 1 or -1 !?",factor);
		warn(ERROR_STRING);
		return(0.0);
	}
#endif /* CAUTIOUS */
	/* the_sos += adj; */
	return(adj);
}
Beispiel #9
0
void dp_zroots(Data_Obj *r_dp, Data_Obj *a_dp, int polish )
{
	int m,n;

	n=OBJ_COLS(a_dp);	/* polynomial degree + 1 */
	m=OBJ_COLS(r_dp);

	if( m != n-1 ){
		sprintf(DEFAULT_ERROR_STRING,
	"dp_zroots:  len of root vector %s (%d) inconsistent with coefficients vector %s (%d)",
			OBJ_NAME(r_dp),OBJ_COLS(r_dp),OBJ_NAME(a_dp),OBJ_COLS(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}

	/* BUG make sure are row vectors */

	if(OBJ_ROWS(a_dp) != 1 ){
		sprintf(DEFAULT_ERROR_STRING,"dp_zroots:  coefficient vector %s should be a row vector, (rows = %d)!?",
			OBJ_NAME(a_dp),OBJ_ROWS(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_ROWS(r_dp) != 1 ){
		sprintf(DEFAULT_ERROR_STRING,"dp_zroots:  root vector %s should be a row vector, (rows = %d)!?",
			OBJ_NAME(r_dp),OBJ_ROWS(r_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}

	/* BUG make sure all vectors have same precision */

	if( OBJ_MACH_PREC(a_dp) == PREC_SP ){
		/* Why do we subtract 1 from the address of the roots, but not
		 * the coefficients!?
		 */

		float_zroots(
			((fcomplex *)OBJ_DATA_PTR(a_dp))/*-1*/,
			m,
			((fcomplex *)OBJ_DATA_PTR(r_dp))-1,
			polish);

	} else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){
		double_zroots( ((dcomplex *)OBJ_DATA_PTR(a_dp))-1,m,((dcomplex *)OBJ_DATA_PTR(r_dp))-1,polish);
	}
	else {
		NWARN("bad machine precision in dp_zroots");
	}
}
Beispiel #10
0
void format_polh_vector(Data_Obj *dp)
{
	uint32_t i;
	short *rpdp;
	Fmt_Pt fp1;
	int station;

	/* assume that the object has already been checked for proper dim, type... */

	if( n_active_stations == 2 )
		station=0;
	else if(n_active_stations < 1 ){
		warn("format_polh_vector:  no active stations!?");
		return;
	} else
		station=curr_station_idx;

	rpdp = (short *) OBJ_DATA_PTR(dp);
	for(i=0;i<OBJ_COLS(dp);i++){
		Polh_Record_Format *prfp;

		prfp = &station_info[station].sd_multi_prf;
		format_polh_data(&fp1,rpdp,prfp);
		display_formatted_point(QSP_ARG  &fp1,prfp);
		rpdp += prfp->rf_n_words;
		if( n_active_stations == 2 )
			station ^= 1;
	}
}
Beispiel #11
0
void _convolve(QSP_ARG_DECL  Data_Obj *dpto,Data_Obj *dpfr,Data_Obj *dpfilt)
{
	dimension_t i,j;
	float val, *frptr;
	dimension_t yos, offset;

	// where is the other error checking done???
	INSIST_RAM_OBJ(dpto,convolve)
	INSIST_RAM_OBJ(dpfr,convolve)
	INSIST_RAM_OBJ(dpfilt,convolve)

	img_clear(dpto);

	frptr = (float *) OBJ_DATA_PTR(dpfr);
	j=OBJ_ROWS(dpto);
	while(j--){
		yos = j * OBJ_ROW_INC(dpfr);
		i=OBJ_COLS(dpfr);
		while(i--){
			offset = yos+i*OBJ_PXL_INC(dpfr);
			val = *(frptr+offset);
			add_impulse(val,dpto,dpfilt,i,j);
		}
	}
}
Beispiel #12
0
static void fb_load(QSP_ARG_DECL Data_Obj *dp,int x, int y)
{
#ifdef HAVE_FB_DEV
	dimension_t i,j;
	/* char *p,*q; */	/* BUG probably a lot faster if we cast to long! */
	long *p,*q;
	u_long bytes_per_row, words_per_row;

	/* BUG assume dp is the right kind of object */

	if( ! IS_CONTIGUOUS(dp) ){
		sprintf(ERROR_STRING,"fb_load:  object %s must be contiguous",
			OBJ_NAME(dp));
		WARN(ERROR_STRING);
		return;
	}

	INSURE_FB("fb_load");

	p=(long *)OBJ_DATA_PTR(dp);
	q=(long *)OBJ_DATA_PTR(curr_fbip->fbi_dp);

	bytes_per_row = OBJ_COLS(dp) * OBJ_COMPS(dp);
	words_per_row = bytes_per_row / sizeof(long);

	for(i=0;i<OBJ_ROWS(dp);i++){
		/* BUG we need to correct the row ptr if dp is narrower than the display */
		for(j=0;j<words_per_row;j++)
			*q++ = *p++;
	}
#endif /* HAVE_FB_DEV */
}
Beispiel #13
0
static void float_sort_svd_eigenvectors(Data_Obj *u_dp, Data_Obj *w_dp, Data_Obj *v_dp)
{
	//SORT_EIGENVECTORS(float)
	dimension_t i,n;
	u_long *index_data;

	n = OBJ_COLS(w_dp);

	index_dp = mkvec("svd_tmp_indices",n,1,PREC_UDI);
	if( index_dp == NULL ){
		NWARN("Unable to create index object for sorting SVD eigenvalues");
		return;
	}

	sort_indices(index_dp,w_dp);
	/* sorting is done from smallest to largest */

	j=0;
	index_data = OBJ_DATA_PTR(index_dp);

	/* We should only have to have 1 column of storage to permute things,
	 * but life is simplified if we copy the data...
	 */

	for(i=n-1;i>=0;i--){
		k= *(index_data+i);
	}
}
Beispiel #14
0
void dobj_iterate(Data_Obj *dp,void (*func)(Data_Obj *,index_t))
{
	dimension_t comp,col,row,frm,seq;

	/* offsets for sequence, frame, row, pixel, component */
	dimension_t s_os, f_os, r_os, p_os, c_os;

	s_os=0;
	for(seq=0;seq<OBJ_SEQS(dp);seq++){
		f_os = s_os;
		for(frm=0;frm<OBJ_FRAMES(dp);frm++){
			r_os = f_os;
			for(row=0;row<OBJ_ROWS(dp);row++){
				p_os = r_os;
				for(col=0;col<OBJ_COLS(dp);col++){
					c_os = p_os;
					for(comp=0;comp<OBJ_COMPS(dp);comp++){
						(*func)(dp,c_os);
						c_os += OBJ_COMP_INC(dp);
					}
					p_os += OBJ_PXL_INC(dp);
				}
				r_os += OBJ_ROW_INC(dp);
			}
			f_os += OBJ_FRM_INC(dp);
		}
		s_os += OBJ_SEQ_INC(dp);
	}
}
Beispiel #15
0
void dp_moment(QSP_ARG_DECL  Data_Obj *d_dp)
{
	/* std_type *d_rowlist[MAX_DIM]; */
	int n;
	if( ! IS_CONTIGUOUS(d_dp) ){
           	sprintf(DEFAULT_ERROR_STRING,"dp_moment:  Object %s must be contiguous for eigsrt",OBJ_NAME(d_dp));
                NWARN(DEFAULT_ERROR_STRING);
                return;
        }
	n = OBJ_COLS(d_dp);

	if( OBJ_MACH_PREC(d_dp) == PREC_SP ){
       		float adev, var, skew, curt;
		float ave, sdev;
	
		/* BUG - the results don't get passed out anywhere!?
		 */

		float_moment(((float *)(OBJ_DATA_PTR(d_dp))),n,&ave,&adev,&sdev,&var,&skew,&curt);
	} else if( OBJ_MACH_PREC(d_dp) == PREC_DP ){
       		double adev, var, skew, curt;
		double ave, sdev;
	
		double_moment(((double *)(OBJ_DATA_PTR(d_dp))),n,&ave,&adev,&sdev,&var,&skew,&curt);
	}
}
Beispiel #16
0
void _make_dragg(QSP_ARG_DECL  const char *name,Data_Obj *bm,Data_Obj *dp)
{
	Draggable *dgp;

	if( !dp_same_size(bm,dp,"make_dragg") ){
		warn("image/bitmap size mismatch");
		return;
	}
	if( OBJ_PREC(bm) != PREC_BIT ){
		sprintf(ERROR_STRING,"Object %s has precision %s, should be %s",
			OBJ_NAME(bm),PREC_NAME(OBJ_PREC_PTR(bm)),
			PREC_NAME(PREC_FOR_CODE(PREC_BIT)));
		warn(ERROR_STRING);
		return;
	}
	if( OBJ_PREC(dp) != PREC_BY && OBJ_PREC(dp) != PREC_UBY ){
		sprintf(ERROR_STRING,"Image %s (for draggable object) has %s precision, should be %s or %s",
			OBJ_NAME(dp),PREC_NAME(OBJ_PREC_PTR(dp)),
			PREC_NAME(PREC_FOR_CODE(PREC_BY)),
			PREC_NAME(PREC_FOR_CODE(PREC_UBY)) );
		warn(ERROR_STRING);
		return;
	}

	dgp = new_dragg(name);
	if( dgp == NULL ) return;

	dgp->dg_width = (int) OBJ_COLS(dp);
	dgp->dg_height = (int) OBJ_ROWS(dp);
	dgp->dg_bitmap = bm;
	dgp->dg_image = dp;
	dgp->dg_np = mk_node(dgp);
}
Beispiel #17
0
static void fb_save(QSP_ARG_DECL Data_Obj *dp,int x, int y)
{
#ifdef HAVE_FB_DEV
	dimension_t i,j,k;
	char *p,*q;

	/* BUG assume dp is the right kind of object */

	if( ! IS_CONTIGUOUS(dp) ){
		sprintf(ERROR_STRING,"fb_save:  object %s must be contiguous",
			OBJ_NAME(dp));
		WARN(ERROR_STRING);
		return;
	}

	INSURE_FB("fb_save");

	p=(char *)OBJ_DATA_PTR(dp);
	q=(char *)OBJ_DATA_PTR(curr_fbip->fbi_dp);

	/* BUG this byte-at-a-time copy is horribly inefficient */
	for(i=0;i<OBJ_ROWS(dp);i++)
		for(j=0;j<OBJ_COLS(dp);j++)
			for(k=0;k<OBJ_COMPS(dp);k++)
				*p++ = *q++;
#endif /* HAVE_FB_DEV */
}
Beispiel #18
0
int get_camera_names( QSP_ARG_DECL  Data_Obj *str_dp )
{
	// Could check format of object here...
	// Should be string table with enough entries to hold the modes
	// Should the strings be rows or multidim pixels?
	List *lp;
	Node *np;
	PGR_Cam *pgcp;
	int i, n;

	lp = pgc_list();
	if( lp == NULL ){
		WARN("No cameras!?");
		return 0;
	}

	n=eltcount(lp);
	if( OBJ_COLS(str_dp) < n ){
		sprintf(ERROR_STRING,"String object %s has too few columns (%ld) to hold %d camera names",
			OBJ_NAME(str_dp),(long)OBJ_COLS(str_dp),n);
		WARN(ERROR_STRING);
		n = OBJ_COLS(str_dp);
	}
		
	np=QLIST_HEAD(lp);
	i=0;
	while(np!=NULL){
		char *dst;
		pgcp = (PGR_Cam *) NODE_DATA(np);
		dst = OBJ_DATA_PTR(str_dp);
		dst += i * OBJ_PXL_INC(str_dp);
		if( strlen(pgcp->pc_name)+1 > OBJ_COMPS(str_dp) ){
			sprintf(ERROR_STRING,"String object %s has too few components (%ld) to hold camera name \"%s\"",
				OBJ_NAME(str_dp),(long)OBJ_COMPS(str_dp),pgcp->pc_name);
			WARN(ERROR_STRING);
		} else {
			strcpy(dst,pgcp->pc_name);
		}
		i++;
		if( i>=n )
			np=NULL;
		else
			np = NODE_NEXT(np);
	}

	return i;
}
Beispiel #19
0
static void _update_pf_viewer(QSP_ARG_DECL  Platform_Viewer *pvp, Data_Obj *dp) 
{
#ifdef HAVE_OPENGL
	int t;
	//cudaError_t e;

	// unmap buffer before using w/ GL
	if( BUF_IS_MAPPED(dp) ){
		if( (*PF_UNMAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp))))
				(QSP_ARG  dp) < 0 ) {
			warn("update_pf_viewer:  buffer unmap error!?");
		}
		CLEAR_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED);
		// propagate change to children and parents
		propagate_flag(dp,DT_BUF_MAPPED);

	}

	glClear(GL_COLOR_BUFFER_BIT);

	glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp));
	// is glBindBuffer REALLY part of libGLEW???
//#ifdef HAVE_LIBGLEW
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp));
//#endif // HAVE_LIBGLEW

	t=gl_pixel_type(dp);
	glTexSubImage2D(GL_TEXTURE_2D, 0,	// target, level
		0, 0,				// x0, y0
		OBJ_COLS(dp), OBJ_ROWS(dp), 	// dx, dy
		t,
		GL_UNSIGNED_BYTE,		// type
		OFFSET(0));			// offset into PIXEL_UNPACK_BUFFER

//#ifdef HAVE_LIBGLEW
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
//#endif // HAVE_LIBGLEW

	glBegin(GL_QUADS);
	glTexCoord2f(0, 1); glVertex2f(-1.0, -1.0);
	glTexCoord2f(0, 0); glVertex2f(-1.0, 1.0);
	glTexCoord2f(1, 0); glVertex2f(1.0, 1.0);
	glTexCoord2f(1, 1); glVertex2f(1.0, -1.0);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);

	if( (*PF_MAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp))))(QSP_ARG  dp) < 0 ){
		warn("update_pf_viewer:  Error mapping buffer!?");
	}


	SET_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED);
	// propagate change to children and parents
	propagate_flag(dp,DT_BUF_MAPPED);
#else // ! HAVE_OPENGL
	NO_OGL_MSG
#endif // ! HAVE_OPENGL
}
Beispiel #20
0
void dp_jacobi(QSP_ARG_DECL  Data_Obj *v_dp, Data_Obj *d_dp, Data_Obj *a_dp, int *nrotp)
{
	void *a_rowlist[MAX_DIM], *v_rowlist[MAX_DIM];
	int n;

	if( OBJ_COLS(a_dp) != OBJ_ROWS(a_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  matrix %s must be square for jacobi",OBJ_NAME(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_COLS(v_dp) != OBJ_ROWS(v_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  matrix %s must be square for jacobi",OBJ_NAME(v_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_COLS(v_dp) != OBJ_COLS(a_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  size of eigenvector matrix %s must match input matrix %s for jacobi",
			OBJ_NAME(v_dp),OBJ_NAME(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_COLS(d_dp) != OBJ_COLS(a_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  size of eigenvalue vector %s must match input matrix %s for jacobi",
			OBJ_NAME(d_dp),OBJ_NAME(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( ! IS_CONTIGUOUS(a_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  Object %s must be contiguous for jacobi",OBJ_NAME(a_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( ! IS_CONTIGUOUS(d_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  Object %s must be contiguous for jacobi",OBJ_NAME(d_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( ! IS_CONTIGUOUS(v_dp) ){
		sprintf(DEFAULT_ERROR_STRING,"dp_jacobi:  Object %s must be contiguous for jacobi",OBJ_NAME(v_dp));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}

	n = OBJ_COLS(a_dp);
	/* BUG make sure types match */

	if( OBJ_MACH_PREC(a_dp) == PREC_SP ){
		float_init_rowlist((float **)(void *)a_rowlist,a_dp);
		float_init_rowlist((float **)(void *)v_rowlist,v_dp);

		float_jacobi(((float **)(void *)a_rowlist)-1,n,((float *)(OBJ_DATA_PTR(d_dp)))-1,((float **)(void *)v_rowlist)-1,nrotp);
	} else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){
		double_init_rowlist((double **)(void *)a_rowlist,a_dp);
		double_init_rowlist((double **)(void *)v_rowlist,v_dp);

		double_jacobi(((double **)(void *)a_rowlist)-1,n,((double *)(OBJ_DATA_PTR(d_dp)))-1,((double **)(void *)v_rowlist)-1,nrotp);
	} else {
		NWARN("bad precision in dp_jacobi");
	}
}
Beispiel #21
0
static void prepare_image_for_mapping(Data_Obj *dp)
{
#ifdef HAVE_OPENGL
	int t;
	cudaError_t e;

	// unmap buffer before using w/ GL
	if( BUF_IS_MAPPED(dp) ){
		e = cudaGLUnmapBufferObject( OBJ_BUF_ID(dp) );   
		if( e != cudaSuccess ){
			describe_cuda_driver_error2("update_cuda_viewer",
				"cudaGLUnmapBufferObject",e);
			NERROR1("failed to unmap buffer object");
		}
		CLEAR_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED);
		// propagate change to children and parents
		propagate_flag(dp,DT_BUF_MAPPED);

	}


	//
	//bind_texture(OBJ_DATA_PTR(dp));

	glClear(GL_COLOR_BUFFER_BIT);

/*
sprintf(ERROR_STRING,"update_cuda_viewer:  tex_id = %d, buf_id = %d",
OBJ_TEX_ID(dp),OBJ_BUF_ID(dp));
advise(ERROR_STRING);
*/
	glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp));
#ifdef HAVE_LIBGLEW
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp));
#endif // HAVE_LIBGLEW

#ifdef FOOBAR
	switch(OBJ_COMPS(dp)){
		/* what used to be here??? */
	}
#endif /* FOOBAR */

	t=gl_pixel_type(dp);
	glTexSubImage2D(GL_TEXTURE_2D, 0,			// target, level
		0, 0,						// x0, y0
		OBJ_COLS(dp), OBJ_ROWS(dp), 			// dx, dy
		t,
		GL_UNSIGNED_BYTE,				// type
		OFFSET(0));					// offset into PIXEL_UNPACK_BUFFER

#ifdef HAVE_LIBGLEW
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
#endif // HAVE_LIBGLEW
}
Beispiel #22
0
int prodimg(QSP_ARG_DECL  Data_Obj *dpto,Data_Obj *rowobj,Data_Obj *colobj)	/** make the product image */
{
	Vec_Obj_Args oa1, *oap=&oa1;

	if( OBJ_COLS(rowobj) != OBJ_COLS(dpto) ){
		sprintf(DEFAULT_ERROR_STRING,
	"prodimg:  row size mismatch, target %s (%d) and row %s (%d)",
			OBJ_NAME(dpto),OBJ_COLS(dpto),OBJ_NAME(rowobj),
			OBJ_COLS(rowobj));
		NWARN(DEFAULT_ERROR_STRING);
		return(-1);
	} else if( OBJ_ROWS(colobj) != OBJ_ROWS(dpto) ){
		sprintf(DEFAULT_ERROR_STRING,
	"prodimg:  column size mismatch, target %s (%d) and column %s (%d)",
			OBJ_NAME(dpto),OBJ_ROWS(dpto),OBJ_NAME(colobj),
			OBJ_ROWS(colobj));
		NWARN(DEFAULT_ERROR_STRING);
		return(-1);
	} else if( !same_pixel_type(QSP_ARG  dpto,rowobj) ){
		NWARN("type/precision mismatch");
		return(-1);
	} else if( !same_pixel_type(QSP_ARG  dpto,colobj) ){
		NWARN("type precision mismatch");
		return(-1);
	}
#ifdef FOOBAR
	else if( ! FLOATING_OBJ(dpto) ){
		NWARN("sorry, only float and double supported for prodimg");
		return(-1);
	} else if( IS_COMPLEX(dpto) || IS_COMPLEX(colobj)
			|| IS_COMPLEX(rowobj) ){
		NWARN("Sorry, complex not supported");
		return(-1);
	}
#endif /* FOOBAR */

	setvarg3(oap,dpto,rowobj,colobj);

	vmul(QSP_ARG  oap);
	return(0);
}
Beispiel #23
0
static void zero_dimension(Data_Obj *dp,float *base,int dim,long index)
{
	dimension_t i;

	if( dim > 1 ){
		for(i=0;i<OBJ_TYPE_DIM(dp,dim);i++)
			zero_dimension(dp,base+i*OBJ_TYPE_INC(dp,dim),dim-1,i);
	} else {
		for(i=0;i<OBJ_COLS(dp);i++)
			base[i] = 0.0;
	}
}
Beispiel #24
0
int real_fft_type(QSP_ARG_DECL  Data_Obj *real_dp,Data_Obj *cpx_dp,const char *funcname)
{
	// First make sure the objects match in precision and are of the correct type
	if( ! real_cpx_objs_ok( real_dp, cpx_dp, funcname ) ) return -1;


	if( OBJ_ROWS(real_dp) == OBJ_ROWS(cpx_dp) ){
		if( ! good_xform_size( real_dp, cpx_dp, 1, funcname ) ) return -1;
		if( ! dim_is_power_of_two(real_dp, 2, funcname ) ) return -1;
		return 1;
	} else if( OBJ_COLS(real_dp) == OBJ_COLS(cpx_dp) ){
		if( ! good_xform_size( real_dp, cpx_dp, 2, funcname ) ) return -1;
		if( ! dim_is_power_of_two(real_dp, 1, funcname ) ) return -1;
		return 2;
	} else {
		sprintf(ERROR_STRING,
"%s:  real data %s (%d x %d) and transform %s (%d x %d) must have one matching dimension!?",
			funcname,OBJ_NAME(real_dp),OBJ_ROWS(real_dp),OBJ_COLS(real_dp),
			         OBJ_NAME(cpx_dp),OBJ_ROWS(cpx_dp),OBJ_COLS(cpx_dp));
		WARN(ERROR_STRING);
		return -1;
	}
}
Beispiel #25
0
int get_video_mode_strings( QSP_ARG_DECL  Data_Obj *str_dp, PGR_Cam *pgcp )
{
	// Could check format of object here...
	// Should be string table with enough entries to hold the modes
	// Should the strings be rows or multidim pixels?

	int i, n;

	if( OBJ_COLS(str_dp) < pgcp->pc_video_modes.num ){
		sprintf(ERROR_STRING,"String object %s has too few columns (%ld) to hold %d modes",
			OBJ_NAME(str_dp),(long)OBJ_COLS(str_dp),pgcp->pc_video_modes.num);
		WARN(ERROR_STRING);
		n = OBJ_COLS(str_dp);
	} else {
		n=pgcp->pc_video_modes.num;
	}
		
	for(i=0;i<n;i++){
		int k;
		const char *src;
		char *dst;

		k=index_of_video_mode(pgcp->pc_video_modes.modes[i]);
		src = all_video_modes[k].nvm_name;
		dst = OBJ_DATA_PTR(str_dp);
		dst += i * OBJ_PXL_INC(str_dp);
		if( strlen(src)+1 > OBJ_COMPS(str_dp) ){
			sprintf(ERROR_STRING,"String object %s has too few components (%ld) to hold mode string \"%s\"",
				OBJ_NAME(str_dp),(long)OBJ_COMPS(str_dp),src);
			WARN(ERROR_STRING);
		} else {
			strcpy(dst,src);
		}
	}
	set_script_var_from_int("n_video_modes",n);
	return n;
}
Beispiel #26
0
Datei: xmvi.c Projekt: E-LLP/QuIP
static void x_play_movie(QSP_ARG_DECL  Movie *mvip)
{
	Data_Obj *dp;
	Viewer *vp;

	dp = (Data_Obj *)mvip->mvi_data;
	/* longlist(dp); */

	vp = vwr_of(QSP_ARG  MOVIE_VIEWER_NAME);

mk_win:
	if( vp == NO_VIEWER ){
		vp = viewer_init(QSP_ARG  MOVIE_VIEWER_NAME,OBJ_COLS(dp),OBJ_ROWS(dp),0);
		if( vp == NO_VIEWER ){
			WARN("couldn't create viewer");
			return;
		}
		default_cmap(QSP_ARG  VW_DPYABLE(vp) );
		show_viewer(QSP_ARG  vp);	/* default state is to be shown */
		select_viewer(QSP_ARG  vp);
	} else {
		if( vp->vw_width != OBJ_COLS(dp) ||
			vp->vw_height != OBJ_ROWS(dp) ){
			sprintf(ERROR_STRING,
				"Resizing movie viewer for movie %s",
				OBJ_NAME(dp));
			advise(ERROR_STRING);
			delete_viewer(QSP_ARG  vp);
			vp=NO_VIEWER;
			goto mk_win;
		}
	}

	/* load_viewer got rewritten, no longer show all frames!? */
	old_load_viewer(QSP_ARG  vp,dp);
}
Beispiel #27
0
void img_clear(Data_Obj *dp)
{
	dimension_t i,j;
	float *ptr;
	incr_t xos, yos;

	ptr=(float *)OBJ_DATA_PTR(dp);
	for(j=0;j<OBJ_ROWS(dp);j++){
		yos = j * OBJ_ROW_INC(dp);
		for(i=0;i<OBJ_COLS(dp);i++){
			xos = i * OBJ_PXL_INC(dp);
			*(ptr + yos + xos ) = 0.0;
		}
	}
}
Beispiel #28
0
//int _wav_to_dp(QSP_ARG_DECL  Data_Obj *dp,Wav_Header *hd_p)
FIO_FT_TO_DP_FUNC(wav,Wav_Header)
{
	Precision * prec_p;
	dimension_t total_samples, samples_per_channel;

	switch( hd_p->wh_bits_per_sample ){
		case 8:  prec_p=PREC_FOR_CODE(PREC_UBY); break;
		case 16: prec_p=PREC_FOR_CODE(PREC_IN); break;
		default:
			sprintf(ERROR_STRING,
		"wav_to_dp:  unexpected # of bits per sample %d",
				hd_p->wh_bits_per_sample);
			warn(ERROR_STRING);
			return(-1);
	}
	SET_OBJ_PREC_PTR(dp, prec_p);

	SET_OBJ_COMPS(dp, hd_p->wh_n_channels );

	total_samples = (dimension_t) (hd_p->wh_datasize / PREC_SIZE( prec_p ));
	samples_per_channel = total_samples / OBJ_COMPS(dp);

	SET_OBJ_COLS(dp, samples_per_channel);
	SET_OBJ_ROWS(dp, 1);
	SET_OBJ_FRAMES(dp, 1);
	SET_OBJ_SEQS(dp, 1);

	SET_OBJ_COMP_INC(dp, 1);
	SET_OBJ_PXL_INC(dp, 1);
	SET_OBJ_ROW_INC(dp, 1);
	SET_OBJ_FRM_INC(dp, 1);
	SET_OBJ_SEQ_INC(dp, 1);

	SET_OBJ_PARENT(dp, NULL);
	SET_OBJ_CHILDREN(dp, NULL);

	SET_OBJ_AREA(dp, ram_area_p);		/* the default */

	/* dp->dt_data = hd_p->image; */		/* where do we allocate data??? */

	SET_OBJ_N_TYPE_ELTS(dp, OBJ_COMPS(dp) * OBJ_COLS(dp) * OBJ_ROWS(dp)
			* OBJ_FRAMES(dp) * OBJ_SEQS(dp) );

	auto_shape_flags(OBJ_SHAPE(dp));

	return 0;
}
Beispiel #29
0
void dp_choldc(Data_Obj *a_dp, Data_Obj *p_dp)
{
	unsigned m, n;
	void *a_rowlist[MAX_DIM];
	/*
	n=OBJ_ROWS(a_dp);

	if( n > MAX_DIM ){
		NWARN("Sorry, MAX dimension exceeded in dp_choldc");
		sprintf(DEFAULT_ERROR_STRING,"dp_choldc:  MAX_DIM = %d, n = %d", MAX_DIM,n);
		NADVISE(DEFAULT_ERROR_STRING);
		return;
	}
	*/
	n=OBJ_COLS(a_dp);
	m=OBJ_ROWS(a_dp);

	if( n > MAX_DIM || m > MAX_DIM ){
		NWARN("Sorry, MAX dimension exceeded in dp_choldc");
		sprintf(DEFAULT_ERROR_STRING,"dp_choldc:  MAX_DIM = %d, n = %d, m = %d",
			MAX_DIM,n,m);
		NADVISE(DEFAULT_ERROR_STRING);
		return;
	}

	printf("nrmenu:numrec.c data %f\n", *((float *)OBJ_DATA_PTR(a_dp)));
	
	
	if( OBJ_MACH_PREC(a_dp) == PREC_SP ){
		float_init_rowlist((float **)(void *)a_rowlist,a_dp);

		float_choldc(((float **)(void *)a_rowlist)-1,n,((float *)OBJ_DATA_PTR(p_dp))-1);
		
	} else if( OBJ_MACH_PREC(a_dp) == PREC_DP ){
		double_init_rowlist((double **)(void *)a_rowlist,a_dp);

		double_choldc(((double **)(void *)a_rowlist)-1,n,((double *)OBJ_DATA_PTR(p_dp))-1);
	}
	else {
		NWARN("bad machine precision in dp_choldc");
	}
	
}
Beispiel #30
0
double get_sos(Data_Obj *edp,Data_Obj *fdp)		/* get the total sq'd error */
{
	incr_t i,j;
	double sos, rowsos,err;

	sos = 0.0;
	for(j=0;j<(incr_t)OBJ_ROWS(edp);j++){
		rowsos=0.0;
		for(i=0;i<(incr_t)OBJ_COLS(edp);i++){
			err = get_ferror(edp,fdp,i,j);
			rowsos += err * err;
		}
		sos += rowsos;
	}

	/* normalize by number of pixels */
	/* why rowinc and not ncols??? */
	sos /= OBJ_ROWS(edp)*OBJ_ROW_INC(edp);
	return(sos);
}