Skip to content

Commit c62b726

Browse files
authored
Merge pull request #444 from EarthyScience/jp/volume-stretching
Volumes have timeratio now
2 parents f31fdbf + b2bcc62 commit c62b726

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/components/plots/AxisLines.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
6969

7070
const depthRatio = useMemo(()=>dataShape[0]/dataShape[2]*timeScale,[dataShape, timeScale]);
7171
const shapeRatio = useMemo(()=>dataShape[1]/dataShape[2], [dataShape])
72+
const timeRatio = Math.max(dataShape[0]/dataShape[2], 2);
7273

7374
const secondaryColor = useCSSVariable('--text-plot') //replace with needed variable
7475
const colorHex = useMemo(()=>{
@@ -89,7 +90,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
8990
return new LineSegments2(geom, lineMat)},[yRange, shapeRatio, lineMat, globalScale])
9091

9192
const zLine = useMemo(()=> {
92-
const geom = new LineSegmentsGeometry().setPositions([0, 0, isPC ? zRange[0]*globalScale*depthRatio-tickLength/2 : zRange[0]-tickLength/2, 0, 0, isPC ? zRange[1]*globalScale*depthRatio+tickLength/2 : zRange[1]+tickLength/2]);
93+
const geom = new LineSegmentsGeometry().setPositions([0, 0, isPC ? zRange[0]*globalScale*depthRatio-tickLength/2 : (zRange[0]*timeRatio-tickLength)/2, 0, 0, isPC ? zRange[1]*globalScale*depthRatio+tickLength/2 : (zRange[1]*timeRatio+tickLength)/2]);
9394
return new LineSegments2(geom, lineMat)},[zRange, depthRatio, isPC, lineMat, globalScale])
9495

9596
const tickLine = useMemo(()=> {
@@ -112,7 +113,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
112113
{/* Horizontal Group */}
113114
<group position={[0, isPC ? shapeRatio*globalScale*yRange[0] : shapeRatio*yRange[0], 0]} >
114115
{/* X Group */}
115-
<group position={[0, 0, flipX ? isPC ? zRange[0]*depthRatio*(globalScale)-tickLength/2 : zRange[0]-tickLength/2 : isPC ? zRange[1] * (globalScale) * depthRatio +tickLength/2 : zRange[1]+tickLength/2]} rotation={[flipDown ? flipX ? -Math.PI/2 : Math.PI/2 : 0, 0, 0]}>
116+
<group position={[0, 0, flipX ? isPC ? zRange[0]*depthRatio*(globalScale)-tickLength/2 : (zRange[0]*timeRatio-tickLength)/2 : isPC ? zRange[1] * (globalScale) * depthRatio +tickLength/2 : (zRange[1]*timeRatio+tickLength)/2]} rotation={[flipDown ? flipX ? -Math.PI/2 : Math.PI/2 : 0, 0, 0]}>
116117
<primitive key={'xLine'} object={xLine} />
117118
{Array(xResolution).fill(null).map((_val,idx)=>(
118119
(((xRange[0] + 1)/2) <= (idx*xDimScale)/xResolution &&
@@ -182,7 +183,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
182183
(((zRange[0] + 1)/2) <= (idx*zDimScale)/zResolution &&
183184
((zRange[1] + 1)/2) >= (idx*zDimScale)/zResolution )
184185
&&
185-
<group key={`zGroup_${idx}`} position={[0, 0, isPC ? -depthRatio*globalScale + idx*zDimScale/(zResolution/2)*depthRatio*(globalScale) : -1 + idx*zDimScale/(zResolution/2)]}>
186+
<group key={`zGroup_${idx}`} position={[0, 0, isPC ? -depthRatio*globalScale + idx*zDimScale/(zResolution/2)*depthRatio*(globalScale) : -0.5*timeRatio + idx*zDimScale/(zResolution/2)*timeRatio/2]}>
186187
<primitive key={idx} object={tickLine.clone()} rotation={[0, flipY ? Math.PI/2 : -Math.PI/2 , 0]} />
187188
<Text
188189
key={`textY_${idx}`}
@@ -242,7 +243,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
242243
</group>
243244
</group>
244245
{/* Vertical Group */}
245-
<group position={[flipY ? xRange[0]*globalScale - tickLength/2 : xRange[1]*globalScale + tickLength/2, 0, flipX ? isPC ? zRange[0]*depthRatio*(globalScale) - tickLength/2 : zRange[0] - tickLength/2 : isPC ? zRange[1]*depthRatio*(globalScale) + tickLength/2 : zRange[1] +tickLength/2]}>
246+
<group position={[flipY ? xRange[0]*globalScale - tickLength/2 : xRange[1]*globalScale + tickLength/2, 0, flipX ? isPC ? zRange[0]*depthRatio*(globalScale) - tickLength/2 : (zRange[0]*timeRatio - tickLength)/2 : isPC ? zRange[1]*depthRatio*(globalScale) + tickLength/2 : (zRange[1]*timeRatio +tickLength)/2]}>
246247
<primitive key={'yLine'} object={yLine} />
247248
{Array(yResolution).fill(null).map((_val,idx)=>(
248249
(((yRange[0] + 1)/2) <= (idx*yDimScale)/yResolution &&

src/components/plots/DataCube.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
3838
})))
3939
const meshRef = useRef<THREE.Mesh>(null!);
4040
const aspectRatio = shape.y/shape.x
41+
const timeRatio = shape.z/shape.x;
4142
const shaderMaterial = useMemo(()=>new THREE.ShaderMaterial({
4243
glslVersion: THREE.GLSL3,
4344
uniforms: {
@@ -49,7 +50,7 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
4950
cScale: {value: cScale},
5051
threshold: {value: new THREE.Vector2(valueRange[0],valueRange[1])},
5152
scale: {value: shape},
52-
flatBounds:{value: new THREE.Vector4(-xRange[1],-xRange[0],zRange[0],zRange[1])},
53+
flatBounds:{value: new THREE.Vector4(-xRange[1],-xRange[0],zRange[0] * timeRatio, zRange[1] * timeRatio)},
5354
vertBounds:{value: new THREE.Vector2(yRange[0]*aspectRatio,yRange[1]*aspectRatio)},
5455
steps: { value: quality },
5556
animateProg: {value: animProg},
@@ -77,7 +78,7 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
7778
uniforms.cScale.value = cScale;
7879
uniforms.threshold.value.set(valueRange[0], valueRange[1]);
7980
uniforms.scale.value = shape;
80-
uniforms.flatBounds.value.set(-xRange[1], -xRange[0], zRange[0], zRange[1]);
81+
uniforms.flatBounds.value.set(-xRange[1], -xRange[0], zRange[0] * timeRatio, zRange[1] * timeRatio);
8182
uniforms.vertBounds.value.set(yRange[0] * aspectRatio, yRange[1] * aspectRatio);
8283
uniforms.steps.value = quality;
8384
uniforms.animateProg.value = animProg;

src/components/plots/Plot.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => {
215215
else{
216216
setIsFlat(false)
217217
}
218-
const shapeRatio = result.shape[shapeLength-2] / result.shape[shapeLength-1] * 2;
219-
setShape(new THREE.Vector3(2, shapeRatio, 2));
218+
const aspectRatio = result.shape[shapeLength-2] / result.shape[shapeLength-1];
219+
const timeRatio = result.shape[shapeLength-3] / result.shape[shapeLength-1];
220+
setShape(new THREE.Vector3(2, aspectRatio * 2, Math.max(timeRatio, 2)));
220221
setDataShape(result.shape)
221222
setShow(true)
222223
setPlotOn(true)

0 commit comments

Comments
 (0)