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

Add options to tool hydrate method #1776

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jmhmd
Copy link
Contributor

@jmhmd jmhmd commented Jan 23, 2025

Context

hydrate methods of tools use whatever the current viewport camera properties are to populate the new annotation metadata, which may not be desired if adding an annotation to some arbitrary location in the volume or to a specific 2D image.

Changes & Results

  • Optional referencedImageId, viewPlaneNormal, and viewUp to populate annotation metadata rather than use current viewport data.
  • Don't calculate spline polyline coordinates on hydration, as this only works for the current camera position, not any passed in parameters. It appears this gets recalculated on annotation render anyways, so seems to be redundant.

Testing

Checklist

PR

  • [] My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] "OS:
  • [] "Node version:
  • [] "Browser:

- Optional referencedImageId, viewPlaneNormal, and viewUp to populate annotation metadata rather than use current viewport data.
- Don't calculate spline polyline coordinates on hydration, as this only works for the current camera position, not any passed in parameters. It appears this gets recalculated on annotation render anyways, so seems to be redundant.
Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit 8d5080a
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/679a4558bcdd9500088b8012
😎 Deploy Preview https://deploy-preview-1776--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

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

see my comments thanks a lot

@jmhmd
Copy link
Contributor Author

jmhmd commented Jan 29, 2025

Changes applied

Copy link
Member

sedghi commented Jan 29, 2025

can we do the refactoring of the base class too?

@jmhmd
Copy link
Contributor Author

jmhmd commented Jan 29, 2025

Which base tool? AnnotationTool.ts doesn't have a hydrate method

@sedghi
Copy link
Member

sedghi commented Jan 29, 2025

Yes, AnnotationTool, so we do something like

protected static hydrateBase(
    ToolClass: new () => T,
    viewportId: string,
    points: Types.Point3[],
    options?: {
      annotationUID?: string;
      instance?: T;
      referencedImageId?: string;
      viewplaneNormal?: Types.Point3;
      viewUp?: Types.Point3;
    }
  ) {
    const enabledElement = getEnabledElementByViewportId(viewportId);
    if (!enabledElement) {
      return;
    }
    const { viewport } = enabledElement;
    const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();

    let { viewPlaneNormal, viewUp } = viewport.getCamera();
    if (options?.viewplaneNormal && options?.viewUp) {
      viewPlaneNormal = options.viewplaneNormal;
      viewUp = options.viewUp;
    }

    const instance = options?.instance || new ToolClass();

    let referencedImageId = instance.getReferencedImageId(
      viewport,
      points[0],
      viewPlaneNormal,
      viewUp
    );

    if (options?.referencedImageId) {
      if (referencedImageId !== options.referencedImageId) {
        viewPlaneNormal = undefined;
        viewUp = undefined;
      }
      referencedImageId = options.referencedImageId;
    }

return those informatino back to the tool 

and in each tool you call it, since you can see the repetition of handling viewUp, viewPlaneNormal with or without options et

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