Skip to content
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

Chloe presentation #150

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This version is only for PR purposes.

# react-volume-viewer

> Aframe container with custom controls for use in react applications
Expand Down
2 changes: 1 addition & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions example/public/data/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "Chloe Particles",
"models": [
{
"name": "Point Cloud",
"range": {
"min": 0,
"max": 255,
"unit": "px"
},
"path": "./assets/models/low_resolution_100slice_chn_0.png",
"intensity": 10.5
}
],
"slices": 101,
"spacing": "0.5 0.5 0.5"
}
]
216 changes: 117 additions & 99 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,129 @@
import React, { useState } from "react";
import styled from "styled-components";
import { VolumeViewer, COLOR_MAPS, Blending } from "react-volume-viewer";
// import React, { useState } from "react";
//import styled from "styled-components";
// import { VolumeViewer, COLOR_MAPS, Blending } from "react-volume-viewer";

const salt = "./assets/models/summer-high-salt.png";
const temp = "./assets/models/summer-high-temp.png";
// const salt = "./assets/models/summer-high-salt.png";
// const temp = "./assets/models/summer-high-temp.png";

const allColorMaps = [...Object.values(COLOR_MAPS)];
// const allColorMaps = [...Object.values(COLOR_MAPS)];

function App() {
const [controlsVisible, setControlsVisible] = useState(false);

const [singleColorMap, setSingleColorMap] = useState(false);
const [enabled, setEnabled] = React.useState(true);
const [blending, setBlending] = useState(Blending.Max);
// function App() {
// const [controlsVisible, setControlsVisible] = useState(false);

const [useTransferFunction, setUseTransferFunction] = useState(true);
const [useColorMap, setUseColorMap] = useState(true);
// const [singleColorMap, setSingleColorMap] = useState(false);
// const [enabled, setEnabled] = React.useState(true);
// const [blending, setBlending] = useState(Blending.Max);

// const [useTransferFunction, setUseTransferFunction] = useState(true);
// const [useColorMap, setUseColorMap] = useState(true);

// return (
// <>
// <Main>
// <div>
// <button onClick={() => setControlsVisible(!controlsVisible)}>
// Controls Visible
// </button>
// <button onClick={() => setUseTransferFunction(!useTransferFunction)}>
// Use Transfer Function
// </button>
// <button onClick={() => setUseColorMap(!useColorMap)}>
// Use Color Map
// </button>
// <button onClick={() => setSingleColorMap(!singleColorMap)}>
// Single Color Map
// </button>
// <button onClick={() => setEnabled(!enabled)}>Enabled</button>
// <button onClick={() => setBlending(Blending.Min)}>
// Min Blending
// </button>
// <button onClick={() => setBlending(Blending.Max)}>
// Max Blending
// </button>
// <button onClick={() => setBlending(Blending.Average)}>
// Average Blending
// </button>
// </div>
// <StyledVolumeViewer
// controlsVisible={controlsVisible}
// blending={blending}
// models={[
// {
// name: "Salt",
// colorMap: COLOR_MAPS.Haline,
// ...(!singleColorMap && {
// colorMaps: [
// COLOR_MAPS.Haline,
// COLOR_MAPS.Thermal,
// COLOR_MAPS.Grayscale,
// ],
// }),
// description: "Model visualizing salinity data",
// enabled: enabled,
// path: salt,
// range: {
// min: 0.05,
// max: 33.71,
// },
// transferFunction: [
// { x: 0, y: 0 },
// { x: 0.5, y: 0.75 },
// { x: 1, y: 1 },
// ],
// useTransferFunction: useTransferFunction,
// useColorMap: useColorMap,
// },
// {
// name: "Temperature",
// colorMap: COLOR_MAPS.Thermal,
// ...(!singleColorMap && { colorMaps: allColorMaps }),
// description: "Model visualizing temperature data",
// enabled: enabled,
// path: temp,
// range: {
// min: 2.5,
// max: 42,
// unit: "°C",
// },
// useTransferFunction: useTransferFunction,
// useColorMap: useColorMap,
// },
// ]}
// rotation="-55 0 0"
// scale="1 -1 1"
// slices={55}
// spacing="2 2 1"
// />
// <hr />
// </Main>
// </>
// );
// }

// const StyledVolumeViewer = styled(VolumeViewer)`
// height: 85vh;
// `;

// const Main = styled.main`
// padding: 25px;
// `;

// export default App;



//import './App.css'

import Visualizer from './components/VolumeVisualizer'

function App () {
return (
<>
<Main>
<div>
<button onClick={() => setControlsVisible(!controlsVisible)}>
Controls Visible
</button>
<button onClick={() => setUseTransferFunction(!useTransferFunction)}>
Use Transfer Function
</button>
<button onClick={() => setUseColorMap(!useColorMap)}>
Use Color Map
</button>
<button onClick={() => setSingleColorMap(!singleColorMap)}>
Single Color Map
</button>
<button onClick={() => setEnabled(!enabled)}>Enabled</button>
<button onClick={() => setBlending(Blending.Min)}>
Min Blending
</button>
<button onClick={() => setBlending(Blending.Max)}>
Max Blending
</button>
<button onClick={() => setBlending(Blending.Average)}>
Average Blending
</button>
</div>
<StyledVolumeViewer
controlsVisible={controlsVisible}
blending={blending}
models={[
{
name: "Salt",
colorMap: COLOR_MAPS.Haline,
...(!singleColorMap && {
colorMaps: [
COLOR_MAPS.Haline,
COLOR_MAPS.Thermal,
COLOR_MAPS.Grayscale,
],
}),
description: "Model visualizing salinity data",
enabled: enabled,
path: salt,
range: {
min: 0.05,
max: 33.71,
},
transferFunction: [
{ x: 0, y: 0 },
{ x: 0.5, y: 0.75 },
{ x: 1, y: 1 },
],
useTransferFunction: useTransferFunction,
useColorMap: useColorMap,
},
{
name: "Temperature",
colorMap: COLOR_MAPS.Thermal,
...(!singleColorMap && { colorMaps: allColorMaps }),
description: "Model visualizing temperature data",
enabled: enabled,
path: temp,
range: {
min: 2.5,
max: 42,
unit: "°C",
},
useTransferFunction: useTransferFunction,
useColorMap: useColorMap,
},
]}
rotation="-55 0 0"
scale="1 -1 1"
slices={55}
spacing="2 2 1"
/>
<hr />
</Main>
<Visualizer />
</>
);
)
}

