隐式函数布尔操作
介绍
vtkImplicitBoolean 允许对隐式函数(如平面、球体、圆柱体和盒子)进行布尔组合。操作包括并集、交集和差集。可以指定多个隐式函数(所有函数都使用相同的操作进行组合)。
支持的操作:'UNION'(<=0),'INTERSECTION'(=1),'DIFFERENCE'(>=2)
效果

核心代码
主要是隐式函数添加,然后执行操作,可视化是需要借助vtkSampleFunction来采样的
javascript
const lCylCut = vtkImplicitBoolean.newInstance({
operation: Operation.UNION,
functions: [cyl, pLeft],
});
const rCylCut = vtkImplicitBoolean.newInstance({
operation: Operation.INTERSECTION,
});
rCylCut.addFunction(lCylCut);
rCylCut.addFunction(pRight);
完整逻辑
javascript
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 pipeline. Boolean together some implicit functions and then sample, isosurface them
const pLeft = vtkSphere.newInstance({
center: [-6.0, 0, 0],
radius: 0.8,
});
const pRight = vtkPlane.newInstance({
normal: [1, 0, 0],
origin: [5, 0, 0],
});
const cyl = vtkCylinder.newInstance({
radius: 0.5,
center: [0, 0, 0],
axis: [1, 0, 0],
});
const lCylCut = vtkImplicitBoolean.newInstance({
operation: Operation.UNION,
functions: [cyl, pLeft],
});
const rCylCut = vtkImplicitBoolean.newInstance({
operation: Operation.INTERSECTION,
});
rCylCut.addFunction(lCylCut);
rCylCut.addFunction(pRight);
const sample = vtkSampleFunction.newInstance({
implicitFunction: rCylCut,
sampleDimensions: [100, 100, 100],
modelBounds: [-7.5, 7.5, -1, 1, -1, 1],
});
const mCubes = vtkImageMarchingCubes.newInstance({ contourValue: 0.0 });
// Connect the pipeline proper
mCubes.setInputConnection(sample.getOutputPort());
mapper.setInputConnection(mCubes.getOutputPort());
renderer.resetCamera();
renderWindow.render();
全部代码都放到github上了
新坑_Learning vtkjs_git地址
关注我,我持续更新vtkjs的example学习案例
也欢迎各位给我提意见,技术交流~
大鸿
WeChat : HugeYen
WeChat Public Account : BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!