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

📄 vcexampledlg.cpp

📁 生成等高线
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			//这里用的是等高线上实际坐标值吧
			//若想画在窗口内,可能需要改变像素,数据需要转换
			if( j > 0 ) 
				pDC->LineTo(CurX, CurY); 
			else 
				pDC->MoveTo(CurX,CurY);
		}
	}
	fclose(pfile);
	//'如果要释放空间
	//ContourOCX1.FreeData();
	ReleaseDC(pDC);
}
void CVCExampleDlg::OnButton1() 
{
	m_Picture1.RedrawWindow(NULL,NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE );
	ContourOCX1.FreeData();
	long row,col;
	float Linestep(1);//等值线间隔
	long  INVALIDDATA(99999) ; //'默认无效值

	double X, Y,value ;//   '实际坐标
	row = EditToValue<int>(&this->m_Row);
	col = EditToValue<int>(&this->m_Col);
	Linestep = EditToValue<float>(&this->m_StepEdit);
	//'initialize

	ContourOCX1.Initial(row,col,Linestep,m_InterposeCheck.GetCheck(),m_RestrictCheck.GetCheck());
	if(CDialog::GetCheckedRadioButton(IDC_RADIO4,IDC_RADIO5)-IDC_RADIO4>0)
	{
		ContourOCX1.AddCustomedStep(3);
		ContourOCX1.AddCustomedStep(4.5);
		ContourOCX1.AddCustomedStep(6);
	}
	//'input data points
	for(int  i = 0 ;i<row;i++)
	{
		for(int  j = 0;j<col;j++)
		{
			X = j * 40 ;//'由列号得出横坐标
			Y = i * 40;// '由行号得出纵坐标
			value = rand() % 10+rand()%10/10.0;
			ContourOCX1.AddPoint(i, j, X, Y, value);// '行号,列号,坐标(X,Y),值(高程)
		}
	}
	//' if there are some invalid data
	ContourOCX1.AddPoint( 3, 2, 80, 120, INVALIDDATA);// '假如(3,2)处为无效点
	ContourOCX1.AddPoint(3, 3, 120, 120, INVALIDDATA);// '假如(3,3)处为无效点

	//'there are 3 methods to create contour

	switch(CDialog::GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3)-IDC_RADIO1)
	{
		case 0: ContourOCX1.Calculate( 1, INVALIDDATA);break;
		case 1: ContourOCX1.calculate2(1,INVALIDDATA,1);break; // '是否要对无效值进行重新插补, 无效值
		case 2: ContourOCX1.Calculate3( 1, INVALIDDATA, 10);break; // '是否要对无效值进行重新插补, 无效值
	}
	//draw
	DrawContourLines();
}

void CVCExampleDlg::OnButton2() 
{

 	
}

void CVCExampleDlg::OnButton3() 
{
	long lineCount, pointCount;
	double x,y, value ;
    CDC *pDC=m_Picture1.GetDC();
	pDC->SetBkMode(TRANSPARENT);
    ContourOCX1.GetLineCount(&lineCount);
    CString s;
    for(long int i= 0 ;i<lineCount;i++)
    {
	   ContourOCX1.GetCtrlPoint(i, 0, &x, &y, &value);
       s.Format("%.1f",value);  
	   pDC->TextOut(x,y,s);
	
   }	
	m_Picture1.ReleaseDC(pDC);
}

void CVCExampleDlg::OnButton4() 
{
	
    for(int i=m_PolyList.GetCount()-1;i>=0;i--)	   
		m_PolyList.DeleteString(i);
	long suc;
	ContourOCX1.ConvertToPolygon(&suc);
	if(suc<=0)
	{
		::AfxMessageBox("can not convert  to polygons");
		return;
	}
	DrawContourSurface();
}

void CVCExampleDlg::OnSelchangeList1() 
{
  
  long pointCount;
  float minValue,maxValue,Area1,Area2;
  //polygon properties
  ContourOCX1.GetPolygonPointCountValueArea(m_PolyList.GetCurSel(),&pointCount,&minValue,&maxValue,&Area1,&Area2);
  CString s;
  s.Format("value range: %.5f - %.5f\r\nArea: %.5f",minValue,maxValue,Area2);
  this->m_PolygonPropertyEdit.SetWindowText(s);
  //flash polygon
  HDC dc=::GetDC(m_Picture2.m_hWnd );  
  ContourOCX1.FlashPolygon((long)dc,m_PolyList.GetCurSel(),
  EditToValue<int>(&m_FlashFillColorEdit),
  EditToValue<int>(&m_m_FlashBorderColorEdit));
  ::ReleaseDC(m_Picture2.m_hWnd ,(HDC)dc);
}

void CVCExampleDlg::OnButton5() 
{
  m_Picture2.RedrawWindow();	
  DrawContourLines();
  DrawContourSurface();
}
void SetButtonEnable(CWnd*parent,UINT IDCNo,int count,bool enalbe)
{
for(int i=0;i<count;i++)
{
   CButton*pButton=(CButton*)parent->GetDlgItem(IDCNo+i);
   pButton->EnableWindow(enalbe);

}
}
void CVCExampleDlg::OnRadio3() 
{

	SetButtonEnable(this,IDC_CHECK1,1,false);
	SetButtonEnable(this,IDC_CHECK2,1,false);
    	
}

