-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/center tool #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/center tool #379
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d249f8f
temp logic
MaxNumerique 6a59f77
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique 4796cb2
logs
MaxNumerique a0dd6c5
yes
MaxNumerique 5070295
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique 3c680e4
refacto
MaxNumerique 8b9e83f
refacto applySnapshot for importStores and add crosshair
MaxNumerique 905ef93
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique 9aa9008
rm constants.js
MaxNumerique 43cf256
refacto
MaxNumerique 5bcd39c
move utils/hybrid_viewer into internal/stores/
MaxNumerique 743cd94
applyCameraOptions import
MaxNumerique 484f650
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique f8ed019
Merge branch 'feat/center-tool' of https://github.com/Geode-solutions…
MaxNumerique fb748fb
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique 2e470d4
Merge branch 'feat/center-tool' of https://github.com/Geode-solutions…
MaxNumerique 884ab05
fix(centerTool): pick to re-center camera
MaxNumerique File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
|
MaxNumerique marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,26 @@ | ||
| import { SHORT_ANIMATION_DURATION } from "@ogw_front/utils/vtk/constants"; | ||
| import { dot } from "@kitware/vtk.js/Common/Core/Math"; | ||
|
|
||
| const RGB_MAX = 255; | ||
| const BACKGROUND_GREY_VALUE = 180; | ||
| const ACTOR_DARK_VALUE = 20; | ||
|
|
||
| const BACKGROUND_COLOR = [ | ||
| BACKGROUND_GREY_VALUE / RGB_MAX, | ||
| BACKGROUND_GREY_VALUE / RGB_MAX, | ||
| BACKGROUND_GREY_VALUE / RGB_MAX, | ||
| ]; | ||
| const ACTOR_COLOR = [ | ||
| ACTOR_DARK_VALUE / RGB_MAX, | ||
| ACTOR_DARK_VALUE / RGB_MAX, | ||
| ACTOR_DARK_VALUE / RGB_MAX, | ||
| ]; | ||
| const WHEEL_TIME_OUT_MS = 600; | ||
| const BUMP_MULTIPLIER = 0.2; | ||
| const ALIGNMENT_THRESHOLD = 0.9; | ||
| const LONG_ANIMATION_DURATION = 1000; | ||
| const SHORT_ANIMATION_DURATION = 500; | ||
| const EASE_EXPONENT = 1.1; | ||
|
|
||
| const SAMPLE_SIZE = 10; | ||
| const TOTAL_CHANNELS = 400; | ||
| const RGBA_CHANNELS = 4; | ||
|
|
@@ -95,6 +115,42 @@ function computeAverageBrightness(rect, options) { | |
| } | ||
| } | ||
|
|
||
| function centerCameraOnPosition(camera, pickedPosition) { | ||
| if (!camera || !pickedPosition) { | ||
| return; | ||
| } | ||
| const focalPoint = camera.getFocalPoint(); | ||
| const position = camera.getPosition(); | ||
| camera.setFocalPoint(...pickedPosition); | ||
| camera.setPosition( | ||
| position[0] + pickedPosition[0] - focalPoint[0], | ||
| position[1] + pickedPosition[1] - focalPoint[1], | ||
| position[2] + pickedPosition[2] - focalPoint[2], | ||
| ); | ||
| } | ||
|
|
||
| function performClickPicking(event, options) { | ||
| const { container, viewerStore, viewer_schemas, genericRenderWindow, syncRemoteCamera } = options; | ||
| const rect = container.getBoundingClientRect(); | ||
| viewerStore.request( | ||
| viewer_schemas.opengeodeweb_viewer.viewer.get_point_position, | ||
| { | ||
| x: Math.round(event.clientX - rect.left), | ||
| y: Math.round(rect.height - (event.clientY - rect.top)), | ||
| }, | ||
| { | ||
| response_function: ({ x, y, z }) => { | ||
| const pickedPos = [x, y, z]; | ||
| if (pickedPos.some((val) => val !== 0)) { | ||
| centerCameraOnPosition(genericRenderWindow.getRenderer().getActiveCamera(), pickedPos); | ||
| genericRenderWindow.getRenderWindow().render(); | ||
| syncRemoteCamera(); | ||
| } | ||
| }, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logique pour center on click |
||
| function animateCamera(options) { | ||
| const { | ||
| camera, | ||
|
|
@@ -140,10 +196,81 @@ function animateCamera(options) { | |
| requestAnimationFrame(animate); | ||
| } | ||
|
|
||
| async function applySnapshot(snapshot, options) { | ||
| const { genericRenderWindow, setZScaling, syncRemoteCamera } = options; | ||
| if (!snapshot) { | ||
| return; | ||
| } | ||
| const z_scale = snapshot.zScale; | ||
| if (typeof z_scale === "number") { | ||
| await setZScaling(z_scale); | ||
| } | ||
| const { camera_options: snapshot_camera_options } = snapshot; | ||
| if (snapshot_camera_options) { | ||
| applyCameraOptions( | ||
| genericRenderWindow.getRenderer().getActiveCamera(), | ||
| snapshot_camera_options, | ||
| ); | ||
| genericRenderWindow.getRenderWindow().render(); | ||
| syncRemoteCamera(); | ||
| } | ||
| } | ||
|
|
||
| function performCameraOrientation(orientation, options) { | ||
| const { genericRenderWindow, is_moving, imageStyle, syncRemoteCamera, constants } = options; | ||
| const config = ORIENTATIONS[orientation.toLowerCase()]; | ||
| const renderer = genericRenderWindow.getRenderer(); | ||
| const camera = renderer.getActiveCamera(); | ||
| const startState = getCameraOptions(camera); | ||
|
|
||
| applyCameraOptions(camera, { | ||
| ...config, | ||
| focal_point: [0, 0, 0], | ||
| }); | ||
| renderer.resetCamera(); | ||
| const targetState = getCameraOptions(camera); | ||
|
|
||
| applyCameraOptions(camera, startState); | ||
|
|
||
| const alignment = dot(camera.getDirectionOfProjection(), config.position); | ||
| const duration = | ||
| alignment > constants.ALIGNMENT_THRESHOLD | ||
| ? constants.LONG_ANIMATION_DURATION | ||
| : constants.SHORT_ANIMATION_DURATION; | ||
| is_moving.value = true; | ||
| imageStyle.opacity = 0; | ||
|
|
||
| animateCamera({ | ||
| camera, | ||
| startState, | ||
| targetState, | ||
| duration, | ||
| bumpMultiplier: constants.BUMP_MULTIPLIER, | ||
| easeExponent: constants.EASE_EXPONENT, | ||
| onUpdate: () => genericRenderWindow.getRenderWindow().render(), | ||
| onEnd: () => { | ||
| is_moving.value = false; | ||
| syncRemoteCamera(); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export { | ||
| BACKGROUND_COLOR, | ||
| ACTOR_COLOR, | ||
| WHEEL_TIME_OUT_MS, | ||
| BUMP_MULTIPLIER, | ||
| ALIGNMENT_THRESHOLD, | ||
| LONG_ANIMATION_DURATION, | ||
| SHORT_ANIMATION_DURATION, | ||
| EASE_EXPONENT, | ||
| ORIENTATIONS, | ||
| animateCamera, | ||
| applyCameraOptions, | ||
| applySnapshot, | ||
| centerCameraOnPosition, | ||
| computeAverageBrightness, | ||
| getCameraOptions, | ||
| performCameraOrientation, | ||
| performClickPicking, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logique pour center on click