【mars3d】实现线面内插值计算效果

news2024/9/20 6:04:32

面插值计算效果展示:

(离屏渲染方式)面插值效果展示:

面内插值计算插点效果展示:

线插值效果展示:

(离屏渲染方式)高密度线内插值计算效果展示:

 相关代码:

import * as mars3d from "mars3d"

export let map // mars3d.Map三维地图对象

// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 30.841762, lng: 116.26537, alt: 3281, heading: 39, pitch: -63 }
  }
}

/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
}

/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}

export function removeAll() {
  map.graphicLayer.clear()

  clearInterResult()
}

/**
 * 面插值
 *
 * @export
 * @param {number} val 步长
 * @returns {void}
 */
export async function interPolygon(val) {
  const graphic = await map.graphicLayer.startDraw({
    type: "polygon",
    style: {
      color: "#29cf34",
      opacity: 0.3,
      outline: true,
      outlineColor: "#ffffff",
      clampToGround: true
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  const resultInter = await mars3d.PolyUtil.interPolygon({
    scene: map.scene,
    positions,
    splitNum: val // splitNum插值分割的个数
  })
  showInterPolygonResult(resultInter.list)
}
function showInterPolygonResult(list) {
  clearInterResult() // 分析结果用于测试分析的,不做太多处理,直接清除之前的,只保留一个

  let pt1, pt2, pt3
  const arrData = []
  for (let i = 0, len = list.length; i < len; i++) {
    const item = list[i]

    pt1 = item.point1.pointDM
    pt2 = item.point2.pointDM
    pt3 = item.point3.pointDM

    // 点
    for (const pt of [item.point1, item.point2, item.point3]) {
      const graphic = new mars3d.graphic.PointPrimitive({
        position: pt.pointDM,
        style: {
          pixelSize: 9,
          color: Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.5)
        }
      })
      interGraphicLayer.addGraphic(graphic)

      graphic.bindTooltip("点高度:" + mars3d.MeasureUtil.formatDistance(pt.height))
    }

    // 横截面面积
    item.area = item.area || mars3d.MeasureUtil.getTriangleArea(pt1, pt2, pt3)
    item.index = i

    // 三角网及边线
    arrData.push({
      positions: [pt1, pt2, pt3, pt1],
      style: {
        color: Cesium.Color.fromRandom({ alpha: 0.6 })
      },
      attr: item
    })
  }

  // 三角网面(单击用)
  const primitivePoly = new mars3d.graphic.PolygonCombine({
    instances: arrData,
    highlight: {
      type: mars3d.EventType.click,
      color: Cesium.Color.YELLOW.withAlpha(0.9)
    }
  })
  interGraphicLayer.addGraphic(primitivePoly)

  primitivePoly.bindTooltip(function (event) {
    const item = event.pickedObject?.data?.attr
    if (!item) {
      return
    }

    return "三角面积:" + mars3d.MeasureUtil.formatArea(item.area) + "(第" + item.index + "个)"
  })

  // 三角网边线
  const primitiveLine = new mars3d.graphic.PolylineCombine({
    instances: arrData,
    highlight: {
      type: mars3d.EventType.click,
      color: Cesium.Color.YELLOW.withAlpha(0.9)
    }
  })
  interGraphicLayer.addGraphic(primitiveLine)
}

export async function interPolygonGrid(val) {
  clearInterResult()

  const graphic = await map.graphicLayer.startDraw({
    type: "polygon",
    style: {
      color: "#29cf34",
      opacity: 0.3,
      outline: true,
      outlineColor: "#ffffff"
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  const result = mars3d.PolyUtil.getGridPointsByPoly(positions, val)
  result.forEach((p, i) => {
    const graphic = new mars3d.graphic.PointPrimitive({
      position: p,
      style: {
        color: "#ff0000",
        pixelSize: 6
      }
    })
    interGraphicLayer.addGraphic(graphic)
  })
}

/**
 * 面插值
 *
 * @export
 * @param {number} val 步长
 * @returns {void}
 */
export async function interPolygonByDepth(val) {
  const graphic = await map.graphicLayer.startDraw({
    type: "polygon",
    style: {
      color: "#29cf34",
      opacity: 0.3,
      outline: true,
      outlineColor: "#ffffff",
      clampToGround: true
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  updateAllGraphicShow(map, false)
  const resultInter = await mars3d.PolyUtil.interPolygonByDepth({
    scene: map.scene,
    positions,
    splitNum: val // splitNum插值分割的个数
  })
  updateAllGraphicShow(map, true)
  showInterPolygonByDepthResult(resultInter)
}
function showInterPolygonByDepthResult(resultInter) {
  clearInterResult() // 分析结果用于测试分析的,不做太多处理,直接清除之前的,只保留一个

  const arrData = []
  for (let i = 0, len = resultInter.count; i < len; i++) {
    const position = resultInter.positions[i]

    // const graphic = new mars3d.graphic.PointPrimitive({
    //   position: position,
    //   style: {
    //     pixelSize: 9,
    //     color: Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.5)
    //   }
    // })
    // interGraphicLayer.addGraphic(graphic)
    // graphic.bindTooltip("点高度:" + mars3d.MeasureUtil.formatDistance(position.height))

    arrData.push({
      positions: position.getOutline(),
      style: {
        color: Cesium.Color.fromRandom({ alpha: 0.4 })
      },
      attr: { height: position.height, index: i }
    })
  }

  const primitivePoly = new mars3d.graphic.PolygonCombine({
    instances: arrData,
    highlight: {
      type: mars3d.EventType.click,
      color: Cesium.Color.YELLOW.withAlpha(0.9)
    }
  })
  interGraphicLayer.addGraphic(primitivePoly)

  primitivePoly.bindTooltip(function (event) {
    const item = event.pickedObject?.data?.attr
    if (!item) {
      return
    }

    return "点高度:" + mars3d.MeasureUtil.formatDistance(item.height) + "(第" + item.index + "个)"
  })
}

// 线插值
export async function interPolyline(val) {
  const graphic = await map.graphicLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3,
      clampToGround: true
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  const arrLine = mars3d.PolyUtil.interPolyline({
    scene: map.scene,
    positions,
    splitNum: val // 插值分割的个数
  })

  showInterLineResult(arrLine)
}

// 高度等分
export async function interLine(val) {
  const graphic = await map.graphicLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  const arrLine = mars3d.PolyUtil.interLine(positions, {
    splitNum: val // 插值分割的个数
  })

  showInterLineResult(arrLine)
}

export async function interLineByDepth(val) {
  const graphic = await map.graphicLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3
    }
  })
  const positions = graphic.positionsShow
  map.graphicLayer.clear()

  updateAllGraphicShow(map, false)

  const resultInter = await mars3d.PolyUtil.interPolylineByDepth({
    scene: map.scene,
    positions,
    splitNum: val // 插值分割的个数
  })
  updateAllGraphicShow(map, true)
  showInterLineResult(resultInter.positions)
}

// 显示影藏矢量数据
function updateAllGraphicShow(map, show) {
  map.eachLayer((layer) => {
    if (layer.type === "graphic") {
      layer.show = show
    }
  })
}

// 显示mars3d.polygon.interPolygon处理后的面内插值分析结果,主要用于测试对比
// 显示面的插值计算结果,方便比较分析
let interGraphicLayer
function clearInterResult() {
  if (!interGraphicLayer) {
    interGraphicLayer = new mars3d.layer.GraphicLayer()
    map.addLayer(interGraphicLayer)
  }

  interGraphicLayer.clear()
}

//
function showInterLineResult(list) {
  clearInterResult() // 分析结果用于测试分析的,不做太多处理,直接清除之前的,只保留最后一个

  const colorList = [Cesium.Color.fromCssColorString("#ffff00"), Cesium.Color.fromCssColorString("#00ffff")]

  const arrData = []
  for (let i = 1, len = list.length; i < len; i++) {
    const pt1 = list[i - 1]
    const pt2 = list[i]

    const color = colorList[i % 2]

    arrData.push({
      positions: [pt1, pt2],
      style: {
        width: 3,
        color,
        depthFailColor: color
      },
      attr: {
        distance: Cesium.Cartesian3.distance(pt1, pt2),
        index: i
      }
    })
  }

  const primitiveLine = new mars3d.graphic.PolylineCombine({
    instances: arrData,
    highlight: {
      type: mars3d.EventType.click,
      color: Cesium.Color.RED
    }
  })
  interGraphicLayer.addGraphic(primitiveLine)

  primitiveLine.bindTooltip(function (event) {
    const item = event.pickedObject?.data?.attr
    if (!item) {
      return
    }
    return "长度:" + mars3d.MeasureUtil.formatDistance(item.distance) + "(第" + item.index + "个)"
  })
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1970731.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

docker二进制包部署(带arm版自动部署包)

文章目录 1.概述2.Docker二进制包下载3.安装脚本制作4.安装5.卸载6.注意事项7.分享一个arm版自动部署安装包8.懒人 X86 版安装包 1.概述 最近需要在Linux上部署docker&#xff0c;于是自己做了一个自动部署包。脚本的写法不区分X86或arm&#xff0c;通用的。 2.Docker二进制包…

网络安全和数据安全到底有什么区别?(非常详细)零基础入门到精通,收藏这一篇就够了

随着信息技术的迅猛发展&#xff0c;网络安全和数据安全已经成为当今社会不可忽视的重要议题。两者在保障信息系统安全、防范数据泄露和保障用户权益方面起着至关重要的作用。然而&#xff0c;尽管网络安全与数据安全在某些方面有着密切的联系&#xff0c;但它们在定义、目标和…

“八股文”:程序员的福音还是梦魇?

——一场关于面试题的“代码战争” 在程序员的世界里&#xff0c;“八股文”这个词儿可谓是“如雷贯耳”。不&#xff0c;咱们可不是说古代科举考试中的那种八股文&#xff0c;而是指程序员面试中的那些固定套路的题目。如今&#xff0c;各大中小企业在招聘程序员时&#xff0…

11.2.0.4 ADG故障 LGWR (ospid: 30945):terminating the instance due to error 4021

11.2.0.4 ADG无法连接&#xff0c;查看数据库为关闭状态&#xff0c;重新启动实例&#xff0c;应用日志后即可正常同步数据并打开到只读模式。 查看alert日志发现有以下报错&#xff1a; 0RA-04021:timeout occurred while waiting to lock obiectLGWR (ospid: 30945):termi…

矩阵、向量、张量 一文彻底理清!

矩阵&#xff1a;可理解为二维数组、二维张量 向量Vector&#xff1a;是只有一列的矩阵 张量&#xff1a;是矩阵向任意维度的推广。 机器学习经常会用到张量做变换&#xff0c;所以下文重点介绍张量。 可以通过.ndim查看numpy数据的张量维度。张量的维度&#xff08;dimens…

【熊猫派对】

游戏简介 熊猫派对是一款滑稽打闹游戏&#xff0c;玩法容易上手简单&#xff0c;游戏中玩家将操控自己的熊猫人&#xff0c;与其他对手对战&#xff0c;重拳、飞脚甚至还有各种各样的武器都可用来击败你的对手。 游戏特色 1、滑稽角色 网络超火的滑稽角色&#xff0c;从表情包…

JNI原理是什么?JNI在DDS binding JAVA中/DDS移植android平台中有什么作用?

1 JNI是什么2 如何在JAVA中调用C/C方法&#xff08;通过JNI调用的demo&#xff09;java中声明一个本地native方法生成JNI头文件Java native方法转换成C的规则与语法说明C实现的native方法本地实现以及.o .dll库的生成查看hello.dll库中的函数运行一下HelloJNI JNI在DDS移植andr…

微信小程序 - 自定义计数器

微信小程序通过自定义组件&#xff0c;实现计数器值的增加、减少、清零、最大最小值限定、禁用等操作。通过按钮事件触发方式&#xff0c;更新计数器的值&#xff0c;并修改相关联的其它变量。通过提升用户体验&#xff0c;对计数器进行优化设计&#xff0c;使用户操作更加便捷…

PHP教育培训小程序系统源码

&#x1f680;【学习新纪元】解锁教育培训小程序的无限可能✨ &#x1f4da; 引言&#xff1a;教育培训新风尚&#xff0c;小程序来引领&#xff01; Hey小伙伴们&#xff0c;是不是还在为找不到合适的学习资源而烦恼&#xff1f;或是厌倦了传统教育模式的单调&#xff1f;今…

Monaco 使用 SignatureHelpProvider

Monaco 中 SignatureHelpProvider 是方法提示说明&#xff0c;当敲入方法名时&#xff0c;系统会提示方法名称和对应的参数信息。效果如下&#xff1a; 通过 registerSignatureHelpProvider 实现 SignatureHelpProvider 处理函数。 实现 signatureHelpTriggerCharacters 和 pro…

我们如何优化 Elasticsearch Serverless 中的刷新成本

作者&#xff1a;来自 Elastic Francisco Fernndez Castao, Henning Andersen 最近&#xff0c;我们推出了 Elastic Cloud Serverless 产品&#xff0c;旨在提供在云中运行搜索工作负载的无缝体验。为了推出该产品&#xff0c;我们重新设计了 Elasticsearch&#xff0c;将存储与…

深入了解下 Markdown 的原理

前面讲了 Markdown 的基本语法&#xff0c;常见的 Markdown 编辑器&#xff0c;在继续讲解其他知识之前&#xff0c;有必要稍微深入了解一下 Markdown 与 HTML 的关系。 ‍ ‍ HTML 简介 什么是 HTML&#xff1f;其实它也是标记语言的一种&#xff0c;但是比 Markdown 更重…

Java面试题--JVM大厂篇之深入分析Parallel GC:从原理到优化

目录 引言: 正文&#xff1a; 1. Parallel GC原理解析 2. Parallel GC关键参数配置 3. 常见调优场景与技巧 4. 监控与日志分析 结束语&#xff1a; 引言: 在Java应用程序中&#xff0c;垃圾回收&#xff08;Garbage Collection, GC&#xff09;扮演着至关重要的角色。对…

【学术会议征稿】第三届图像处理、计算机视觉与机器学习国际学术会议(ICICML 2024)

第三届图像处理、计算机视觉与机器学习国际学术会议(ICICML 2024) 2024 3rd International Conference on Image Processing, Computer Vision and Machine Learning 重要信息 大会官网&#xff1a;参会投稿/了解会议详情 大会时间&#xff1a;2024年11月22日-24日 大会地…

大米cms支付逻辑漏洞

1.打开环境 注册账户 随机选择一个产品 修改数据

什么是折叠幼儿床?该如何认证?

​折叠幼儿床具有如下特征&#xff1a; 轻巧便携 用于睡眠的幼儿床&#xff0c;不使用时会折叠 有幼儿护栏&#xff0c;且必须带底板&#xff08;不包括没有地板的婴儿围栏&#xff09; 图片 亚马逊政策规定&#xff0c;通过亚马逊网站销售的折叠幼儿床必须符合特定标准的测…

视频转文字在线提取怎么弄?5款软件帮你解决

三伏天炎炎&#xff0c;阳光炽热&#xff0c;视频内容分享正当时。然而&#xff0c;在海量视频信息中快速提取关键信息却成了难题。试想&#xff0c;如果能一键将视频中的精彩讲解或会议要点转换成文字&#xff0c;岂不省时又高效&#xff1f; 那么问题来了&#xff0c;面对市…

项目实战--不推荐使用@Autowired实现注入

不推荐使用Autowired实现字段注入 一、前言二、字段注入2.1 字段注入的使用2.2 字段注入的弊端2.2.1 与Spring的IOC机制紧密耦合2.2.2 无法使用final修饰符2.2.3 隐藏依赖性2.2.4 无法对注入的属性进行安全检查2.2.5 掩饰单一职责的设计思想 三、设值注入四、构造器注入五、总结…

前端面试:项目细节重难点问题分享(十五)

更多详情&#xff1a;爱米的前端小笔记&#xff08;csdn~xitujuejin~zhiHu~Baidu~小红shu&#xff09;同步更新&#xff0c;等你来看&#xff01;都是利用下班时间整理的&#xff0c;整理不易&#xff0c;大家多多&#x1f44d;&#x1f49b;➕&#x1f914;哦&#xff01;你们…

ComfyUI 实战教程:图片添加文字

大家好&#xff0c;我是每天分享AI应用的萤火君&#xff01; 在AI绘画中书写文字一直是个老大难的问题&#xff0c;直到SDXL的出现&#xff0c;文字生成才迎来转机&#xff0c;可以在提示词中指定一些英文字符&#xff0c;不过也是经常出错&#xff0c;生成中文就更加不可求了…