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

Non-linear mesh warping #234

Open
dbirman opened this issue Nov 6, 2022 · 2 comments
Open

Non-linear mesh warping #234

dbirman opened this issue Nov 6, 2022 · 2 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@dbirman
Copy link
Member

dbirman commented Nov 6, 2022

https://sourceforge.net/projects/simpleitk/files/SimpleITK/1.2.4/CSharp/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using sitk = itk.simple.SimpleITK;
using simple = itk.simple;

namespace CoordinateTransforms
{
    public class ANTsTransform : CoordinateTransform
    {

        string affineFileName = "C:/Users/yoni.browning/OneDrive - Allen Institute/Desktop/PaxinosAlignment/FromCodeOcean/results/twentyfive_um_resolution0GenericAffine.mat";
        string forwardFileName = "C:/Users/yoni.browning/OneDrive - Allen Institute/Desktop/PaxinosAlignment/FromCodeOcean/results/twentyfive_um_resolution1Warp.nii.gz";
        string inverseFileName = "C:/Users/yoni.browning/OneDrive - Allen Institute/Desktop/PaxinosAlignment/FromCodeOcean/results/twentyfive_um_resolution1InverseWarp.nii.gz";

        simple.Transform  affineTransform;

        simple.DisplacementFieldTransform  forwardWarping;

        simple.DisplacementFieldTransform inverseWarping;

        public override string Name { get { return "ANTs"; } }

        public override string Prefix { get { return "an"; } }

        // Start is called before the first frame update
        public ANTsTransform()
        {
            Debug.Log("Fitting Affine");
            affineTransform = sitk.ReadTransform(affineFileName);
            
            
            simple.CastImageFilter castFilter = new simple.CastImageFilter();
            castFilter.SetOutputPixelType(simple.PixelIDValueEnum.sitkFloat64);

            Debug.Log("Fitting FWD");

            simple.Image forwardImage = sitk.ReadImage(forwardFileName);
            forwardImage = sitk.Cast(forwardImage,simple.PixelIDValueEnum.sitkVectorFloat64);
            forwardWarping = new simple.DisplacementFieldTransform(3);
            forwardWarping.SetDisplacementField(forwardImage);
            Debug.Log("Fitting INV");

            simple.Image inverseImage = sitk.ReadImage(inverseFileName);
            inverseImage = sitk.Cast(inverseImage,simple.PixelIDValueEnum.sitkVectorFloat64);
            inverseWarping = new simple.DisplacementFieldTransform(3);
            inverseWarping.SetDisplacementField(inverseImage);
            Debug.Log("Done");

        }


        public override Vector3 Transform2Space(Vector3 coord)
        {
            List<double> point = new List<double>();
            point.Add(coord.x);
            point.Add(coord.y);
            point.Add(coord.z);
            simple.VectorDouble transform_pt = new simple.VectorDouble(point);
            transform_pt = forwardWarping.TransformPoint(transform_pt);
            transform_pt = affineTransform.TransformPoint(transform_pt);
            return new Vector3((float)transform_pt[0],(float)transform_pt[1],(float)transform_pt[2]);
        }

        public override Vector3 Space2Transform(Vector3 coord)
        {
            List<double> point = new List<double>();
            point.Add(coord.x);
            point.Add(coord.y);
            point.Add(coord.z);

            simple.VectorDouble transform_pt = new simple.VectorDouble(point);
            transform_pt = affineTransform.TransformPoint(transform_pt);
            transform_pt = inverseWarping.TransformPoint(transform_pt);
            return new Vector3((float)transform_pt[0],(float)transform_pt[1],(float)transform_pt[2]);        }

        public override Vector3 Transform2SpaceRot(Vector3 coordTransformed)
        {
            throw new System.NotImplementedException();
        }

        public override Vector3 Space2TransformRot(Vector3 coordSpace)
        {
            throw new System.NotImplementedException();
;
        }
    }
}
@dbirman dbirman added the feature New feature or request label Nov 6, 2022
@dbirman dbirman added this to the v0.8.3 milestone Nov 6, 2022
@dbirman dbirman self-assigned this Nov 6, 2022
@dbirman
Copy link
Member Author

dbirman commented Dec 13, 2022

Tested w/ ITK -- 120MB for ITK, mesh warps are 1.2GB each for forward and inverse warp functions... not practical.

Possible options:

  • Implement a server and query the warp at select coordinates (slow)
  • Convert the warp into a volume with warp coordinates embedded, then save that Asset and load it via Addressables (fast, high memory pressure, might not work on WebGL?)
  • Windows-only?

@dbirman dbirman modified the milestones: v0.8.X, v0.10.X Dec 22, 2022
@dbirman
Copy link
Member Author

dbirman commented Dec 22, 2022

Pushing feature back to 0.10.X

@dbirman dbirman modified the milestones: v1.0.0, v1.0.X Aug 1, 2023
@dbirman dbirman modified the milestones: v1.0.X, v1.3.X Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant