Skip to content

Commit 41f82a9

Browse files
authored
Merge pull request #50 from EarthyScience/Fixes
Fixes
2 parents 506fc8b + 6b6eccf commit 41f82a9

File tree

9 files changed

+187
-73
lines changed

9 files changed

+187
-73
lines changed

src/components/CanvasGeometry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export function CanvasGeometry() {
184184
{metadata && <Metadata data={metadata} /> }
185185

186186
<plotContext.Provider value={plotObj} >
187-
<PlotArea />
187+
{variable !== "Default" && <PlotArea />}
188188
</plotContext.Provider>
189189

190190
{/* <Leva theme={lightTheme} /> */}

src/components/PlotObjects/PlotArea/PlotArea.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.plot-coords{
2-
position: relative;
3-
width: 200px;
2+
position: absolute;
3+
max-width:150px;
44
bottom:50%;
55
left:2%;
6-
pointer-events: none;
6+
padding: 5px 5px;
7+
background-color: rgba(0, 0, 0, 0.445);
8+
box-shadow: 0px 0px 4px white;
9+
cursor: move;
10+
user-select: none;
711
}
812

913
.point-info{

src/components/PlotObjects/PlotArea/PlotArea.tsx

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Canvas } from '@react-three/fiber'
22
import { parseLoc } from '@/utils/HelperFuncs'
33
import { PlotLine, FixedTicks } from '@/components/PlotObjects'
4-
import { useContext, useEffect, useState } from 'react'
4+
import { useContext, useEffect, useRef, useState } from 'react'
55
import { plotContext } from '@/components/Contexts'
66
import { ResizeBar, YScaler,XScaler } from '@/components/UI'
77
import './PlotArea.css'
@@ -46,8 +46,71 @@ function PointInfo({pointID,pointLoc,showPointInfo}:pointInfo){
4646
)
4747
}
4848

49+
function PointCoords(){
50+
const {coords} = useContext(plotContext);
51+
const [moving,setMoving] = useState<boolean>(false)
52+
const initialMouse = useRef<number[]>([40,115])
53+
const initialDiv = useRef<number[]>([40,115])
54+
const [xy, setXY] = useState<number[]>([40,115])
55+
56+
function handleDown(e: any){
57+
initialMouse.current = [e.clientX,e.clientY]
58+
initialDiv.current = [...xy]
59+
setMoving(true)
60+
}
61+
62+
function handleMove(e: any){
63+
if (moving){
64+
const deltaX = initialMouse.current[0]-e.clientX
65+
const deltaY = initialMouse.current[1]-e.clientY
66+
const x = Math.max(initialDiv.current[0]-deltaX,10)
67+
const y = Math.max(initialDiv.current[1]+deltaY,14) //Again hardcoded footer height
68+
setXY([Math.min(x,window.innerWidth-100),Math.min(y,window.innerHeight-100)])
69+
}
70+
}
71+
72+
function handleUp(){
73+
setMoving(false)
74+
}
75+
76+
useEffect(() => {
77+
if (moving) {
78+
document.addEventListener('mousemove', handleMove);
79+
document.addEventListener('mouseup', handleUp);
80+
}
81+
return () => {
82+
document.removeEventListener('mousemove', handleMove);
83+
document.removeEventListener('mouseup', handleUp);
84+
};
85+
}, [moving]);
86+
87+
return(
88+
<>
89+
{ //Only show coords when coords exist
90+
coords && coords.first.name !== 'Default' &&
91+
<div className='plot-coords'
92+
style={{
93+
left:`${xy[0]}px`,
94+
bottom:`${xy[1]}px`
95+
}}
96+
onPointerDown={handleDown}
97+
onPointerMove={handleMove}
98+
onPointerUp={()=>setMoving(false)}
99+
>
100+
<b>{`${coords['first'].name}: `}</b>
101+
{`${parseLoc(coords['first'].loc,coords['first'].units)}`}
102+
<br/> <br/>
103+
<b>{`${coords['second'].name}: `}</b>
104+
{`${parseLoc(coords['second'].loc,coords['second'].units)}`}
105+
</div>
106+
}
107+
</>
108+
)
109+
110+
}
111+
112+
49113
export function PlotArea() {
50-
const {coords} = useContext(plotContext)
51114
const [pointID, setPointID] = useState<number>(0);
52115
const [pointLoc, setPointLoc] = useState<number[]>([0,0])
53116
const [showPointInfo,setShowPointInfo] = useState<boolean>(false)
@@ -86,16 +149,7 @@ export function PlotArea() {
86149
<PlotLine height={height} pointSetters={pointSetters} yScale={yScale} xScale={xScale}/>
87150
<FixedTicks height={height} yScale={yScale} xScale={xScale}/>
88151
</Canvas>
89-
{ //Only show coords when coords exist
90-
coords && coords.first.name !== 'Default' &&
91-
<div className='plot-coords'>
92-
<b>{`${coords['first'].name}: `}</b>
93-
{`${parseLoc(coords['first'].loc,coords['first'].units)}`}
94-
<br/> <br/>
95-
<b>{`${coords['second'].name}: `}</b>
96-
{`${parseLoc(coords['second'].loc,coords['second'].units)}`}
97-
</div>
98-
}
152+
<PointCoords/>
99153
</div>
100154
)
101155
}

