过滤器 阈值过滤器
介绍
vtkThresholdPoints - 提取满足阈值条件的点
vtkThresholdPoints 是一个过滤器,它从数据集中提取满足阈值条件的点。该条件可以采用三种形式:
1)大于特定值;
2) 小于特定值;
3) 在特定值之间。
过滤器的输出是多边形数据。
效果
核心代码
主要流程
// ----------------------------------------------------------------------------// Standard rendering code setup// ----------------------------------------------------------------------------const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({background: [0.9, 0.9, 0.9],rootContainer: vtkContainerRef.current,});const renderer = fullScreenRenderer.getRenderer();const renderWindow = fullScreenRenderer.getRenderWindow();// ----------------------------------------------------------------------------// Example code// ----------------------------------------------------------------------------const lookupTable = vtkLookupTable.newInstance({ hueRange: [0.666, 0] });const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });reader.setUrl(BaseUrlPross("/data/cow.vtp")).then(() => {reader.loadData().then(() => {renderer.resetCamera();renderWindow.render();});});const calc = vtkCalculator.newInstance();calc.setInputConnection(reader.getOutputPort());calc.setFormula({getArrays: (inputDataSets) => ({input: [{ location: FieldDataTypes.COORDINATE }], // Require point coordinates as inputoutput: [// Generate two output arrays:{location: FieldDataTypes.POINT, // This array will be point-data ...name: 'sine wave', // ... with the given name ...dataType: 'Float64Array', // ... of this type ...attribute: AttributeTypes.SCALARS, // ... and will be marked as the default scalars.},{location: FieldDataTypes.UNIFORM, // This array will be field data ...name: 'global', // ... with the given name ...dataType: 'Float32Array', // ... of this type ...numberOfComponents: 1, // ... with this many components ...tuples: 1, // ... and this many tuples.},],}),evaluate: (arraysIn, arraysOut) => {// Convert in the input arrays of vtkDataArrays into variables// referencing the underlying JavaScript typed-data arrays:const [coords] = arraysIn.map((d) => d.getData());const [sine, glob] = arraysOut.map((d) => d.getData());// Since we are passed coords as a 3-component array,// loop over all the points and compute the point-data output:for (let i = 0, sz = coords.length / 3; i < sz; ++i) {const dx = coords[3 * i] - 0.5;const dy = coords[3 * i + 1] - 0.5;sine[i] = 10 * dx * dx + dy * dy;}// Use JavaScript's reduce method to sum the output// point-data array and set the uniform array's value:glob[0] = sine.reduce((result, value) => result + value, 0);// Mark the output vtkDataArray as modifiedarraysOut.forEach((x) => x.modified());},});const mapper = vtkMapper.newInstance({interpolateScalarsBeforeMapping: true,colorMode: ColorMode.DEFAULT,scalarMode: ScalarMode.DEFAULT,useLookupTableScalarRange: true,lookupTable,});const actor = vtkActor.newInstance();actor.getProperty().setEdgeVisibility(true);const scalarBarActor = vtkScalarBarActor.newInstance();scalarBarActor.setScalarsToColors(lookupTable);renderer.addActor(scalarBarActor);const thresholder = vtkThresholdPoints.newInstance();thresholder.setInputConnection(calc.getOutputPort());mapper.setInputConnection(thresholder.getOutputPort());actor.setMapper(mapper);renderer.addActor(actor);context.current = {renderer,renderWindow,mapper,thresholder,};
全部代码都放到github上了
新坑_Learning vtkjs_git地址
关注我,我持续更新vtkjs的example学习案例
也欢迎各位给我提意见,技术交流~
大鸿
WeChat : HugeYen
WeChat Public Account : BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!