www.pudn.com > sa_read.rar > sa_readView.cpp, change:2009-05-25,size:5210b


// sa_readView.cpp : implementation of the CSa_readView class 
// 
 
#include "stdafx.h" 
#include "sa_read.h" 
 
#include "sa_readDoc.h" 
#include "sa_readView.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView 
 
IMPLEMENT_DYNCREATE(CSa_readView, CView) 
 
BEGIN_MESSAGE_MAP(CSa_readView, CView) 
	//{{AFX_MSG_MAP(CSa_readView) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView construction/destruction 
 
CSa_readView::CSa_readView() 
{ 
	// TODO: add construction code here 
 
} 
 
CSa_readView::~CSa_readView() 
{ 
} 
 
BOOL CSa_readView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView drawing 
 
void CSa_readView::OnDraw(CDC* pDC) 
{ 
	CSa_readDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	FILE* fp; 
	BYTE head[128]; 
	int volflag=0; 
	int layernum; 
	bool volbegin,layerbegin; 
	int Zflag,Vflag; 
	int z_gatenum,v_gatenum; 
	char buffer[1000]; 
	float dbz; 
	int color; 
	float az; 
	float x,y; 
	int num=0; 
	int jjj=0; 
	int aznum[30]; 
	DWORD colortable[16]={RGB(192,192,192),RGB(128,128,128),RGB(255,192,192),RGB(224,160,160),RGB(192,128,128) 
						,RGB(128,255,128),RGB(0,192,0),RGB(255,255,0),RGB(192,192,0),RGB(255,0,0) 
						,RGB(192,0,0),RGB(128,0,0),RGB(0,255,255),RGB(0,0,255),RGB(0,0,128),RGB(255,255,255)}; 
 
	int  dbz_value[15]={5,10,15,20,25,30,35,40,45,50,55,60,65,70,75}; 
 
 	fp=fopen("2008030607.36A","rb"); 
	int layer=0; 
	layernum=0; 
	do 
	{ 
		fread(head,sizeof(BYTE),128,fp); 
		volflag=head[40]+head[41]*256;		 
		if(volflag==0) 
		{ 
			num=1; 
			layernum=layernum+1; 
		} 
		if(volflag==3) 
		{ 
			num=1; 
			layernum=0; 
		} 
		if(volflag==1) 
			num=num+1;			 
		if(volflag==2) 
		{ 
			num=num+1; 
			aznum[layernum]=num;	 
		} 
		if(volflag==4) 
		{ 
			num=num+1; 
			aznum[layernum]=num;	 
		} 
		fseek(fp,2304,SEEK_CUR); 
 
	}while(volflag!=4); 
			 
	fseek(fp,0,SEEK_SET);	 
	for(int l=0;l<layer;l++) 
		fseek(fp,aznum[l]*2432,SEEK_CUR); 
	do 
	{	 
		fread(head,sizeof(BYTE),128,fp); 
		volflag=head[40]+head[41]*256; 
		if(volflag==3)	 
			volbegin=true; 
		else if(volflag==0) 
			layerbegin=true; 
			 
		z_gatenum=head[54]+head[55]*256; 
		v_gatenum=head[56]+head[57]*256; 
		Zflag=head[64]+head[65]*256; 
		Vflag=head[66]+head[67]*256; 
 
		if(Zflag!=0) 
		{	 
			for(int i=0;i<z_gatenum;i++) 
			{ 
				fread(&buffer[i],1,1,fp); 
				az=((head[36]+head[37]*256)/8.)*(180./4096.)*3.1415926/180; 
				for(int j=0;j<6;j++) 
				{ 
					if(az>360)					 
						az=az-360; 
					if(az>=0&&az<=90) 
					{ 
						x=sin(az)*i+460; 
						y=460-cos(az)*i; 
					} 
					else if(az>90&&az<=180) 
					{ 
						x=cos(az-90)*i+460; 
						y=sin(az-90)*i+460; 
					} 
					else if(az>180&&az<=270) 
					{ 
						x=460-sin(az-180)*i; 
						y=460+cos(az-180)*i; 
					} 
					else if((az>270&&az<=360)) 
					{ 
						x=460-cos(az-270)*i; 
						y=460-sin(az-270)*i; 
					} 
					dbz=(buffer[i]-2)/2.-32; 
					if(dbz<3) 
						color=colortable[15]; 
					else 
					{ 
						for(int count=0;count<15;count++)    
						{ 
							if(dbz>dbz_value[count])  
								color=colortable[count]; 
						} 
					} 
					az=az+0.005; 
					pDC->SetPixel(x,y,color); 
				} 
			} 
			fseek(fp,(460-z_gatenum*1)+1844,SEEK_CUR);	 
		} 
		else 
		{ 
			AfxMessageBox("本层没有强度数据"); 
			break; 
		} 
	}while((volflag!=2)&&(volflag!=4)); 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView printing 
 
BOOL CSa_readView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CSa_readView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CSa_readView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView diagnostics 
 
#ifdef _DEBUG 
void CSa_readView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CSa_readView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CSa_readDoc* CSa_readView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSa_readDoc))); 
	return (CSa_readDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CSa_readView message handlers