Added automatic naming of seam cells based on the lattice and the 488 marker.
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Mon, 23 Apr 2018 17:52:49 +0000 (17:52 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Mon, 23 Apr 2018 17:52:49 +0000 (17:52 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15455 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/view/renderer/WildMagic/WormUntwisting/LatticeModel.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/WormUntwisting/WormData.java
mipav/src/plugins/PlugInDialogVolumeRender.java

index 21814c0..de4e507 100644 (file)
@@ -77,7 +77,8 @@ public class LatticeModel {
                                        final File lrFile = new File(voiDir + list[i]);\r
                                        lrFile.delete();\r
                                }\r
-                       } else if (voiFileDir.exists() && !voiFileDir.isDirectory()) { // voiFileDir.delete();\r
+                       } else if (voiFileDir.exists() && !voiFileDir.isDirectory()) { \r
+                               voiFileDir.delete();\r
                        } else { // voiFileDir does not exist\r
 //                             System.err.println( "saveAllVOIsTo " + voiDir);\r
                                voiFileDir.mkdir();\r
@@ -123,7 +124,7 @@ public class LatticeModel {
        public static void saveAnnotationsAsCSV(final String dir, final String fileName, VOI annotations)\r
        {\r
                Preferences.debug("Saving annotations list: " + "\n", Preferences.DEBUG_ALGORITHM );\r
-               System.err.println("Saving annotations list: " );\r
+               System.err.println("Saving annotations list: " + dir + "  " + fileName );\r
                int numSaved = 0;\r
                // check files, create new directories and delete any existing files:\r
                final File fileDir = new File(dir);\r
index f210309..9bde106 100644 (file)
@@ -11,12 +11,14 @@ import gov.nih.mipav.view.dialogs.JDialogBase;
 \r
 import java.awt.Color;\r
 import java.io.File;\r
+import java.util.Arrays;\r
 import java.util.HashMap;\r
 import java.util.Vector;\r
 \r
 import WildMagic.LibFoundation.Containment.ContBox3f;\r
 import WildMagic.LibFoundation.Mathematics.Box3f;\r
 import WildMagic.LibFoundation.Mathematics.Matrix3f;\r
+import WildMagic.LibFoundation.Mathematics.Vector2d;\r
 import WildMagic.LibFoundation.Mathematics.Vector3f;\r
 \r
 public class WormData\r
@@ -230,6 +232,13 @@ public class WormData
                return lattice;\r
        }\r
        \r
+       public VOIVector openStraightSeamCells()\r
+       {\r
+               VOIVector lattice = new VOIVector();\r
+               LatticeModel.loadAllVOIsFrom(wormImage, outputDirectory + File.separator + straightenedSeamCells + File.separator, true, lattice, true);\r
+               return lattice;\r
+       }\r
+       \r
        public VOIVector[] readAutoLattice()\r
        {\r
                VOIVector[] latticeList = new VOIVector[5];\r
@@ -426,7 +435,7 @@ public class WormData
                return (count == 2) || (count == 0);\r
        }\r
        \r
-       public void saveSeamAnnotations()\r
+       public void saveSeamAnnotations(boolean rename)\r
        {               \r
                seamCellPoints = new Vector<Vector3f>();\r
                for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
@@ -606,16 +615,20 @@ public class WormData
                }\r
                System.err.println( seamCellPoints.size() + "  allfound? " + allMatch );\r
 \r
-               int id = 1;\r
-               for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+               if ( rename )\r
                {\r
-                       VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
-                       if ( !(text.getText().equalsIgnoreCase("origin") || text.getText().contains("nose") || text.getText().contains("Nose")) )\r
+                       int id = 1;\r
+                       for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
                        {\r
-                               text.setText( "" + id++ );\r
+                               VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                               if ( !(text.getText().equalsIgnoreCase("origin") || text.getText().contains("nose") || text.getText().contains("Nose")) )\r
+                               {\r
+                                       text.setText( "" + id++ );\r
+                               }\r
                        }\r
                }\r
-               \r
+               wormImage.unregisterAllVOIs();\r
+               wormImage.registerVOI(seamAnnotations);\r
                seamAnnotations.setName("seam cells");\r
                LatticeModel.saveAllVOIsTo(outputDirectory + File.separator + editSeamCellOutput + File.separator, wormImage);\r
                LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editSeamCellOutput + File.separator, "seamCellInfo.csv", seamAnnotations);\r
@@ -861,6 +874,138 @@ public class WormData
                //              System.err.println( "   segmentSeamCells: end " + minSeamCellSegmentationIntensity );\r
        }\r
        \r
+       public void segmentSeamFromLattice()\r
+       {\r
+               System.err.println("segmentSeamFromLattice");\r
+               \r
+               VOI lattice = readFinalLattice();\r
+               VOIContour left = (VOIContour) lattice.getCurves().elementAt(0);\r
+               VOIContour right = (VOIContour) lattice.getCurves().elementAt(1);\r
+               \r
+               seamAnnotations = new VOI((short) 0, "seam cells", VOI.ANNOTATION, -1.0f);\r
+               wormImage.unregisterAllVOIs();\r
+               \r
+               wormImage.registerVOI(seamAnnotations);\r
+\r
+               float[] pairSort = new float[left.size()];\r
+               // decide which 10 points are seam cells by taking max pair values\r
+               for ( int i = 0; i < left.size() -1; i++ )\r
+               {\r
+                       int x = (int)left.elementAt(i).X;\r
+                       int y = (int)left.elementAt(i).Y;\r
+                       int z = (int)left.elementAt(i).Z;\r
+                       float value;\r
+                       if ( wormImage.isColorImage() ) \r
+                       {\r
+                               value = wormImage.getFloatC(x,y,z,2);\r
+                       }\r
+                       else\r
+                       {\r
+                               value = wormImage.getFloat(x,y,z);\r
+                       }\r
+\r
+                       x = (int)right.elementAt(i).X;\r
+                       y = (int)right.elementAt(i).Y;\r
+                       z = (int)right.elementAt(i).Z;\r
+                       if ( wormImage.isColorImage() ) \r
+                       {\r
+                               value += wormImage.getFloatC(x,y,z,2);\r
+                       }\r
+                       else\r
+                       {\r
+                               value += wormImage.getFloat(x,y,z);\r
+                       }\r
+                       pairSort[i] = value;\r
+               }\r
+               Arrays.sort(pairSort);\r
+               \r
+               int pairCount = 0;\r
+               for ( int i = 0; i < left.size(); i++ )\r
+               {\r
+                       int x = (int)left.elementAt(i).X;\r
+                       int y = (int)left.elementAt(i).Y;\r
+                       int z = (int)left.elementAt(i).Z;\r
+                       float value;\r
+                       if ( wormImage.isColorImage() ) \r
+                       {\r
+                               value = wormImage.getFloatC(x,y,z,2);\r
+                       }\r
+                       else\r
+                       {\r
+                               value = wormImage.getFloat(x,y,z);\r
+                       }\r
+                       x = (int)right.elementAt(i).X;\r
+                       y = (int)right.elementAt(i).Y;\r
+                       z = (int)right.elementAt(i).Z;\r
+                       if ( wormImage.isColorImage() ) \r
+                       {\r
+                               value += wormImage.getFloatC(x,y,z,2);\r
+                       }\r
+                       else\r
+                       {\r
+                               value += wormImage.getFloat(x,y,z);\r
+                       }\r
+                       \r
+                       boolean isSeamPair = (left.size() <= 10) || (i == left.size() -1);\r
+                       if ( !isSeamPair )\r
+                       {\r
+                               // check if this pair has a high enough value to be added to the list of seam cells:\r
+                               for ( int j = 0; j < Math.min(9, pairSort.length); j++ )\r
+                               {\r
+                                       if ( value >= pairSort[(pairSort.length -1) - j] )\r
+                                       {\r
+                                               System.err.println( value + "  " + pairSort[(pairSort.length -1) - j]);\r
+                                               isSeamPair = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if ( isSeamPair )\r
+                       {\r
+                               String name = pairCount < 3 ? ("H" + pairCount) : (pairCount < 9) ? ("V" + (pairCount - 2)) : "T";\r
+                               pairCount++;\r
+                               \r
+                               // left seam cell:\r
+                               VOIText text = new VOIText();\r
+                               text.add(left.elementAt(i));\r
+                               text.add(left.elementAt(i));\r
+                               text.setText( name + "L" );\r
+                               text.setUseMarker(false);\r
+                               text.update();\r
+\r
+                               //                      int x = (int)seamCellPoints.elementAt(i).X;\r
+                               //                      int y = (int)seamCellPoints.elementAt(i).Y;\r
+                               //                      int z = (int)seamCellPoints.elementAt(i).Z;\r
+                               //                      if ( (i+1) != seamSegmentation.getFloat(x,y,z) )\r
+                               //                      {\r
+                               //                              System.err.println( "Seam Cell " + (i+1) + "  " + seamSegmentation.getFloat(x,y,z) );\r
+                               //                      }\r
+                               seamAnnotations.getCurves().add(text);\r
+\r
+                               // right seam cell:\r
+                               // left seam cell:\r
+                               text = new VOIText();\r
+                               text.add(right.elementAt(i));\r
+                               text.add(right.elementAt(i));\r
+                               text.setText( name + "R" );\r
+                               text.setUseMarker(false);\r
+                               text.update();\r
+                               seamAnnotations.getCurves().add(text);\r
+                       }\r
+               }\r
+\r
+               String seamCellDir = outputDirectory + File.separator + autoSeamCellSegmentationOutput + File.separator;\r
+               File outputFileDir = new File(seamCellDir);\r
+               if ( !outputFileDir.exists() )\r
+               {\r
+                       //                      System.err.println( "segmentSeamCells " + seamCellDir);\r
+                       outputFileDir.mkdir();\r
+               }\r
+               LatticeModel.saveAllVOIsTo(outputDirectory + File.separator + editSeamCellOutput + File.separator, wormImage);\r
+               LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editSeamCellOutput + File.separator, "seamCellInfo.csv", seamAnnotations);\r
+\r
+       }\r
+       \r
        public void segmentSkin()\r
        {\r
                if ( skinSegmentation == null )\r
index ff84f05..b37ce7c 100644 (file)
@@ -104,9 +104,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
        public static final int EditNONE = 0;\r
        public static final int EditSeamCells = 1;\r
        public static final int EditLattice = 2;\r
-       public static final int EditAnnotations1 = 3;\r
-       public static final int EditAnnotations2 = 4;\r
-       public static final int ReviewResults = 5;\r
+       public static final int CheckSeam = 3;\r
+       public static final int EditAnnotations1 = 4;\r
+       public static final int EditAnnotations2 = 5;\r
+       public static final int ReviewResults = 6;\r
        \r
        private JPanel algorithmsPanel;\r
        private VOIVector annotationList;\r
@@ -132,6 +133,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
        private JRadioButton editAnnotations1;\r
        private JRadioButton editAnnotations2;\r
        private JRadioButton editLattice;\r
+       private JRadioButton checkSeamCells;\r
        private int editMode = EditNONE;\r
        private JPanel editPanel;\r
        private JRadioButton editSeamCells;\r
@@ -335,6 +337,21 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                                openLattice();\r
                                        }\r
                                }\r
+                               else if ( checkSeamCells.isSelected() )\r
+                               {\r
+                                       // start lattice editing:\r
+                                       if ( !integratedDisplay )\r
+                                       {\r
+                                               PlugInDialogVolumeRender editor = new PlugInDialogVolumeRender( this, PlugInDialogVolumeRender.CheckSeam, includeRange, imageIndex, baseFileDir, baseFileNameText.getText() );\r
+                                               editor.setLocation( this.getWidth(), this.getY() );\r
+                                               editor.checkSeam();\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               editMode = CheckSeam;\r
+                                               checkSeam();\r
+                                       }\r
+                               }\r
                                else if ( editAnnotations1.isSelected() )\r
                                {\r
                                        // start annotation editing:\r
@@ -421,6 +438,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                {\r
                                        openLattice();\r
                                }\r
+                               else if ( editMode == CheckSeam )\r
+                               {\r
+                                       checkSeam();\r
+                               }\r
                                else if ( editMode == EditAnnotations1 )\r
                                {\r
                                        openAnnotations(0);\r
@@ -465,6 +486,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                {\r
                                        openLattice();\r
                                }\r
+                               else if ( editMode == CheckSeam )\r
+                               {\r
+                                       checkSeam();\r
+                               }\r
                                else if ( editMode == EditAnnotations1 )\r
                                {\r
                                        openAnnotations(0);\r
@@ -614,14 +639,14 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
 //             System.err.println( "algorithmPerformed" );\r
                voiManager = new VOILatticeManagerInterface( null, volumeImage.GetImage(), null, 0, true, null );\r
                volumeRenderer.setVOILatticeManager(voiManager);\r
-               if ( (editMode == EditSeamCells) || (editMode == EditAnnotations1) || (editMode == EditAnnotations2) )\r
+               if ( (editMode == EditSeamCells) || (editMode == EditAnnotations1) || (editMode == EditAnnotations2) || (editMode == CheckSeam) )\r
                {\r
                        if ( annotations != null )\r
                        {\r
                                if ( annotations.size() > 0 )\r
                                {\r
                                        voiManager.setAnnotations(annotations);\r
-                                       if ( editMode == EditAnnotations1 || editMode == EditAnnotations2 )\r
+                                       if ( (editMode == EditAnnotations1) || (editMode == EditAnnotations2) || (editMode == CheckSeam) )\r
                                        {\r
                                                if ( finalLattice != null ) {\r
                                                        VOIVector latticeVector = new VOIVector();\r
@@ -746,6 +771,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                }\r
                else if ( mode == EditLattice )\r
                {\r
+                       checkSeamCells.setSelected(true);\r
+               }\r
+               else if ( mode == CheckSeam )\r
+               {\r
                        editAnnotations1.setSelected(true);\r
                }\r
                else if ( mode == EditAnnotations1 )\r
@@ -1248,6 +1277,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                        wormData = new WormData(wormImage);\r
                                        wormData.openStraightLattice();\r
                                        wormData.openStraightAnnotations();\r
+                                       wormData.openStraightSeamCells();\r
                                        if ( voiFile2 != null )\r
                                        {\r
                                                wormData.openStraightAnnotations(voiFile2.getParentFile().getParent());\r
@@ -1928,13 +1958,20 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                gbc.gridy++;\r
 \r
                gbc.gridx = 0;\r
-               editLattice = gui.buildRadioButton("4). edit lattice", false );\r
+               editLattice = gui.buildRadioButton("4a). edit lattice", false );\r
                editLattice.addActionListener(this);\r
                editLattice.setActionCommand("editLattice");\r
                panel.add(editLattice.getParent(), gbc);\r
                gbc.gridy++;\r
 \r
                gbc.gridx = 0;\r
+               checkSeamCells = gui.buildRadioButton("4b). check seam cells", false );\r
+               checkSeamCells.addActionListener(this);\r
+               checkSeamCells.setActionCommand("checkSeamCells");\r
+               panel.add(checkSeamCells.getParent(), gbc);\r
+               gbc.gridy++;\r
+\r
+               gbc.gridx = 0;\r
                editAnnotations1 = gui.buildRadioButton("5a). add annotations channel 1", false );\r
                editAnnotations1.addActionListener(this);\r
                editAnnotations1.setActionCommand("editAnnotations");\r
@@ -1964,6 +2001,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
 \r
                group.add(editSeamCells);\r
                group.add(editLattice);\r
+               group.add(checkSeamCells);\r
                group.add(editAnnotations1);\r
                group.add(editAnnotations2);\r
                group.add(createAnimation);\r
@@ -2048,6 +2086,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                {\r
                        saveLattice();\r
                }\r
+               else if ( editMode == CheckSeam )\r
+               {\r
+                       saveSeamCells();\r
+               }\r
                else if ( editMode == EditAnnotations1 )\r
                {\r
                        saveAnnotations();\r
@@ -2098,6 +2140,52 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                }\r
                String outputDirectory = new String(wormImage.getImageDirectory() + JDialogBase.makeImageName(imageName, "") + File.separator + JDialogBase.makeImageName(imageName, "_results") );\r
                voiManager.saveLattice( outputDirectory + File.separator, PlugInAlgorithmWormUntwisting.editLatticeOutput );\r
+\r
+       }\r
+       \r
+       private void checkSeam()\r
+       {               \r
+               if ( includeRange != null )\r
+               {                       \r
+                       if ( (imageIndex >= 0) && (imageIndex < includeRange.size()) )\r
+                       {\r
+                               String fileName = baseFileName + "_" + includeRange.elementAt(imageIndex) + ".tif";\r
+                               File voiFile = new File(baseFileDir + File.separator + fileName);\r
+                               if ( openImages( voiFile, null, fileName ) )\r
+                               {\r
+                                       wormData = new WormData(wormImage);\r
+\r
+                                       wormData.segmentSeamFromLattice();\r
+                                       wormData.saveSeamAnnotations( false );\r
+\r
+                                       finalLattice = wormData.readFinalLattice();\r
+                                       if ( (finalLattice != null) && (voiManager != null) ) \r
+                                       {\r
+                                               VOIVector latticeVector = new VOIVector();\r
+                                               latticeVector.add(finalLattice);\r
+                                               voiManager.setLattice( latticeVector );\r
+                                       }                                       \r
+                                       \r
+                                       wormData.readSeamCells();                               \r
+                                       \r
+                                       if ( annotations != null )\r
+                                       {\r
+                                               annotations.clear();\r
+                                               annotations = null;\r
+                                       }\r
+                                       annotations = new VOIVector();\r
+                                       annotations.add( wormData.getSeamAnnotations() );\r
+                                       wormImage.registerVOI( wormData.getSeamAnnotations() );\r
+\r
+                                       if ( (annotations.size() > 0) && (voiManager != null) )\r
+                                       {\r
+                                               voiManager.setAnnotations(annotations);\r
+                                               voiManager.editAnnotations(true);\r
+                                               voiManager.colorAnnotations(false);\r
+                                       }\r
+                               }\r
+                       }\r
+               }       \r
        }\r
 \r
        /**\r
@@ -2117,7 +2205,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                {\r
                        return;\r
                }\r
-               wormData.saveSeamAnnotations();\r
+               wormData.saveSeamAnnotations( editMode != CheckSeam );\r
                wormData.dispose();\r
        }\r
 \r