]> Creatis software - gdcm.git/blobdiff - Dicts/CMakeLists.txt
Fix mistypings
[gdcm.git] / Dicts / CMakeLists.txt
index 708d663090219fdd98d8133235ff5c1b2edfe7b9..f6ba194f262695f8b5fd5b403f4c19b3375a8684 100644 (file)
 #-----------------------------------------------------------------------------
 # DICOM dictionary stuff
 
-
-INSTALL_FILES(${GDCM_DATA_DIR} FILES 
+#-----------------------------------------------------------------------------
+# Generate our own 'DICOM' dictionary, based on the following dictionaries:
+SET(ALL_DICTS
   dicomV3.dic
-  dicomVR.dic
-  dicomTS.dic
-  DicomDir.dic
-)
+  #Papyrus.dic
+  #NIH.dic     #the forbidden one...
+  #  SPI.dic
+  #  PHILIPS-Intera.dic # uncomment me if you want
+  #GEMS.dic #Commented out to avoid polluting 'non GEMS' images
+  #GEMS-HiSpeed.dic
+  #  GEMS-Advance.dic
+  )
+
+# Better solution
+SET(TEST_DICT_BODY)
+FOREACH(dict ${ALL_DICTS})
+  # Properly set dependencies, therefore `touch Philips-Intera.dic` does not rebuild
+  # but adding/removing a line in Philips-Intera.dic rebuild as expected
+  CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/${dict}"
+       "${GDCM_BINARY_DIR}/Dicts/${dict}" COPYONLY IMMEDIATE)
+  FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${dict}" dict_append)
+  SET(TEST_DICT_BODY "${TEST_DICT_BODY}\n${dict_append}")
+ENDFOREACH(dict)
+CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/gdcm.dic.in"
+  "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" @ONLY IMMEDIATE)
 
+#-----------------------------------------------------------------------------
 # Nice trick to avoid creating a .h file each time we compile gdcm
 # Since CONFIGURE_FILE do a 'copy if different'
 # We have to write the file here since is contains 'DICOM_DICTIONARY'
 # Which is a variable afterward...
-#FILE(WRITE "/tmp/output.h.in" "@DICOM_DICTIONARY@" )
 
-# Following code contributing by Andy Cedilnik
-SET(INFILE "dicomV3.dic")
+# Following code contributing by Andy Cedilnik (Kitware)
+FILE(READ "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" ENT)
+STRING(REGEX REPLACE "\r?\n" ";" ENT "${ENT}")
+SET(DICOM_DATA_DICTIONARY "")
+
+FOREACH(line ${ENT})
+  STRING(REGEX REPLACE
+    "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([1-9n-]+) (.*)$"
+    "   {0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"}, " nline "${line}")
+  SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY}\n${nline}")
+ENDFOREACH(line)
 
-FILE(READ "${INFILE}" ENT)
+SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY} \n {0,0,0,0,0}")
 
-STRING(REGEX REPLACE "\n" ";" ENT "${ENT}")
-SET(DICOM_DICTIONARY
-  "void FillDefault()\n{"
-)
+#-----------------------------------------------------------------------------
+# ... for DicomTS file
+FILE(READ "dicomTS.dic" ENT_TS)
+STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
+SET(DICOM_TS_DICTIONARY "")
 
-FOREACH(line ${ENT})
+FOREACH(line ${ENT_TS})
   STRING(REGEX REPLACE
-#    "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([A-Z]+) (.*)([ \(RET\)]*)$"
-   # FIXME ? is not properly used, just luck
-    "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([A-Z?]+) (.*)$"
-#    "   { \\1, \\2, \"\\3\" , \"\\4\" , \"\\5\", \"\\6\"}," nline "${line}")
-#    "   { \\1, \\2, \"\\3\" , \"\\4\" , \"\\5\"}," nline "${line}")
-    "  AddNewEntry( DictEntry ( 0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"));" nline "${line}")
-  SET(DICOM_DICTIONARY "${DICOM_DICTIONARY}\n${nline}")
+    "^([0-9.]+) +(.*)$"
+    "  ts[\"\\1\"] = \"\\2\"; " nline "${line}")
+  SET(DICOM_TS_DICTIONARY "${DICOM_TS_DICTIONARY}\n${nline}")
 ENDFOREACH(line)
 
