From 133c48579f06eaafae0c6fc99dcff8dcb272f230 Mon Sep 17 00:00:00 2001 From: yrs224 Date: Sat, 17 Jul 2021 12:57:41 +0800 Subject: [PATCH 1/2] fix(Coordinate): Incorrect coordinate calculation for multiple view ports. --- Sources/Rendering/Core/Coordinate/index.js | 28 ++++++++++++++++--- .../SceneGraph/RenderWindowViewNode/index.js | 4 +-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Sources/Rendering/Core/Coordinate/index.js b/Sources/Rendering/Core/Coordinate/index.js index 5a228fd2fd8..6360c4b55ae 100644 --- a/Sources/Rendering/Core/Coordinate/index.js +++ b/Sources/Rendering/Core/Coordinate/index.js @@ -428,7 +428,12 @@ function vtkCoordinate(publicAPI, model) { val = renderer.viewToProjection(val[0], val[1], val[2], aspect); val = renderer.projectionToNormalizedViewport(val[0], val[1], val[2]); - val = view.normalizedViewportToViewport(val[0], val[1], val[2]); + val = view.normalizedViewportToViewport( + val[0], + val[1], + val[2], + renderer + ); val = view.viewportToNormalizedDisplay( val[0], val[1], @@ -441,7 +446,12 @@ function vtkCoordinate(publicAPI, model) { case Coordinate.VIEW: { val = renderer.viewToProjection(val[0], val[1], val[2], aspect); val = renderer.projectionToNormalizedViewport(val[0], val[1], val[2]); - val = view.normalizedViewportToViewport(val[0], val[1], val[2]); + val = view.normalizedViewportToViewport( + val[0], + val[1], + val[2], + renderer + ); val = view.viewportToNormalizedDisplay( val[0], val[1], @@ -453,7 +463,12 @@ function vtkCoordinate(publicAPI, model) { } case Coordinate.PROJECTION: { val = renderer.projectionToNormalizedViewport(val[0], val[1], val[2]); - val = view.normalizedViewportToViewport(val[0], val[1], val[2]); + val = view.normalizedViewportToViewport( + val[0], + val[1], + val[2], + renderer + ); val = view.viewportToNormalizedDisplay( val[0], val[1], @@ -464,7 +479,12 @@ function vtkCoordinate(publicAPI, model) { break; } case Coordinate.NORMALIZED_VIEWPORT: { - val = view.normalizedViewportToViewport(val[0], val[1], val[2]); + val = view.normalizedViewportToViewport( + val[0], + val[1], + val[2], + renderer + ); if (model.referenceCoordinate) { const refValue = model.referenceCoordinate.getComputedDoubleViewportValue( diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index 27ed4618f0b..c6eb66a9e85 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -117,8 +117,8 @@ function vtkRenderWindowViewNode(publicAPI, model) { return [x, y, z]; }; - publicAPI.normalizedViewportToViewport = (x, y, z) => { - const size = publicAPI.getFramebufferSize(); + publicAPI.normalizedViewportToViewport = (x, y, z, renderer) => { + const size = publicAPI.getViewportSize(renderer); return [x * (size[0] - 1.0), y * (size[1] - 1.0), z]; }; From 6483b77b7305f8ffcf4dcf40f6926f3ec426a15f Mon Sep 17 00:00:00 2001 From: yrs224 Date: Tue, 20 Jul 2021 13:55:05 +0800 Subject: [PATCH 2/2] test(Coordinate): Added multi renderers test. --- .../Core/Coordinate/test/testCoordinate.js | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/Sources/Rendering/Core/Coordinate/test/testCoordinate.js b/Sources/Rendering/Core/Coordinate/test/testCoordinate.js index 7c9a6d7b241..65c4f5fb2d8 100644 --- a/Sources/Rendering/Core/Coordinate/test/testCoordinate.js +++ b/Sources/Rendering/Core/Coordinate/test/testCoordinate.js @@ -113,6 +113,169 @@ test('Test vtkCoordinate publicAPI', (t) => { viewPort = [50.0, 50.0]; testGetters(coord, renderer, testVal, world, display, localDisplay, viewPort); + // --------------------- Multi Renderers + // In my previous test, some view ports were normal and some not. so create a 2x2 grid view to test. + const renderers = new Array(4); + for (let i = 0; i < renderers.length; i++) { + const ren = gc.registerResource(vtkRenderer.newInstance()); + /* index order + 0 1 + 2 3 + */ + const x = (i % 2) * 0.5; + const y = 1 - Math.floor(i / 2) * 0.5; + ren.setViewport(x, y - 0.5, x + 0.5, y); + ren.setActiveCamera(vtkCamera.newInstance()); + renderWindow.addRenderer(ren); + renderers[i] = ren; + } + + coord.setCoordinateSystemToWorld(); + testVal = [0.0, 0.0, 0.0]; + world = [0.0, 0.0, 0.0]; + let displays = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + let localDisplays = [ + [25.0, 24.0], + [75.0, 24.0], + [25.0, 74.0], + [75.0, 74.0], + ]; + viewPort = [25.0, 25.0]; + + for (let i = 0; i < renderers.length; i++) { + testGetters( + coord, + renderers[i], + testVal, + world, + displays[i], + localDisplays[i], + viewPort + ); + } + + coord.setCoordinateSystemToDisplay(); + testVal = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + world = [0.0, 0.0, 0.99]; + displays = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + localDisplays = [ + [25.0, 24.0], + [75.0, 24.0], + [25.0, 74.0], + [75.0, 74.0], + ]; + viewPort = [25.0, 25.0]; + for (let i = 0; i < renderers.length; i++) { + testGetters( + coord, + renderers[i], + testVal[i], + world, + displays[i], + localDisplays[i], + viewPort + ); + } + + coord.setCoordinateSystemToViewport(); + testVal = [25.0, 25.0, 0.0]; + world = [0.0, 0.0, 0.99]; + displays = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + localDisplays = [ + [25.0, 24.0], + [75.0, 24.0], + [25.0, 74.0], + [75.0, 74.0], + ]; + viewPort = [25.0, 25.0]; + for (let i = 0; i < renderers.length; i++) { + testGetters( + coord, + renderers[i], + testVal, + world, + displays[i], + localDisplays[i], + viewPort + ); + } + + coord.setCoordinateSystemToNormalizedViewport(); + testVal = [0.5, 0.5, 0.0]; + world = [0.0, 0.0, 0.99]; + displays = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + localDisplays = [ + [25.0, 24.0], + [75.0, 24.0], + [25.0, 74.0], + [75.0, 74.0], + ]; + viewPort = [25.0, 25.0]; + for (let i = 0; i < renderers.length; i++) { + testGetters( + coord, + renderers[i], + testVal, + world, + displays[i], + localDisplays[i], + viewPort + ); + } + + coord.setCoordinateSystemToView(); + testVal = [0.0, 0.0, 0.0]; + world = [0.0, 0.0, 1.0]; + displays = [ + [25.0, 75.0], + [75.0, 75.0], + [25.0, 25.0], + [75.0, 25.0], + ]; + localDisplays = [ + [25.0, 24.0], + [75.0, 24.0], + [25.0, 74.0], + [75.0, 74.0], + ]; + viewPort = [25.0, 25.0]; + for (let i = 0; i < renderers.length; i++) { + testGetters( + coord, + renderers[i], + testVal, + world, + displays[i], + localDisplays[i], + viewPort + ); + } + // --------------------- Add a specific renderer coord.setRenderer(renderer);