• 大小: 236KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: 其他
  • 标签: c  

资源简介

课程作业,道格拉斯普克算法,写了很久了,不过肯定可以用。

资源截图

代码片段和文件信息

// DouglasPeuker.cpp : Defines the entry point for the console application.
//

#include “stdafx.h“
#include 
#include 
#include 
using namespace std;

typedef struct point
{
double x;
double y;
}POINT;

vector initialPoints;
vector FinalPoints;
bool *bTag=NULL;
//////////////////////////////////////////////////////////////////////////
void Readdata(char *);
void DouglasPeuker(int int double);
double cacuDistance(int int int);
void Writedata(char *);

//////////////////////////////////////////////////////////////////////////
int main(int argc char* argv[])
{
int nums=0;
char path1[]=“.\\jpl_vegetation_grass2.txt“;//打开文件的路径
char path2[]=“.\\2.txt“;//输出文件的路径
double torelance;
int i;
int nums2=0;

Readdata(path1);

nums=initialPoints.size();
bTag=(bool *)malloc(sizeof(bool)*nums);
memset(bTag0nums);
torelance=0.00002;

    DouglasPeuker(0nums-1torelance);

for (i=0;i {
if(bTag[i])
{
FinalPoints.push_back(initialPoints[i]);
}
}

Writedata(path2);
/* nums2=FinalPoints.size();
printf(“final data:%d \n“nums2);
for (i=0;i {

printf(“%lf %lf\n“FinalPoints[i].xFinalPoints[i].y);
}*/
free(bTag);
return 0;
}
void Readdata(char *filename)
{

char predata1[256];
char predata2[256];
char predata3[256];

FILE *filein;
// int i;
POINT point0;
//float xiyi;

memset(predata10256);
memset(predata20256);
memset(predata30256);
filein=fopen(filename“r“);
// for (i=0;i<3;i++)
{
fscanf(filein“%[^\n]c\n“predata1);
// fscanf(filein“%[^\n]c\n“predata2);
// fscanf(filein“%[^\n]c\n“predata3);
}


point0.x=0.00000;//启用浮点库,不加报错
point0.y=0.00000;

while (fscanf(filein“%lf%lf“&point0.x&point0.y)!=EOF)
//while (fscanf(filein“%f%f“&xi&yi)!=EOF)
{
initialPoints.push_back(point0);
printf(“%f %f\n“point0.xpoint0.y);
}
fclose(filein);
}
void DouglasPeuker(int leftpointint rightpointdouble tolerance)
{
int imaxindex;
double dismaxdis;
maxdis=0;
maxindex=0;
for (i=leftpoint;i {
dis=cacuDistance(leftpointrightpointi);
if (dis>maxdis)
{
maxdis=dis;
maxindex=i;
}
}

if (maxdis>tolerance)
{
bTag[maxindex]=1;
// p=initialPoints(maxindex);
       // FinalPoints.push_back(initialPoints[maxindex]);
DouglasPeuker(leftpointmaxindextolerance);
DouglasPeuker(maxindexrightpointtolerance);//回调
}
else
{
// FinalPoints.push_back(initialPoints[leftpoint]);
// FinalPoints.push_back(initialPoints[rightpoint]);
}

}

double cacuDistance(int lint rint n)
{
double abc;
//POINT p1p2p;
double x1x2y1y2xy;
double dis=0;


y1=initialPoints[l].y*1000;
x1=initialPoints[l].x*1000;
x2=initialPoints[r].x*1000;
y2=initialPoints[r].y*1000;

x=initialPoints[n].x*1000;
y=initialPoints[n].y*1000;

if (x1==x2)
{
dis=abs(x-x1);//两点式失效的情况
r

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        239  2011-08-25 21:56  DouglasPeuker\1.txt

     文件       3859  2011-08-26 09:52  DouglasPeuker\2.txt

     文件     200770  2011-08-26 09:52  DouglasPeuker\Debug\DouglasPeuker.exe

     文件     276840  2011-08-26 09:52  DouglasPeuker\Debug\DouglasPeuker.ilk

     文件      31825  2011-08-26 09:52  DouglasPeuker\Debug\DouglasPeuker.obj

     文件     187000  2011-08-25 21:23  DouglasPeuker\Debug\DouglasPeuker.pch

     文件     508928  2011-08-26 09:52  DouglasPeuker\Debug\DouglasPeuker.pdb

     文件       1656  2011-08-25 21:23  DouglasPeuker\Debug\StdAfx.obj

     文件      66560  2011-08-26 09:52  DouglasPeuker\Debug\vc60.idb

     文件      94208  2011-08-26 09:52  DouglasPeuker\Debug\vc60.pdb

     文件       3484  2011-08-26 09:52  DouglasPeuker\DouglasPeuker.cpp

     文件       4620  2011-08-25 20:57  DouglasPeuker\DouglasPeuker.dsp

     文件        549  2011-08-25 20:57  DouglasPeuker\DouglasPeuker.dsw

     文件      41984  2011-11-09 11:44  DouglasPeuker\DouglasPeuker.ncb

     文件      53760  2011-11-09 11:44  DouglasPeuker\DouglasPeuker.opt

     文件       1352  2011-08-26 09:52  DouglasPeuker\DouglasPeuker.plg

     文件       9360  2011-08-25 12:22  DouglasPeuker\jpl_vegetation_grass.txt

     文件       9289  2011-08-25 21:32  DouglasPeuker\jpl_vegetation_grass2.txt

     文件       1250  2011-08-25 20:57  DouglasPeuker\ReadMe.txt

     文件        300  2011-08-25 20:57  DouglasPeuker\StdAfx.cpp

     文件        667  2011-08-25 20:57  DouglasPeuker\StdAfx.h

     目录          0  2011-08-26 09:52  DouglasPeuker\Debug

     目录          0  2011-11-09 11:44  DouglasPeuker

----------- ---------  ---------- -----  ----

              1498500                    23


评论

共有 条评论