src/components/PlotObjects/PointCloud.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ interface PCProps {
1212

1313
export const PointCloud = ({textures} : {textures:PCProps} )=>{
1414
const {texture, colormap } = textures;
15-
const {pointScale,scalePoints} = useControls({
15+
const {pointScale,scalePoints,scaleIntensity} = useControls({
1616
pointScale:{
1717
value:1,
1818
min:1,
19-
max:40,
19+
max:100,
2020
step:1
2121
},
2222
scalePoints:{
2323
value:false,
2424
label:"Scale Points By Value"
25+
},
26+
scaleIntensity:{
27+
value:2,
28+
min:1,
29+
max:10,
30+
step:.2,
31+
labe: "Scale Intensity"
2532
}
33+
2634
}
2735
)
2836
//Extract data and shape from Data3DTexture
@@ -82,7 +90,8 @@ export const PointCloud = ({textures} : {textures:PCProps} )=>{
8290
uniforms: {
8391
pointSize: {value: pointScale},
8492
cmap: {value: colormap},
85-
scalePoints:{value: scalePoints}
93+
scalePoints:{value: scalePoints},
94+
scaleIntensity: {value: scaleIntensity}
8695
},
8796
vertexShader:pointVert,
8897
fragmentShader:pointFrag,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// by Jeran Poehls
2+
precision highp float;
3+
precision highp sampler3D;
4+
5+
uniform mat4 modelViewMatrix;
6+
uniform mat4 projectionMatrix;
7+
8+
in vec3 vOrigin;
9+
in vec3 vDirection;
10+
11+
out vec4 color;
12+
13+
uniform sampler3D map;
14+
uniform sampler2D cmap;
15+
16+
uniform vec3 scale;
17+
uniform float threshold;
18+
uniform float steps;
19+
uniform bool flip;
20+
uniform vec4 flatBounds;
21+
uniform vec2 vertBounds;
22+
uniform float intensity;
23+
24+
vec2 hitBox(vec3 orig, vec3 dir) {
25+
vec3 box_min = vec3(-(scale * 0.5));
26+
vec3 box_max = vec3(scale * 0.5);
27+
vec3 inv_dir = 1.0 / dir;
28+
vec3 tmin_tmp = (box_min - orig) * inv_dir;
29+
vec3 tmax_tmp = (box_max - orig) * inv_dir;
30+
vec3 tmin = min(tmin_tmp, tmax_tmp);
31+
vec3 tmax = max(tmin_tmp, tmax_tmp);
32+
float t0 = max(tmin.x, max(tmin.y, tmin.z));
33+
float t1 = min(tmax.x, min(tmax.y, tmax.z));
34+
return vec2(t0, t1);
35+
}
36+
37+
float sample1( vec3 p ) {
38+
return texture( map, p ).r;
39+
}
40+
41+
#define epsilon 0.0001
42+
43+
void main() {
44+
vec3 rayDir = normalize(vDirection);
45+
vec2 bounds = hitBox(vOrigin, rayDir);
46+
47+
if (bounds.x > bounds.y) discard;
48+
49+
bounds.x = max(bounds.x, 0.0);
50+
51+
vec3 p = vOrigin + bounds.x * rayDir;
52+
vec3 inc = 1.0 / abs(rayDir);
53+
float delta = min(inc.x, min(inc.y, inc.z));
54+
delta /= steps;
55+
56+
vec4 accumColor = vec4(0.0);
57+
float alphaAcc = 0.0;
58+
for (float t = bounds.x; t < bounds.y; t += delta) {
59+
if (p.x > -flatBounds.x || p.x < -flatBounds.y) {
60+
p += rayDir * delta;
61+
continue;
62+
}
63+
if (-p.z > -flatBounds.z || -p.z < -flatBounds.w) {
64+
p += rayDir * delta;
65+
continue;
66+
}
67+
if (p.y < vertBounds.x || p.y > vertBounds.y) {
68+
p += rayDir * delta;
69+
continue;
70+
}
71+
72+
float d = sample1(p / scale + 0.5);
73+
74+
bool cond = (d > threshold) || (d == 0.0 && threshold == 0.0);
75+
cond = flip ? !cond : cond;
76+
77+
if (cond) {
78+
vec4 col = texture(cmap, vec2(d, 0.5));
79+
// Change this later back to use intensity then delete comment. Or maybe we don't need intensity
80+
float alpha = float(col.a > 0.);
81+
82+
accumColor.rgb += (1.0 - alphaAcc) * alpha * col.rgb;
83+
alphaAcc += alpha * (1.0 - alphaAcc);
84+
85+
if (alphaAcc >= 1.0) break;
86+
}
87+
88+
p += rayDir * delta;
89+
}
90+
91+
accumColor.a = alphaAcc; // Set the final accumulated alpha
92+
color = accumColor;
93+
if (color.a == 0.0) discard;
94+
}

src/components/Textures/shaders/fragDebug.glsl

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/components/Textures/shaders/pointVertex.glsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ attribute float value;
22
varying float vValue;
33
uniform float pointSize;
44
uniform bool scalePoints;
5+
uniform float scaleIntensity;
56

67
void main() {
78
vValue = value/255.;
89
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
910
//If it is nan we just yeet it tf out of the screen space. LMAO I love this solution
10-
if (value == 255.){
11+
float pointScale = pointSize/gl_Position.w;
12+
pointScale = scalePoints ? pointScale*pow(vValue,scaleIntensity) : pointScale;
13+
if (value == 255. || pointScale < 0.75){
1114
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
1215
}
13-
float pointScale = pointSize/gl_Position.w;
14-
gl_PointSize = scalePoints ? pointScale*pow(vValue,2.) : pointScale ;
16+
17+
gl_PointSize = pointScale;
1518
}

src/components/UI/XScaler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const XScaler = ({scale,setScale}:{scale:number,setScale:React.Dispatch<React.Se
1010
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
1111
e.preventDefault(); // Prevent text selection
1212
setIsResizing(true);
13-
initialPosition.current = e.clientY // Record starting height
13+
initialPosition.current = e.clientX // Record starting height
1414
};
1515

1616
// Adjust height on mousemove

src/components/ZarrLoaderLRU.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ export class ZarrDataset{
134134
const pz = slice[0] == null ? 0 : stride[0]*slice[0]
135135
const py = slice[1] == null ? 0 : stride[1]*slice[1]
136136
const px = slice[2] == null ? 0 : stride[2]*slice[2]
137-
138-
// console.log(`
139-
// Slice:${slice}
140-
// mapDim:${mapDim}
141-
// dimStride:${dimStride}
142-
// pz:${pz}
143-
// py:${py}
144-
// px:${px}
145-
// `)
146137
const ts = [];
147138

148139
for (let i = 0; i < shape[mapDim] ; i++){

0 commit comments

Comments
 (0)