Disabled remembering of previous run's dir/files at Marie's request. Directory selec...
authormccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 8 Mar 2018 18:27:12 +0000 (18:27 +0000)
committermccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 8 Mar 2018 18:27:12 +0000 (18:27 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15405 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInAlgorithmStrokeSegmentation.java
mipav/src/plugins/PlugInDialogStrokeSegmentation.java

index 1df6161..2b7d901 100644 (file)
@@ -36,7 +36,9 @@ public class PlugInAlgorithmStrokeSegmentation extends AlgorithmBase {
     private int minAdcObjectSize = 10;\r
     private int maxAdcObjectSize = 100000;\r
     \r
-    private String outputBasename = "CoreSeg";\r
+    public static final String outputLabel = "CoreSeg";\r
+    \r
+    private String outputBasename;\r
     \r
     private static final String voiExtension = ".xml";\r
     \r
@@ -57,7 +59,7 @@ public class PlugInAlgorithmStrokeSegmentation extends AlgorithmBase {
         doSymmetryRemoval = symmetryRemoval;\r
         coreOutputDir = outputDir;\r
         \r
-        outputBasename = new File(coreOutputDir).getName() + "_" + outputBasename;\r
+        outputBasename = new File(coreOutputDir).getName() + "_" + outputLabel;\r
     }\r
     \r
     /**\r
index 8a019c3..ff0290d 100644 (file)
@@ -1,15 +1,12 @@
 import gov.nih.mipav.plugins.JDialogStandaloneScriptablePlugin;\r
 \r
 import gov.nih.mipav.model.algorithms.*;\r
-import gov.nih.mipav.model.file.FileIO;\r
-import gov.nih.mipav.model.file.FileUtility;\r
+import gov.nih.mipav.model.file.*;\r
 import gov.nih.mipav.model.scripting.*;\r
 import gov.nih.mipav.model.scripting.parameters.ParameterFactory;\r
 import gov.nih.mipav.model.structures.*;\r
 \r
 import gov.nih.mipav.view.*;\r
-import gov.nih.mipav.view.dialogs.AlgorithmParameters;\r
-import gov.nih.mipav.view.dialogs.JDialogScriptableBase;\r
 \r
 import java.awt.*;\r
 import java.awt.event.ActionEvent;\r
@@ -20,6 +17,8 @@ import javax.swing.*;
 \r
 \r
 public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptablePlugin implements AlgorithmInterface {\r
+    private static final long serialVersionUID = -8203006546174953787L;\r
+    \r
     private JRadioButton dirMethodRadio;\r
     private JRadioButton fileMethodRadio;\r
     \r
@@ -27,6 +26,12 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
     \r
     private String dirFileString;\r
     \r
+    private String adcPath = null;\r
+    private String dwiPath = null;\r
+    \r
+    private boolean foundADC = false;\r
+    private boolean foundDWI = false;\r
+    \r
     private String outputDir;\r
     \r
     private JTextField adcImageFileField;\r
@@ -169,48 +174,12 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
     }\r
     \r
     protected boolean setVariables() {\r
-        String adcPath = null;\r
-        String dwiPath = null;\r
-        \r
         boolean doDirMethod = dirMethodRadio.isSelected();\r
         \r
         if (doDirMethod) {\r
             dirFileString = dirFileField.getText();\r
-            final File dirFile = new File(dirFileString);\r
-            \r
-            File[] dirContents = dirFile.listFiles();\r
             \r
-            for (File file : dirContents) {\r
-                String nameNoExt = FileUtility.stripExtension(file.getName());\r
-                if (nameNoExt.equalsIgnoreCase(adcFileStub)) {\r
-                    if (file.isDirectory()) {\r
-                        File[] subContents = file.listFiles();\r
-                        if (subContents.length > 0) {\r
-                            adcPath = subContents[0].getAbsolutePath();\r
-                            adcImageMultifile = true;\r
-                        } else {\r
-                            MipavUtil.displayError("No files found in ADC directory: " + file.getAbsolutePath());\r
-                            return false;\r
-                        }\r
-                    } else if (file.getName().endsWith(".img")) {\r
-                        adcPath = file.getAbsolutePath();\r
-                    }\r
-                } else if (nameNoExt.equalsIgnoreCase(dwiFileStub)) {\r
-                    if (file.isDirectory()) {\r
-                        File[] subContents = file.listFiles();\r
-                        if (subContents.length > 0) {\r
-                            dwiPath = subContents[0].getAbsolutePath();\r
-                            dwiImageMultifile = true;\r
-                        } else {\r
-                            MipavUtil.displayError("No files found in DWI directory: " + file.getAbsolutePath());\r
-                            return false;\r
-                        }\r
-                    } else if (file.getName().endsWith(".img")) {\r
-                        dwiPath = file.getAbsolutePath();\r
-                    }\r
-                }\r
-            }\r
-            outputDir = dirFile.getAbsolutePath() + File.separator;\r
+            findVolumesInDir(dirFileString);\r
         } else {\r
             adcPath = adcImageFileField.getText();\r
             dwiPath = dwiImageFileField.getText();\r
@@ -393,7 +362,7 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
         mainPanel.add(labelDir, gbc);\r
         \r
         dirFileField = new JTextField(50);\r
-        dirFileField.setText(lastDir);\r
+        //dirFileField.setText(lastDir);\r
         gbc.gridx++;\r
         mainPanel.add(dirFileField, gbc);\r
         \r
@@ -439,7 +408,7 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
         mainPanel.add(labelDWI, gbc);\r
         \r
         dwiImageFileField = new JTextField(50);\r
-        dwiImageFileField.setText(lastDwi);\r
+        //dwiImageFileField.setText(lastDwi);\r
         gbc.gridx++;\r
         mainPanel.add(dwiImageFileField, gbc);\r
         \r
@@ -460,7 +429,7 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
         mainPanel.add(labelADC, gbc);\r
         \r
         adcImageFileField = new JTextField(50);\r
-        adcImageFileField.setText(lastAdc);\r
+        //adcImageFileField.setText(lastAdc);\r
         gbc.gridx++;\r
         mainPanel.add(adcImageFileField, gbc);\r
         \r
@@ -641,4 +610,95 @@ public class PlugInDialogStrokeSegmentation extends JDialogStandaloneScriptableP
 \r
         return fileIO.readImage(file.getName(), file.getParent() + File.separator, isMultiFile, null);\r
     }\r
+    \r
+    private boolean findVolumesInDir(final String dir) {\r
+        final File dirFile = new File(dir);\r
+        \r
+        File[] dirContents = dirFile.listFiles();\r
+        \r
+        for (File file : dirContents) {\r
+            String nameNoExt = FileUtility.stripExtension(file.getName());\r
+            if (nameNoExt.equalsIgnoreCase(adcFileStub)) {\r
+                if (file.isDirectory()) {\r
+                    File[] subContents = file.listFiles();\r
+                    if (subContents.length > 0) {\r
+                        adcPath = subContents[0].getAbsolutePath();\r
+                        adcImageMultifile = true;\r
+                        foundADC = true;\r
+                    }\r
+                } else if (file.getName().endsWith(".img")) {\r
+                    adcPath = file.getAbsolutePath();\r
+                    foundADC = true;\r
+                }\r
+            } else if (nameNoExt.equalsIgnoreCase(dwiFileStub)) {\r
+                if (file.isDirectory()) {\r
+                    File[] subContents = file.listFiles();\r
+                    if (subContents.length > 0) {\r
+                        dwiPath = subContents[0].getAbsolutePath();\r
+                        dwiImageMultifile = true;\r
+                        foundDWI = true;\r
+                    }\r
+                } else if (file.getName().endsWith(".img")) {\r
+                    dwiPath = file.getAbsolutePath();\r
+                    foundDWI = true;\r
+                }\r
+            }\r
+        }\r
+\r
+        if (!foundADC || !foundDWI) {\r
+            findDicomFilesRecursive(dirFile);\r
+        }\r
+        \r
+        if (!foundADC) {\r
+            MipavUtil.displayError("No ADC files found in directory: " + dir);\r
+            return false;\r
+        }\r
+        \r
+        if (!foundDWI) {\r
+            MipavUtil.displayError("No DWI files found in directory: " + dir);\r
+            return false;\r
+        }\r
+        \r
+        outputDir = dirFile.getAbsolutePath() + File.separator;\r
+        \r
+        return true;\r
+    }\r
+    \r
+    private void findDicomFilesRecursive(final File dirFile) {\r
+        \r
+        File[] dirContents = dirFile.listFiles();\r
+        \r
+        boolean checkedFirstFile = false;\r
+        for (File file : dirContents) {\r
+            if (file.isDirectory()) {\r
+                findDicomFilesRecursive(file);\r
+            } else {\r
+                if (!checkedFirstFile && !file.getName().contains(PlugInAlgorithmStrokeSegmentation.outputLabel)) {\r
+                    checkedFirstFile = true;\r
+                    ModelImage img = openImage(file, false);\r
+                    if (img != null) {\r
+                        if (img.getFileInfo(0) instanceof FileInfoDicom) {\r
+                            String imageType = (String)((FileInfoDicom)img.getFileInfo(0)).getTagTable().getValue("0008,0008");\r
+                            \r
+                            for (String val : imageType.split("\\\\")) {\r
+                                if (val.equalsIgnoreCase("ADC") || val.equalsIgnoreCase("ADC_UNSPECIFIED")) {\r
+                                    adcPath = file.getAbsolutePath();\r
+                                    adcImageMultifile = true;\r
+                                    foundADC = true;\r
+                                    break;\r
+                                } else if (val.equalsIgnoreCase("SE") || val.equalsIgnoreCase("M_SE")) {\r
+                                    dwiPath = file.getAbsolutePath();\r
+                                    dwiImageMultifile = true;\r
+                                    foundDWI = true;\r
+                                    break;\r
+                                }\r
+                            }\r
+                        }\r
+                    }\r
+                    img.disposeLocal();\r
+                    img = null;\r
+                }\r
+            }\r
+        }\r
+    }\r
 }\r