当前位置: 首页 > news >正文

Learning vtkjs之WarpScalar

过滤器 WarpScalar

介绍

先看一个官方的一句话介绍:

vtkWarpScalar - deform geometry with scalar data

vtkWarpScalar - 使用标量数据变形几何体
详细介绍

vtkWarpScalar is a filter that modifies point coordinates by moving
points along point normals by the scalar amount times the scale
factor. Useful for creating carpet or x-y-z plots.

If normals are not present in data, the Normal instance variable will
be used as the direction along which to warp the geometry. If normals
are present but you would like to use the Normal instance variable,
set the UseNormal boolean to true.

If XYPlane boolean is set true, then the z-value is considered to be a
scalar value (still scaled by scale factor), and the displacement is
along the z-axis. If scalars are also present, these are copied
through and can be used to color the surface.

Note that the filter passes both its point data and cell data to its
output, except for normals, since these are distorted by the warping.

vtkWarpScalar是一个过滤器,它通过沿点法线移动点坐标,移动的距离是标量值乘以缩放因子来修改点坐标。这对于创建地毯图或x-y-z图非常有用。

如果数据中不存在法线,将使用Normal实例变量作为变形几何体的方向。如果数据中存在法线,但您想要使用Normal实例变量,请将UseNormal布尔值设置为true。

如果设置了XYPlane布尔值为true,那么z值将被视为标量值(仍然乘以缩放因子),位移将沿z轴进行。如果也存在标量值,这些值将被复制并通过它们可以用来给表面着色。

请注意,该过滤器将其点数据和单元数据传递到输出,但不包括法线,因为这些法线由于变形而发生了扭曲。

代码效果

wrapscralar
核心代码是:

//wrapscalar的过滤器const filter = vtkWarpScalar.newInstance({scaleFactor: 0.1,useNormal: false,});
//自定义的过滤器const randFilter = macro.newInstance((publicAPI, model) => {macro.obj(publicAPI, model); // make it an objectmacro.algo(publicAPI, model, 1, 1); // mixin algorithm code 1 in, 1 outpublicAPI.requestData = (inData, outData) => {console.log(inData[0].getPoints());// implement requestDataif (!outData[0] || inData[0].getMTime() > outData[0].getMTime()) {const newArray = new Float32Array(inData[0].getPoints().getNumberOfPoints());for (let i = 0; i < newArray.length; i++) {// newArray[i] = i % 2 ? 1 : 0;// scalar是随机newArray[i] = Math.random();}const da = vtkDataArray.newInstance({name: "spike",values: newArray,});const newDataSet = vtk({ vtkClass: inData[0].getClassName() });// 浅拷贝数据newDataSet.shallowCopy(inData[0]);newDataSet.getPointData().setScalars(da);outData[0] = newDataSet;}};})();randFilter.setInputConnection(planeSource.getOutputPort());filter.setInputConnection(randFilter.getOutputPort());mapper.setInputConnection(filter.getOutputPort());// Select array to processfilter.setInputArrayToProcess(0, "spike", "PointData", "Scalars");

打印了一下中间数据inData[0].getPoints().getData()
在这里插入图片描述
总共是363个数据,表示是121个点,因为我们平面是10 X10分段的,意味着有(10+1)X(10+1)个点,没错。
其实这个过滤器还有一个问题就是目前看,每次都要从上次数据里面拷贝数据过来,如果过滤器多了,这个数据不清楚释放的是否及时。


如果scalar变成这个值:newArray[i] = i % 2 ? 1 : 0;显示效果是
在这里插入图片描述
这个用来做地形图和热力图会比较有场景

全部代码都放到github上了
新坑_Learning vtkjs_git地址
关注我,我持续更新vtkjs的example学习案例

也欢迎各位给我提意见,技术交流~

大鸿

WeChat : HugeYen
WeChat Public Account : BIM树洞

做一个静谧的树洞君

用建筑的语言描述IT事物;

用IT的思维解决建筑问题;

共建BIM桥梁,聚合团队。

本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • HOW - 保证 WebSocket 持续正常连接
  • [解决方法]Request failed with status code 500错误之一
  • AI测试入门(1):认识AI大语言模型(LLM)
  • nodejs安装+踩坑报错解决
  • django报错(二):NotSupportedError:MySQL 8 or later is required (found 5.7.43)
  • Python 基础——列表(list)
  • Xcode如何创建多个工程
  • 提高Java程序效率:ImmutableList、Stream API 和 JSON序列化实战指南
  • 【保姆级】Python项目部署到Linux生产环境(uwsgi+python+flask+nginx服务器)
  • python编程技巧——list计算
  • 继承与多态 Java
  • macOS 环境Qt Creator 快捷键
  • SimMIM:一个类BERT的计算机视觉的预训练框架
  • vue学习笔记(十)——Vuex(状态管理,组件间共享数据)
  • 极狐GitLab 如何管理 PostgreSQL 扩展?
  • 【399天】跃迁之路——程序员高效学习方法论探索系列(实验阶段156-2018.03.11)...
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • DataBase in Android
  • Essential Studio for ASP.NET Web Forms 2017 v2,新增自定义树形网格工具栏
  • Java 最常见的 200+ 面试题:面试必备
  • JavaScript学习总结——原型
  • Java的Interrupt与线程中断
  • js ES6 求数组的交集,并集,还有差集
  • Linux链接文件
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • Redis的resp协议
  • Sublime text 3 3103 注册码
  • TypeScript迭代器
  • Vue小说阅读器(仿追书神器)
  • 动手做个聊天室,前端工程师百无聊赖的人生
  • 聊聊flink的TableFactory
  • 目录与文件属性:编写ls
  • 前端面试题总结
  • 使用 Docker 部署 Spring Boot项目
  • 要让cordova项目适配iphoneX + ios11.4,总共要几步?三步
  • 移动端唤起键盘时取消position:fixed定位
  • - 转 Ext2.0 form使用实例
  • media数据库操作,可以进行增删改查,实现回收站,隐私照片功能 SharedPreferences存储地址:
  • 阿里云IoT边缘计算助力企业零改造实现远程运维 ...
  • #Datawhale AI夏令营第4期#多模态大模型复盘
  • #Ubuntu(修改root信息)
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (23)Linux的软硬连接
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (Spark3.2.0)Spark SQL 初探: 使用大数据分析2000万KF数据
  • (层次遍历)104. 二叉树的最大深度
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (四) Graphivz 颜色选择
  • (四)opengl函数加载和错误处理
  • (学习日记)2024.01.19
  • (一)VirtualBox安装增强功能
  • (转)Linux整合apache和tomcat构建Web服务器
  • (转)项目管理杂谈-我所期望的新人