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

📄 getpicture.cpp

📁 雷达资料的处理和应用
💻 CPP
字号:
// GetPicture.cpp : implementation file
//

#include "stdafx.h"
//#include "Radar.h"
#include "GetPicture.h"
//#include "ColorVal.h"

#include "math.h"
 #include "imageRGB.h"
#include "Reference.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/*extern  CString   szColorData2[16] =
{
	" 28.0",  " 24.0",  " 20.0",  " 16.0",
	" 12.0",  "  8.0",  "  4.0",  "  0.0",
	"  0.0",  " -4.0",  " -8.0",  "-12.0",
	"-16.0",  "-20.0",  "-24.0",  "-28.0"
};*/
/////////////////////////////////////////////////////////////////////////////
// CGetPicture

CGetPicture::CGetPicture()
{
	m_Buff = new float[SWEEP*(POINT+2)];
}

CGetPicture::~CGetPicture()
{
	delete []m_Buff;
}


BEGIN_MESSAGE_MAP(CGetPicture, CWnd)
	//{{AFX_MSG_MAP(CGetPicture)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CGetPicture message handlers

BOOL CGetPicture::DrawCircle(int x,int y,float radio,CDC*pDC)
{
	if ( x<0||x>800||y<0||y>530||radio<0.0 )
		return FALSE;

	// decalare a NULL brush
	pDC->SelectStockObject(NULL_BRUSH);
	
	// Create a new pen and select it into the DC
	CPen pen (PS_SOLID,1,RGB(192,192,192));
	CPen *oldPen = pDC->SelectObject(&pen);

	// Draw a distance circle
	int  x1, x2, y1, y2;
	for (int i=1; i<=5; i++) {
		x1 = (int)(x-radio*(RADIO*i)); 
		y1 = (int)(y-radio*(RADIO*i));
		x2 = (int)(x+radio*(RADIO*i)); 
		y2 = (int)(y+radio*(RADIO*i));
		pDC->Ellipse(x1, y1, x2, y2);
	}
	// Draw a horizontal line to radar map
	pDC->MoveTo(x1,y);
	pDC->LineTo(x2,y);
	// Draw a vertical line to radar map 
	pDC->MoveTo(x,y1);
	pDC->LineTo(x,y2);

	// Restore the old pen to the DC memory
	pDC->SelectObject(oldPen);

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// to dowith radar data to display the picture in the window
BOOL CGetPicture::GetimageData(CFile*file,CDC*pDC)
{
	short int*iBuff = new short int[POINT];
	unsigned char cBuff[4];
	float radio = (float)0.8;

	// 开始读取文件头和资料, 
    file->Read(m_Head,384);
	m_iRadarMode = m_Head[175];
	for ( int i=0; i<SWEEP; i++ ) {
		file->Read(cBuff,4);
		file->Read(iBuff,POINT*2);
		m_Buff[i*258]  = (float)((cBuff[1]*256+cBuff[0])*Deg);
		m_Buff[i*258+1]= (float)((cBuff[3]*256+cBuff[2])*Deg);
		if ( m_iRadarMode == 1 )
			for (int j=0; j<POINT; j++) 
				m_Buff[i*258+j+2]=(float)iBuff[j];
		else 
			for (int j=0; j<POINT; j++) {
				if (iBuff[j]<128)
					m_Buff[i*258+(j+2)] = (float)(iBuff[j]*LSB);
				else
					m_Buff[i*258+(j+2)] = (float)((iBuff[j]-255)*LSB);
			}
	}
	delete [] iBuff;
	// show the vertical color-table 
	if (m_iRadarMode == 1)	
		DrawColorTable(650,80,ColorTable1,szColorData1,pDC);
	if (m_iRadarMode == 2)
		DrawColorTable(650,80,ColorTable2,szColorData2,pDC);

	MainPicture(300,265,radio,pDC);
	
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// List the intensitive pictures of rdar
BOOL CGetPicture::MainPicture(int x_cen,int y_cen,float radio,CDC*pDC)
{
    static int    iColorIndex = 0;
	float         value;
	double        ColorVal[16];	
	COLORREF      color[17];
	
	// display some reference of the Doppler-radar
	ShowRadarReference(650,80,pDC); //////绘制一些相关信息
	for (int i=0; i<SWEEP; i++) {// 对每根径向的256个点进行色彩取定
		float  direction = (float)(i*PI);
		// it is intensity map when m_iRadarMode=1
		for (int j=0; j<POINT; j++ ) {
			value = m_Buff[i*258+j+2];        /////方位角
			if (m_iRadarMode == 1) {
				if(value>80)value=0;
				memcpy(ColorVal,dColorVal1,sizeof(double)*16);
				memcpy(color,ColorTable1,sizeof(COLORREF)*17);
			    if ( value < 2.0 ) iColorIndex = 16;
			    else
				for ( int k=0; k<15; k++ )
	                if (value>ColorVal[k]) iColorIndex = k;         ////找出速度值对应的颜色值
			}
			else {
				if(value>16.0f)value=16.0f;
				if(value<-16.0f)value=-16.0f;
				memcpy(ColorVal,dColorVal2,sizeof(double)*16);
				memcpy(color,ColorTable2,sizeof(COLORREF)*17);
			    if (value>-0.1&&value<0.1) iColorIndex = 16;
			    else
				for (int k=0; k<=15; k++)
	                if (value>ColorVal[k]) iColorIndex = k;
			}
			for ( int k=0; k<8; k++) {
	            int x = (int)(x_cen+sin(direction+0.005*k)*j*radio);
	            int y = (int)(y_cen-cos(direction+0.005*k)*j*radio);
	            pDC->SetPixel(x,y,color[iColorIndex]);               ///
			}
		}
		// 原来此处有显示方位角的代码,由于影响了显示速度而取消.
	}
	// Display the distance circles of radar
	DrawCircle(x_cen,y_cen,radio,pDC);

	return TRUE;
}

//////////////////////////////////////////////////////////////////////
//函数名称:DrawColorTab(int x_top, int y_top, COLORREF*ColorIndex,)
//                        CString*strIndex,CClientDC*pDC)
//功能    :根据指定的入口参数画竖立色标
//参数    :x_top, y_top     :  所画色标的左上角逻辑坐标,
//          ColorIndex       :  指向色表表示数组的指针,
//          strIndex         :  所要进行比较的域值数组指针,
//          m_pdc            :  绘图指针
BOOL CGetPicture::DrawColorTable(int x_top,int y_top,
								 COLORREF*ColorIndex,
								 CString *strIndex,
								 CDC*pDC)
{
	if (x_top<0||x_top>800||y_top<0||y_top>600)
		return FALSE;

	// draw a color rectangle
	CRect rectangle;
	// Create the new pen to draw
	CPen pen(PS_SOLID,1,RGB(128,128,128));
	CPen *oldPen=pDC->SelectObject(&pen);

	//int x_bottom = x_top + 30;
	
	int y_bottom=y_top+15*16;
	int top, bottom;
	if (m_iRadarMode==2) {
		pDC->TextOut(x_top-5,y_top-20,"AWAY"); 	
		pDC->TextOut(x_top+5,y_bottom+3,"TO");
	}
	////////画色标/////////////////////////////////////////////////////////
	for (int i=0; i<16; i++) {
		top    = y_top+15*i;
		bottom = top+15;
//		int ddd=ColorIndex[i];
		CBrush * pBrush = new CBrush(ColorIndex[i]);
		CBrush * oldBrush = pDC->SelectObject(pBrush);
		rectangle.SetRect(x_top,top,x_top+30,bottom);
		pDC->FillRect(&rectangle,pBrush);
//		CString sss=strIndex[i];
		pDC->TextOut(x_top+34,top-6,strIndex[i]);	
		
		pDC->SelectObject(oldBrush);
		delete pBrush;
	}
	// Restore the old pen to the DC
	pDC->SelectObject(oldPen);
	
	return TRUE;
}

BOOL CGetPicture::ShowRadarReference(int x_top,int y_top,CDC*pDC)
{
	short int y_bottom,iClassMode,iProcessCode,iAttenuation;
	char lpString[30],csEle[20];
	float lElevation;
	CString RadarMode[4] = {
		"No",  "VAD",
		"RHV",  "ASI" };
	CString MtiMode[2]   = { "OFF", "ON" };
	CString ClassMode[4] = { "No",  "强度(dbz)", 
		"速度(m/s)",  "谱宽(m/s)" };
	CString staname[2] = {
		"观测站:   凤台",
		"观测站:   寿县"};

	if (x_top<0||x_top>800||y_top<0||y_top>600)
		return FALSE;
	y_bottom = y_top+15*16;
	sprintf(lpString,"%02d\\%02d\\%02d    %02d:%02d:%02d",m_Head[63],
		m_Head[67],m_Head[71],m_Head[75],m_Head[79],m_Head[83]);
	pDC->TextOut(x_top-40,y_top-50,lpString);	
	pDC->TextOut(x_top-10,y_bottom+30,ClassMode[m_iRadarMode]);
	iClassMode = m_Head[131];
	pDC->TextOut(x_top-20,y_bottom+140,"工作模式:      ");
	pDC->TextOut(x_top+63,y_bottom+140,RadarMode[iClassMode]);
	iProcessCode = m_Head[155];
	pDC->TextOut(x_top-20,y_bottom+100,"MTI(R.C):      ");
	pDC->TextOut(x_top+60,y_bottom+100,MtiMode[iProcessCode]);
	pDC->TextOut(x_top-20,y_bottom+160,"探测距离: 64.0km");
	iAttenuation = m_Head[159];
	pDC->TextOut(x_top-20,y_bottom+120,"距离订正:    ");
	pDC->TextOut(x_top+63,y_bottom+120,MtiMode[iAttenuation]);
	if(m_Head[93]=='1')
		pDC->TextOut(x_top-20,y_bottom+60,staname[0]);
	if(m_Head[93]=='4')
		pDC->TextOut(x_top-20,y_bottom+60,staname[1]);
	lElevation = m_Buff[1]-90;
	sprintf(csEle,"%6.3f",lElevation);
	pDC->TextOut(x_top-20,y_bottom+80,"仰角:          ");
	pDC->TextOut(x_top+50,y_bottom+80,csEle);
	if (m_Head[245] == 5) 
		pDC->TextOut(90,y_bottom+100,"Already Dealiased!");

	return TRUE;
}

//////////////////////////////////////////////////////////////////////
// 这一节是为了显示退过模糊的径向速度场的情况,以及和未退模糊的径向速度
// 进行对比. 目的是为了解退模糊的情况是否理想,退模糊方法在CDealiase类
// 中,欢迎使用由南京大学大气科学系徐晖完成的系统.
BOOL CGetPicture::GetDealiasedData(CFile*file,CDC*pDC)
{
	unsigned char    *iBuff = new unsigned char[POINT];
	unsigned char cBuff[4];

	CString lpFileName = file->GetFilePath();
	file->Read(m_Head,384);
	m_iRadarMode = m_Head[175];
	if (m_Head[245]==5 && m_iRadarMode==2) {
		for (int i=0; i<SWEEP; i++) {                      /////SWEEP=360
			file->Read(cBuff,4);                           /////读出每个径向的初始四个字节
			file->Read(iBuff,POINT);                     /////POINT=256,每个数据为两个字节
			m_Buff[i*258] = (float)((cBuff[0]*256+cBuff[1])*Deg);      ///每一个径向的数据开始两个
			m_Buff[i*258+1] = (float)((cBuff[2]*256+cBuff[3])*Deg);    
			for (int j=0; j<POINT; j++)
				m_Buff[i*258+j+2] = (float)(iBuff[j]*LSB);      ///LSB=16/128;16种颜色   ??????????     
		}
	    // show the vertical color-table

	    DrawColorTable(620,90,ColorTable2,szColorData2,pDC);
	    // Display the dealiased velocity
	    MainPicture(160,265,(float)0.55,pDC);

	    int iNameLength = lpFileName.GetLength();		
	    lpFileName.SetAt(iNameLength-1,'v');
//////打开没有经过处理的原始数据///////////////////////////////////////////////
	    CFile pFile(lpFileName,CFile::modeRead);
		pFile.Seek(384,CFile::begin);
		for (i=0; i<SWEEP; i++) {
			pFile.Read(cBuff, 4);
			pFile.Read(iBuff,POINT);
		    m_Buff[i*258] = (float)((cBuff[0]*256+cBuff[1])*Deg);
		    m_Buff[i*258+1] = (float)((cBuff[2]*256+cBuff[3])*Deg);
			for (int j=0; j<POINT; j++) {
			    if (iBuff[j]<128)
				    m_Buff[i*258+j+2] = (float)(iBuff[j]*LSB);
			    else
				    m_Buff[i*258+j+2] = (float)((iBuff[j]-255)*LSB);
			}
		}
	    delete []iBuff;
	    MainPicture(450,265,(float)0.55,pDC);

		return TRUE;
	}
	
	return FALSE;
}

BOOL CGetPicture::ListMultiPicture(CFile*file,CDC*pDC)
{
	short int*iBuff = new short int[POINT];
	unsigned char cBuff[4];

	// 开始读取文件头和资料, 并断定是否是强度资料.若不是强度资料,则
	// 返回,并返回BOOL值FALSE
    file->Read(m_Head,384);
	if ((m_iRadarMode = m_Head[175]) != 1)
		return FALSE;
	
	// Intervene the one sweep between two to draw
	for ( int i=0; i<SWEEP; i++ ) {
		file->Read(cBuff,4);
		file->Read(iBuff,POINT);
		m_Buff[i*258] = (float)((cBuff[0]*256+cBuff[1])*Deg);
		m_Buff[i*258+1] = (float)((cBuff[2]*256+cBuff[3])*Deg);
		for (int j=0; j<POINT; j++)
			//  Noted: LSB=80/255=0.3137
			m_Buff[i*258+j+2] = (float)iBuff[j];
	}
	delete [] iBuff;

	float radio = (float)0.6;
	MainPicture(160,160,radio,pDC);
	
	return TRUE;
}

float CGetPicture::CalculateConstant(int buffer,int RainType)
{
	double mPower=40.0, loss=9.0, pr, reflectivity;
	double pt=mPower*1e6;
	double tau=0.5*1e-6;
	double f=9.415*1e9;
	double cv=3.0*1e10;
	double G=42.9;
	double zeta=1.97*1e-2;
	double epsilon=2.02*1e-2;
	double E=0.93;
	double Kg=0.01;
	double r=6.4*1e6;
	double nodata=-9999.0;

	if (buffer>0) {
		if (buffer<=21)
			pr=-142.832+3.474*buffer-0.074*buffer*buffer;
		else 
			pr=-109.1+80.0/255.0*buffer;
		reflectivity=-10.0*log10(PAI*PAI*PAI/pow(2.0,10)/log(2.0))
			-10.0*log10(pt)-10.0*log10(f*f*tau*E/cv)
			-2.0*G-10.0*log10(zeta*epsilon)
			+20.0*log10(r)+120.0+2.0*Kg*r*1e-5+loss+pr;
		if (RainType==0)
			reflectivity=reflectivity+7.2;
	}		
	else		
		reflectivity=nodata;

	return ((float)reflectivity);
}

/////////////////强度场显示///////////////////////////////////////////////////////////////
void CGetPicture::GetDbzData(CFile *sFile, CDC *pDC)
{
	unsigned char  *iBuff = new unsigned char[POINT];
	unsigned char cBuff[4];     ///记录角度
	
	CString lpFileName = sFile->GetFilePath();
	sFile->Read(m_Head,384);
//	FILE*file;
//	if((file=fopen("F:\\dd.txt","wt"))==NULL)
//		return;
	
	m_iRadarMode = m_Head[175];
	for (int i=0; i<SWEEP; i++) {
		sFile->Read(cBuff,4);
		sFile->Read(iBuff,POINT);
		m_Buff[i*258] = (float)((cBuff[0]*256+cBuff[1])*Deg);       ////得到仰角
		m_Buff[i*258+1] = (float)((cBuff[2]*256+cBuff[3])*Deg);     ////得到方位角
		
		for (int j=0; j<POINT; j++)
		{
			m_Buff[i*258+j+2] = (float)(iBuff[j]/*LBS*/);  
//			fwrite(&m_Buff[i*258+j+2],sizeof(float),1,file);
//			fprintf(file,"%f  ",m_Buff[i*258+j+2]);
		}////得到强度的dB
//		fprintf(file,"\n");
	}
//	fclose(file);
	// show the vertical color-table
	DrawColorTable(650,90,ColorTable1,szColorData1,pDC);
	// Display the dealiased velocity
	MainPicture(285,360,(float)0.95,pDC);
	

	delete [] iBuff;
	
	return;
	
	
}
//////////////////////////////////////////

void CGetPicture::GetVolData(CFile *file, CDC *pDC)
{

	unsigned char    *iBuff = new unsigned char[POINT];
	unsigned char cBuff[4];
	CString lpFileName = file->GetFilePath();
	file->Read(m_Head,384);
	m_iRadarMode = m_Head[175];
	
	
	if (m_iRadarMode==2){
		for (int i=0; i<SWEEP; i++) {
			file->Read(cBuff,4);
			file->Read(iBuff,POINT);
			m_Buff[i*258] = (float)((cBuff[0]*256+cBuff[1])*Deg);       ////得到方位角
			m_Buff[i*258+1] = (float)((cBuff[2]*256+cBuff[3])*Deg);     ////得到仰角角
			for (int j=0; j<POINT; j++)
			{
				if (iBuff[j]<128)
				    m_Buff[i*258+j+2] = (float)(iBuff[j]*LSB);
			    else
				    m_Buff[i*258+j+2] = (float)((iBuff[j]-255)*LSB);
			}                                                    ////得到速度的值(-16~16)
		}
		// show the vertical color-table
		DrawColorTable(650,90,ColorTable2,szColorData2,pDC);
		// Display the dealiased velocity
		MainPicture(285,360,(float)0.95f,pDC);
	}
	
	
	delete [] iBuff;
	
	return;
	
}

⌨️ 快捷键说明

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