Fixed interaction bug with the automatic seam cells generated from the lattice.
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 25 Apr 2018 00:09:52 +0000 (00:09 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 25 Apr 2018 00:09:52 +0000 (00:09 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15458 ba61647d-9d00-f842-95cd-605cb4296b96

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

index 9bde106..33ab01e 100644 (file)
@@ -55,8 +55,6 @@ public class WormData
        private int minSeamRadius = 8;\r
        private int maxSeamRadius = 25;\r
        \r
-       private Vector<Vector3f> markerPoints;\r
-       private VOI markerAnnotations;\r
        \r
        private boolean seamEdited = false;\r
        \r
@@ -176,6 +174,7 @@ public class WormData
        \r
        public VOI getMarkerAnnotations()\r
        {\r
+               VOI markerAnnotations = readMarkers();\r
                if ( markerAnnotations == null )\r
                        markerAnnotations = new VOI( (short)0, "markers", VOI.ANNOTATION, 0 );\r
                return markerAnnotations;\r
@@ -285,8 +284,9 @@ public class WormData
                return null;\r
        }\r
 \r
-       public void readMarkers()\r
+       private VOI readMarkers()\r
        {\r
+               VOI markerAnnotations = null;\r
                VOIVector annotationVector = new VOIVector();\r
                LatticeModel.loadAllVOIsFrom(wormImage, outputDirectory + File.separator + editAnnotationOutput + File.separator, true, annotationVector, false);\r
                if ( annotationVector.size() > 0 )\r
@@ -301,6 +301,7 @@ public class WormData
                                markerAnnotations = annotationVector.elementAt(0);\r
                        }\r
                }\r
+               return markerAnnotations;\r
        }\r
        \r
        public Vector<Vector3f> readSeamCells()\r
@@ -368,47 +369,52 @@ public class WormData
                LatticeModel.saveAllVOIsTo(outputDirectory + File.separator + editLatticeOutput + File.separator, wormImage);\r
        }\r
        \r
-       public void saveMarkerAnnotations()\r
+       public String getAnnotationsPath()\r
+       {\r
+               return outputDirectory + File.separator + editAnnotationOutput + File.separator;\r
+       }\r
+       \r
+       public void saveMarkerAnnotations(VOI annotations)\r
        {               \r
                wormImage.unregisterAllVOIs();\r
-               wormImage.registerVOI(markerAnnotations);\r
-               markerAnnotations.setName("markers");\r
+               wormImage.registerVOI(annotations);\r
+               annotations.setName("markers");\r
                System.err.println( outputDirectory + File.separator + editAnnotationOutput + File.separator );\r
                LatticeModel.saveAllVOIsTo(outputDirectory + File.separator + editAnnotationOutput + File.separator, wormImage);\r
-               LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editAnnotationOutput + File.separator, "markerInfo.csv", markerAnnotations);\r
+               LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editAnnotationOutput + File.separator, "markerInfo.csv", annotations);\r
                wormImage.unregisterAllVOIs();\r
        }\r
 \r
        \r
-       public boolean checkSeamCells()\r
+       public boolean checkSeamCells(VOI annotations)\r
        {\r
-               if ( seamAnnotations.getCurves().size() == 0 )\r
+               if ( annotations.getCurves().size() == 0 )\r
                {\r
                        return false;\r
                }\r
                int count = 0;\r
-               for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+               for ( int i = 0; i < annotations.getCurves().size(); i++ )\r
                {\r
-                       VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                       VOIText text = (VOIText)annotations.getCurves().elementAt(i);\r
                        if ( !(text.getText().equalsIgnoreCase("origin") || text.getText().contains("nose") || text.getText().contains("Nose")) )\r
                        {\r
                                count++;\r
                        }\r
                }\r
-//             System.err.println("checkSeamCells " + count );\r
+               System.err.println("checkSeamCells " + count );\r
                return ((count%2) == 0);\r
        }\r
        \r
