]> Creatis software - gdcm.git/blob - Dicts/CMakeLists.txt
ENH: Split PHILIPS dict into the Intera one, and the genie one
[gdcm.git] / Dicts / CMakeLists.txt
1 #-----------------------------------------------------------------------------
2 # DICOM dictionary stuff
3
4 #-----------------------------------------------------------------------------
5 # Generate our own 'DICOM' dictionary, based on the following dictionaries:
6 SET(ALL_DICTS
7   dicomV3.dic
8   Papyrus.dic
9   NIH.dic     #the forbidden one...
10   )
11
12 # The following line make sure we are not appending on an already existing file
13 #FILE(WRITE "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" "")
14 #FOREACH(dict ${ALL_DICTS})
15 #  FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${dict}" dict_append)
16 #  FILE(APPEND "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" ${dict_append})
17 #ENDFOREACH(dict)
18
19 # Better solution
20 SET(TEST_DICT_BODY)
21 FOREACH(dict ${ALL_DICTS})
22   FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${dict}" dict_append)
23   SET(TEST_DICT_BODY "${TEST_DICT_BODY}\n${dict_append}")
24 ENDFOREACH(dict)
25 CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/gdcm.dic.in"
26   "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" @ONLY IMMEDIATE)
27
28 #-----------------------------------------------------------------------------
29 # Nice trick to avoid creating a .h file each time we compile gdcm
30 # Since CONFIGURE_FILE do a 'copy if different'
31 # We have to write the file here since is contains 'DICOM_DICTIONARY'
32 # Which is a variable afterward...
33
34 # Following code contributing by Andy Cedilnik (Kitware)
35 FILE(READ "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" ENT)
36 STRING(REGEX REPLACE "\r?\n" ";" ENT "${ENT}")
37 SET(DICOM_DATA_DICTIONARY "")
38
39 FOREACH(line ${ENT})
40   STRING(REGEX REPLACE
41     "^([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-]+) (.*)$"
42     "   {0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"}, " nline "${line}")
43   #MESSAGE( "${nline}" )
44   SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY}\n${nline}")
45 ENDFOREACH(line)
46
47
48 #FILE(READ "dicomV3PhilipsIntera.dic" ENT)
49 #STRING(REGEX REPLACE "\r?\n" ";" ENT "${ENT}")
50 #SET(DICOM_DATA_DICTIONARY "")
51 #FOREACH(line ${ENT})
52 #  STRING(REGEX REPLACE
53 #    "^([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-]+) (.*)$"
54 #    "   {0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"}, " nline "${line}")
55 #  #SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY}\n${nline}")
56 #  MESSAGE( "${nline}" )
57 #ENDFOREACH(line)
58
59
60 SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY} \n {0,0,0,0,0}")
61
62 #-----------------------------------------------------------------------------
63 # ... for DicomTS file
64 FILE(READ "dicomTS.dic" ENT_TS)
65 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
66 SET(DICOM_TS_DICTIONARY "")
67
68 FOREACH(line ${ENT_TS})
69   STRING(REGEX REPLACE
70     "^([0-9.]+) +(.*)$"
71     "  ts[\"\\1\"] = \"\\2\"; " nline "${line}")
72   SET(DICOM_TS_DICTIONARY "${DICOM_TS_DICTIONARY}\n${nline}")
73 ENDFOREACH(line)
74
75 #-----------------------------------------------------------------------------
76 # ... for DicomVR file
77 FILE(READ "dicomVR.dic" ENT_VR)
78 STRING(REGEX REPLACE ";" "/" ENT_VR "${ENT_VR}") # CMake doesn't like ';'
79 STRING(REGEX REPLACE "\r?\n" ";" ENT_VR "${ENT_VR}")
80 SET(DICOM_VR_DICTIONARY "")
81
82 FOREACH(line ${ENT_VR})
83   STRING(REGEX REPLACE
84     "^([A-Z][A-Z]) (.*)/ +//.*$"
85     "  vr[\"\\1\"] = \"\\2\"; " nline "${line}")
86   SET(DICOM_VR_DICTIONARY "${DICOM_VR_DICTIONARY}\n${nline}")
87 ENDFOREACH(line)
88
89 #-----------------------------------------------------------------------------
90 # ... for DictGroupName file
91 FILE(READ "DictGroupName.dic" ENT_TS)
92 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
93 SET(DICT_GROUP_NAME_DICTIONARY "")
94
95 FOREACH(line ${ENT_TS})
96   STRING(REGEX REPLACE
97     "^([0-9a-f]+) +(.*)$"
98     "  groupName[0x\\1] = \\2; " nline "${line}")
99   SET(DICT_GROUP_NAME_DICTIONARY "${DICT_GROUP_NAME_DICTIONARY}\n${nline}")
100 ENDFOREACH(line)
101
102 #-----------------------------------------------------------------------------
103 # ... for DicomDir file
104 FILE(READ "DicomDir.dic" ENT_DIR)
105 STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ENT_DIR "${ENT_DIR}")
106 STRING(REGEX REPLACE ";" "/" ENT_DIR "${ENT_DIR}") # CMake doesn't like ';'
107 STRING(REGEX REPLACE "\r?\n" ";" ENT_DIR "${ENT_DIR}")
108 SET(DICOM_DIR_DICTIONARY "")
109
110 FOREACH(line ${ENT_DIR})
111   STRING(REGEX REPLACE
112     "^(metaElem|patientElem|studyElem|serieElem|imageElem) *([a-f0-9]+) ([a-f0-9]+) [\"](.*)[\"](.*)$"
113     "  {\"\\1\" , 0x\\2 , 0x\\3 , \"\\4\"}, \\5" nline "${line}")
114   SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY}\n${nline}")
115 ENDFOREACH(line)
116
117 #-----------------------------------------------------------------------------
118 # ... Set the dictionnary
119 SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY} \n {0,0,0,0}")
120
121 #FOREACH(file dicomV3.dic dicomTS.dic dicomVR.dic DicomDir.dic DictGroupName.dic)
122 #  CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/${file}"
123 #    "${GDCM_BINARY_DIR}/Dicts/${file}.out")
124 #ENDFOREACH(file)
125
126 CONFIGURE_FILE("${GDCM_SOURCE_DIR}/src/gdcmDefaultDicts.cxx.in" 
127   "${GDCM_BINARY_DIR}/src/gdcmDefaultDicts.cxx" IMMEDIATE)
128
129 #-----------------------------------------------------------------------------
130 INSTALL_FILES(${GDCM_DATA_DIR} .dic
131   dicomV3
132   dicomVR
133   dicomTS
134   DicomDir
135   DictGroupName
136   gdcm
137 )
138