Added bounds checking.
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 7 Mar 2018 21:39:18 +0000 (21:39 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 7 Mar 2018 21:39:18 +0000 (21:39 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15402 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInDialogUntwistedToTwisted.java

index 2dac2bc..b8a5c53 100644 (file)
@@ -253,6 +253,9 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
                        toTwisted = fileIO.readImage(toTwistedName);  \r
                        if ( toTwisted != null )\r
                        {\r
+                               int dimX = toTwisted.getExtents().length > 0 ? toTwisted.getExtents()[0] : 1;\r
+                               int dimY = toTwisted.getExtents().length > 1 ? toTwisted.getExtents()[1] : 1;\r
+                               int dimZ = toTwisted.getExtents().length > 2 ? toTwisted.getExtents()[2] : 1;\r
 //                             System.err.println("displaying image...");\r
 //                             new ViewJFrameImage(toTwisted);\r
                                VOI annotations = LatticeModel.readAnnotationsCSV(straightenedAnnotationFile);\r
@@ -268,23 +271,25 @@ public class PlugInDialogUntwistedToTwisted extends JDialogStandalonePlugin impl
                                                        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
+                                                       if ( ((int)pos.X < dimX) && ((int)pos.Y < dimY)  && ((int)pos.Z < dimZ) )\r
                                                        {\r
-                                                               VOIText newText = new VOIText();\r
-                                                               newText.setText(name);\r
-                                                               newText.add(newPos);\r
-\r
-                                                               annotationVOI.getCurves().add(newText);\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
                                                        else\r
                                                        {\r