changeset 2025:64cf7a23db08

Scan coordinate and location information for validity before relying on it
author bert <bert>
date Fri, 18 Mar 2005 19:10:31 +0000
parents 1993bd740588
children 9b7a5add60c5
files conversion/dcm2mnc/dcm2mnc.c conversion/dcm2mnc/dcm2mnc.h
diffstat 2 files changed, 61 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/conversion/dcm2mnc/dcm2mnc.c
+++ b/conversion/dcm2mnc/dcm2mnc.c
@@ -5,7 +5,10 @@
 @CREATED    : June 2001 (Rick Hoge)
 @MODIFIED   : 
  * $Log: dcm2mnc.c,v $
- * Revision 1.7  2005-03-15 17:03:34  bert
+ * Revision 1.8  2005-03-18 19:10:31  bert
+ * Scan coordinate and location information for validity before relying on it
+ *
+ * Revision 1.7  2005/03/15 17:03:34  bert
  * Yet another directory expansion fix (sigh)
  *
  * Revision 1.6  2005/03/14 22:51:33  bert
@@ -65,7 +68,7 @@
  *
 ---------------------------------------------------------------------------- */
 
-static const char rcsid[]="$Header: /private-cvsroot/minc/conversion/dcm2mnc/dcm2mnc.c,v 1.7 2005-03-15 17:03:34 bert Exp $";
+static const char rcsid[]="$Header: /private-cvsroot/minc/conversion/dcm2mnc/dcm2mnc.c,v 1.8 2005-03-18 19:10:31 bert Exp $";
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -522,6 +525,7 @@
     int acq_num_files;
     const char **acq_file_list;
     int *used_file;
+    int *acq_file_index;
     double cur_study_id;
     int cur_acq_id;
     int cur_rec_num;
@@ -537,6 +541,9 @@
     int output_gid;
     string_t string;
     FILE *fp;
+    int trust_location;
+    int trust_coord;
+    int user_opts;              /* Options as set by user. We may override.. */
 
     if (out_dir != NULL) {    /* if an output directory name has been 
                                * provided on the command line
@@ -559,6 +566,9 @@
     acq_file_list = malloc(num_files * sizeof(*acq_file_list));
     CHKMEM(acq_file_list);
 
+    acq_file_index = malloc(num_files * sizeof(*acq_file_index));
+    CHKMEM(acq_file_index);
+
     used_file = malloc(num_files * sizeof(*used_file));
     CHKMEM(used_file);
 
@@ -632,6 +642,7 @@
                    counter) */
 
                 acq_file_list[acq_num_files] = di_ptr[ifile]->file_name;
+                acq_file_index[acq_num_files] = ifile;
                 acq_num_files++;
             }
         }
@@ -655,6 +666,41 @@
             }
         }
 
+        /* Do some sanity checks on the acquisition.  In particular, we 
+         * verify that the coordinate and/or slice location information
+         * looks reliable.
+         */
+        trust_location = 1;
+        trust_coord = 1;
+
+        for (ifile = 0; ifile < acq_num_files; ifile++) {
+            int jfile;
+            int ix = acq_file_index[ifile];
+
+            if (!di_ptr[ix]->coord_found) {
+                trust_coord = 0;
+            }
+
+            for (jfile = ifile + 1; jfile < acq_num_files; jfile++) {
+                int jx = acq_file_index[jfile];
+
+                if (NEARLY_EQUAL(di_ptr[ix]->slice_location,
+                                 di_ptr[jx]->slice_location)) {
+                    trust_location = 0;
+                }
+            }
+        }
+
+        user_opts = G.opts;
+
+        if (!trust_coord) {
+            printf("WARNING: Image coordinates absent or incomplete.\n");
+            if (!trust_location) {
+                printf("WARNING: Slice location is untrustworthy.\n");
+                G.opts |= OPTS_NO_LOCATION;
+            }
+        }
+
         /* Create minc file
          */
         exit_status = dicom_to_minc(acq_num_files, 
@@ -664,9 +710,11 @@
                                     file_prefix, 
                                     &output_file_name);
 
+        G.opts = user_opts;
+       
         if (exit_status != EXIT_SUCCESS) 
             continue;
-       
+
         /* Print log message */
         if (G.Debug) {
             printf("Created minc file %s.\n", output_file_name);
--- a/conversion/dcm2mnc/dcm2mnc.h
+++ b/conversion/dcm2mnc/dcm2mnc.h
@@ -7,7 +7,10 @@
 @MODIFIED   : 
 
  * $Log: dcm2mnc.h,v $
- * Revision 1.6  2005-03-13 19:34:41  bert
+ * Revision 1.7  2005-03-18 19:10:39  bert
+ * Scan coordinate and location information for validity before relying on it
+ *
+ * Revision 1.6  2005/03/13 19:34:41  bert
  * Add pms_element_defs.h to the header
  *
  * Revision 1.5  2005/03/03 20:10:14  bert
@@ -93,6 +96,7 @@
 #include "spi_element_defs.h"
 #include "ext_element_defs.h"
 #include "pms_element_defs.h"   /* Philips Medical Systems */
+#include "gems_element_defs.h"  /* GE Medical Systems */
 
 #ifndef TRUE
 #  define TRUE 1
@@ -155,6 +159,8 @@
     string_t protocol_name;
     string_t patient_name;
     string_t patient_id;
+    double slice_location;
+    int coord_found;
 } Data_Object_Info;
 
 #include "dicom_to_minc.h"
@@ -190,8 +196,9 @@
 };
 
 /* Values for options flags */
-#define OPTS_NO_MOSAIC 0x00000001 /* Don't parse mosaic information. */
-#define OPTS_KEEP_COORD 0x00000002 /* Don't flip DICOM coordinates */
+#define OPTS_NO_MOSAIC   0x00000001 /* Don't parse mosaic information. */
+#define OPTS_KEEP_COORD  0x00000002 /* Don't flip DICOM coordinates */
+#define OPTS_NO_LOCATION 0x00000004 /* Never rely on slice location */
 
 extern struct globals G;