const StyledVolumeViewer = styled(VolumeViewer)`
height: 85vh;
`;

const Main = styled.main`
padding: 25px;
`;
export default App

export default App;
84 changes: 84 additions & 0 deletions example/src/components/VolumeVisualizer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { React, useState, useEffect } from 'react'
import { Container, Row, Col, ToggleButton, ToggleButtonGroup, Button } from 'react-bootstrap'
import { VolumeViewer, COLOR_MAPS, Blending } from 'react-volume-viewer'
import styled from "styled-components";
const colorMaps = [
COLOR_MAPS.BlueScale,
COLOR_MAPS.RedScale,
COLOR_MAPS.Algae,
COLOR_MAPS.Solar
]

export default function VolumeVisualizer () {
const [controlsVisible, setControlsVisible] = useState(false)
const [datasets, setDatasets] = useState([])
const [selected, setSelected] = useState({
// Initialize to an empty volume
name: '',
models: [],
slices: 1,
spacing: '0 0 0'
})

useEffect(() => {
// npm run lint was failing without the reference to window object
window
.fetch('./data/data.json', {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
}
})
.then((response) => response.json())
.then((data) => {
data.forEach(dataset => {
dataset.models.forEach((model, modelIndex) => {
model.colorMap = colorMaps[modelIndex]
model.useColorMap = true
model.useTransferFunction = true
})
})
setDatasets(data)
setSelected(data[0])
})
}, [])

return (
<Container fluid className='px-5'>
<Row className='mb-4'>
<Col className='text-center'>
<Button onClick={() => setControlsVisible(!controlsVisible)}>
Options
</Button>
</Col>
<Col className='text-center'>
<ToggleButtonGroup
name='datasetsButtonGroup'
type='radio'
value={selected}
onChange={selection => setSelected(selection)}
>
{datasets.map(dataset => (
<ToggleButton key={dataset.name} value={dataset}>
{dataset.name}
</ToggleButton>
))}
</ToggleButtonGroup>
</Col>
</Row>
<Row>
<StyledVolumeViewer
className='volumeViewer'
blending={Blending.Max}
controlsVisible={controlsVisible}
models={selected.models}
slices={selected.slices}
spacing={selected.spacing}
/>
</Row>
</Container>
)
}
const StyledVolumeViewer = styled(VolumeViewer)`
height: 85vh;
`;
Loading
Loading