-       public boolean checkHeadSeamCells()\r
+       public boolean checkHeadSeamCells(VOI annotations)\r
        {\r
-               if ( seamAnnotations.getCurves().size() == 0 )\r
+               if ( annotations.getCurves().size() == 0 )\r
                {\r
                        return false;\r
                }\r
                int count = 0;\r
-               for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+               for ( int i = 0; i < annotations.getCurves().size(); i++ )\r
                {\r
-                       VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                       VOIText text = (VOIText)annotations.getCurves().elementAt(i);\r
                        if ( LatticeModel.match(text.getColor(), Color.green) )\r
                        {\r
                                count++;\r
@@ -417,16 +423,16 @@ public class WormData
                return (count == 2) || (count == 0);\r
        }\r
        \r
-       public boolean checkTailSeamCells()\r
+       public boolean checkTailSeamCells(VOI annotations)\r
        {\r
-               if ( seamAnnotations.getCurves().size() == 0 )\r
+               if ( annotations.getCurves().size() == 0 )\r
                {\r
                        return false;\r
                }\r
                int count = 0;\r
-               for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+               for ( int i = 0; i < annotations.getCurves().size(); i++ )\r
                {\r
-                       VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                       VOIText text = (VOIText)annotations.getCurves().elementAt(i);\r
                        if ( LatticeModel.match(text.getColor(), Color.red) )\r
                        {\r
                                count++;\r
@@ -435,12 +441,12 @@ public class WormData
                return (count == 2) || (count == 0);\r
        }\r
        \r
-       public void saveSeamAnnotations(boolean rename)\r
+       public void saveSeamAnnotations(VOI annotations, boolean rename)\r
        {               \r
-               seamCellPoints = new Vector<Vector3f>();\r
-               for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+               Vector<Vector3f> seamCellPoints = new Vector<Vector3f>();\r
+               for ( int i = 0; i < annotations.getCurves().size(); i++ )\r
                {\r
-                       VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                       VOIText text = (VOIText)annotations.getCurves().elementAt(i);\r
                        if ( !(text.getText().equalsIgnoreCase("origin") || text.getText().contains("nose") || text.getText().contains("Nose")) )\r
                        {\r
                                Vector3f temp = new Vector3f(text.elementAt(0) );\r
@@ -618,9 +624,9 @@ public class WormData
                if ( rename )\r
                {\r
                        int id = 1;\r
-                       for ( int i = 0; i < seamAnnotations.getCurves().size(); i++ )\r
+                       for ( int i = 0; i < annotations.getCurves().size(); i++ )\r
                        {\r
-                               VOIText text = (VOIText)seamAnnotations.getCurves().elementAt(i);\r
+                               VOIText text = (VOIText)annotations.getCurves().elementAt(i);\r
                                if ( !(text.getText().equalsIgnoreCase("origin") || text.getText().contains("nose") || text.getText().contains("Nose")) )\r
                                {\r
                                        text.setText( "" + id++ );\r
@@ -628,10 +634,10 @@ public class WormData
                        }\r
                }\r
                wormImage.unregisterAllVOIs();\r
-               wormImage.registerVOI(seamAnnotations);\r
-               seamAnnotations.setName("seam cells");\r
+               wormImage.registerVOI(annotations);\r
+               annotations.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
+               LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editSeamCellOutput + File.separator, "seamCellInfo.csv", annotations);\r
        }\r
        \r
        public void segmentSeamCells(int minRadius, int maxRadius)\r
@@ -882,7 +888,7 @@ public class WormData
                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
+               VOI seamAnnotations = new VOI((short) 0, "seam cells", VOI.ANNOTATION, -1.0f);\r
                wormImage.unregisterAllVOIs();\r
                \r
                wormImage.registerVOI(seamAnnotations);\r
@@ -1004,6 +1010,7 @@ public class WormData
                LatticeModel.saveAllVOIsTo(outputDirectory + File.separator + editSeamCellOutput + File.separator, wormImage);\r
                LatticeModel.saveAnnotationsAsCSV(outputDirectory + File.separator + editSeamCellOutput + File.separator, "seamCellInfo.csv", seamAnnotations);\r
 \r
+               wormImage.unregisterAllVOIs();\r
        }\r
        \r
        public void segmentSkin()\r
index 7770872..e667a0e 100644 (file)
@@ -443,7 +443,6 @@ public class PlugInAlgorithmWormUntwisting
                                        model.interpolateLattice( false, false, false, true );  \r
                                        model.saveAnnotationStraight(wormImage, "straightened_seamcells", "straightened_seamcells.csv" );       \r
                                        \r
-                                       wormData.readMarkers();\r
                                        VOI markers = wormData.getMarkerAnnotations();\r
                                        if ( (markers != null) && (markers.getCurves().size() > 0) )\r
                                        {\r
@@ -485,7 +484,6 @@ public class PlugInAlgorithmWormUntwisting
 //                                             }\r
 \r
                                                wormData = new WormData(nucleiImage);\r
-                                               wormData.readMarkers();\r
                                                markers = wormData.getMarkerAnnotations();\r
                                                if ( (markers != null) && (markers.getCurves().size() > 0) )\r
                                                {\r
index b37ce7c..396943b 100644 (file)
@@ -51,6 +51,7 @@ import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarInterface;
 import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarRender;\r
 import gov.nih.mipav.view.renderer.WildMagic.Interface.JPanelClip_WM;\r
 import gov.nih.mipav.view.renderer.WildMagic.Render.VolumeImage;\r
+import gov.nih.mipav.view.renderer.WildMagic.WormUntwisting.LatticeModel;\r
 import gov.nih.mipav.view.renderer.WildMagic.WormUntwisting.WormData;\r
 import gov.nih.mipav.view.renderer.WildMagic.WormUntwisting.WormSegmentation;\r
 import gov.nih.mipav.view.renderer.WildMagic.VOI.VOILatticeManagerInterface;\r
@@ -410,17 +411,17 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                        {\r
                                if ( editMode == EditSeamCells )\r
                                {\r
-                                       if ( (wormData != null) && !wormData.checkSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate an even number of seam cells (optional: one nose point; optional: highlight first pair and last pair)");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkHeadSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkHeadSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the first pair");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkTailSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkTailSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the last pair");\r
                                                return;\r
@@ -459,17 +460,17 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                        {\r
                                if ( editMode == EditSeamCells )\r
                                {\r
-                                       if ( (wormData != null) && !wormData.checkSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate an even number of seam cells (optional: one nose point; optional: highlight first pair and last pair)");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkHeadSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkHeadSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the first pair");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkTailSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkTailSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the last pair");\r
                                                return;\r
@@ -509,17 +510,17 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                buttonPanel.remove(displayModel);\r
                                if ( editMode == EditSeamCells )\r
                                {\r
-                                       if ( (wormData != null) && !wormData.checkSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate an even number of seam cells (optional: one nose point; optional: highlight first pair and last pair)");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkHeadSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkHeadSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the first pair");\r
                                                return;\r
                                        }\r
-                                       if ( (wormData != null) && !wormData.checkTailSeamCells() )\r
+                                       if ( (wormData != null) && !wormData.checkTailSeamCells(voiManager.getAnnotations()) )\r
                                        {\r
                                                MipavUtil.displayError( "Please designate two seam cells as the last pair");\r
                                                return;\r
@@ -926,8 +927,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                                if ( finalLattice != null ) \r
                                                {\r
                                                        wormImage.registerVOI( finalLattice );\r
-                                               }\r
-                                               wormData.readMarkers();                         \r
+                                               }               \r
 \r
                                                if ( annotations != null )\r
                                                {\r
@@ -957,7 +957,6 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                                {\r
                                                        wormData = new WormData(wormImage);\r
                                                        wormImage.registerVOI( finalLattice );\r
-                                                       wormData.readMarkers();                         \r
 \r
                                                        if ( annotations != null )\r
                                                        {\r
@@ -2117,7 +2116,14 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                {\r
                        return;\r
                }\r
-               wormData.saveMarkerAnnotations();\r
+               if ( voiManager == null )\r
+               {\r
+                       return;\r
+               }\r
+               \r
+//             LatticeModel.saveAnnotationsAsCSV( wormData.getAnnotationsPath(), "markerInfo.csv", voiManager.getAnnotations());\r
+\r
+               wormData.saveMarkerAnnotations(voiManager.getAnnotations());\r
                wormData.dispose();\r
        }\r
 \r
@@ -2154,18 +2160,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                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
@@ -2180,9 +2175,16 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                        if ( (annotations.size() > 0) && (voiManager != null) )\r
                                        {\r
                                                voiManager.setAnnotations(annotations);\r
-                                               voiManager.editAnnotations(true);\r
+                                               voiManager.editAnnotations(false);\r
                                                voiManager.colorAnnotations(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
                        }\r
                }       \r
@@ -2205,7 +2207,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                {\r
                        return;\r
                }\r
-               wormData.saveSeamAnnotations( editMode != CheckSeam );\r
+               wormData.saveSeamAnnotations( voiManager.getAnnotations(), editMode != CheckSeam );\r
                wormData.dispose();\r
        }\r
 \r