psimpl - generic n-dimensional polyline simplification. psimpl is a lightweight C++ library that is generic, easy to use, and supports multiple simplification algorithms, including Douglas-Peucker.
https://sourceforge.net/projects/psimpl/
https://trove.nla.gov.au/work/81412136?q&versionId=94716767
// test123Dlg.cpp : 实现文件 // #include "stdafx.h" #include <vector> #include "psimpl_reference.h" #undef max #include "psimpl.h" #include <iterator> #include <fstream> #include "test123.h" #include "test123Dlg.h" //#include "afxdialogex.h" #include "basMath70.h" //这又是什么库? #include "basclass70.h" #include "cln_bas70.h" #include "GDelegateDefine.h" //这又是什么库? #include "GBaseJTOper.h" using namespace std; using namespace psimpl; using namespace util; void LoadLine(char* fname,vector<double>& generatedPoints) { char buf[1024]; fstream infile; char sep[2]={0}; double d; strcpy(sep,","); infile.open(fname,ios::in); while(1) { buf[0]=0; infile.getline(buf,1024); if(strlen(buf)<1) break; d=atof(strtok(buf,sep)); generatedPoints.push_back(d); d=atof(strtok(NULL,sep)); generatedPoints.push_back(d); } infile.close(); } void SaveLine(char* fname,vector<double>& generatedPoints) { char buf[1024]={0}; fstream outfile; int i; outfile.open(fname,ios::out); for(i=0;i<generatedPoints.size();i+=2) { sprintf_s(buf,1024,"%f,%f",generatedPoints[i],generatedPoints[i+1]); outfile<<buf<<endl; } outfile.close(); } void SaveDList(char* fname,vector<double>& dlist) { char buf[1024]={0}; fstream outfile; int i; outfile.open(fname,ios::out); for(i=0;i<dlist.size();i++) { sprintf_s(buf,1024,"%f",dlist[i]); outfile<<buf<<endl; } outfile.close(); } // //int _tmain(int argc, _TCHAR* argv[]) //{ // int n=10; // vector<double> mSimplifiedCoords; // vector<double> generatedPoints; // // // LoadLine("C:\\Users\\lenovo\\Desktop\\wo\\Export_Output.txt",generatedPoints); // // // vector <double>::const_iterator begin = generatedPoints.begin (); // vector <double>::const_iterator end = generatedPoints.end (); // // simplify_nth_point <2> (begin, end, n,std::back_inserter(mSimplifiedCoords)); // // n=mSimplifiedCoords.size(); // // SaveLine("C:\\Users\\lenovo\\Desktop\\wo\\ss0.txt",mSimplifiedCoords); // SaveLine("C:\\Users\\lenovo\\Desktop\\wo\\ss1.txt",generatedPoints); // generatedPoints.clear(); // mSimplifiedCoords.clear(); // return 0; //} #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // Ctest123Dlg 对话框 Ctest123Dlg::Ctest123Dlg(CWnd* pParent /*=NULL*/) : CDialogEx(Ctest123Dlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void Ctest123Dlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(Ctest123Dlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, &Ctest123Dlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &Ctest123Dlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &Ctest123Dlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &Ctest123Dlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &Ctest123Dlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON6, &Ctest123Dlg::OnBnClickedButton6) END_MESSAGE_MAP() // Ctest123Dlg 消息处理程序 BOOL Ctest123Dlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void Ctest123Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void Ctest123Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR Ctest123Dlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void Ctest123Dlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 CFileDialog dlg(TRUE); if(dlg.DoModal()==IDOK) { m_path1 = dlg.GetPathName(); m_path1 = "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt"; } } void Ctest123Dlg::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码 CFileDialog dlg(TRUE); if(dlg.DoModal()==IDOK) { m_path2 = dlg.GetPathName(); m_path2 = "C:\\Users\\lenovo\\Desktop\\wo\\L2.txt"; } } void CalDist(char* fname1,char* fname2,char* fname3) { int i; long len; double d ; vector<double> generatedPoints1; vector<double> generatedPoints2; vector<double> dlist; LoadLine(fname1,generatedPoints1); LoadLine(fname2,generatedPoints2); //功能: 计算点到折线之间的距离 D_DOT pnt; len=generatedPoints1.size()/2; D_DOT *lxy=new D_DOT[len]; for(i=0;i<len;i++) { lxy[i].x = generatedPoints1[i*2]; lxy[i].y = generatedPoints1[i*2+1]; } for(i=0;i<generatedPoints2.size()/2;i++) { pnt.x=generatedPoints2[i*2]; pnt.y=generatedPoints2[i*2+1]; d=_DistofPntToLin(&pnt,lxy,len); dlist.push_back(d); } SaveDList(fname3,dlist); delete [] lxy; generatedPoints1.clear(); generatedPoints2.clear(); dlist.clear(); } void Ctest123Dlg::OnBnClickedButton3() { // TODO: 在此添加控件通知处理程序代码 CalDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt", "C:\\Users\\lenovo\\Desktop\\wo\\L_159.txt","C:\\Users\\lenovo\\Desktop\\wo\\ssd_159.txt"); CalDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt", "C:\\Users\\lenovo\\Desktop\\wo\\L_538.txt","C:\\Users\\lenovo\\Desktop\\wo\\ssd_538.txt"); CalDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt", "C:\\Users\\lenovo\\Desktop\\wo\\L_640.txt","C:\\Users\\lenovo\\Desktop\\wo\\ssd_640.txt"); CalDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt", "C:\\Users\\lenovo\\Desktop\\wo\\L_718.txt","C:\\Users\\lenovo\\Desktop\\wo\\ssd_718.txt"); CalDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt", "C:\\Users\\lenovo\\Desktop\\wo\\L_810.txt","C:\\Users\\lenovo\\Desktop\\wo\\ssd_810.txt"); } void Ctest123Dlg::OnBnClickedButton4() { // TODO: 在此添加控件通知处理程序代码 long i,j; CAnyLine anyLine; vector<double> generatedPoints1; LoadLine("C:\\Users\\lenovo\\Desktop\\wo\\YY1.txt",generatedPoints1); long len=generatedPoints1.size()/2; vector<double> dlist; double d; D_DOT *lxy=new D_DOT[len]; for(i=0;i<len;i++) { lxy[i].x = generatedPoints1[i*2]; lxy[i].y = generatedPoints1[i*2+1]; } CGBaseGenOper obj; SimpleParam param; /*sp.dBendDepth=100; sp.dstep=1;*/ char ss[100]={0}; param.dstep =2.5; D_RECT rc; double wid,hei; vector<long> numlist; anyLine.m_varLin.Set(lxy,len); for(j=0;j<100;j++) { param.dBendDepth =2*(j+1); anyLine.CalRect(&rc); wid=rc.xmax-rc.xmin; hei=rc.ymax-rc.ymin; obj.ContourLinSimple(anyLine,¶m); long dotnum=anyLine.m_varLin.dotNum(); D_DOT* pxy=(D_DOT*)anyLine.m_varLin.ptXY(); vector<double> generatedPoints; for(i=0;i<dotnum;i++) { generatedPoints.push_back(pxy[i].x); generatedPoints.push_back(pxy[i].y); } sprintf(ss,"C:\\Users\\lenovo\\Desktop\\wo\\bpI_%d.txt",j+1); numlist.push_back(dotnum); SaveLine(ss,generatedPoints); generatedPoints.clear(); } //// for(i=0;i<dotnum;i++) ////{ //// d=_DistofPntToLin(&(pxy[i]),lxy,len); //// dlist.push_back(d); ////} //// ////SaveDList("C:\\Users\\lenovo\\Desktop\\wo\\ssd.txt",dlist); delete [] lxy; generatedPoints1.clear(); } #include "windows.h" #include "math.h" #include "basclass70.h" // //double c(D_DOT *zb1,D_DOT *zb2,int i,int j,double **ca) //{ // if(ca[i][j] > -1) return ca[i][j]; // else if(i == 1&&j == 1) ca[i][j] = sqrt((zb1[1].x-zb2[1].x)*(zb1[1].x-zb2[1].x)+(zb1[1].y-zb2[1].y)*(zb1[1].y-zb2[1].y)); // else if(i > 1&&j == 1) ca[i][j] = max(c(zb1,zb2,i-1,1,ca),sqrt((zb1[i].x-zb2[1].x)*(zb1[i].x-zb2[1].x)+(zb1[i].y-zb2[1].y)*(zb1[i].y-zb2[1].y))); // else if(i == 1&&j > 1) ca[i][j] = max(c(zb1,zb2,1,j-1,ca),sqrt((zb1[1].x-zb2[j].x)*(zb1[1].x-zb2[j].x)+(zb1[1].y-zb2[j].y)*(zb1[1].y-zb2[j].y))); // else if(i > 1&&j > 1) // { // if(c(zb1,zb2,i-1,j,ca)<c(zb1,zb2,i-1,j-1,ca)&&c(zb1,zb2,i-1,j,ca)<c(zb1,zb2,i,j-1,ca)) ca[i][j] = max(c(zb1,zb2,i-1,j,ca),sqrt((zb1[i].x-zb2[j].x)*(zb1[i].x-zb2[j].x)+(zb1[i].y-zb2[j].y)*(zb1[i].y-zb2[j].y))); // else if(c(zb1,zb2,i-1,j-1,ca)<c(zb1,zb2,i-1,j,ca)&&c(zb1,zb2,i-1,j-1,ca)<c(zb1,zb2,i,j-1,ca)) ca[i][j] = max(c(zb1,zb2,i-1,j-1,ca),sqrt((zb1[i].x-zb2[j].x)*(zb1[i].x-zb2[j].x)+(zb1[i].y-zb2[j].y)*(zb1[i].y-zb2[j].y))); // else ca[i][j] = max(c(zb1,zb2,i,j-1,ca),sqrt((zb1[i].x-zb2[j].x)*(zb1[i].x-zb2[j].x)+(zb1[i].y-zb2[j].y)*(zb1[i].y-zb2[j].y))); // } // else ca[i][j] = 9999; // //printf("i = %d j = %d ca[i][j] = %.2f\n",i,j,ca[i][j]); // return ca[i][j]; //} double pi_pj(D_DOT& pi,D_DOT& pj) { double dx=pi.x-pj.x; double dy=pi.y-pj.y; return sqrt(dx*dx+dy*dy); } typedef double* DBLPtr; double c(D_DOT *zb1,D_DOT *zb2,int i,int j,double **ca) { int curI,curJ; double **caao; caao = (double **)new DBLPtr[i+1]; for(curI=0;curI<=i;curI++) { caao[curI]=new double[j+1]; } for(curI=1;curI<=i;curI++) { for(curJ=1;curJ<=j;curJ++) { caao[curI][curJ]=pi_pj(zb1[curI],zb2[curJ]); } } ca[1][1]=caao[1][1]; for(curJ=1;curJ<=j;curJ++) { for(curI=1;curI<=i;curI++) { if(curJ==1) { if(curI>1) { ca[curI][curJ]=caao[curI][curJ]; if(ca[curI][curJ]<ca[curI-1][1]) { ca[curI][curJ]=ca[curI-1][1]; } } } else if(curI==1) { if(curJ>1) { ca[curI][curJ]=caao[curI][curJ]; if(ca[curI][curJ]<ca[1][curJ-1]) { ca[curI][curJ]=ca[1][curJ-1]; } } } else if(curI>1&&curJ>1) { ca[curI][curJ]=caao[curI][curJ]; double tmp1 = ca[curI-1][curJ]; double tmp2 = ca[curI-1][curJ-1]; double tmp3 = ca[curI][curJ-1]; if(tmp1<tmp2&&tmp1<tmp3) { if(ca[curI][curJ]<tmp1) ca[curI][curJ]=tmp1; } else if(tmp2<tmp1&&tmp2<tmp3) { if(ca[curI][curJ]<tmp2) ca[curI][curJ]=tmp2; } else { if(ca[curI][curJ]<tmp3) ca[curI][curJ]=tmp3; } } else ca[curI][curJ] = 9999; } } for(curI=0;curI<=i;curI++) { delete [] caao[curI]; } delete [] caao; return ca[i][j]; } double Frechet(D_DOT *zb1,int n1,D_DOT *zb2,int n2,double** fm) { int i,j; double **caa; double result; caa = (double **)new DBLPtr[n1+1]; for(i=0;i<=n1;i++) { caa[i]=new double[n2+1]; } for(i=0;i<=n1;i++) { for(j=0;j<=n2;j++) { caa[i][j] = -1; } } result = c(zb1,zb2,n1,n2,caa); for(i=0;i<=n1;i++) { for(j=0;j<=n2;j++) { fm[j][i] = caa[i][j]; } } for(i=0;i<=n1;i++) { delete [] (caa[i]); } delete [] caa; return result; } //判断(fmx,fmy)是否小于等于(mdx,mdy),若小于等于,则函数返回值为1,否则为0 int Xiaoyu(double fmx,double fmy,double mdx,double mdy) { if(fmx < mdx||((fmx == mdx)&&(fmy <= mdy))) return 1; else return 0; } void MinXiaoyu(double fmx,double fmy,double mdx,double mdy,double *x,double *y) { if(Xiaoyu(fmx,fmy,mdx,mdy)) { x[0] = fmx; y[0] = fmy; } else { x[0] = mdx; y[0] = mdy; } } typedef struct PointIndex { int p1; int p2; struct PointIndex* next; }PointIndex; //m为第一条线上点数,n为第2条线上点数,fm,md为n*m二维数组 void SearchPointMatching(double **fm,double **md,int m,int n,PointIndex **Proot,int *Num) { int i,j; double x,y; PointIndex *pip,*pib; Num[0] = 0; pip=new PointIndex; pip->p1=0; pip->p2=0; pip->next=0; pip->p1=m; pip->p2=n; if(Proot[0]==0) { pib=Proot[0]=pip; } else { pib->next=pip; pib=pip; } Num[0]++; i = n;j = m; while(i > 1&&j > 1) { //printf("i = %d j = %d\n",i,j); MinXiaoyu(fm[i-1][j],md[i-1][j],fm[i][j-1],md[i][j-1],&x,&y); //printf("x = %lf y = %lf\n",x,y); if(Xiaoyu(fm[i-1][j-1],md[i-1][j-1],x,y)) { pip=new PointIndex; pip->p1=0; pip->p2=0; pip->next=0; pip->p1=j-1; pip->p2=i-1; if(Proot[0]==0) { pib=Proot[0]=pip; } else { pib->next=pip; pib=pip; } Num[0]++; i = i-1; j = j-1; } else { if(Xiaoyu(fm[i-1][j],md[i-1][j],fm[i][j-1],md[i][j-1])) { pip=new PointIndex; pip->p1=0; pip->p2=0; pip->next=0; pip->p1=j; pip->p2=i-1; if(Proot[0]==0) { pib=Proot[0]=pip; } else { pib->next=pip; pib=pip; } Num[0]++; i = i-1; j = j; } else { pip=new PointIndex; pip->p1=0; pip->p2=0; pip->next=0; pip->p1=j-1; pip->p2=i; if(Proot[0]==0) { pib=Proot[0]=pip; } else { pib->next=pip; pib=pip; } Num[0]++; i = i; j = j-1; } } } } #define max(a,b) (((a)>(b))?(a):(b)) float dis(D_DOT *p1, D_DOT* p2, int i, int j) { return sqrt(pow(p1[i].x - p2[j].x, 2) + pow(p1[i].y - p2[j].y, 2)); } float min3(double f1, double f2, double f3) { double minf = (f1 < f2) ? f1 : f2; minf = (minf < f3) ? minf : f3; return minf; } float Cal(D_DOT* p1, D_DOT *p2, double** ca, int i, int j) { if (ca[i][j] > -1.0) { return ca[i][j]; } else if (i == 0 && j == 0) { ca[i][j] = dis(p1, p2, 0, 0); } else if (i > 0 && j == 0) { ca[i][j] = max(Cal(p1, p2, ca, i - 1, 0), dis(p1, p2, i, 0)); } else if (i == 0 && j > 0) { ca[i][j] = max(Cal(p1, p2, ca, 0, j - 1), dis(p1, p2, 0, j)); } else if (i > 0 && j > 0) { ca[i][j] = max(min3(Cal(p1, p2, ca, i - 1, j), Cal(p1, p2, ca, i - 1, j - 1), Cal(p1, p2, ca, i, j - 1)), dis(p1, p2, i, j)); } else { ca[i][j] = 0xFFFFFFFF; } return ca[i][j]; } float calcFrechet(D_DOT *p1, int p, D_DOT* p2, int q) { double **ca = new double*[p]; for (int i = 0; i < p; i++) { ca[i] = new double[q]; } for (int i = 0; i < p; i++) { for (int j = 0; j < q; j++) { ca[i][j] = -1.0; } } double r = Cal(p1, p2, ca, p - 1, q - 1); for (int i = 0; i < p; i++) delete[]ca[i]; delete[]ca; return r; } // //int main() //{ // //sPoint pp1[5] = { { 1.0, 2.0 }, { 2.0, 3.0 }, { 3.0, 4.0 }, { 4.0, 5.0 }, { 5.0, 6.0 } }; // //sPoint pp2[7] = { { 1.0, -2.0 }, { 2.0, -3.0 }, { 3.0, -4.0 }, { 4.0, -5.0 }, { 5.0, -6.0 }, { 6.0, -7.0 }, { 7.0, -8.0 } }; // // fstream readinsrc; // fstream readindst; // vector<frePoint> src; // vector<frePoint> dst; // frePoint tmp; // readinsrc.open("E:\\线数据\\新建文件夹\\3\\ZD_Simplify_src3.txt", ios::in); // while (!readinsrc.eof()) // { // readinsrc >> tmp.x >> tmp.y; // src.push_back(tmp); // } // readindst.open("E:\\线数据\\新建文件夹\\3\\ZD_Simplify_ContourLinSimple_5594.txt", ios::in); // while (!readindst.eof()) // { // readindst >> tmp.x >> tmp.y; // dst.push_back(tmp); // } // // int p1size = src.size(); // int p2size = dst.size(); // // frePoint* p1 = new frePoint[p1size]; // frePoint* p2 = new frePoint[p2size]; // // for (int i = 0; i < p1size; ++i) // { // p1[i].x = src[i].x; // p1[i].y = src[i].y; // } // for (int j = 0; j < p2size; ++j) // { // p2[j].x = dst[j].x; // p2[j].y = dst[j].y; // } // // float DiscreteFrechetDist = calcFrechet(p1, p1size, p2, p2size); // // printf("Frechet distance: %f \n", DiscreteFrechetDist); // // // delete[]p1; // delete[]p2; // readinsrc.close(); // readindst.close(); // return 0; //} //double CalFrechetDist(char* fname1,char* fname2) //{ // int i; // long len1,len2; // double d ; // vector<double> generatedPoints1; // vector<double> generatedPoints2; // // LoadLine(fname1,generatedPoints1); // LoadLine(fname2,generatedPoints2); // // // len1=generatedPoints1.size()/2; // D_DOT *lxy1=new D_DOT[len1]; // for(i=0;i<len1;i++) // { // lxy1[i].x = generatedPoints1[i*2]; // lxy1[i].y = generatedPoints1[i*2+1]; // } // len2=generatedPoints2.size()/2; // D_DOT *lxy2=new D_DOT[len2]; // for(i=0;i<len2;i++) // { // lxy2[i].x = generatedPoints2[i*2]; // lxy2[i].y = generatedPoints2[i*2+1]; // } // // d = calcFrechet(lxy1,len1,lxy2,len2); // // delete [] lxy1; // delete [] lxy2; // // // generatedPoints1.clear(); // generatedPoints2.clear(); // // return d; //} double CalFrechetDist(char* fname1,char* fname2,long& pnum) { int i; long len1,len2; double d ; vector<double> generatedPoints1; vector<double> generatedPoints2; LoadLine(fname1,generatedPoints1); LoadLine(fname2,generatedPoints2); len1=generatedPoints1.size()/2+1; D_DOT *lxy1=new D_DOT[len1]; for(i=0;i<len1-1;i++) { lxy1[i+1].x = generatedPoints1[i*2]; lxy1[i+1].y = generatedPoints1[i*2+1]; } len2=generatedPoints2.size()/2+1; D_DOT *lxy2=new D_DOT[len2]; for(i=0;i<len2-1;i++) { lxy2[i+1].x = generatedPoints2[i*2]; lxy2[i+1].y = generatedPoints2[i*2+1]; } DBLPtr* fm=new DBLPtr[len2]; for(i=0;i<len2;i++) { fm[i]=new double[len1]; } d =Frechet(lxy1,len1-1,lxy2,len2-1,(double**)fm); delete [] lxy1; delete [] lxy2; for(i=0;i<len2;i++) { delete [] fm[i]; } delete [] fm; generatedPoints1.clear(); generatedPoints2.clear(); pnum=len2; return d; } #include "GGisSpaAnaly.h" void Ctest123Dlg::OnBnClickedButton5() { // TODO: 在此添加控件通知处理程序代码 int i; double d1; vector<double> dlist; vector<long> pnumlist; char ss[100]={0}; long pnum; for(i=0;i<40;i++) { sprintf(ss,"C:\\Users\\lenovo\\Desktop\\wo\\YYI_%d.txt",i+1); d1=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\YY1.txt",ss,pnum); dlist.push_back(d1); pnumlist.push_back(pnum); } /* double d1=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt","C:\\Users\\lenovo\\Desktop\\wo\\L_159.txt"); double d2=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt","C:\\Users\\lenovo\\Desktop\\wo\\L_538.txt"); double d3=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt","C:\\Users\\lenovo\\Desktop\\wo\\L_640.txt"); double d4=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt","C:\\Users\\lenovo\\Desktop\\wo\\L_718.txt"); double d5=CalFrechetDist( "C:\\Users\\lenovo\\Desktop\\wo\\L0.txt","C:\\Users\\lenovo\\Desktop\\wo\\L_810.txt");*/ } void LoadLine(char* fname,CAnyLine& anylin) { int i; vector<double> generatedPoints; LoadLine(fname,generatedPoints); long len=generatedPoints.size()/2; D_DOT *lxy=new D_DOT[len]; for(i=0;i<len;i++) { lxy[i].x = generatedPoints[i*2]; lxy[i].y = generatedPoints[i*2+1]; } anylin.m_varLin.Set(lxy,len); delete [] lxy; generatedPoints.clear(); } void Ctest123Dlg::OnBnClickedButton6() { // TODO: 在此添加控件通知处理程序代码 CAnyLine anylin1; CAnyLine anylin2; LoadLine("C:\\Users\\lenovo\\Desktop\\wo\\YY1.txt",anylin1); LoadLine("C:\\Users\\lenovo\\Desktop\\wo\\bpI_4.txt",anylin2); char* clsName="线缠绕"; char* clsNameR="缠绕区"; CGDBServer svr; CGDataBase gdb; CSFeatureCls cls; CSFeatureCls clsR; long rtn; svr.Connect(); rtn=gdb.Open(&svr,"sample"); long lLinFclsID = gdb.xcls_IsExist( XCLS_TYPE_SFCLS, clsName); if(lLinFclsID < 1) { lLinFclsID = cls.cls_Create(&gdb, clsName, 0, 0, 1, "", "", "", NULL, FCLS_SLIN_TYPE); } else { cls.cls_Open(&gdb, lLinFclsID, 1); cls.cls_Clear(); } long lRegFclsID = gdb.xcls_IsExist( XCLS_TYPE_SFCLS, clsNameR); if(lRegFclsID < 1) { lRegFclsID = clsR.cls_Create(&gdb, clsNameR, 0, 0, 1, "", "", "", NULL, FCLS_SREG_TYPE); } else { clsR.cls_Open(&gdb, lRegFclsID, 1); clsR.cls_Clear(); } rtn=cls.line_Append(&anylin1); rtn=cls.line_Append(&anylin2); rtn=sf_TopoRegion(&cls,NULL,&clsR,NULL,0.0001,false); //功能: 计算折线长度 //double _CalculateLength(D_DOT *xy,gisLONG len); D_DOT* pxy1=(D_DOT*)(anylin1.m_varLin.ptXY()); long num1=anylin1.m_varLin.dotNum(); D_DOT* pxy2=(D_DOT*)(anylin2.m_varLin.ptXY()); long num2=anylin2.m_varLin.dotNum(); long i; double d1=_CalculateLength(pxy1,num1); double d2=_CalculateLength(pxy2,num2); double dd=d1-d2; CAnyPolygon anypolygon; D_DOT* dots = NULL; long* ne = NULL; long neLen = 0; double area=0; long rnum=clsR.GetObjCount(); for(i=0;i<rnum;i++) { clsR.polygon_Get(i+1, &anypolygon); CPolygon tempPolygon; tempPolygon = anypolygon; dots = tempPolygon.xy(); ne = tempPolygon.ne(); neLen = tempPolygon.neLen(); //功能: 计算多边形一圈的面积 //double _CalculateOneArea(D_DOT *xy,gisLONG len); area+=_CalculateOneArea(dots,ne[0]); } cls.cls_Close(); clsR.cls_Close(); gdb.Close(); svr.Disconnect(); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2017-06-04 声音处理(Cool Edit)