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

Hoover curson over cells for info #149

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions CONFIG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const config = {
// When opening the viewer, or refreshing the page, the viewer will revert to the following default dataset
data:{
// Default dataset URL (must be publically accessible)
default_dataset: "https://public.czbiohub.org/royerlab/zoo/Zebrafish/tracks_zebrafish_bundle.zarr/"
// default_dataset: "https://public.czbiohub.org/royerlab/zoo/Zebrafish/tracks_zebrafish_bundle.zarr/"
default_dataset: "https://public.czbiohub.org/royerlab/zoo/Ascidian/tracks_ascidian_bundle.zarr/"
},

// Default settings for certain parameters
Expand All @@ -32,7 +33,7 @@ const config = {
highlight_point_color: [0.9, 0, 0.9], //pink

// Point color (when selector hovers over)
preview_hightlight_point_color: [0.8, 0.8, 0], //yellow
preview_hightlight_point_color: [0.8, 0.8, 0.0], //yellow

}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { TrackManager, loadTrackManager } from "@/lib/TrackManager";
import { PointSelectionMode } from "@/lib/PointSelector";
import LeftSidebarWrapper from "./leftSidebar/LeftSidebarWrapper";
// import { TimestampOverlay } from "./overlays/TimestampOverlay";
import { TimestampOverlay } from "./overlays/TimestampOverlay";
import { ColorMap } from "./overlays/ColorMap";
import { TrackDownloadData } from "./DownloadButton";

Expand Down Expand Up @@ -269,7 +269,7 @@
}

// TODO: add missing dependencies
}, [trackManager, dispatchCanvas, canvas.selectedPointIds]);

Check warning on line 272 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / lint-and-test

React Hook useEffect has missing dependencies: 'canvas.fetchedPointIds' and 'updateTracks'. Either include them or remove the dependency array

// playback time points
// TODO: this is basic and may drop frames
Expand Down Expand Up @@ -487,6 +487,7 @@
>
<Scene isLoading={isLoadingPoints || numLoadingTracks > 0} />
{/* <TimestampOverlay timestamp={canvas.curTime} /> */}
<TimestampOverlay timestamp={canvas.selector.sphereSelector.closestIndex} />
<ColorMap />
</Box>

Expand Down
6 changes: 3 additions & 3 deletions src/components/overlays/TimestampOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { Tag } from "@czi-sds/components";
import "@czi-sds/components/dist/variables.css";

interface TimestampOverlayProps {
timestamp: number; // Currently timestamp is a frame number, but it could be the actual timestamp
timestamp: number | undefined; // Currently timestamp is a frame number, but it could be the actual timestamp
}

export const TimestampOverlay = (props: TimestampOverlayProps) => {
return (
<Tag
label={props.timestamp.toString()}
label={props.timestamp !== undefined ? `cell = ${props.timestamp.toString()}` : "-"}
sdsStyle="square"
sdsType="secondary"
size="small"
sx={{
position: "absolute",
bottom: "0.5rem",
left: "16.5rem",
left: "0.5rem",
backgroundColor: "rgba(255, 255, 255, 0.6)",
zIndex: 100,
borderRadius: "var(--sds-corner-m)",
Expand Down
35 changes: 35 additions & 0 deletions src/lib/SpherePointSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class SpherePointSelector {
readonly selectionChanged: SelectionChanged;
readonly selectionPreviewChanged: SelectionPreviewChanged;
readonly pointer = new Vector2(0, 0);
closestIndex: number | undefined = undefined;

// True if this should not respond to pointer movements, false otherwise.
cursorLock = true;
Expand Down Expand Up @@ -149,6 +150,9 @@ export class SpherePointSelector {
this.pointer.y = (-(event.clientY - canvasElement.top) / canvasElement.height) * 2 + 1;
this.raycaster.setFromCamera(this.pointer, this.camera);
const intersects = this.raycaster.intersectObject(this.points);

const closestIndex = this.findClosestPointsToSelector();
this.closestIndex = closestIndex;
if (intersects.length > 0) {
this.cursor.position.set(intersects[0].point.x, intersects[0].point.y, intersects[0].point.z);
this.findPointsWithinSelector();
Expand Down Expand Up @@ -199,6 +203,37 @@ export class SpherePointSelector {
return selected;
}

findClosestPointsToSelector(): number | undefined {
// find the points within the cursor sphere
const normalMatrix = new Matrix3();
normalMatrix.setFromMatrix4(this.cursor.matrixWorld);
normalMatrix.invert();
const center = this.cursor.position;
const geometry = this.points.geometry;

// Check if geometry has a valid 'position' attribute (not the case in the beginning of the app, when the eventListerer of the cursor already call this function)
if (!geometry || !geometry.getAttribute("position") || geometry.getAttribute("position").count === 0) {
return;
}

const positions = geometry.getAttribute("position");
const numPoints = positions.count;
let closestDistance: number = Infinity;
let closestIndex: number = -1;
for (let i = 0; i < numPoints; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const vecToCenter = new Vector3(x, y, z).sub(center);
const scaledVecToCenter = vecToCenter.applyMatrix3(normalMatrix);
if (scaledVecToCenter.length() < closestDistance) {
closestIndex = i;
closestDistance = scaledVecToCenter.length();
}
}
return closestIndex;
}

MobileFindAndSelect() {
// if used on Mobile Device, this will select the cells upon button click
const radius = this.cursor.geometry.parameters.radius;
Expand Down
Loading