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

feat(annotation) Add default annontation properties #694

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

chrisj
Copy link
Contributor

@chrisj chrisj commented Jan 11, 2025

add line length property

This came up during a meeting that the scale bar has been used as a rough measure of the size of features in datasets. I was thinking we should have a better way to measure distance and the line annotation is already a tool that has most of the requirements.

I think it would also make sense to add additional properties for other types such as ellipsoid volume and semi axis lengths, bounding box volume and dimensions.

I am currently making assumptions to cast float32array to a vec3 and there might be a better method of using the globalCoordinateSpace.

@chrisj chrisj force-pushed the cj-annotation-default-properties branch from c826934 to 47f8d34 Compare January 11, 2025 22:52
@jbms
Copy link
Collaborator

jbms commented Jan 16, 2025

Overall I like this idea, thanks!

Originally some default properties like length, volume, etc. were shown for annotations but that support was left out when I refactored some years ago to support more than 3 dimensions.

The logic related to scales will need to change ---- the coordinate space of the annotation is not necessarily 3d and doesn't necessarily directly correspond to the global coordinate space, so some coordinate transforms will need to happen, and units taken into account also.

this.manager.root.coordinateSpace.value;
const defaultProperties = annotationTypeHandlers[
annotation.type
].defaultProperties(annotation, globalCoordinateSpace.scales);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not correct --- you need to transform the scales, taking into account the various affine transforms that apply, similar to what is done here:

function getMousePositionInAnnotationCoordinates(

let length = 0;
for (let dim = 0; dim < rank; dim++) {
length +=
(((annotation.pointA[dim] - annotation.pointB[dim]) / 1e-9) *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't always be nanometers --- it should take into account the units set in the coordinate space.

If all dimensions have the same base unit, e.g. meter, then you could just choose an appropriate scale automatically as in the scale bar.

If there are mixed units, e.g. meters and seconds, then probably just don't display the length at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to use globalCoordinateSpace.units and using ALLOWED_UNITS from scale_bar.ts to disable the property. If any unit is a non-length unit, it won't add the property. Also cleaned up the code

@chrisj chrisj force-pushed the cj-annotation-default-properties branch 2 times, most recently from c45bba8 to aad7550 Compare January 18, 2025 16:26
…ming meters

split line length code into a separate function
@chrisj chrisj force-pushed the cj-annotation-default-properties branch from aad7550 to 324342f Compare January 18, 2025 16:36
@jbms
Copy link
Collaborator

jbms commented Jan 18, 2025

The points stored in the annotation are in the "model" coordinate space. There is an affine transform that maps between that coordinate space and the concatenation of the layer-local and global coordinate spaces.

The lengths could be computed either in the "model" coordinate space or in the global coordinate space,.or maybe both, but right now you are using the untransformed points in the model coordinate space with the global coordinate space scales, which is not correct.

@chrisj
Copy link
Contributor Author

chrisj commented Jan 21, 2025

Hi Jeremy, I am now passing in the positions from visitTransformedAnnotationGeometry to the defaultAnnotationProperties function. I think I could clean it up a bit if visitTransformedAnnotationGeometry was changed from being a function that uses callbacks to instead returning an array of [layerPosition, isVector].

Does this fix the coordinate space issue? It I'm still using global scales/units. this.localCoordinateSpace.value.scales, this.localCoordinateSpace.value.units show empty. When would it have a value?

Here is an example where i can see the length increase when I give the x dimension a 10x scale.
Screenshot 2025-01-21 at 4 34 02 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants