资源简介
使用python实现了可视域计算的几种经典算法,包括LOS算法,Xdraw算法,参考面算法等
代码片段和文件信息
#-*-coding:utf8-*-
“““
written: 2014.04.02; by guoning; vision: 0.1
function: 比较三种算法的效率
“““
import gdal
import time
import math
import numpy
#边界扫描算法(基于bresenham近似)
def Los_sweep(arearadius):
blockvisib = [[0 for i in range(radius+1)]for i in range(radius+1)] #可视性存储矩阵(r+1)*(r+1)
blockvisib[0][0] = 1
#area = band.ReadAsArray(int(x0)int(y0)int(radius+1)int(radius+1))
area = numpy.transpose(area) #转置,使x,y符合使用习惯
viewheight = area[0][0]
mslope = -65535
x = 0
y = 0
dx = radius
for i in range(radius+1):
dy = i
dp = 2*dy-dx
while(x < dx):
x+=1
if(dp < 0):
dp+=2*dy
else:
y+=1
dp+=2*(dy-dx)
tslope = (area[x][y] - viewheight)/math.sqrt(x*x+y*y)
if(tslope > mslope):
blockvisib[y][x] = 1
mslope = tslope
#将两矩阵转置进行相同的运算
area = numpy.transpose(area)
blockvisib = numpy.transpose(blockvisib)
mslope = -65535
x = 0
y = 0
dx = radius
for i in range(radius+1):
dy = i
dp = 2*dy-dx
while(x < dx):
x+=1
if(dp < 0):
dp+=2*dy
else:
y+=1
dp+=2*(dy-dx)
tslope = (area[x][y] - viewheight)/math.sqrt(x*x+y*y)
if(tslope > mslope):
blockvisib[y][x] = 1
mslope = tslope
#得到完整区块可视性
blockvisib = numpy.transpose(blockvisib)
return blockvisib
#xdraw算法
def XDraw(arearadius):
blockvisib = [[0 for i in range(radius+1)]for i in range(radius+1)] #可视性存储矩阵(r+1)*(r+1)
blockvisib[0][0] = 1
#area = band.ReadAsArray(int(x0)int(y0)int(radius+1)int(radius+1))
area = numpy.transpose(area) #转置,使x,y符合使用习惯
lowestvisibalh = [[0 for i in range(radius+1)]for i in range(radius+1)] #初始化最低可视海拔存储矩阵为原海拔矩阵
lowestvisibalh[0][0] = area[0][0]
viewheight = area[0][0] #视点高度
#判断x轴方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist1 = [area[i+1][0] for i in range(radius)]
mslope = -65535
for i in range(radius):
tslope = float(heightlist1[i] - viewheight)/(i+1)
if(tslope > mslope):
blockvisib[i+1][0] = 1
mslope = tslope
lowestvisibalh[i+1][0] = area[i+1][0]
else:
lowestvisibalh[i+1][0] = lowestvisibalh[i][0]+mslope
#判断y轴方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist2 = [area[0][i+1] for i in range(radius)]
mslope = -65535
for i in range(radius):
tslope = float(heightlist2[i] - viewheight)/(i+1)
if(tslope > mslope):
blockvisib[0][i+1] = 1
mslope = tslope
lowestvisibalh[0][i+1] = area[0][i+1]
else:
lowestvisibalh[0][i+1] = lowestvisibalh[0][i]+mslope
#判断对角线方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist3 = [area[i+1][i+1] for i in range(radius)]
sqrt2 = math.sqrt(2)
mslope = -65535
for i in range(radius):
tslope = float(heightlist3[i] - viewheight
- 上一篇:Python爬取东方财富公司公告
- 下一篇:python3.4爬取网络图片
相关资源
- python3.4爬取网络图片
- Python爬取东方财富公司公告
- python大作业
- Python二级考试试题
- Python实现朴素贝叶斯算法文本分类器
- 树莓派避障小车.py
- Apartment_Manager.py
- python编程相关的161本书内含解压密码
-
wxPython实现fr
ame界面的跳转 - 模式识别ISODATA算法
- Python - 截取指定帧数间隔指定大小的
- Graph Cut图像分割算法——Python+Opencv实
- 球面拟合-基于最小二乘法
- python+pyqt5显示图像,播放视频,绘图
- karmarkar.py
- python keylogger键盘记录源码
- Python基础训练100题(带答案).docx
- 燕大《Python机器学习》实验报告 .do
- 正向云模型发生器python
- 鱼C小甲鱼零基础入门学习Python视频课
- Python爬虫爬取51Job职位数据
- BP神经网络_Python实习_包含鸢尾花分类
- Python调用CAD生成多边形骨料
- python爬取豆瓣电影源码+报告.zip
- 利用python爬虫爬取王者荣耀数据.py
- Fiona-1.8.6-cp37-cp37m-win_amd64.whl
- FP_Growth算法python实现.rar.rar
- PyQt4-4.11.4 win32 python3.4直接安装版(
- 基于python+mysql的图书管理系统,有g
- 多目标优化算法(一)NSGA2python版
评论
共有 条评论