Learning vtkjs之ImageMarchingCubes
体积 等值面处理
介绍
vtkImageMarchingCubes - 对体积进行等值面处理
给定一个指定的等值,使用Marching Cubes算法生成一个等值面。
效果
新建了一个球,对比一下原始的(透明的)和ISO的效果
核心代码
参数部分
const updateParam = (type, obj) => {const { sample, sphere, sphereSource, mCubes, renderWindow } =context.current;let value;switch (type) {case "volumeResolution":value = obj.volumeResolution;sample.setSampleDimensions(value, value, value);renderWindow.render();setState({ ...state, ...obj });break;case "isoValue":value = obj.isoValue;mCubes.setContourValue(value);console.log(value);renderWindow.render();setState({ ...state, ...obj });break;case "sphereRadius":value = obj.sphereRadius;sphere.setRadius(value); renderWindow.render();setState({ ...state, ...obj });break;case "computeNormals":value = obj.computeNormals;mCubes.setComputeNormals(!!value);renderWindow.render();setState({ ...state, ...obj });break;case "mergePoints":value = obj.mergePoints;mCubes.setMergePoints(!!value);renderWindow.render();setState({ ...state, ...obj });break;default:break;}};
主体流程
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({background: [0, 0, 0],rootContainer: vtkContainerRef.current,});const renderer = fullScreenRenderer.getRenderer();const renderWindow = fullScreenRenderer.getRenderWindow();const actor = vtkActor.newInstance();renderer.addActor(actor);const mapper = vtkMapper.newInstance();actor.setMapper(mapper);// Build pipelineconst radius = 1;const sampleDimension = 50;const sphere = vtkSphere.newInstance({center: [0.0, 0.0, 0.0],radius: radius,});// value of implicit function // x = x1 - center// x*x + y*y + z*z - R*R = valueconst sample = vtkSampleFunction.newInstance({implicitFunction: sphere,sampleDimensions: [sampleDimension, sampleDimension, sampleDimension],modelBounds: [-radius, radius, -radius, radius, -radius, radius],});// Create the isosurface by contourValueconst mCubes = vtkImageMarchingCubes.newInstance({ contourValue: 0.0 });// Connect the pipeline propermCubes.setInputConnection(sample.getOutputPort());mapper.setInputConnection(mCubes.getOutputPort());context.current = {sample,mCubes,sphere,renderer,renderWindow,};// 同步sphereconst sphereActor = createSphere();renderer.addActor(sphereActor);renderer.resetCamera();renderWindow.render();
全部代码都放到github上了
新坑_Learning vtkjs_git地址
关注我,我持续更新vtkjs的example学习案例
也欢迎各位给我提意见,技术交流~
大鸿
WeChat : HugeYen
WeChat Public Account : BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!