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

Learning vtkjs之ImageMarchingSquares

体积 等值线处理

介绍

vtkImageMarchingSquares - 对图像(或来自体积的切片)进行等值线处理

给定一个指定的等值,使用Marching Squares算法(3D Marching Cubes算法的2D版本)生成等值线。

效果

在这里插入图片描述
自己增加了两个小球,主要是对比一下ISO前后的效果

核心代码

参数更新

const updateParam = (value) => {const { mSquares, renderWindow } = context.current;mSquares.setSlicingMode(value);setState({...state,slicingMode: value,});renderWindow.render();};

主要流程

const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({background: [0, 0, 0],rootContainer: vtkContainerRef.current,});const renderer = fullScreenRenderer.getRenderer();const renderWindow = fullScreenRenderer.getRenderWindow();const { Operation } = vtkImplicitBoolean;const actor = vtkActor.newInstance();renderer.addActor(actor);const mapper = vtkMapper.newInstance();actor.setMapper(mapper);// Build pipelineconst sphere = vtkSphere.newInstance({center: [-2.5, 0.0, 0.0],radius: 3.0,});const sphere2 = vtkSphere.newInstance({center: [2.5, 0.0, 0.0],radius: 0.5,});// const plane = vtkPlane.newInstance({ origin: [0, 0, 0], normal: [0, 1, 0] });const impBool = vtkImplicitBoolean.newInstance({operation: Operation.UNION,functions: [sphere, sphere2],});const sample = vtkSampleFunction.newInstance({implicitFunction: impBool,sampleDimensions: [50, 50, 50],modelBounds: [-5.0, 5.0, -2.0, 2.0, -1.0, 1.0],});// Isocontourconst mSquares = vtkImageMarchingSquares.newInstance({ slice: 1 });mSquares.setSlicingMode(2);// Connect the pipeline propermSquares.setInputConnection(sample.getOutputPort());mapper.setInputConnection(mSquares.getOutputPort());// Update the pipeline to obtain metadata (range) about scalarssample.update();const cValues = [];const [min, max] = sample.getOutputData().getPointData().getScalars().getRange();const step = 20;for (let i = 0; i < step; ++i) {cValues[i] = min + (i / (step - 1)) * (max - min);}mSquares.setContourValues(cValues);mSquares.setSlice(25);// Create an outline// Bounding boxconst outline = vtkOutlineFilter.newInstance();outline.setInputConnection(sample.getOutputPort());const outlineMapper = vtkMapper.newInstance();outlineMapper.setInputConnection(outline.getOutputPort());const outlineActor = vtkActor.newInstance();outlineActor.setMapper(outlineMapper);renderer.addActor(outlineActor);context.current = {mSquares,renderer,renderWindow,};// 同步sphereconst sphereReference = createSphere([-2.5, 0.0, 0.0], 3.0);renderer.addActor(sphereReference);const sphereReference2 = createSphere([2.5, 0.0, 0.0], 0.5);renderer.addActor(sphereReference2);renderer.resetCamera();renderWindow.render();

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

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

大鸿

WeChat : HugeYen
WeChat Public Account : BIM树洞

做一个静谧的树洞君

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

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

共建BIM桥梁,聚合团队。

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

相关文章:

  • 在Java中使用Files类的copy()方法复制文件的示例
  • Ubuntu20.04安装NVIDIA Warp
  • 【数据结构】——顺序表刷题
  • Linux远程管理
  • WPACS基于HTML5的DICOM影像浏览
  • 92.一个简单的输入与显示示例 Maui例子 C#例子
  • 【计算机视觉】目标检测:深度解析MMDetection:OpenMMLab开源目标检测框架实战指南
  • C++中std::map、std::list和std::deque的底层实现是怎样的?
  • 2025 新生 DL-FWI 培训
  • MT6765 android上层获取VCM lens位置
  • 上海地区IDC机房服务器托管选型报告(2025年4月30日)
  • Power Automate:发送邮件时加入表格
  • pinia实现数据持久化插件pinia-plugin-persist-uni
  • w313安康学院新型冠状病毒肺炎疫情防控专题网站设计与实现
  • MySQL慢查询日志分析工具mysqldumpslow教程
  • Roboflow标注数据集
  • 【MCP Node.js SDK 全栈进阶指南】高级篇(6):MCP服务大规模部署方案
  • 安卓AppWidget桌面小组件在国产移动设备的一些适配问题
  • 驱动车辆诊断测试创新 | 支持诊断测试的模拟器及数据文件转换生成
  • pybind11 使用指南+示例
  • 图忆|上海车展40年:中国人的梦中情车有哪些变化(下)
  • 龚正盛秋平王晓真共同启动2025国际消费季暨第六届上海“五五购物节”
  • 遍体鳞伤就是击不倒,这是国米老男孩最后的倔强
  • 滨江集团:一季度营收225.07亿元,净利润9.75亿元
  • 中央宣传部、全国总工会联合发布2025年“最美职工”先进事迹
  • 为治理商家“卷款跑路”“退卡难”,预付式消费司法解释5月起实施