-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VV: Add VolumetricViewer to
lib-subject-viewers
(#6349)
- Add VolumetricViewer to lib-subject-viewers - Add "data-testid" to all DOM elements we want to test for existence - Add PropTypes to all Components based on linter output - Add shims for Canvas, WebGL, and requestAnimationFrame for Cube rendering and testing - Restructure VolumetricViewer directory to have all components, css, data, helpers, models, and tests in respective directories - Specs for AlgorithmAStar - Specs for ModelAnnotation - Specs for ModelTool - Specs for ModelViewer - Specs for pointColor - Specs for SortedSet - Specs for VolumetricViewer that simply tests for existence in the DOM - Write skeleton of a README - Remove ProtoViewer. Clean up README. Fix Orbitals. - Fix OrbitControls in the test:ci for GH - Update yarn.lock - Add instructions for M1 chips to lib-subject-viewers (#6385) --------- Co-authored-by: Delilah C. <[email protected]>
- Loading branch information
1 parent
4062f39
commit c0c1959
Showing
34 changed files
with
2,924 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 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
8 changes: 0 additions & 8 deletions
8
packages/lib-subject-viewers/src/components/ProtoViewer/ProtoViewer.js
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
packages/lib-subject-viewers/src/components/ProtoViewer/ProtoViewer.spec.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/lib-subject-viewers/src/components/ProtoViewer/ProtoViewer.stories.js
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/lib-subject-viewers/src/components/ProtoViewer/README.md
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
packages/lib-subject-viewers/src/components/VolumetricViewer/README.md
This file contains 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,6 @@ | ||
# VolumetricViewer | ||
|
||
This directory holds all the relevant code for rendering the VolumetricViewer. There are two primary exports: | ||
|
||
- `VolumetricViewerComponent` - a React component for the VolumetricViewer | ||
- `VolumetricViewerData` - a function that returns the data with instantiated models along with the React Component |
73 changes: 73 additions & 0 deletions
73
packages/lib-subject-viewers/src/components/VolumetricViewer/VolumetricViewer.js
This file contains 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,73 @@ | ||
import { object, string } from 'prop-types' | ||
import { useEffect, useState } from 'react' | ||
import { Buffer } from 'buffer' | ||
import { ComponentViewer } from './components/ComponentViewer.js' | ||
import { ModelViewer } from './models/ModelViewer.js' | ||
import { ModelAnnotations } from './models/ModelAnnotations.js' | ||
import { ModelTool } from './models/ModelTool.js' | ||
|
||
export default function VolumetricViewerComponent ({ | ||
config = {}, | ||
subjectData = '', | ||
subjectUrl = '', | ||
models | ||
}) { | ||
const [data, setData] = useState(null) | ||
if (!models) { | ||
const [modelState] = useState({ | ||
annotations: ModelAnnotations(), | ||
tool: ModelTool(), | ||
viewer: ModelViewer() | ||
}) | ||
models = modelState | ||
} | ||
|
||
// Figure out subject data | ||
useEffect(() => { | ||
if (subjectData !== '') { | ||
setData(Buffer.from(subjectData, 'base64')) | ||
} else if (subjectUrl !== '') { | ||
fetch(subjectUrl) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
setData(Buffer.from(data, 'base64')) | ||
}) | ||
} else { | ||
console.log('No data to display') | ||
} | ||
}, []) | ||
|
||
// Loading screen will always display if we have no subject data | ||
if (!data || !models) return <div>Loading...</div> | ||
|
||
return ( | ||
<ComponentViewer | ||
config={config} | ||
data={data} | ||
models={models} | ||
/> | ||
) | ||
} | ||
|
||
export const VolumetricViewerData = ({ subjectData = '', subjectUrl = '' }) => { | ||
return { | ||
data: { | ||
config: {}, | ||
subjectData, | ||
subjectUrl, | ||
models: { | ||
annotations: ModelAnnotations(), | ||
tool: ModelTool(), | ||
viewer: ModelViewer() | ||
} | ||
}, | ||
component: VolumetricViewerComponent | ||
} | ||
} | ||
|
||
VolumetricViewerComponent.propTypes = { | ||
config: object, | ||
subjectData: string, | ||
subjectUrl: string, | ||
models: object | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/lib-subject-viewers/src/components/VolumetricViewer/components/AnnotationView.js
This file contains 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,32 @@ | ||
import { array, number, object } from 'prop-types' | ||
|
||
export const AnnotationView = ({ annotation, annotations, index }) => { | ||
function annotationActive () { | ||
annotations.actions.annotation.active({ index }) | ||
} | ||
|
||
function annotationDelete (e) { | ||
e.stopPropagation() | ||
annotations.actions.annotation.remove({ index }) | ||
} | ||
|
||
const color = annotations.config.activeAnnotation === index ? '#555' : '#222' | ||
|
||
return ( | ||
<li | ||
style={{ padding: '20px', backgroundColor: color }} | ||
onClick={annotationActive} | ||
> | ||
<p>Label: {annotation.label}</p> | ||
<p>Threshold: {annotation.threshold}</p> | ||
<p>Points: {annotation.points.active.length}</p> | ||
<p onClick={annotationDelete}>Delete Annotation</p> | ||
</li> | ||
) | ||
} | ||
|
||
AnnotationView.propTypes = { | ||
annotation: object, | ||
annotations: array, | ||
index: number | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/lib-subject-viewers/src/components/VolumetricViewer/components/ComponentViewer.js
This file contains 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,65 @@ | ||
import { object } from 'prop-types' | ||
import { AlgorithmAStar } from './../helpers/AlgorithmAStar.js' | ||
import { Cube } from './Cube.js' | ||
import { Plane } from './Plane.js' | ||
import { Box } from 'grommet' | ||
|
||
export const ComponentViewer = ({ | ||
data, | ||
models | ||
}) => { | ||
// Initialize Annotations | ||
if (models.annotations) { | ||
models.annotations.initialize({ | ||
algorithm: AlgorithmAStar, | ||
data: [], // will come from Caesar if they exist | ||
viewer: models.viewer | ||
}) | ||
} | ||
|
||
// Initialize Tool | ||
if (models.tool) { | ||
models.tool.initialize({ | ||
annotations: models.annotations | ||
}) | ||
} | ||
|
||
// Initialize Viewer | ||
if (models.viewer) { | ||
models.viewer.initialize({ | ||
annotations: models.annotations, | ||
data, | ||
tool: models.tool | ||
}) | ||
} | ||
|
||
return ( | ||
<Box direction='row' style={{ maxWidth: '800px', padding: '20px' }}> | ||
<Box flex> | ||
{models.viewer.dimensions.map((dimensionName, dimension) => { | ||
return ( | ||
<Plane | ||
annotations={models.annotations} | ||
dimension={dimension} | ||
key={`dimension-${dimensionName}`} | ||
tool={models.tool} | ||
viewer={models.viewer} | ||
/> | ||
) | ||
})} | ||
</Box> | ||
<Box flex> | ||
<Cube | ||
annotations={models.annotations} | ||
tool={models.tool} | ||
viewer={models.viewer} | ||
/> | ||
</Box> | ||
</Box> | ||
) | ||
} | ||
|
||
ComponentViewer.propTypes = { | ||
data: object, | ||
models: object | ||
} |
107 changes: 107 additions & 0 deletions
107
packages/lib-subject-viewers/src/components/VolumetricViewer/components/Config.js
This file contains 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,107 @@ | ||
import { object } from 'prop-types' | ||
import { useEffect, useState } from 'react' | ||
import { AnnotationView } from './AnnotationView.js' | ||
import { InputRangeDual } from './InputRangeDual.js' | ||
|
||
export const Config = ({ | ||
annotations, | ||
viewer | ||
}) => { | ||
const [_annotations, setAnnotations] = useState(annotations.annotations) | ||
|
||
function annotationsChange ({ annotations }) { | ||
setAnnotations([...annotations]) | ||
} | ||
|
||
// State Change Management through useEffect() | ||
useEffect(() => { | ||
// State Listeners to bypass React rerenders | ||
annotations.on('active:annotation', annotationsChange) | ||
annotations.on('add:annotation', annotationsChange) | ||
annotations.on('update:annotation', annotationsChange) | ||
annotations.on('remove:annotation', annotationsChange) | ||
|
||
return () => { | ||
annotations.off('active:annotation', annotationsChange) | ||
annotations.off('add:annotation', annotationsChange) | ||
annotations.off('update:annotation', annotationsChange) | ||
annotations.off('remove:annotation', annotationsChange) | ||
} | ||
}, []) | ||
|
||
function downloadPoints () { | ||
const rows = annotations.annotations.map((annotation) => { | ||
return [ | ||
annotation.label, | ||
annotation.threshold, | ||
annotation.points.active.join('|'), | ||
annotation.points.all.data.join('|') | ||
] | ||
}) | ||
|
||
rows.unshift([ | ||
'annotation name', | ||
'annotation threshold', | ||
'control points', | ||
'connected points' | ||
]) | ||
const csvContent = | ||
'data:text/csv;charset=utf-8,' + rows.map((r) => r.join(',')).join('\n') | ||
const encodedUri = encodeURI(csvContent) | ||
const link = document.createElement('a') | ||
link.setAttribute('href', encodedUri) | ||
link.setAttribute('download', 'brainsweeper.csv') | ||
document.body.appendChild(link) | ||
link.click() | ||
} | ||
|
||
function saveScreenshot () { | ||
viewer.saveScreenshot() | ||
} | ||
|
||
return ( | ||
<> | ||
<h3 style={{ paddingBottom: '10px' }}>Volumetric File</h3> | ||
<br /> | ||
|
||
<h3>Brightness Range</h3> | ||
<InputRangeDual | ||
valueMax={255} | ||
valueMin={0} | ||
valueMaxCurrent={viewer.threshold.max} | ||
valueMinCurrent={viewer.threshold.min} | ||
onChange={(min, max) => { | ||
viewer.setThreshold({ min, max }) | ||
}} | ||
/> | ||
<br /> | ||
<br /> | ||
|
||
<button onClick={downloadPoints} style={{ marginBottom: '20px' }}> | ||
Download Active Points | ||
</button> | ||
|
||
<button onClick={saveScreenshot} style={{ marginBottom: '20px' }}> | ||
Save Screenshot | ||
</button> | ||
|
||
<ul> | ||
{_annotations.map((annotation, index) => { | ||
return ( | ||
<AnnotationView | ||
annotation={annotation} | ||
annotations={annotations} | ||
index={index} | ||
key={`annotation-${index}`} | ||
/> | ||
) | ||
})} | ||
</ul> | ||
</> | ||
) | ||
} | ||
|
||
Config.propTypes = { | ||
annotations: object, | ||
viewer: object | ||
} |
Oops, something went wrong.