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

📄 myrayview.cpp

📁 地震勘探的射线追踪程序
💻 CPP
字号:
// MyRayView.cpp : implementation of the CMyRayView class
//

#include "stdafx.h"
#include "MyRay.h"

#include "MyRayDoc.h"
#include "MyRayView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyRayView

IMPLEMENT_DYNCREATE(CMyRayView, CView)

BEGIN_MESSAGE_MAP(CMyRayView, CView)
	//{{AFX_MSG_MAP(CMyRayView)
	ON_COMMAND(IMD_START, OnStart)
	ON_UPDATE_COMMAND_UI(IMD_START, OnUpdateStart)
	ON_COMMAND(IMD_IMAGIN_RAY, OnImaginRay)
	ON_UPDATE_COMMAND_UI(IMD_IMAGIN_RAY, OnUpdateImaginRay)
	ON_COMMAND(IMD_INCIDENT_RAY, OnIncidentRay)
	ON_UPDATE_COMMAND_UI(IMD_INCIDENT_RAY, OnUpdateIncidentRay)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyRayView construction/destruction

CMyRayView::CMyRayView()
{
	// TODO: add construction code here

}

CMyRayView::~CMyRayView()
{
}

BOOL CMyRayView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyRayView drawing

void CMyRayView::OnDraw(CDC* pDC)
{
	CMyRayDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	int zuo=20,shang=20,bei=4;
	int kk;
	CPen penBlue(PS_SOLID,3,RGB(0,0,255));
	CPen penRed(PS_SOLID,1,RGB(255,0,0));
	CPen *pOldPen=NULL;
	pOldPen=pDC->SelectObject(&penBlue);
	pDC->MoveTo(point[0][4]*bei+zuo,point[0][5]*bei+shang);
	for(kk=1;kk<120;kk++)
		pDC->LineTo(point[kk][4]*bei+zuo,point[kk][5]*bei+shang);
	pDC->MoveTo(point[0][0]*bei+zuo,point[0][1]*bei+shang);
	for(kk=1;kk<120;kk++)
		pDC->LineTo(point[kk][0]*bei+zuo,point[kk][1]*bei+shang);
	pDC->MoveTo(point[0][2]*bei+zuo,point[0][3]*bei+shang);
	for(kk=1;kk<120;kk++)
		pDC->LineTo(point[kk][2]*bei+zuo,point[kk][3]*bei+shang);
	pDC->SelectObject(&penRed);
	for(kk=0;kk<120;kk++)
	{
		pDC->MoveTo(point[kk][0]*bei+zuo,point[kk][1]*bei+shang);
		pDC->LineTo(point[kk][2]*bei+zuo,point[kk][3]*bei+shang);
		pDC->LineTo(point[kk][4]*bei+zuo,point[kk][5]*bei+shang);
	}	
	pDC->SelectObject(pOldPen);
}

/////////////////////////////////////////////////////////////////////////////
// CMyRayView printing

BOOL CMyRayView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyRayView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyRayView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyRayView diagnostics

#ifdef _DEBUG
void CMyRayView::AssertValid() const
{
	CView::AssertValid();
}

