Saves any annotations in the resliced coordinates when the user selects 'reslice...
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 16 Feb 2018 02:30:30 +0000 (02:30 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 16 Feb 2018 02:30:30 +0000 (02:30 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15381 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInAlgorithmWormUntwisting.java

index 4de814f..75f3d0d 100644 (file)
@@ -36,6 +36,7 @@ import gov.nih.mipav.model.structures.ModelImageToImageJConversion;
 import gov.nih.mipav.model.structures.ModelStorageBase;\r
 import gov.nih.mipav.model.structures.TransMatrix;\r
 import gov.nih.mipav.model.structures.VOI;\r
+import gov.nih.mipav.model.structures.VOIBase;\r
 import gov.nih.mipav.model.structures.VOIVector;\r
 import gov.nih.mipav.view.MipavUtil;\r
 import gov.nih.mipav.view.ViewJFrameImage;\r
@@ -50,6 +51,8 @@ import java.util.Vector;
 \r
 import javax.swing.JProgressBar;\r
 \r
+import WildMagic.LibFoundation.Mathematics.Vector3f;\r
+\r
 /**\r
  * Implements batch algorithms for worm untwisting:\r
  * 1. automatic seam cell detection\r
@@ -280,18 +283,24 @@ public class PlugInAlgorithmWormUntwisting
                                File imageFile = new File(baseFileDir + File.separator + subDirName + subDirNameResults + PlugInAlgorithmWormUntwisting.outputImages + File.separator + imageName);\r
                                File imageFile2 = new File(baseFileDir2 + File.separator + subDirName + subDirNameResults + PlugInAlgorithmWormUntwisting.outputImages + File.separator + imageName);\r
                                \r
-                               if ( imageFile.exists() ) {\r
-                                       resliceRotate(imageFile, imageName, xSize, ySize, zSize );\r
+                               if ( imageFile.exists() ) {                                     \r
+                                       Vector3f[] conversion = resliceRotate(imageFile, imageName, xSize, ySize, zSize );                                      \r
+                                       resliceAnnotations( baseFileDir + File.separator + subDirName + subDirNameResults + "straightened_annotations" + File.separator, "straightened_annotations", conversion);\r
+                                       resliceAnnotations( baseFileDir + File.separator + subDirName + subDirNameResults + "straightened_lattice" + File.separator, "straightened_lattice", conversion);\r
+                                       resliceAnnotations( baseFileDir + File.separator + subDirName + subDirNameResults + "straightened_seamcells" + File.separator, "straightened_seamcells", conversion);\r
                                }\r
                                if ( imageFile2.exists() ) {\r
-                                       resliceRotate(imageFile2, imageName, xSize, ySize, zSize );\r
+                                       Vector3f[] conversion = resliceRotate(imageFile2, imageName, xSize, ySize, zSize );                                     \r
+                                       resliceAnnotations( baseFileDir2 + File.separator + subDirName + subDirNameResults + "straightened_annotations" + File.separator, "straightened_annotations", conversion);\r
+                                       resliceAnnotations( baseFileDir2 + File.separator + subDirName + subDirNameResults + "straightened_lattice" + File.separator, "straightened_lattice", conversion);\r
+                                       resliceAnnotations( baseFileDir2 + File.separator + subDirName + subDirNameResults + "straightened_seamcells" + File.separator, "straightened_seamcells", conversion);\r
                                }\r
                        }\r
                }\r
                MipavUtil.displayInfo( "Image reslicing complete." );\r
        }\r
        \r
-       private static void resliceRotate( File imageFile, String imageName, int xSize, int ySize, int zSize ) {\r
+       private static Vector3f[] resliceRotate( File imageFile, String imageName, int xSize, int ySize, int zSize ) {\r
 \r
                FileIO fileIO = new FileIO();\r
                ModelImage wormImage = fileIO.readImage(imageName, imageFile.getParent() + File.separator, false, null); \r
@@ -303,7 +312,10 @@ public class PlugInAlgorithmWormUntwisting
                        int[] marginX = new int[]{(xSize - dimX)/2, (xSize - dimX)/2};\r
                        int[] marginY = new int[]{(ySize - dimY)/2, (ySize - dimY)/2};\r
                        int[] marginZ = new int[]{0, (zSize - dimZ)};\r
-                                                                       \r
+\r
+                       Vector3f shiftV = new Vector3f( dimX/2, dimY/2, 0 );\r
+                       Vector3f offsetV = new Vector3f( (xSize - dimX)/2, (ySize - dimY)/2, 0 );\r
+                       \r
                        int[] destExtents = new int[]{xSize,ySize,zSize};\r
 \r
             ModelImage resliceImage = new ModelImage(wormImage.getType(), destExtents, JDialogBase.makeImageName(wormImage.getImageName(), "_temp.xml"));\r
@@ -333,8 +345,46 @@ public class PlugInAlgorithmWormUntwisting
                wormImage.disposeLocal(false);\r
                resliceImage.disposeLocal(false);\r
                resultImage.disposeLocal(false);\r
+               \r
+               return new Vector3f[]{shiftV, offsetV};\r
+               }\r
+               \r
+               return null;\r
+       }\r
+       \r
+       private static void resliceAnnotations( String path, String name, Vector3f[] conversion ) {\r
+\r
+               Vector3f shift = conversion[0];\r
+               Vector3f offset = conversion[1];\r
+               \r
+               VOI annotations = LatticeModel.readAnnotationsCSV(path + name + ".csv");\r
+               if ( annotations == null ) return;\r
+               VOI localVOI = new VOI(annotations);\r
+               for ( int i = 0; i < localVOI.getCurves().size(); i++ ) {\r
+                       VOIBase curveOrig = localVOI.getCurves().elementAt(i);\r
+                       // add offset:\r
+                       for ( int j = 0; j < curveOrig.size(); j++ ) {\r
+                               curveOrig.elementAt(j).X -= shift.X;\r
+                               curveOrig.elementAt(j).Y -= shift.Y;\r
+\r
+                               curveOrig.elementAt(j).X += offset.X;\r
+                               curveOrig.elementAt(j).Y += offset.Y;\r
+\r
+                               curveOrig.elementAt(j).X += shift.X;\r
+                               curveOrig.elementAt(j).Y += shift.Y;\r
+                       }\r
+                       // swap y and z coordinates:\r
+                       for ( int j = 0; j < curveOrig.size(); j++ ) {\r
+                               float temp = curveOrig.elementAt(j).Y;\r
+                               curveOrig.elementAt(j).Y = curveOrig.elementAt(j).Z;\r
+                               curveOrig.elementAt(j).Z = temp;\r
+                       }\r
                }\r
+\r
+               LatticeModel.saveAnnotationsAsCSV(path, name + "_reslice.csv", localVOI);\r
+               \r
        }\r
+       \r
 \r
        /**\r
         * Run the lattice-based worm straightening algorithm for the list of input files.\r