void CVCExampleDlg::OnRadio1() 
{

	SetButtonEnable(this,IDC_CHECK1,1,true);
	SetButtonEnable(this,IDC_CHECK2,1,true);
    OnCheck1() ;
}

void CVCExampleDlg::OnRadio2() 
{

	OnRadio1();

	
}

void CVCExampleDlg::OnCheck1() 
{
	SetButtonEnable(this,IDC_CHECK2,1,m_InterposeCheck.GetCheck());
	
}

void CVCExampleDlg::OnButton7() 
{
	m_Picture1.RedrawWindow();
	ContourOCX1.FreeData();

	CString s;

	//Smooth Parameter
	int Smooth=EditToValue<int>(&m_SmoothParaEdit);
	//line step
	float linestep =EditToValue<float>(&m_StepEdit);
	//method
	switch(CDialog::GetCheckedRadioButton(IDC_RADIO6,IDC_RADIO8)-IDC_RADIO6)
	{
		case 0: ContourOCX1.InitialRandomIIDW(-1, -1, linestep, Smooth);break;
		case 1: ContourOCX1.InitialRandomCFWAI( -1, linestep, Smooth);break;
		case 2: ContourOCX1.InitialRandomKrigingOK(-1,30,1,Smooth,-1);break;//ordinary Kriging ,nugget=0
	}

	//Uneven line values
	if(CDialog::GetCheckedRadioButton(IDC_RADIO4,IDC_RADIO5)-IDC_RADIO4>0)
	{
		
		ContourOCX1.AddCustomedStep(3);
		ContourOCX1.AddCustomedStep(4.5);
		ContourOCX1.AddCustomedStep(6);
	}

	//add random points
	int i;
	CPen pen1,pen2,pen3,*oldPen;
	CDC *dc=NULL;
	//discrete point amount 
	int PointCount;
	switch(CDialog::GetCheckedRadioButton(IDC_RADIO9,IDC_RADIO10)-IDC_RADIO9)
	{
		case 0://create random points

		PointCount=EditToValue<int>(&m_RandomPointCountEdit);
		dc=m_Picture1.GetDC();
		pen1.CreatePen(PS_SOLID,1,0xff0000);
		pen3.CreatePen(PS_SOLID,1,0xff0000);
		oldPen=dc->SelectObject(&pen1);
		float X,Y,value;
		for( i = 0 ;i<PointCount;i++)
		{
			X = float(rand()%300 );//'由列号得出横坐标
			Y = float(rand()%300);// '由行号得出纵坐标
			value = rand() % 10+rand()%10/10.0;
			ContourOCX1.AddPointRandom(X, Y, value);
			//point position and value
			dc->SelectObject(&pen1);
			dc->Ellipse(X-2,Y-2,X+2,Y+2);
			dc->SelectObject(&pen3);
			s.Format("%.1f",value);
			if (m_ShowValueCheck.GetCheck())  
				dc->TextOut(X,Y,s);

		}
		dc->SelectObject(oldPen);
		m_Picture1.ReleaseDC(dc);
		break;
		case 1://from data file
	
		TCHAR FileName[MAX_PATH];
		GetModuleFileName(NULL,FileName,MAX_PATH);
		(_tcsrchr(FileName,'\\'))[1] = 0;
		CString path = CString(FileName)+"1.txt";
		BSTR bstrPath = path.AllocSysString();
		//The data file is debug/1.txt.You can change it
		PointCount = ContourOCX1.AddRandomPointsFromFile(&bstrPath);

		CString str;
		str.Format("%d",PointCount);
		m_RandomPointCountEdit.SetWindowText(str);

		break;
	}//switch

	if(PointCount>1)
		ContourOCX1.CalculateRandom();
	//draw
	DrawContourLines();
}

void CVCExampleDlg::OnButton6() 
{
	
	
	m_SaveDialog.ShowSave();
	CString path(m_SaveDialog.GetFileName()),type;
	if(path.GetLength()>0)
	{
		long lineCount,PolygonCount;
		ContourOCX1.GetLineCount(&lineCount);
        ContourOCX1.GetPolygonCount(&PolygonCount);
		//line
		
		if(lineCount > 0)
		{
			path+="_line";
			type="line";
			BSTR _path=path.AllocSysString();
		    BSTR _type=type.AllocSysString();
			ContourOCX1.InitializeSHPFile(&_path,&_type);
		    ContourOCX1.CreateShapeFile();
		}
		//surface
        if(PolygonCount > 0)
		{
			path+="_polygon";
			type="polygon";
			BSTR _path=path.AllocSysString();
		    BSTR _type=type.AllocSysString();
			ContourOCX1.InitializeSHPFile(&_path,&_type);
		    ContourOCX1.CreateShapeFile();
	
		}
		
        
	}
}

⌨️ 快捷键说明

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