Prototype straight->twisted takes a file of annotations in the straightened space...
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Tue, 6 Mar 2018 21:23:18 +0000 (21:23 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Tue, 6 Mar 2018 21:23:18 +0000 (21:23 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15400 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInDialogUntwistedToTwisted.java

index 87f595b..2dac2bc 100644 (file)
@@ -35,6 +35,7 @@ import gov.nih.mipav.util.MipavCoordinateSystems;
 import gov.nih.mipav.util.MipavInitGPU;\r
 import gov.nih.mipav.view.MipavUtil;\r
 import gov.nih.mipav.view.Preferences;\r
+import gov.nih.mipav.view.ViewJFrameImage;\r
 import gov.nih.mipav.view.ViewUserInterface;\r
 import gov.nih.mipav.view.dialogs.GuiBuilder;\r
 import gov.nih.mipav.view.dialogs.JDialogBase;\r
@@ -74,19 +75,23 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
         * \r
         */\r
        private static final long serialVersionUID = -5858343401705223389L;\r
-       private JRadioButton untwistedToTwisted;\r
-       private JRadioButton twistedToUntwisted;\r
-       private JRadioButton noseCentric;\r
-       private JRadioButton defaultCoords;\r
-       private ModelImage wormImage;\r
-\r
-       private String baseFileDir;\r
-       private JTextField  baseFileLocText;\r
-       private String baseFileName;\r
-       private JTextField  baseFileNameText;\r
-       private Vector<Integer> includeRange;\r
+//     private JRadioButton untwistedToTwisted;\r
+//     private JRadioButton twistedToUntwisted;\r
+//     private JRadioButton noseCentric;\r
+//     private JRadioButton defaultCoords;\r
+//     private ModelImage wormImage;\r
+\r
+//     private String baseFileDir;\r
+//     private JTextField  baseFileLocText;\r
+//     private String baseFileName;\r
+       private JTextField straightenedAnnotationText;\r
+       private String straightenedAnnotationFile;\r
+       private JTextField targetLocText;\r
+       private String targetDir;\r
+//     private JTextField  baseFileNameText;\r
+//     private Vector<Integer> includeRange;\r
        private JPanel inputsPanel;\r
-       private JTextField rangeFusionText;\r
+//     private JTextField rangeFusionText;\r
 \r
        public PlugInDialogUntwistedToTwisted()\r
        {\r
@@ -102,16 +107,16 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
         */\r
        public void actionPerformed(ActionEvent event)\r
        {\r
-               if ( event.getSource() == twistedToUntwisted && twistedToUntwisted.isSelected() )\r
-               {\r
-                       defaultCoords.setSelected(true);\r
-                       noseCentric.setSelected(false);\r
-                       noseCentric.setEnabled(false);\r
-               }\r
-               if ( event.getSource() == untwistedToTwisted && untwistedToTwisted.isSelected() )\r
-               {\r
-                       noseCentric.setEnabled(true);\r
-               }\r
+//             if ( event.getSource() == twistedToUntwisted && twistedToUntwisted.isSelected() )\r
+//             {\r
+//                     defaultCoords.setSelected(true);\r
+//                     noseCentric.setSelected(false);\r
+//                     noseCentric.setEnabled(false);\r
+//             }\r
+//             if ( event.getSource() == untwistedToTwisted && untwistedToTwisted.isSelected() )\r
+//             {\r
+//                     noseCentric.setEnabled(true);\r
+//             }\r
                \r
                String command = event.getActionCommand();\r
                if (command.equals("OK")) {\r
@@ -135,11 +140,11 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
        public void dispose()\r
        {\r
                super.dispose();\r
-               if ( wormImage != null )\r
-               {\r
-                       wormImage.disposeLocal();\r
-                       wormImage = null;\r
-               }               \r
+//             if ( wormImage != null )\r
+//             {\r
+//                     wormImage.disposeLocal();\r
+//                     wormImage = null;\r
+//             }               \r
        }\r
 \r
        public void saveSegmentationStatistics(final String dir, Vector<String> fileNamesList, Vector<Integer> numSegmented, Vector<Integer> numMatched )\r
@@ -221,189 +226,271 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
 \r
        private void callAlgorithm()\r
        {\r
-               if ( includeRange != null )\r
+               System.err.println( targetDir );\r
+               System.err.println( straightenedAnnotationFile );\r
+               \r
+               if ( (targetDir.length() == 0) || (straightenedAnnotationFile.length() == 0) ) {\r
+                       return;\r
+               }\r
+               String targetDirName = targetDir.substring(targetDir.lastIndexOf( File.separator ) + 1, targetDir.length());\r
+               System.err.println(targetDirName);\r
+\r
+               String outputDirName = straightenedAnnotationFile.substring(0, straightenedAnnotationFile.lastIndexOf( File.separator ) + 1);\r
+               String inputFileName = straightenedAnnotationFile.substring(straightenedAnnotationFile.lastIndexOf( File.separator ) + 1, straightenedAnnotationFile.lastIndexOf( '.' ));\r
+               System.err.println(outputDirName);\r
+               System.err.println(inputFileName);\r
+               \r
+               String toTwistedName = targetDir + File.separator + targetDirName + "_results" + File.separator + \r
+                               "output_images" + File.separator + targetDirName + "_toTwisted.xml";\r
+               File toTwistedFile = new File( toTwistedName );\r
+               File annotationFile = new File( straightenedAnnotationFile );\r
+               System.err.println(toTwistedName + " " + toTwistedFile.exists() );\r
+               ModelImage toTwisted = null;\r
+               if ( toTwistedFile.exists() && annotationFile.exists() )\r
                {\r
-                       System.err.println("Starting plugin" );\r
-                       for ( int i = 0; i < includeRange.size(); i++ )\r
-                       {                               \r
-                               // Build the full image name:\r
-                               baseFileName = baseFileNameText.getText();\r
-                               String fileName = baseFileName + "_" + includeRange.elementAt(i) + ".tif";\r
-                               File imageFile = new File(baseFileDir + File.separator + fileName);\r
-\r
-                               if ( imageFile.exists() )\r
-                               {       \r
-                                       System.err.println( "   " + fileName );\r
-                                       FileIO fileIO = new FileIO();\r
-                                       if ( wormImage != null )\r
+                       System.err.println("opening image...");\r
+                       FileIO fileIO = new FileIO();\r
+                       toTwisted = fileIO.readImage(toTwistedName);  \r
+                       if ( toTwisted != null )\r
+                       {\r
+//                             System.err.println("displaying image...");\r
+//                             new ViewJFrameImage(toTwisted);\r
+                               VOI annotations = LatticeModel.readAnnotationsCSV(straightenedAnnotationFile);\r
+                               if ( annotations != null )\r
+                               {\r
+                                       if ( annotations.getCurves().size() > 0 )\r
                                        {\r
-                                               wormImage.disposeLocal(false);\r
-                                               wormImage = null;\r
+                                               Vector<String> failedList = new Vector<String>();\r
+                                               VOI annotationVOI = new VOI( (short)0, inputFileName + "_" + targetDirName, VOI.ANNOTATION, 0 );\r
+                                               for ( int j = 0; j < annotations.getCurves().size(); j++ )\r
+                                               {\r
+                                                       VOIText text = (VOIText) annotations.getCurves().elementAt(j);\r
+                                                       Vector3f pos = text.elementAt(0);\r
+                                                       String name = text.getText();\r
+\r
+                                                       float valid = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 0 );\r
+                                                       //                                              if ( valid != 1 )\r
+                                                       //                                              {\r
+                                                       //                                                      System.err.println( name + " invalid position" );\r
+                                                       //                                              }\r
+                                                       float x = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 1 );\r
+                                                       float y = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 2 );\r
+                                                       float z = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 3 );\r
+                                                       Vector3f newPos = new Vector3f(x, y, z);\r
+\r
+                                                       if ( !newPos.equals( Vector3f.ZERO ) )\r
+                                                       {\r
+                                                               VOIText newText = new VOIText();\r
+                                                               newText.setText(name);\r
+                                                               newText.add(newPos);\r
+\r
+                                                               annotationVOI.getCurves().add(newText);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               failedList.add(name);\r
+                                                       }\r
+                                               }\r
+                                               LatticeModel.saveAnnotationsAsCSV(outputDirName, inputFileName + "_" + targetDirName + ".csv", annotationVOI);\r
+                                               String msg = "Retwisted " + annotationVOI.getCurves().size() + " out of " + annotations.getCurves().size() + " annotations" + "\n";\r
+                                               for ( int j = 0; j < failedList.size(); j++ )\r
+                                               {\r
+                                                       msg += failedList.elementAt(j) + " failed" + "\n";\r
+                                               }\r
+                                               MipavUtil.displayInfo( msg );\r
                                        }\r
-                                       wormImage = fileIO.readImage(fileName, baseFileDir + File.separator, false, null);  \r
-                                       WormData wormData = new WormData(wormImage);\r
-\r
-//                                     String positionsFile = baseFileName + "_" + includeRange.elementAt(i) + "_positions.csv";\r
-//                                     System.err.println( "   " + positionsFile );\r
-//                                     File textFile = new File(baseFileDir + File.separator + "Positions" + File.separator + positionsFile);\r
-//                                     if ( textFile.exists() )\r
-//                                     {                       \r
-//                                             if ( twistedToUntwisted.isSelected() )\r
-//                                             {\r
-//                                                     String latticeFile = baseFileDir + File.separator + baseFileName + "_"  + includeRange.elementAt(i) + File.separator +\r
-//                                                                     baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator +                                                                  \r
-//                                                                     PlugInAlgorithmWormUntwisting.autoLatticeGenerationOutput + "1" + File.separator;\r
-//                                                     VOIVector latticeVector = new VOIVector();\r
-//                                                     PlugInAlgorithmWormUntwisting.loadAllVOIsFrom(wormImage, latticeFile, true, latticeVector, false);\r
-//                                                     if ( latticeVector.size() != 0 )\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               System.err.println("image open failed");\r
+                       }\r
+               }\r
+               \r
+               \r
+//             if ( includeRange != null )\r
+//             {\r
+//                     System.err.println("Starting plugin" );\r
+//                     for ( int i = 0; i < includeRange.size(); i++ )\r
+//                     {                               \r
+//                             // Build the full image name:\r
+//                             baseFileName = baseFileNameText.getText();\r
+//                             String fileName = baseFileName + "_" + includeRange.elementAt(i) + ".tif";\r
+//                             File imageFile = new File(baseFileDir + File.separator + fileName);\r
+//\r
+//                             if ( imageFile.exists() )\r
+//                             {       \r
+//                                     System.err.println( "   " + fileName );\r
+//                                     FileIO fileIO = new FileIO();\r
+//                                     if ( wormImage != null )\r
+//                                     {\r
+//                                             wormImage.disposeLocal(false);\r
+//                                             wormImage = null;\r
+//                                     }\r
+//                                     wormImage = fileIO.readImage(fileName, baseFileDir + File.separator, false, null);  \r
+//                                     WormData wormData = new WormData(wormImage);\r
+//\r
+////                                   String positionsFile = baseFileName + "_" + includeRange.elementAt(i) + "_positions.csv";\r
+////                                   System.err.println( "   " + positionsFile );\r
+////                                   File textFile = new File(baseFileDir + File.separator + "Positions" + File.separator + positionsFile);\r
+////                                   if ( textFile.exists() )\r
+////                                   {                       \r
+////                                           if ( twistedToUntwisted.isSelected() )\r
+////                                           {\r
+////                                                   String latticeFile = baseFileDir + File.separator + baseFileName + "_"  + includeRange.elementAt(i) + File.separator +\r
+////                                                                   baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator +                                                                  \r
+////                                                                   PlugInAlgorithmWormUntwisting.autoLatticeGenerationOutput + "1" + File.separator;\r
+////                                                   VOIVector latticeVector = new VOIVector();\r
+////                                                   PlugInAlgorithmWormUntwisting.loadAllVOIsFrom(wormImage, latticeFile, true, latticeVector, false);\r
+////                                                   if ( latticeVector.size() != 0 )\r
+////                                                   {\r
+////                                                           VOIVector vois = readMarkerPositions(positionsFile, textFile, null);\r
+////                                                           VOI annotations = vois.elementAt(0);\r
+////\r
+////                                                           if ( annotations != null )\r
+////                                                           {\r
+////                                                                   if ( annotations.getCurves().size() > 0 )\r
+////                                                                   {\r
+////                                                                           LatticeModel model = new LatticeModel(wormImage);\r
+////                                                                           model.setSeamCellImage( wormData.readSeamSegmentation() );\r
+////                                                                           model.setLattice(latticeVector.elementAt(0));\r
+////                                                                           model.setMarkers(annotations);\r
+////\r
+////                                                                           model.interpolateLattice( false, false, false, true );  \r
+////\r
+////                                                                           VOI annotationsStraight = model.getAnnotationsStraight();\r
+////\r
+////\r
+////                                                                           String distanceName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
+////                                                                                           baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
+////                                                                                           "output_images" + File.separator + \r
+////                                                                                           baseFileName + "_" + includeRange.elementAt(i) + "_distanceMap.xml";\r
+////                                                                           File distanceMapFile = new File(baseFileDir + File.separator + distanceName );\r
+//////                                                                         System.err.println(distanceName + " " + distanceMapFile.exists() );                                                                                     \r
+////                                                                           ModelImage distanceMap = null;\r
+////                                                                           if ( distanceMapFile.exists() )\r
+////                                                                           {\r
+////                                                                                   distanceMap = fileIO.readImage(distanceName, baseFileDir + File.separator, false, null);\r
+////                                                                           }\r
+////                                                                           Vector<Integer> distance = null;\r
+////                                                                           if ( distanceMap != null )\r
+////                                                                           {\r
+////                                                                                   distance = new Vector<Integer>();\r
+////                                                                                   for ( int j = 0; j < annotationsStraight.getCurves().size(); j++ )\r
+////                                                                                   {\r
+////                                                                                           VOIText text = (VOIText) annotationsStraight.getCurves().elementAt(j);\r
+////                                                                                           Vector3f pos = text.elementAt(0);\r
+////                                                                                           int d = (distanceMap == null) ? 0 : distanceMap.getInt( (int)pos.X, (int)pos.Y, (int)pos.Z );\r
+////                                                                                           distance.add(d);\r
+////                                                                                   }\r
+////                                                                                   \r
+////                                                                                   distanceMap.disposeLocal(false);\r
+////                                                                                   distanceMap = null;\r
+////                                                                           }\r
+////\r
+////                                                                           String fileBase = baseFileName + "_" + includeRange.elementAt(i) + "_positions_straight.csv";\r
+////                                                                           saveMarkerPositions(baseFileDir + File.separator + "Positions" + File.separator + fileBase, annotationsStraight, distance);\r
+////                                                                           model.dispose();\r
+////                                                                           model = null;\r
+////                                                                   }\r
+////                                                           }\r
+////                                                   }\r
+////                                           }\r
+////                                           else if ( untwistedToTwisted.isSelected() )\r
+////                                           {\r
+//                                                     String toTwistedName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
+//                                                                     baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
+//                                                                     "output_images" + File.separator + \r
+//                                                                     baseFileName + "_" + includeRange.elementAt(i) + "_toTwisted.xml";\r
+//                                                     File toTwistedFile = new File(baseFileDir + File.separator + toTwistedName );\r
+////                                                   System.err.println(toTwistedName + " " + toTwistedFile.exists() );\r
+//                                                     ModelImage toTwisted = null;\r
+//                                                     if ( toTwistedFile.exists() )\r
+//                                                     {\r
+//                                                             toTwisted = fileIO.readImage(toTwistedName, baseFileDir + File.separator, false, null);  \r
+//                                                     }\r
+//                                                     String distanceName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
+//                                                                     baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
+//                                                                     "output_images" + File.separator + \r
+//                                                                     baseFileName + "_" + includeRange.elementAt(i) + "_distanceMap.xml";\r
+//                                                     File distanceMapFile = new File(baseFileDir + File.separator + distanceName );\r
+////                                                   System.err.println(distanceName + " " + distanceMapFile.exists() );\r
+//                                                     ModelImage distanceMap = null;\r
+//                                                     if ( distanceMapFile.exists() )\r
+//                                                     {\r
+//                                                             distanceMap = fileIO.readImage(distanceName, baseFileDir + File.separator, false, null);  \r
+//                                                     }\r
+//                                                     if ( toTwisted != null )\r
 //                                                     {\r
-//                                                             VOIVector vois = readMarkerPositions(positionsFile, textFile, null);\r
+//                                                             String positionsFile = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
+//                                                                             baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + "tracked_annotations" + File.separator + \r
+//                                                                             "tracked_annotations.csv";\r
+//                                                             File textFile = new File(baseFileDir + File.separator + positionsFile);\r
+//                                                                             \r
+//                                                             int[] imageExtents = new int[]{toTwisted.getExtents()[0], toTwisted.getExtents()[1]};\r
+//                                                             VOIVector vois = readMarkerPositions(positionsFile, textFile, imageExtents);\r
 //                                                             VOI annotations = vois.elementAt(0);\r
 //\r
 //                                                             if ( annotations != null )\r
 //                                                             {\r
 //                                                                     if ( annotations.getCurves().size() > 0 )\r
 //                                                                     {\r
-//                                                                             LatticeModel model = new LatticeModel(wormImage);\r
-//                                                                             model.setSeamCellImage( wormData.readSeamSegmentation() );\r
-//                                                                             model.setLattice(latticeVector.elementAt(0));\r
-//                                                                             model.setMarkers(annotations);\r
 //\r
-//                                                                             model.interpolateLattice( false, false, false, true );  \r
+//                                                                             VOI annotationVOI = new VOI( (short)0, fileName, VOI.ANNOTATION, 0 );\r
+//                                                                             Vector<Integer> distance = new Vector<Integer>();\r
+//                                                                             for ( int j = 0; j < annotations.getCurves().size(); j++ )\r
+//                                                                             {\r
+//                                                                                     VOIText text = (VOIText) annotations.getCurves().elementAt(j);\r
+//                                                                                     Vector3f pos = text.elementAt(0);\r
+//                                                                                     String name = text.getText();\r
+//\r
+//                                                                                     float valid = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 0 );\r
+////                                                                                   if ( valid != 1 )\r
+////                                                                                   {\r
+////                                                                                           System.err.println( name + " invalid position" );\r
+////                                                                                   }\r
+//                                                                                     float x = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 1 );\r
+//                                                                                     float y = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 2 );\r
+//                                                                                     float z = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 3 );\r
+//                                                                                     Vector3f newPos = new Vector3f(x, y, z);\r
 //\r
-//                                                                             VOI annotationsStraight = model.getAnnotationsStraight();\r
+//                                                                                     VOIText newText = new VOIText();\r
+//                                                                                     newText.setText(name);\r
+//                                                                                     newText.add(newPos);\r
 //\r
+//                                                                                     annotationVOI.getCurves().add(newText);\r
 //\r
-//                                                                             String distanceName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
-//                                                                                             baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
-//                                                                                             "output_images" + File.separator + \r
-//                                                                                             baseFileName + "_" + includeRange.elementAt(i) + "_distanceMap.xml";\r
-//                                                                             File distanceMapFile = new File(baseFileDir + File.separator + distanceName );\r
-////                                                                           System.err.println(distanceName + " " + distanceMapFile.exists() );                                                                                     \r
-//                                                                             ModelImage distanceMap = null;\r
-//                                                                             if ( distanceMapFile.exists() )\r
-//                                                                             {\r
-//                                                                                     distanceMap = fileIO.readImage(distanceName, baseFileDir + File.separator, false, null);\r
+//\r
+//                                                                                     int d = (distanceMap == null) ? 0 : distanceMap.getInt( (int)pos.X, (int)pos.Y, (int)pos.Z );\r
+//                                                                                     distance.add(d);\r
 //                                                                             }\r
-//                                                                             Vector<Integer> distance = null;\r
+//                                                                             \r
+//                                                                             String outputFile = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
+//                                                                                             baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + "tracked_annotations" + File.separator + \r
+//                                                                                             "tracked_annotations_twisted.csv";\r
+//                                                                             saveMarkerPositions(baseFileDir + File.separator + outputFile, annotationVOI, distance);\r
+//                                                                             \r
+//                                                                             toTwisted.disposeLocal(false);\r
+//                                                                             toTwisted = null;\r
 //                                                                             if ( distanceMap != null )\r
 //                                                                             {\r
-//                                                                                     distance = new Vector<Integer>();\r
-//                                                                                     for ( int j = 0; j < annotationsStraight.getCurves().size(); j++ )\r
-//                                                                                     {\r
-//                                                                                             VOIText text = (VOIText) annotationsStraight.getCurves().elementAt(j);\r
-//                                                                                             Vector3f pos = text.elementAt(0);\r
-//                                                                                             int d = (distanceMap == null) ? 0 : distanceMap.getInt( (int)pos.X, (int)pos.Y, (int)pos.Z );\r
-//                                                                                             distance.add(d);\r
-//                                                                                     }\r
-//                                                                                     \r
 //                                                                                     distanceMap.disposeLocal(false);\r
 //                                                                                     distanceMap = null;\r
 //                                                                             }\r
-//\r
-//                                                                             String fileBase = baseFileName + "_" + includeRange.elementAt(i) + "_positions_straight.csv";\r
-//                                                                             saveMarkerPositions(baseFileDir + File.separator + "Positions" + File.separator + fileBase, annotationsStraight, distance);\r
-//                                                                             model.dispose();\r
-//                                                                             model = null;\r
 //                                                                     }\r
 //                                                             }\r
 //                                                     }\r
-//                                             }\r
-//                                             else if ( untwistedToTwisted.isSelected() )\r
-//                                             {\r
-                                                       String toTwistedName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
-                                                                       baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
-                                                                       "output_images" + File.separator + \r
-                                                                       baseFileName + "_" + includeRange.elementAt(i) + "_toTwisted.xml";\r
-                                                       File toTwistedFile = new File(baseFileDir + File.separator + toTwistedName );\r
-//                                                     System.err.println(toTwistedName + " " + toTwistedFile.exists() );\r
-                                                       ModelImage toTwisted = null;\r
-                                                       if ( toTwistedFile.exists() )\r
-                                                       {\r
-                                                               toTwisted = fileIO.readImage(toTwistedName, baseFileDir + File.separator, false, null);  \r
-                                                       }\r
-                                                       String distanceName = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
-                                                                       baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + \r
-                                                                       "output_images" + File.separator + \r
-                                                                       baseFileName + "_" + includeRange.elementAt(i) + "_distanceMap.xml";\r
-                                                       File distanceMapFile = new File(baseFileDir + File.separator + distanceName );\r
-//                                                     System.err.println(distanceName + " " + distanceMapFile.exists() );\r
-                                                       ModelImage distanceMap = null;\r
-                                                       if ( distanceMapFile.exists() )\r
-                                                       {\r
-                                                               distanceMap = fileIO.readImage(distanceName, baseFileDir + File.separator, false, null);  \r
-                                                       }\r
-                                                       if ( toTwisted != null )\r
-                                                       {\r
-                                                               String positionsFile = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
-                                                                               baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + "tracked_annotations" + File.separator + \r
-                                                                               "tracked_annotations.csv";\r
-                                                               File textFile = new File(baseFileDir + File.separator + positionsFile);\r
-                                                                               \r
-                                                               int[] imageExtents = new int[]{toTwisted.getExtents()[0], toTwisted.getExtents()[1]};\r
-                                                               VOIVector vois = readMarkerPositions(positionsFile, textFile, imageExtents);\r
-                                                               VOI annotations = vois.elementAt(0);\r
-\r
-                                                               if ( annotations != null )\r
-                                                               {\r
-                                                                       if ( annotations.getCurves().size() > 0 )\r
-                                                                       {\r
-\r
-                                                                               VOI annotationVOI = new VOI( (short)0, fileName, VOI.ANNOTATION, 0 );\r
-                                                                               Vector<Integer> distance = new Vector<Integer>();\r
-                                                                               for ( int j = 0; j < annotations.getCurves().size(); j++ )\r
-                                                                               {\r
-                                                                                       VOIText text = (VOIText) annotations.getCurves().elementAt(j);\r
-                                                                                       Vector3f pos = text.elementAt(0);\r
-                                                                                       String name = text.getText();\r
-\r
-                                                                                       float valid = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 0 );\r
-//                                                                                     if ( valid != 1 )\r
-//                                                                                     {\r
-//                                                                                             System.err.println( name + " invalid position" );\r
-//                                                                                     }\r
-                                                                                       float x = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 1 );\r
-                                                                                       float y = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 2 );\r
-                                                                                       float z = toTwisted.getFloatC( (int)pos.X, (int)pos.Y, (int)pos.Z, 3 );\r
-                                                                                       Vector3f newPos = new Vector3f(x, y, z);\r
-\r
-                                                                                       VOIText newText = new VOIText();\r
-                                                                                       newText.setText(name);\r
-                                                                                       newText.add(newPos);\r
-\r
-                                                                                       annotationVOI.getCurves().add(newText);\r
-\r
-\r
-                                                                                       int d = (distanceMap == null) ? 0 : distanceMap.getInt( (int)pos.X, (int)pos.Y, (int)pos.Z );\r
-                                                                                       distance.add(d);\r
-                                                                               }\r
-                                                                               \r
-                                                                               String outputFile = baseFileName + "_" + includeRange.elementAt(i) + File.separator + \r
-                                                                                               baseFileName + "_" + includeRange.elementAt(i) + "_results" + File.separator + "tracked_annotations" + File.separator + \r
-                                                                                               "tracked_annotations_twisted.csv";\r
-                                                                               saveMarkerPositions(baseFileDir + File.separator + outputFile, annotationVOI, distance);\r
-                                                                               \r
-                                                                               toTwisted.disposeLocal(false);\r
-                                                                               toTwisted = null;\r
-                                                                               if ( distanceMap != null )\r
-                                                                               {\r
-                                                                                       distanceMap.disposeLocal(false);\r
-                                                                                       distanceMap = null;\r
-                                                                               }\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-//                                             }\r
-//                                     }\r
-                               }\r
-                               else\r
-                               {\r
-                                       MipavUtil.displayError( "Error in reading image file " + fileName );\r
-                               }\r
-\r
-                       }\r
-                       System.err.println("Done plugin" );\r
-               }\r
+////                                           }\r
+////                                   }\r
+//                             }\r
+//                             else\r
+//                             {\r
+//                                     MipavUtil.displayError( "Error in reading image file " + fileName );\r
+//                             }\r
+//\r
+//                     }\r
+//                     System.err.println("Done plugin" );\r
+//             }\r
        }     \r
 \r
 \r
@@ -443,17 +530,21 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
                inputsPanel.setBorder(JDialogBase.buildTitledBorder("Input Options"));\r
                inputsPanel.setForeground(Color.black);\r
 \r
-               baseFileLocText = gui.buildFileField("Data directory: ", "", false, JFileChooser.DIRECTORIES_ONLY, this);\r
-               inputsPanel.add(baseFileLocText.getParent(), gbc);\r
+               straightenedAnnotationText = gui.buildFileField("Annotations to retwist: ", "", false, JFileChooser.FILES_ONLY, this);\r
+               inputsPanel.add(straightenedAnnotationText.getParent(), gbc);\r
                gbc.gridy++;\r
 \r
-               baseFileNameText = gui.buildField("Base images name: ", "Decon");\r
-               inputsPanel.add(baseFileNameText.getParent(), gbc);\r
+               targetLocText = gui.buildFileField("Target directory: ", "", false, JFileChooser.DIRECTORIES_ONLY, this);\r
+               inputsPanel.add(targetLocText.getParent(), gbc);\r
                gbc.gridy++;\r
 \r
-               rangeFusionText = gui.buildField("Range of images to segment (ex. 3-7, 12, 18-21, etc.): ", "             ");\r
-               inputsPanel.add(rangeFusionText.getParent(), gbc);\r
-               gbc.gridy++;\r
+//             baseFileNameText = gui.buildField("Base images name: ", "Decon");\r
+//             inputsPanel.add(baseFileNameText.getParent(), gbc);\r
+//             gbc.gridy++;\r
+//\r
+//             rangeFusionText = gui.buildField("Range of images to segment (ex. 3-7, 12, 18-21, etc.): ", "             ");\r
+//             inputsPanel.add(rangeFusionText.getParent(), gbc);\r
+//             gbc.gridy++;\r
 \r
 //             ButtonGroup group = new ButtonGroup();\r
 //             untwistedToTwisted = gui.buildRadioButton( "untwisted->twisted", true);\r
@@ -591,35 +682,39 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
         */\r
        private boolean setVariables()\r
        {           \r
-               baseFileDir = baseFileLocText.getText();\r
-               includeRange = new Vector<Integer>();\r
-               String rangeFusion = rangeFusionText.getText();\r
-               if(rangeFusion != null) {  \r
-                       String[] ranges = rangeFusion.split("[,;]");\r
-                       for(int i=0; i<ranges.length; i++) {\r
-                               String[] subset = ranges[i].split("-");\r
-                               int lowerBound = -1, bound = -1;\r
-                               for(int j=0; j<subset.length; j++) {\r
-                                       try {\r
-                                               bound = Integer.valueOf(subset[j].trim());\r
-                                               if(lowerBound == -1) {\r
-                                                       lowerBound = bound;\r
-                                                       includeRange.add(lowerBound);\r
-                                               } \r
-                                       } catch(NumberFormatException e) {\r
-                                               Preferences.debug("Invalid range specified: "+bound, Preferences.DEBUG_ALGORITHM);\r
-                                       }\r
-                               }\r
-\r
-                               for(int k=lowerBound+1; k<=bound; k++) {\r
-                                       includeRange.add(k);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if(includeRange.size() == 0) {\r
-                       includeRange = null;\r
-               }\r
+               straightenedAnnotationFile = straightenedAnnotationText.getText();\r
+               targetDir = targetLocText.getText();\r
+               \r
+               \r
+//             baseFileDir = baseFileLocText.getText();\r
+//             includeRange = new Vector<Integer>();\r
+//             String rangeFusion = rangeFusionText.getText();\r
+//             if(rangeFusion != null) {  \r
+//                     String[] ranges = rangeFusion.split("[,;]");\r
+//                     for(int i=0; i<ranges.length; i++) {\r
+//                             String[] subset = ranges[i].split("-");\r
+//                             int lowerBound = -1, bound = -1;\r
+//                             for(int j=0; j<subset.length; j++) {\r
+//                                     try {\r
+//                                             bound = Integer.valueOf(subset[j].trim());\r
+//                                             if(lowerBound == -1) {\r
+//                                                     lowerBound = bound;\r
+//                                                     includeRange.add(lowerBound);\r
+//                                             } \r
+//                                     } catch(NumberFormatException e) {\r
+//                                             Preferences.debug("Invalid range specified: "+bound, Preferences.DEBUG_ALGORITHM);\r
+//                                     }\r
+//                             }\r
+//\r
+//                             for(int k=lowerBound+1; k<=bound; k++) {\r
+//                                     includeRange.add(k);\r
+//                             }\r
+//                     }\r
+//             }\r
+//\r
+//             if(includeRange.size() == 0) {\r
+//                     includeRange = null;\r
+//             }\r
 \r
                return true;\r
        }\r