-
Notifications
You must be signed in to change notification settings - Fork 93
Polygon Tool: Add + Delete Points #396
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3456a7c
feat(polygon): add polyline representation between points
PaulHax b23b6ac
feat(polygon): add delete points by right click
PaulHax e9ec76b
feat(polygon): click to add point
PaulHax 38fe331
feat(polygon): when adding point to segment, drag immediately
PaulHax 6203d96
fix(polygon): dragging, release, dragging again without mouse move
PaulHax 23369f3
fix(polygon): dont add point on segment if over handle still
PaulHax 81c70a4
fix(polygon): stop deleting placed points on double click
PaulHax 0f44c9b
refactor(polygon): use LineGlyphRepresentation
PaulHax 15ee908
doc(toolbar): add edit polygon instructions
PaulHax 21e2c82
fix(polygon): easier pickable handles, behavior logic cleanup
PaulHax 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import macro from '@kitware/vtk.js/macros'; | ||
| import * as vtkMath from '@kitware/vtk.js/Common/Core/Math'; | ||
| import vtkGlyph3DMapper from '@kitware/vtk.js/Rendering/Core/Glyph3DMapper'; | ||
| import vtkGlyphRepresentation from '@kitware/vtk.js/Widgets/Representations/GlyphRepresentation'; | ||
| import { Behavior } from '@kitware/vtk.js/Widgets/Representations/WidgetRepresentation/Constants'; | ||
| import { allocateArray } from '@kitware/vtk.js/Widgets/Representations/WidgetRepresentation'; | ||
| import vtkCylinderSource from '@kitware/vtk.js/Filters/Sources/CylinderSource'; | ||
| import { OrientationModes } from '@kitware/vtk.js/Rendering/Core/Glyph3DMapper/Constants'; | ||
| import { getPixelWorldHeightAtCoord } from '@kitware/vtk.js/Widgets/Core/WidgetManager'; | ||
|
|
||
| function vtkLineGlyphRepresentation(publicAPI, model) { | ||
| model.classHierarchy.push('vtkLineGlyphRepresentation'); | ||
|
|
||
| publicAPI.setGlyphResolution = macro.chain( | ||
| publicAPI.setGlyphResolution, | ||
| model._pipeline.glyph.setResolution | ||
| ); | ||
| } | ||
|
|
||
| function cylinderScale(publicAPI, model) { | ||
| return (polyData, states) => { | ||
| model._pipeline.mapper.setScaleArray('scale'); | ||
| model._pipeline.mapper.setScaleFactor(1); | ||
| model._pipeline.mapper.setScaling(true); | ||
| model._pipeline.mapper.setScaleMode( | ||
| vtkGlyph3DMapper.ScaleModes.SCALE_BY_COMPONENTS | ||
| ); | ||
| const scales = allocateArray( | ||
| polyData, | ||
| 'scale', | ||
| states.length, | ||
| 'Float32Array', | ||
| 3 | ||
| ).getData(); | ||
| let j = 0; | ||
| for (let i = 0; i < states.length; ++i) { | ||
| const state = states[i]; | ||
| const origin = state.getOrigin(); | ||
| const nextOrigin = | ||
| states[i === states.length - 1 ? 0 : i + 1].getOrigin(); | ||
|
|
||
| const direction = vtkMath.subtract(nextOrigin, origin, []); | ||
| const length = vtkMath.normalize(direction); | ||
|
|
||
| let scaleFactor = state.getActive() ? model.activeScaleFactor : 1; | ||
| if (publicAPI.getScaleInPixels()) { | ||
| scaleFactor *= getPixelWorldHeightAtCoord( | ||
| state.getOrigin(), | ||
| model.displayScaleParams | ||
| ); | ||
| } | ||
| if (!model.forceLineThickness) { | ||
| scaleFactor *= state.getScale1?.() ?? 1; | ||
| } | ||
| const scale = [1, model.lineThickness, model.lineThickness]; | ||
| scales[j++] = length * scale[0]; | ||
| scales[j++] = scaleFactor * scale[1]; | ||
| scales[j++] = scaleFactor * scale[2]; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function cylinderDirection(publicAPI, model) { | ||
| return (polyData, states) => { | ||
| model._pipeline.mapper.setOrientationArray('orientation'); | ||
| model._pipeline.mapper.setOrientationMode(OrientationModes.MATRIX); | ||
| const orientation = allocateArray( | ||
| polyData, | ||
| 'orientation', | ||
| states.length, | ||
| 'Float32Array', | ||
| 9 | ||
| ).getData(); | ||
| for (let i = 0; i < states.length; ++i) { | ||
| const state = states[i]; | ||
| const origin = state.getOrigin(); | ||
| const nextOrigin = | ||
| states[i === states.length - 1 ? 0 : i + 1].getOrigin(); | ||
|
|
||
| const direction = vtkMath.subtract(nextOrigin, origin, []); | ||
| vtkMath.normalize(direction); | ||
| const right = [1, 0, 0]; | ||
| const up = [0, 1, 0]; | ||
| vtkMath.perpendiculars(direction, up, right, 0); | ||
|
|
||
| orientation.set(direction, 9 * i); | ||
| orientation.set(up, 9 * i + 3); | ||
| orientation.set(right, 9 * i + 6); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
| // Object factory | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| function defaultValues(publicAPI, model, initialValues) { | ||
| return { | ||
| behavior: Behavior.CONTEXT, | ||
| glyphResolution: 32, | ||
| lineThickness: 0.5, // radius of the cylinder | ||
| forceLineThickness: false, | ||
| ...initialValues, | ||
| _pipeline: { | ||
| glyph: | ||
| initialValues?.pipeline?.glyph ?? | ||
| vtkCylinderSource.newInstance({ | ||
| direction: [1, 0, 0], | ||
| center: [0.5, 0, 0], // origin of cylinder at end, not center | ||
| capping: false, | ||
| }), | ||
| ...initialValues?.pipeline, | ||
| }, | ||
| applyMixin: { | ||
| noScale: cylinderScale(publicAPI, model), | ||
| scale1: cylinderScale(publicAPI, model), | ||
| noOrientation: cylinderDirection(publicAPI, model), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| export function extend(publicAPI, model, initialValues = {}) { | ||
| vtkGlyphRepresentation.extend( | ||
| publicAPI, | ||
| model, | ||
| defaultValues(publicAPI, model, initialValues) | ||
| ); | ||
| macro.setGet(publicAPI, model, [ | ||
| 'glyphResolution', | ||
| 'lineThickness', | ||
| 'forceLineThickness', | ||
| ]); | ||
| macro.get(publicAPI, model._pipeline, ['glyph', 'mapper', 'actor']); | ||
|
|
||
| vtkLineGlyphRepresentation(publicAPI, model); | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| export const newInstance = macro.newInstance( | ||
| extend, | ||
| 'vtkLineGlyphRepresentation' | ||
| ); | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| export default { newInstance, extend }; |
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.
Uh oh!
There was an error while loading. Please reload this page.