-
Notifications
You must be signed in to change notification settings - Fork 24
Reslice mapper representation #112
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
base: master
Are you sure you want to change the base?
Changes from all commits
db1fe17
ac2276e
30d136b
fd1d4ec
a1cb931
37411af
dad5d98
88a6d91
68efb4d
5ee0718
c542db2
9fe333b
5991fce
e147c78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,7 @@ | |
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
|
|
||
| # AI assistant memory | ||
| memories/ | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,148 @@ | ||||||
| import vtkImageResliceMapper, { | ||||||
| vtkImageResliceMapper as IvtkImageResliceMapper, | ||||||
| } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper'; | ||||||
| import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants'; | ||||||
| import { forwardRef, PropsWithChildren, useRef } from 'react'; | ||||||
| import useComparableEffect from '../utils/useComparableEffect'; | ||||||
| import SliceRepresentation, { | ||||||
| SliceRepresentationProps, | ||||||
| } from './SliceRepresentation'; | ||||||
|
|
||||||
| export interface ResliceRepresentationProps extends SliceRepresentationProps { | ||||||
| /** | ||||||
| * Slice plane | ||||||
| */ | ||||||
| slicePlane?: any; | ||||||
|
|
||||||
| /** | ||||||
| * Optional slice polydata | ||||||
| */ | ||||||
| slicePolyData?: any; | ||||||
|
Collaborator
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.
Suggested change
|
||||||
|
|
||||||
| /** | ||||||
| * Slab type | ||||||
| */ | ||||||
| slabType?: number; | ||||||
|
|
||||||
| /** | ||||||
| * Slab thickness | ||||||
| */ | ||||||
| slabThickness?: number; | ||||||
|
|
||||||
| /** | ||||||
| * Slab trapezoid integration | ||||||
| */ | ||||||
| slabTrapezoidIntegration?: boolean; | ||||||
| } | ||||||
|
|
||||||
| export default forwardRef(function ResliceRepresentation( | ||||||
| props: PropsWithChildren<ResliceRepresentationProps>, | ||||||
| fwdRef | ||||||
| ) { | ||||||
| const { | ||||||
| slicePlane, | ||||||
| slicePolyData, | ||||||
| slabType = SlabTypes.MEAN, | ||||||
| slabThickness = 0.0, | ||||||
| slabTrapezoidIntegration = false, | ||||||
| mapperInstance: providedMapper, | ||||||
| ...sliceProps | ||||||
| } = props; | ||||||
|
|
||||||
| // Create reslice mapper once and reuse it across renders. | ||||||
| const internalMapperRef = useRef<IvtkImageResliceMapper | null>(null); | ||||||
| if (!internalMapperRef.current) { | ||||||
| internalMapperRef.current = vtkImageResliceMapper.newInstance(); | ||||||
| } | ||||||
| const mapperInstance = (providedMapper || | ||||||
| internalMapperRef.current) as IvtkImageResliceMapper; | ||||||
|
|
||||||
| // Handle reslice-specific mapper updates | ||||||
| useComparableEffect( | ||||||
| () => { | ||||||
| if (!providedMapper && mapperInstance) { | ||||||
| trackModified(true); | ||||||
| mapperInstance.setSlicePlane(slicePlane); | ||||||
| } | ||||||
| }, | ||||||
| [slicePlane, providedMapper], | ||||||
| ([cur, prevMapped], [prev, prevProvided]) => | ||||||
| cur === prev && prevMapped === prevProvided | ||||||
| ); | ||||||
|
|
||||||
| useComparableEffect( | ||||||
| () => { | ||||||
| if (!providedMapper && mapperInstance) { | ||||||
| trackModified(true); | ||||||
| mapperInstance.setSlicePolyData(slicePolyData); | ||||||
| } | ||||||
| }, | ||||||
| [slicePolyData, providedMapper], | ||||||
| ([cur, prevMapped], [prev, prevProvided]) => | ||||||
| cur === prev && prevMapped === prevProvided | ||||||
| ); | ||||||
|
|
||||||
| useComparableEffect( | ||||||
| () => { | ||||||
| if (!providedMapper && mapperInstance) { | ||||||
| trackModified(true); | ||||||
| if ( | ||||||
| slabType != null && | ||||||
| slabType >= SlabTypes.MIN && | ||||||
| slabType <= SlabTypes.SUM | ||||||
| ) { | ||||||
| mapperInstance.setSlabType(slabType); | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
| [slabType, providedMapper], | ||||||
| ([cur, prevMapped], [prev, prevProvided]) => | ||||||
| cur === prev && prevMapped === prevProvided | ||||||
| ); | ||||||
|
|
||||||
| useComparableEffect( | ||||||
| () => { | ||||||
| if (!providedMapper && mapperInstance) { | ||||||
| trackModified(true); | ||||||
| if (slabThickness != null) { | ||||||
| mapperInstance.setSlabThickness(slabThickness); | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
| [slabThickness, providedMapper], | ||||||
| ([cur, prevMapped], [prev, prevProvided]) => | ||||||
| cur === prev && prevMapped === prevProvided | ||||||
| ); | ||||||
|
|
||||||
| useComparableEffect( | ||||||
| () => { | ||||||
| if (!providedMapper && mapperInstance) { | ||||||
| trackModified(true); | ||||||
| if (slabTrapezoidIntegration != null) { | ||||||
| mapperInstance.setSlabTrapezoidIntegration( | ||||||
| slabTrapezoidIntegration ? 1 : 0 | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
| [slabTrapezoidIntegration, providedMapper], | ||||||
| ([cur, prevMapped], [prev, prevProvided]) => | ||||||
| cur === prev && prevMapped === prevProvided | ||||||
| ); | ||||||
|
|
||||||
| function trackModified(changed: boolean) { | ||||||
| if (changed) { | ||||||
| // Trigger render | ||||||
|
Collaborator
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. Do we leave this implementation empty for now? It does nothing. But in the parent SliceRepresentation, trackModified comes from useBooleanAccumulator() and is what actually drives renderer.requestRender(). So every trackModified(true) call in the five reslice effects (slicePlane, slicePolyData, slabType, slabThickness, slabTrapezoidIntegration) is dead code with a comment promising a render that never happens. |
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return ( | ||||||
| <SliceRepresentation | ||||||
| {...sliceProps} | ||||||
| mapperInstance={mapperInstance as any} | ||||||
|
Collaborator
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. Why is |
||||||
| ref={fwdRef} | ||||||
| > | ||||||
| {props.children} | ||||||
| </SliceRepresentation> | ||||||
| ); | ||||||
| }); | ||||||
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.
Is this a vtkPlane?