Skip to content

Commit 1afa26d

Browse files
committed
Match Flat Analysis Logic
1 parent c51e5f4 commit 1afa26d

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/components/plots/FlatBlocks.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useMemo } from 'react'
2-
import { useGlobalStore, usePlotStore } from '@/utils/GlobalStates'
2+
import { useAnalysisStore, useGlobalStore, usePlotStore } from '@/utils/GlobalStates'
33
import { useShallow } from 'zustand/shallow'
44
import * as THREE from 'three'
55
import { sphereBlocksFrag, flatBlocksVert, flatBlocksVert3D } from '../textures/shaders'
@@ -20,14 +20,25 @@ const FlatBlocks = ({textures} : {textures: THREE.Data3DTexture[] | THREE.DataTe
2020
displacement: state.displacement, sphereResolution: state.sphereResolution,
2121
offsetNegatives: state.offsetNegatives, rotateFlat:state.rotateFlat
2222
})))
23-
24-
const width = dataShape[dataShape.length-1]
25-
const height = dataShape[dataShape.length-2]
23+
const {analysisMode, axis} = useAnalysisStore(useShallow(state => ({
24+
analysisMode: state.analysisMode, axis:state.axis
25+
})))
26+
const {width, height} = useMemo(()=>{
27+
if (dataShape.length == 2){
28+
return {width: dataShape[1], height: dataShape[0]}
29+
} else if (analysisMode){
30+
const thisShape = dataShape.filter((_val, idx) => idx != axis)
31+
return {width: thisShape[1], height: thisShape[0]}
32+
} else {
33+
return {width: dataShape[2], height: dataShape[1]}
34+
}
35+
},[analysisMode, axis, dataShape])
36+
const rotateMap = analysisMode && axis == 2;
2637
const geometry = useMemo(()=>{
2738
const count = width * height;
28-
const sqWidth = 1;
39+
const sqWidth = 2;
2940
const aspect = width/height
30-
const geo = new THREE.BoxGeometry(sqWidth/width*aspect, sqWidth/height, .01);
41+
const geo = new THREE.BoxGeometry(sqWidth/width, sqWidth/height/aspect, .01);
3142
const uvs = new Float32Array(count * 2);
3243
let idx = 0;
3344
for (let i = 0; i < width; i++) {
@@ -45,6 +56,7 @@ const FlatBlocks = ({textures} : {textures: THREE.Data3DTexture[] | THREE.DataTe
4556
);
4657
return geo
4758
},[width, height])
59+
4860
const shaderMaterial = useMemo(()=>{
4961
const shader = new THREE.ShaderMaterial({
5062
glslVersion: THREE.GLSL3,
@@ -81,15 +93,16 @@ const FlatBlocks = ({textures} : {textures: THREE.Data3DTexture[] | THREE.DataTe
8193
uniforms.cOffset.value = cOffset
8294
uniforms.cScale.value = cScale
8395
uniforms.displaceZero.value = offsetNegatives ? 0 : (-valueScales.minVal/(valueScales.maxVal-valueScales.minVal))
96+
uniforms.aspect.value = width/height;
8497
}
8598
invalidate();
86-
},[animProg, valueScales, displacement, colormap, cScale, cOffset, offsetNegatives, textures])
99+
},[animProg, valueScales, displacement, colormap, cScale, cOffset, offsetNegatives, textures, analysisMode, axis, width, height])
87100

88101
return (
89102

90103
<instancedMesh
91-
scale={[1, flipY ? -1 : 1, 1]}
92-
rotation={[rotateFlat ? -Math.PI/2 : 0, 0, 0]}
104+
scale={[((analysisMode && axis == 2) && flipY) ? -1: 1, flipY ? -1 : ((analysisMode && axis == 2) ? -1 : 1) , 1]}
105+
rotation={[rotateFlat ? -Math.PI/2 : 0, 0, rotateMap ? Math.PI/2 : 0]}
93106
args={[geometry, shaderMaterial, (width * height)]}
94107
frustumCulled={false}
95108
/>

src/components/plots/FlatMap.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const FlatMap = ({textures, infoSetters, ZarrDS} : {textures : THREE.DataTexture
7272
return dataShape[1]/dataShape[2]
7373
}
7474
}, [axis, analysisMode] )
75-
7675
const geometry = useMemo(()=>new THREE.PlaneGeometry(2,2*shapeRatio),[shapeRatio])
7776
const infoRef = useRef<boolean>(false)
7877
const lastUV = useRef<THREE.Vector2>(new THREE.Vector2(0,0))
@@ -206,7 +205,6 @@ const FlatMap = ({textures, infoSetters, ZarrDS} : {textures : THREE.DataTexture
206205
}
207206
},[cScale, cOffset, textures, colormap, animProg, nanColor, nanTransparency, bounds, selectTS])
208207

209-
210208
return (
211209
<>
212210
<mesh

src/components/textures/shaders/flatBlocksVert.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ uniform float animateProg;
1010
#define PI 3.1415926535
1111

1212
vec3 givePosition(vec2 uv) {
13-
return vec3(uv.x*aspect, uv.y, 0.);
13+
return vec3(uv.x*2., uv.y/aspect*2., 0.);
1414
}
1515

1616

src/components/textures/shaders/flatBlocksVert3D.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ uniform float animateProg;
1313
#define PI 3.1415926535
1414

1515
vec3 givePosition(vec2 uv) {
16-
return vec3(uv.x*aspect, uv.y, 0.);
16+
return vec3(uv.x*2., uv.y/aspect*2., 0.);
1717
}
1818

1919

0 commit comments

Comments
 (0)