void CMyRayView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMyRayDoc* CMyRayView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyRayDoc)));
	return (CMyRayDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyRayView message handlers

void CMyRayView::OnStart() 
{
	// TODO: Add your command handler code here
	int ii=0;
	int mm,nn;
	float v1=2500;
	float v2=3400;
	for(mm=0;mm<XMAX;mm++)
		for(nn=0;nn<ZMAX;nn++)
		{
			vel[mm][nn]=v2;
		}
	for(mm=0;mm<XMAX;mm++)
		for(nn=0;nn<20;nn++)
		{
			vel[mm][nn]=v1;
		}
	for(mm=30;mm<50;mm++)
		for(nn=20;nn<40;nn++)
		{
			if((mm-30)>(nn-20))
				vel[mm][nn]=v1;
		}
	for(mm=50;mm<70;mm++)
		for(nn=20;nn<40;nn++)
		{
			vel[mm][nn]=v1;
		}
	for(mm=70;mm<90;mm++)
		for(nn=20;nn<40;nn++)
		{
			if((90-mm)>(nn-20))
				vel[mm][nn]=v1;
		}
	for(ii=0;ii<XMAX;ii++)
		trace(ii,XMAX,ZMAX);
	Invalidate();
}

void CMyRayView::OnUpdateStart(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(uod==1||uod==-1)
		pCmdUI->Enable();
	else
		pCmdUI->Enable(FALSE);
}

void CMyRayView::OnImaginRay() 
{
	// TODO: Add your command handler code here
	uod=1;
}

void CMyRayView::OnUpdateImaginRay(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(uod==1)
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
}

void CMyRayView::OnIncidentRay() 
{
	// TODO: Add your command handler code here
	uod=-1;
}

void CMyRayView::OnUpdateIncidentRay(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(uod==-1)
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
}

void CMyRayView::trace(int x, int xmax, int zmax)
{
	float x1, y1, x2, y2;
	float xielv;
	float temp;
	int jj;
	if(uod==-1)
	{
		point[x][0]=x;
		point[x][1]=zmax-1;
		vdown=vel[x][zmax-1];
		for(jj=zmax-1;jj>0;jj--)
		{
			if(vdown!=vel[x][jj])
			{
				vup=vel[x][jj];
				point[x][2]=x;
				point[x][3]=jj;
				if(x==0)
				{
					x1=x;
					y1=jj;
					x2=x+1;
					y2=jj;		
				}
				else if(x!=0&&x!=(xmax-1))
				{
					x1=x-1;
					x2=x+1;
					if(vel[x][jj]==vel[x-1][jj+1])       y1=jj+1;
					else if(vel[x][jj]==vel[x-1][jj])    y1=jj;
					else if(vel[x][jj]==vel[x-1][jj-1])  y1=jj-1;
					if(vel[x][jj]==vel[x+1][jj+1])       y2=jj+1;
					else if(vel[x][jj]==vel[x+1][jj])    y2=jj;
					else if(vel[x][jj]==vel[x+1][jj-1])  y2=jj-1;
				}
				else if(x==(xmax-1))
				{
					x1=x-1;
					y1=jj;
					x2=x;
					y2=jj;
				}
				xielv=(y2-y1)/(x2-x1);
				if(xielv==0)
				{	
					point[x][4]=x;
					point[x][5]=0;
				}	
				else if(xielv!=0)
				{
					point[x][5]=0;
					temp=vup*sin(atan(xielv))/vdown;
					temp=PI/2-atan(xielv)+asin(temp);
					temp=jj/tan(temp)+x;
					point[x][4]=(int)(temp+0.5);
				}
				break;
			}			
		}
	}
	else if(uod==1)
	{
		point[x][0]=x;
		point[x][1]=0;
		vup=vel[x][0];
		for(jj=0;jj<zmax;jj++)
		{
			if(vup!=vel[x][jj])
			{
				vdown=vel[x][jj];
				point[x][2]=x;
				point[x][3]=jj;
				if(x==0)
				{
					x1=x;
					y1=jj;
					x2=x+1;
					y2=jj;		
				}
				else if(x!=0&&x!=(xmax-1))
				{
					x1=x-1;
					x2=x+1;
					if(vel[x][jj]==vel[x-1][jj-1])       y1=jj-1;
					else if(vel[x][jj]==vel[x-1][jj])    y1=jj;
					else if(vel[x][jj]==vel[x-1][jj+1])  y1=jj+1;
					if(vel[x][jj]==vel[x+1][jj-1])       y2=jj-1;
					else if(vel[x][jj]==vel[x+1][jj])    y2=jj;
					else if(vel[x][jj]==vel[x+1][jj+1])  y2=jj+1;
				}
				else if(x==(xmax-1))
				{
					x1=x-1;
					y1=jj;
					x2=x;
					y2=jj;
				}
				xielv=(y2-y1)/(x2-x1);
				if(xielv==0)
				{	
					point[x][4]=x;
					point[x][5]=zmax-1;
				}	
				else if(xielv!=0)
				{
					point[x][5]=zmax-1;
					temp=vup*sin(atan(xielv))/vdown;
					temp=PI/2-atan(xielv)+asin(temp);
					temp=jj/tan(temp)+x;
					point[x][4]=(int)(temp+0.5);
				}
				break;
			}			
		}
	}
}

⌨️ 快捷键说明

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