⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgetdata.cpp

📁 StaMps最新测试版
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        temparr = new float [nsamps * 2] ;         // get the scaling parameters for magnitude        if (expflag) cout << "Applying exponent : " << expval << endl ;        if (!expflag) cout << "Not Applying exponent  " << endl  ;        totmag = 0. ;        for (i =startline; i<startline+nlines; i+=32) {                ifil.seekg (long(i) * nsamps * 4 * 2, ios::beg) ;		// just read in the magnitude portion of the line (first band)                ifil.read ((char*)temparr, nsamps * 4) ;                for (j=32; j<nsamps-32; j+= 32) {                        count += 1 ;			magval = *(temparr+ j) ;                        if (expflag)                        {                        	totmag += pow ( double(magval), double(expval)) ;                        }                        else {                        	totmag += magval ;                        }                }        }         // get the avereage of the red and grn        totmag /= count ;	scalemag = scalefac * 150. / totmag ;	scalehgt = 255. / (float) cont_interval ;         cout << "Magnitude scaling parameter   :   "   << scalemag << endl ;        cout << "Height scaling parameter      :   "   << scalehgt << endl ;	double min=1.E18, max=-1.E18;          ifil.seekg (startline * nsamps * 4 * 2, ios::beg) ;        for (i=0; i<nlines; i++) {		// first read in the magnitude                ifil.read ((char*)temparr, nsamps * 4) ;                for (j=0; j<nsamps; j++)                {			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;                        optr1 = mag + i_out * nsamps + j_out ;                        iptr0 = temparr + j  ;			magval = *iptr0 ;			//cout << magval << endl;                        if (expflag) {                                b1 = pow (double(magval), double(expval)) ;                        }                        else {                                b1 = magval ;                        }                        magval = b1 * scalemag ;			redval = magval ;                        redval = (redval < 0) ? 0. : redval ;                        redval = (redval > 255) ? 255. : redval ;                        *optr1 = (unsigned char) redval ;                }		// then the height                ifil.read ((char*)temparr, nsamps * 4) ;                for (j=0; j<nsamps; j++)                {			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;                        optr1 = hgt + i_out * nsamps + j_out ;                        iptr1 = temparr + j ;			if (*iptr1 > max) max = *iptr1 ;			if (*iptr1 < min) min = *iptr1 ;			// added 18mar02 hz for real contour interval			contours = (*iptr1) / cont_interval;			contours = (contours - floor(contours)) * cont_interval;			hgtval = int (contours * scalehgt);			//  test lines			//cout << (*iptr1) << "  " << hgtval << "  " << contours << endl;			// ** hgtval = int (float(int(*iptr1) % cont_interval) * scalehgt) ; 			hgtval = (hgtval < 0) ? 0 : hgtval ;			hgtval = (hgtval > 255) ? 255 : hgtval ;			*optr1 = (unsigned char) (hgtval) ;                 }        }        delete [] temparr ;	cout << "Min hgt is " << min << endl ;	cout << "Max hgt is " << max << endl ;        ifil.close() ;        return (1) ;}          int CGetData::getarrayByte (int min, int max, int flipflag){        unsigned char *optr0 ;        int  i, j, i_out, j_out, vflip=0, hflip=0 ;        long lpos ;        unsigned char *temparr ;	float scalebyte, offset=0. ;        double redval ;        ifstream ifil (infile, ios::in) ;         // exponent apply flag and exponent value are class members         ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps) ; 	if (flipflag) {		hflip = flipflag % 2 ;			vflip = flipflag / 2 ;		}	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}        if (nlines ==0) {                nlines = totlines - startline ;        }         mag = new unsigned char [nsamps * nlines] ;        temparr = new unsigned char [nsamps] ;	scalebyte = 255 / (max -min)  ;	offset = min ;         // get the scaling parameters        cout << "Applying scalefactor  : " << scalebyte << endl ;        cout << "Applying offset       : " << offset  ;           ifil.seekg (startline * nsamps, ios::beg) ;        for (i=0; i<nlines; i++) {                ifil.read ((char*)temparr, nsamps) ;                for (j=0; j<nsamps; j++)                {			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;			optr0 = mag + i_out * nsamps + j_out ;			redval = (*(temparr + j) - offset) * scalebyte ;			redval = (redval <0)? 0 : redval ;			redval = (redval >255)? 255 : redval ;                        *optr0 = (unsigned char) redval ;                }        }        delete [] temparr ;        ifil.close() ;        return (1) ;}          int CGetData::Raw2Mag (int dtype, float min, float max, int flipflag) {	float scale, offset ;	scale = 255. / (max - min) ; 	offset = -min * scale ;		cout << "Raw2Mag scaling " << endl ;	cout << "Scale  : " << scale << endl ;	cout << "Offset : " << offset << endl ;        mag = new unsigned char [nsamps * nlines] ;	bytescale (raw, mag, nsamps, nlines, scale, offset, dtype, flipflag) ;	return (1) ;}	int CGetData::getarrayRaw (int dtype) {	int bytespersample ;	long lpos, npix = 0 ;        ifstream ifil (infile, ios::in) ; 	bytespersample = bpp [dtype] ;         ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps * bytespersample) ;	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}	if (nlines ==0) {		nlines = totlines - startline ;	} 	npix = nsamps * (totlines - startline) * bytespersample ;	raw = new unsigned char [npix] ;	if (raw == NULL) {		cout << "Could not allocate memory for the raw data array " << endl ;		return (-1) ;	}	ifil.seekg (startline * nsamps * bytespersample, ios::beg) ;	ifil.read ((char*)raw, npix) ;	ifil.close () ;	return (1) ;} int CGetData::getarrayRG (float scalefac, int expfl, float expv, int flipflag) {	unsigned char *optr0, *optr1 ;	int  i, j, count=0, hflip=0, vflip=0, i_out, j_out;	long lpos ; 	float *temparr, redval, grnval, *iptr0, *iptr1 ;	float b1, b2 ;	double totred, totgrn ;	ifstream ifil (infile, ios::in) ;	// exponent apply flag and exponent value are class members	expflag = expfl ;	expval = expv ;	if (flipflag) {		hflip = flipflag % 2 ;			vflip = flipflag / 2 ;		}		ifil.seekg (long(0), ios::end ) ;	lpos = ifil.tellg () ;	totlines = lpos / (nsamps * 8) ;		if (nlines > totlines-startline) {                nlines = totlines - startline ;	}	if (nlines ==0) {		nlines = totlines - startline ;	} 	red = new unsigned char [nsamps * nlines] ;	grn = new unsigned char [nsamps * nlines] ;	temparr = new float [nsamps * 2] ;	// get the scaling parameters 	if (expflag) cout << "Applying exponent : " << expval << endl ;	if (!expflag) cout << "Not Applying exponent  " << endl  ;	totred = 0. ;	totgrn = 0. ;	for (i =startline; i<startline+nlines; i+=32) {		ifil.seekg (long(i) * nsamps * 8, ios::beg) ;		ifil.read ((char*)temparr, nsamps * 8) ;		for (j=32; j<nsamps-32; j+= 32) {			count += 1 ;			if (expflag) 			{			totred += pow (double (*(temparr + j*2)), double(expval)) ;			totgrn += pow (double (*(temparr + j*2+1)), double(expval)) ;			}			else {			totred += *(temparr + j*2) ;			totgrn += *(temparr + j*2+1) ;			}		}	}	// get the avereage of the red and grn 	totred /= count ;	totgrn /= count ;	scalered = scalefac * 150./totred ;	scalegrn = scalefac * 150./totgrn ;	// 	cout << "Scaling parameters   Red :   "   << scalered << "    Green :   " << scalegrn << endl ; 	ifil.seekg (long(startline)*nsamps*8, ios::beg) ;	for (i=0; i<nlines; i++) {		ifil.read ((char*)temparr, nsamps * 8) ;		for (j=0; j<nsamps; j++)			{			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;			optr0 = red + i_out * nsamps + j_out ;			optr1 = grn + i_out * nsamps + j_out ;						iptr0 = temparr + j * 2 ; 			iptr1 = temparr + j * 2 + 1; 			if (expflag) {				b1 = pow (*iptr0, expval) ;				b2 = pow (*iptr1, expval) ;			}			else {				b1 = *iptr0 ;				b2 = *iptr1 ;			}			redval = b1 * scalered ;			redval = (redval < 0) ? 0. : redval ; 			redval = (redval > 255) ? 255. : redval ; 			*optr0 = (unsigned char) redval ;			grnval = b2 * scalegrn ;			grnval = (grnval < 0) ? 0. : grnval ; 			grnval = (grnval > 255) ? 255. : grnval ; 			*optr1 = (unsigned char) grnval ;		}	}	delete [] temparr ;	ifil.close() ;	return (1) ;}int CGetData::DeleteRG () {	if (red) delete [] red ;	if (grn) delete [] grn ;	red = NULL ;	grn = NULL ;	return (1) ;}int CGetData::DeleteMag () {	if (mag) delete [] mag ;	mag = NULL ;	return (1) ;}int CGetData::DeleteRaw () {	if (raw) delete [] raw ;	raw = NULL ;	return (1) ;}int CGetData::DeleteHgt () {	if (hgt) delete [] hgt ;	hgt = NULL ;	if (mag) delete [] mag ;	mag = NULL ;	return (1) ;}	int CGetData::DeleteMPH () {	if (mag) delete [] mag ;	if (phase) delete [] phase ;	mag = NULL ;	phase = NULL ;	return (1) ;}										

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -