|
| 1 | +import test from 'tape'; |
| 2 | +import testUtils from 'vtk.js/Sources/Testing/testUtils'; |
| 3 | + |
| 4 | +import 'vtk.js/Sources/Rendering/OpenGL/RenderWindow'; |
| 5 | +import 'vtk.js/Sources/Rendering/OpenGL/Camera'; |
| 6 | +import 'vtk.js/Sources/Rendering/OpenGL/Renderer'; |
| 7 | +import 'vtk.js/Sources/Rendering/OpenGL/Actor'; |
| 8 | +import 'vtk.js/Sources/Rendering/OpenGL/PolyDataMapper'; |
| 9 | + |
| 10 | +import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow'; |
| 11 | +import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer'; |
| 12 | +import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; |
| 13 | +import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; |
| 14 | +import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; |
| 15 | +import { FieldAssociations } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants'; |
| 16 | + |
| 17 | +test('Test HardwareSelector', (tapeContext) => { |
| 18 | + const gc = testUtils.createGarbageCollector(tapeContext); |
| 19 | + tapeContext.ok('rendering', 'vtkHardwareSelector TestHardwareSelector'); |
| 20 | + |
| 21 | + // Create some control UI |
| 22 | + const container = document.querySelector('body'); |
| 23 | + const renderWindowContainer = gc.registerDOMElement( |
| 24 | + document.createElement('div') |
| 25 | + ); |
| 26 | + container.appendChild(renderWindowContainer); |
| 27 | + |
| 28 | + // Create a polydata with many cells to force high24 pass |
| 29 | + // 17 million vert cells and one poly cell (a triangle) |
| 30 | + const bigPolydata = gc.registerResource(vtkPolyData.newInstance()); |
| 31 | + const numberOfVerts = 17_000_000; |
| 32 | + // Points of the triangle |
| 33 | + const pointsData = Float32Array.from([ |
| 34 | + ...[0, 0, 0], |
| 35 | + ...[1, 0, 0], // This point will be also for verts |
| 36 | + ...[0.5, 0.7, 0], |
| 37 | + ]); |
| 38 | + bigPolydata.getPoints().setData(pointsData, 3); |
| 39 | + // The triangle cell |
| 40 | + const polysData = Uint32Array.from([3, 0, 1, 2]); |
| 41 | + bigPolydata.getPolys().setData(polysData, 1); |
| 42 | + // The vert cells, all using the point of index 1 |
| 43 | + const vertsData = new Uint32Array(2 * numberOfVerts); |
| 44 | + vertsData.fill(1); |
| 45 | + bigPolydata.getVerts().setData(vertsData, 1); |
| 46 | + |
| 47 | + // Setup the rest of the rendering pipeline, from mapper to OpenGL render window |
| 48 | + const mapper = gc.registerResource(vtkMapper.newInstance()); |
| 49 | + mapper.setInputData(bigPolydata); |
| 50 | + |
| 51 | + const actor = gc.registerResource(vtkActor.newInstance()); |
| 52 | + actor.setMapper(mapper); |
| 53 | + |
| 54 | + const renderer = gc.registerResource(vtkRenderer.newInstance()); |
| 55 | + renderer.setBackground(0.32, 0.34, 0.43); |
| 56 | + renderer.addActor(actor); |
| 57 | + |
| 58 | + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); |
| 59 | + renderWindow.addRenderer(renderer); |
| 60 | + |
| 61 | + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); |
| 62 | + glwindow.setContainer(renderWindowContainer); |
| 63 | + glwindow.setSize(400, 400); |
| 64 | + renderWindow.addView(glwindow); |
| 65 | + |
| 66 | + // Render to make set up the rendering pipeline |
| 67 | + renderWindow.render(); |
| 68 | + |
| 69 | + // Selector |
| 70 | + const selector = glwindow.getSelector(); |
| 71 | + selector.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_CELLS); |
| 72 | + selector.setCaptureZValues(false); |
| 73 | + selector.attach(glwindow, renderer); |
| 74 | + selector.setArea(200, 200, 200, 200); |
| 75 | + |
| 76 | + const bufferCaptured = selector.captureBuffers(); |
| 77 | + tapeContext.ok(bufferCaptured, 'Selector captured buffer'); |
| 78 | + |
| 79 | + const info = selector.getPixelInformation([200, 200], 0, [0, 0]); |
| 80 | + tapeContext.equal(info?.attributeID, numberOfVerts, 'Last triangle picked'); |
| 81 | + |
| 82 | + gc.releaseResources(); |
| 83 | +}); |
0 commit comments