-SET(DICOM_DICTIONARY "${DICOM_DICTIONARY} \n }")
+#-----------------------------------------------------------------------------
+# ... for DicomVR file
+FILE(READ "dicomVR.dic" ENT_VR)
+STRING(REGEX REPLACE ";" "/" ENT_VR "${ENT_VR}") # CMake doesn't like ';'
+STRING(REGEX REPLACE "\r?\n" ";" ENT_VR "${ENT_VR}")
+SET(DICOM_VR_DICTIONARY "")
 
-# See above
-CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/gdcmDefaultDict.h.in" "${GDCM_BINARY_DIR}/gdcmDefaultDict.h")
+FOREACH(line ${ENT_VR})
+  STRING(REGEX REPLACE
+    "^([A-Z][A-Z]) (.*)/ +//.*$"
+    "  vr[\"\\1\"] = \"\\2\"; " nline "${line}")
+  SET(DICOM_VR_DICTIONARY "${DICOM_VR_DICTIONARY}\n${nline}")
+ENDFOREACH(line)
 
-#MESSAGE("${DICOM_DICTIONARY}")
+#-----------------------------------------------------------------------------
+# ... for DictGroupName file
+FILE(READ "DictGroupName.dic" ENT_TS)
+STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
+SET(DICT_GROUP_NAME_DICTIONARY "")
 
-FILE(READ "dicomV3VM2004.dic" ENT)
-STRING(REGEX REPLACE "\n" ";" ENT "${ENT}")
-SET(DICOM_DICTIONARY2 "")
+FOREACH(line ${ENT_TS})
+  STRING(REGEX REPLACE
+    "^([0-9a-f]+) +(.*)$"
+    "  groupName[0x\\1] = \\2; " nline "${line}")
+  SET(DICT_GROUP_NAME_DICTIONARY "${DICT_GROUP_NAME_DICTIONARY}\n${nline}")
+ENDFOREACH(line)
 
-FOREACH(line ${ENT})
+#-----------------------------------------------------------------------------
+# ... for DicomDir file
+FILE(READ "DicomDir.dic" ENT_DIR)
+STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ENT_DIR "${ENT_DIR}")
+STRING(REGEX REPLACE ";" "/" ENT_DIR "${ENT_DIR}") # CMake doesn't like ';'
+STRING(REGEX REPLACE "\r?\n" ";" ENT_DIR "${ENT_DIR}")
+SET(DICOM_DIR_DICTIONARY "")
+
+FOREACH(line ${ENT_DIR})
   STRING(REGEX REPLACE
-#    "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([A-Z]+) (.*)([ \(RET\)]*)$"
-    "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([0-9]|[1]-[0-9n]|[2]-[2][n]|[3]-[3][n]) (.*)$"
-#    "   { \\1, \\2, \"\\3\" , \"\\4\" , \"\\5\", \"\\6\"}," nline "${line}")
-    "   { \\1, \\2, \"\\3\" , \"\\4\" , \"\\5\"}," nline "${line}")
-  SET(DICOM_DICTIONARY2 "${DICOM_DICTIONARY2}\n${nline}")
+    "^(metaElem|patientElem|studyElem|serieElem|imageElem) *([a-f0-9]+) ([a-f0-9]+) [\"](.*)[\"] [\"](.*)[\"] (.*)$"
+    "  {\"\\1\" , 0x\\2 , 0x\\3 , \"\\4\", \"\\5\"}, \\6" nline "${line}")
+  SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY}\n${nline}")
 ENDFOREACH(line)
 
-#MESSAGE("${DICOM_DICTIONARY2}")
+#-----------------------------------------------------------------------------
+# ... Set the dictionnary
+SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY} \n {0,0,0,0,0}")
+
+CONFIGURE_FILE("${GDCM_SOURCE_DIR}/src/gdcmDefaultDicts.cxx.in"
+  "${GDCM_BINARY_DIR}/src/gdcmDefaultDicts.cxx" IMMEDIATE)
+
+#-----------------------------------------------------------------------------
+# For now GDCM_INSTALL_NO_DICTIONARY is a hidden variables
+IF(NOT GDCM_INSTALL_NO_DICTIONARY)
+  INSTALL_FILES(${GDCM_INSTALL_DATA_DIR} .dic
+    dicomV3
+    dicomVR
+    dicomTS
+    DicomDir
+    DictGroupName
+    gdcm
+    )
+ENDIF(NOT GDCM_INSTALL_NO_DICTIONARY)