📄 testdlg.cpp
字号:
pt=m_DemGroup.GetAt(i);
dbDist=sqrt(pow((dbX-pt.x),2)+pow((dbY-pt.y),2))+0.001;
dbDist/=1000.0;
dbNumerator+=pt.z/dbDist;
dbDenominator+=1/dbDist;
}
dbZ=dbNumerator/dbDenominator;
return dbZ;
}
BOOL CTestDlg::SaveDem()
{
CString strFileName=GetParentPath(m_strFileDem)+"\\"+"top.dem";
FILE *fp;
fp=fopen(strFileName,"w");
if(fp==NULL)
{
AfxMessageBox("文件读取失败!");
return FALSE;
}
CString strMark="TERRAIN_DATA_DEM";
fprintf(fp,"%s\n",strMark);
strMark="NullData:-99999.900000";
fprintf(fp,"%s\n",strMark);
fprintf(fp,"%d %d\n",m_nCols,m_nRows);
C3DPoint pt;
for(int i=0;i<m_nRows;i++)
{
for(int j=0;j<m_nCols;j++)
{
pt=m_DemFullGroup.GetAt(i*m_nCols+j);
fprintf(fp,"%lf %lf %lf\n",pt.x,pt.y,pt.z);
}
}
fclose(fp);
return TRUE;
}
CString CTestDlg::GetParentPath(CString strPath)
{
strPath.TrimRight ('\\');
CString strParentPath;
int nIndex = strPath.ReverseFind('\\');
if (nIndex>=0)
strParentPath = strPath.Left(nIndex);
else
strParentPath = "";
return strParentPath;
}
void CTestDlg::DivLayer()
{
m_dbDeltaLayerZ=m_dbLengthZ/m_nLayers;
m_LayerArray.Clear();
for(int i=0;i<m_nLayers;i++) //创建层
{
CLayer *pLayer=new CLayer;
m_LayerArray.Add(pLayer);
}
//***********搜索***************
double x,y,z;
int nColIndex,nRowIndex;
int nCount=m_3DOGroup.GetSize();
for(i=0;i<nCount;i++)
{
CGLVertex vertex=m_3DOGroup.GetAt(i);
x=vertex.x;
y=vertex.y;
z=vertex.z;
GetGripPos(x,y,nColIndex,nRowIndex);
C3DPoint pos=m_DemFullGroup.GetAt(nRowIndex*m_nCols+nColIndex);
for(int j=0;j<m_nLayers;j++)
{
if(z<=(pos.z+j*m_dbDeltaLayerZ-m_dbDeltaLayerZ/3)&&z>=(pos.z+(j+1)*m_dbDeltaLayerZ)+m_dbDeltaLayerZ/3)
{
CLayer *pLayer=m_LayerArray.GetAt(j);
pLayer->m_ScatterArray.Add(vertex);
}
}
}
CorrentLayerArray();
}
BOOL CTestDlg::OpenD3doFile(CString strFileName)
{
FILE *fp;
fp=fopen(strFileName,"r");
if(fp==NULL)
{
AfxMessageBox("文件读取失败!");
return FALSE;
}
int nCount;
int nVal;
double x,y,z,v;
CGLVertex vertex;
fscanf(fp,"%d%d%d",&nCount,&nVal,&nVal);
m_3DOGroup.Init(nCount);
for(int i=0;i<nCount;i++)
{
fscanf(fp,"%lf%lf%lf%lf",&x,&y,&z,&v);
vertex.x=x;
vertex.y=y;
vertex.z=z;
vertex.v=v;
m_3DOGroup.SetAt(i,vertex);
}
fclose(fp);
m_dbMinZ=m_dbMaxZ=m_3DOGroup.GetAt(0).z;
for(i=1;i<nCount;i++)
{
vertex=m_3DOGroup.GetAt(i);
if(vertex.z<m_dbMinZ)
m_dbMinZ=vertex.z;
if(vertex.z>m_dbMaxZ)
m_dbMaxZ=vertex.z;
}
nCount=m_DemFullGroup.GetSize();
for(i=0;i<nCount;i++)
{
C3DPoint pt=m_DemFullGroup.GetAt(i);
if(pt.z<m_dbMinZ)
m_dbMinZ=pt.z;
if(pt.z>m_dbMaxZ)
m_dbMaxZ=pt.z;
}
m_dbDeltaZ=-(m_dbMaxZ-m_dbMinZ)/(m_nSamples-1);
m_dbLengthZ=-(m_dbMaxZ-m_dbMinZ);
m_dbDeltaLayerZ=m_dbLengthZ/m_nLayers;
return TRUE;
}
void CTestDlg::GetGripPos(double x,double y,int &nColIndex,int &nRowIndex)
{
nColIndex=int((x-m_dbMinX)/m_dbDeltaX);
nRowIndex=int((y-m_dbMinY)/m_dbDeltaY);
if(nColIndex<0)
nColIndex=0;
if(nColIndex>(m_nCols-1))
nColIndex=m_nCols-1;
if(nRowIndex<0)
nRowIndex=0;
if(nRowIndex>(m_nRows-1))
nRowIndex=m_nRows-1;
}
BOOL CTestDlg::CorrentLayerArray() //使每个粗层位中都有点子
{
BOOL bRet=FALSE;
int nCount=m_LayerArray.GetSize();
for(int i=0;i<nCount;i++)
{
CLayer *pLayer=m_LayerArray.GetAt(i);
if(pLayer==NULL)
return FALSE;
int nNum=pLayer->m_ScatterArray.GetSize();
if(nNum<1)
bRet=TRUE;
}
if(bRet)
{
m_nLayers--;
if(m_nLayers<1)
return FALSE;
m_dbDeltaLayerZ=m_dbLengthZ/m_nLayers;
DivLayer();
}
return bRet;
}
int CTestDlg::GetPointLieLayer(int nColIndex,int nRowIndex,double z)
{
int nn=-1;
int nIndex=nRowIndex*m_nCols+nColIndex;
C3DPoint pt=m_DemFullGroup.GetAt(nIndex);
for(int i=0;i<m_nLayers;i++)
{
if(z<=(pt.z+i*m_dbDeltaLayerZ)&&z>=(pt.z+(i+1)*m_dbDeltaLayerZ))
{
nn=i;
return nn;
}
}
return nn;
}
double CTestDlg::GetValue(double x,double y,double z,int nLayerIndex)
{
double cf = 0.0;
double v = 0.0;
if(nLayerIndex<0)
nLayerIndex=0;
if(nLayerIndex>m_nLayers-1)
nLayerIndex=m_nLayers-1;
int nCount=m_LayerArray[nLayerIndex]->m_ScatterArray.GetSize();
for(int i=0;i<nCount;i++)
{
CGLVertex vertex=m_LayerArray[nLayerIndex]->m_ScatterArray.GetAt(i);
double xi = vertex.x;
double yi = vertex.y ;
double zi = vertex.z;
double vi = vertex.v ;
double s =(xi-x)*(xi-x)*m_dbConeffX +(yi-y)*(yi-y)*m_dbConeffY + (zi-z)*(zi-z)*m_dbConeffZ + 0.01;
cf += 1.0/s;
v += vi /s;
}
v /= cf;
return v;
}
BOOL CTestDlg::Save3dv()
{
GetValueMaxMin();
EA3DDATAFILEHEADER header;
InitImageFileHeader(&header);
int nDataSize = m_nSamples*4*sizeof(double);
BYTE*pData = new BYTE[nDataSize];
CString strFileName=GetFileMainName(m_strFileName);
CString strName=m_str3DVFile+"\\"+m_strSave3dvFileName+".3dv";
FILE *fp;
fp=fopen(strName,"wb");
if(fp==NULL)
{
AfxMessageBox("三维数据文件读写出错!");
return FALSE;
}
CGLVertex vertex;
double *pValue=(double*)pData;
fwrite(&header,sizeof(EA3DDATAFILEHEADER),1,fp);
int nSize=sizeof(double);
for(int i=0;i<m_nRows;i++)
for(int j=0;j<m_nCols;j++)
{
for(int s=0;s<m_nSamples;s++)
{
int nIndex=(i*m_nCols+j)*m_nSamples+s;
vertex=m_3DVGroup.GetAt(nIndex);
pValue[4*s]=vertex.x;
pValue[4*s+1]=vertex.y;
pValue[4*s+2]=vertex.z;
pValue[4*s+3]=vertex.v;
}
fwrite(pData,nDataSize,1,fp);
}
fclose(fp);
if (pData != NULL)
{
delete[] pData;
pData = NULL;
}
AfxMessageBox("插值完毕!");
return TRUE;
}
void CTestDlg::GetValueMaxMin()
{
int nCount=m_3DVGroup.GetSize();
CGLVertex vertex;
vertex=m_3DVGroup.GetAt(0);
m_dbMaxV=m_dbMinV=vertex.v;
for(int i=1;i<nCount;i++)
{
vertex=m_3DVGroup.GetAt(i);
if(vertex.v>m_dbMaxV)
m_dbMaxV=vertex.v;
if(vertex.v<m_dbMinV)
m_dbMinV=vertex.v;
}
}
void *CTestDlg::alloc1 (size_t n1, size_t size)
{
void *p;
if ((p=malloc(n1*size))==NULL)
return NULL;
return p;
}
double *CTestDlg::alloc1double(size_t n1)
{
return (double*)alloc1(n1,sizeof(double));
}
void CTestDlg::free1 (void *p)
{
free(p);
}
void CTestDlg::free1double(double *p)
{
free1(p);
}
void CTestDlg::Init3dGroup()
{
CGLVertex vertex;
m_3DVGroup.Init(m_nCols*m_nRows*m_nSamples);
for(int r=0;r<m_nRows;r++)
for(int c=0;c<m_nCols;c++)
{
C3DPoint pt=m_DemFullGroup.GetAt(r*m_nCols+c);
for(int s=0;s<m_nSamples;s++)
{
vertex.x=pt.x;
vertex.y=pt.y;
vertex.z=pt.z+s*m_dbDeltaZ;
vertex.v=0;
m_3DVGroup.SetAt((r*m_nCols+c)*m_nSamples+s,vertex);
}
}
//m_dbMinZ=m_dbMaxZ=m_3DVGroup.GetAt(0).z;
for(r=0;r<m_nRows;r++)
for(int c=0;c<m_nCols;c++)
{
for(int s=0;s<m_nSamples;s++)
{
vertex=m_3DVGroup.GetAt((r*m_nCols+c)*m_nSamples+s);
if(vertex.z<m_dbMinZ)
m_dbMinZ=vertex.z;
if(vertex.z>m_dbMaxZ)
m_dbMaxZ=vertex.z;
}
}
}
void CTestDlg::Trans3DV()
{
}
void CTestDlg::OnButton3dv()
{
// TODO: Add your control notification handler code here
CString strPath;
GetBrowserPath(this,strPath,"选择导入的井数据目录:");
m_str3DVFile=strPath;
UpdateData(FALSE);
}
CString CTestDlg::GetFileMainName(CString strFileName)
{
CString strMainName;
int nLen = strFileName.GetLength();
int nIndex = strFileName.ReverseFind('\\');
if (nIndex>=0)
strMainName = strFileName.Right(nLen-nIndex-1);
else
strMainName = strFileName;
return strMainName;
}
CString CTestDlg::GetFileCoreName(CString strFileName)
{
strFileName = GetFileMainName(strFileName);
CString strCoreName;
int nIndex = strFileName.ReverseFind('.');
if (nIndex>=0)
strCoreName = strFileName.Left(nIndex);
else
strCoreName = strFileName;
return strCoreName;
}
BOOL CTestDlg::GetBrowserPath(CWnd* pwndOwner,CString& strPath,CString strTitle)
{
char pszDisplayName[MAX_PATH];
BROWSEINFO fbi;
ZeroMemory(&fbi,sizeof(BROWSEINFO));
fbi.hwndOwner = pwndOwner->m_hWnd;
fbi.pidlRoot = NULL;
fbi.pszDisplayName = pszDisplayName;
fbi.lpszTitle = strTitle;
fbi.ulFlags = BIF_RETURNONLYFSDIRS;
fbi.lpfn = NULL;
fbi.lParam = NULL;
LPITEMIDLIST pidl;
if ((pidl = SHBrowseForFolder(&fbi)) != NULL)
{
char pszPath[MAX_PATH];
if ( SHGetPathFromIDList(pidl,pszPath)== TRUE)
{
strPath = pszPath;
return TRUE;
}
}
return FALSE;
}
void CTestDlg::SetControlSize()
{
CRect rect;
GetClientRect(rect);
rect.DeflateRect(1,1,1,1);
CRect Ctrl3doBoxRect,Ctrl3dvBoxRect;
Ctrl3doBoxRect.left=rect.left;
Ctrl3doBoxRect.top=rect.top;
Ctrl3doBoxRect.bottom=rect.bottom-60;
Ctrl3doBoxRect.right=rect.left+rect.Width()*4/9;
Ctrl3dvBoxRect.left=Ctrl3doBoxRect.right+10;
Ctrl3dvBoxRect.top=rect.top;
Ctrl3dvBoxRect.bottom=rect.bottom-60;
Ctrl3dvBoxRect.right=rect.right;
m_Ctrl3DOBox.MoveWindow(Ctrl3doBoxRect);
m_Ctrl3DOBox.UpdateData(FALSE);
m_Ctrl3DVBox.MoveWindow(Ctrl3dvBoxRect);
m_Ctrl3DVBox.UpdateData(FALSE);
////////////////////////////////////////////////////////////////////
CRect RadioOneRect,RadioTwoRect;
RadioOneRect.top=Ctrl3doBoxRect.top+30;
RadioOneRect.left=Ctrl3doBoxRect.left+Ctrl3doBoxRect.Width()/6;
RadioOneRect.bottom=RadioOneRect.top+30;
RadioOneRect.right=RadioOneRect.left+70;
RadioTwoRect.top=Ctrl3doBoxRect.top+30;
RadioTwoRect.right=Ctrl3doBoxRect.right-Ctrl3doBoxRect.Width()/6;
RadioTwoRect.left=RadioTwoRect.right-70;
RadioTwoRect.bottom=RadioTwoRect.top+30;
m_RadioModeOne.MoveWindow(RadioOneRect);
m_RadioModeOne.UpdateData(FALSE);
m_RadioModeTwo.MoveWindow(RadioTwoRect);
m_RadioModeTwo.UpdateData(FALSE);
////////////////////////////////////////////////////////////////////
CRect StaticModeOneRect,StaticModeTwoRect,BrowserRect;
StaticModeOneRect.top=RadioOneRect.bottom+30;
StaticModeOneRect.left=Ctrl3doBoxRect.left+5;
StaticModeOneRect.right=Ctrl3doBoxRect.right-5;
StaticModeOneRect.bottom=StaticModeOneRect.top+rect.Height()/6;
StaticModeTwoRect.top=StaticModeOneRect.bottom+10;
StaticModeTwoRect.left=Ctrl3doBoxRect.left+5;
StaticModeTwoRect.right=Ctrl3doBoxRect.right-5;
StaticModeTwoRect.bottom=StaticModeTwoRect.top+rect.Height()/6;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -