]> Creatis software - creaBruker.git/blob - appli/testBruker2Dicom/testBruker2Dicom.cxx
Feature #1767
[creaBruker.git] / appli / testBruker2Dicom / testBruker2Dicom.cxx
1 /*
2         # ---------------------------------------------------------------------
3         #
4         # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5         #                        pour la Santé)
6         # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7         # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8         # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9         #
10         #  This software is governed by the CeCILL-B license under French law and 
11         #  abiding by the rules of distribution of free software. You can  use, 
12         #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13         #  license as circulated by CEA, CNRS and INRIA at the following URL 
14         #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15         #  or in the file LICENSE.txt.
16         #
17         #  As a counterpart to the access to the source code and  rights to copy,
18         #  modify and redistribute granted by the license, users are provided only
19         #  with a limited warranty  and the software's author,  the holder of the
20         #  economic rights,  and the successive licensors  have only  limited
21         #  liability. 
22         #
23         #  The fact that you are presently reading this means that you have had
24         #  knowledge of the CeCILL-B license and that you accept its terms.
25         # ------------------------------------------------------------------------
26 */
27
28 /*=========================================================================
29                                                                                 
30   Program:   creaBruker
31   Module:    $RCSfile: testBruker2Dicom.cxx,v $
32   Language:  C++
33   Date:      $Date: 2012/11/15 13:31:58 $
34   Version:   $Revision: 1.12 $
35                                                                                 
36                                                                                 
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notices for more information.
40                                       
41 =========================================================================*/
42
43 /**
44  * Transform private Bruker tree structure
45  * into the equivalent, with DICOM files *and/or* MHD files. 
46  * 
47  */
48 #include "bruker2dicom.h"
49
50 #include "gdcmCommon.h"
51 #include "gdcmDebug.h"
52 #include "gdcmUtil.h"
53 #include "gdcmDirList.h"
54
55 #include "gdcmArgMgr.h"
56
57 #include "bruker2dicom.h"
58 #include "brukerexception.h"
59
60 // ===================================================================================================
61 /**
62   * \brief
63   *          - explores  the given root directory e.g. :
64   *            B67d1.Bp1
65   *              subject
66   *              AdjStatePerStudy
67   *              1
68   *                 acqp
69   *                 AdjStatePerScan
70   *                 fid
71   *                 imnd / method
72   *                 pulseprogram
73   *                 spnam0
74   *                 spnam1
75   *                 pdata
76   *                    1                // only 'native' images
77   *                       2dseq
78   *                       d3proc
79   *                       meta
80   *                       procs
81   *                       reco  <--
82   *                       roi
83   *                       CreatisComputedCartoFile
84   *                    2                // post processed images (if any)
85   *                       2dseq
86   *                       d3proc
87   *                       isa  <--
88   *                       meta
89   *                       procs
90   *                       roi                      ...
91   *                       roi
92   *                    3                // post processed images (if any)
93   *                       2dseq
94   *                       d3proc
95   *                       isa  <--
96   *                       meta
97   *                       procs
98   *                       roi
99   *                    ...
100   *              2
101   *                 acqp
102   *                 fid
103   *                 ...
104   *                 pdata
105   *              3
106   *                ...
107   *          - fills an equivalent Directory with the MHD / DICOM files,
108   */
109
110
111 int main(int argc, char *argv[])
112 {
113    START_USAGE(usage)
114    " \n testBruker2Dicom : \n                                                 ",
115    " - explores the given directory (holding a FULL Bruker exam), at the 3 levels,",
116    " - fills an equivalent Directory with the MHD files and/or the DICOM files",
117    " usage: testBruker2Dicom --dirin=rootDirectoryName                        ",
118    "                         --dirout=outputDirectoryName                     ",
119    "                   [-D] [-M]                                              ",
120    "                   [{-b|-l}] b:BigEndian,l:LittleEndian default : l       ",
121    "                   [--debug] [--verbose] [--listonly] [--usage]           ",
122    "                                                                          ",
123    "   D         : user wants to export as DICOM                              ",
124    "   M         : user wants to export as MHD                                ",   
125    "  debug      : developper wants to run the program in 'debug mode'        ",
126    "                                                                          ",   
127    "  REMARK :                                                                ",   
128    "         If you were supplied  an *incomplete* Bruker exam                ",
129    "        (e.g. only the '2' serie) put it a 'root' directory,              ",
130    "         and run this test using this 'root' directory as 'dirin'         ",   
131    FINISH_USAGE
132    
133    // ------------ Initialize Arguments Manager ----------------  
134    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
135   
136    if (argc == 1 || am->ArgMgrDefined("--usage") )
137    {
138       am->ArgMgrUsage(usage); // Display 'usage'
139       delete am;
140       return 1;
141    }
142
143    // create the devilish object!
144    Bruker2Dicom b2d;
145       
146    const char *dirNamein;   
147    dirNamein  = am->ArgMgrGetString("--dirin",".");
148
149    const char *dirNameout;   
150    dirNameout  = am->ArgMgrGetString("--dirout",".");
151
152 // note : Big Endian / Little Endian pb not yet dealt with.
153 //        not a great issue, since everybody (?) works on Intell procs  
154    int b = am->ArgMgrDefined("-b");
155    int l = am->ArgMgrDefined("-l");
156
157    if (am->ArgMgrDefined("--debug"))
158       GDCM_NAME_SPACE::Debug::DebugOn();
159
160    b2d.verbose  = am->ArgMgrDefined("--verbose");      
161    int listonly = am->ArgMgrDefined("--listonly");
162    
163    int dicom    = am->ArgMgrDefined("-D");
164    int mhd      = am->ArgMgrDefined("-M");
165    
166    if (dicom)
167       b2d.SetConvertModeToDicom();
168    if (mhd)
169       b2d.SetConvertModeToMhd();
170
171    /* if unused Param we give up */
172    if ( am->ArgMgrPrintUnusedLabels() )
173    {
174       am->ArgMgrUsage(usage);
175       delete am;
176       return 1;
177    } 
178
179 // patientName : found in Bruker parameter files
180 // patientName  = am->ArgMgrGetString("patientname", "Patient^Name");
181
182 // b2d.day : unused  ...
183    b2d.day          = am->ArgMgrGetString("day", "You_forget_the_Day");
184
185  delete am;  // we don't need Argument Manager any longer
186
187    // ----------- End Arguments Manager ---------
188    
189
190    // ----- Begin Processing -----
191
192    b2d.SetInputDirectory(dirNamein);
193    b2d.SetOutputDirectory(dirNameout);
194
195    /// \TODO : *do* use exceptions in the methods!
196
197    try {
198       b2d.Execute();
199    }
200    catch (int i)
201    {
202       std::cout << "Exception was thrown  (" << i << ") " << std::endl;
203    }
204    /*
205    catch (std::exception& e) {
206    std::cerr << "ERREUR: " << e.what() << "expected length: " << e.getExpectedLgt()
207              << " Found : " << e.getFoundLgt() << std::endl;
208    }
209   */
210
211    catch (BrukerHopelessException &e)
212    {
213       std::cout << "And Hopless Exception was thrown  (" << e.what() << ") " << std::endl;
214    }
215
216
217 }
218
219