過濾器 閾值過濾器
介紹
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橋梁,聚合團隊。
本學習分享資料不得用于商業用途,僅做學習交流!!如有侵權立即刪除!!