]> Creatis software - creaBruker.git/blob - appli/testBruker2Dicom/testBruker2Dicom.cxx
Prepare except
[creaBruker.git] / appli / testBruker2Dicom / testBruker2Dicom.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: testBruker2Dicom.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/05/27 10:43:07 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                       
17 =========================================================================*/
18
19 /**
20  * Transform private Bruker tree structure
21  * into the equivalent, with DICOM files *and/or* MHD files. 
22  * 
23  */
24 #include "bruker2dicom.h"
25
26 #include "gdcmCommon.h"
27 #include "gdcmDebug.h"
28 #include "gdcmUtil.h"
29 #include "gdcmDirList.h"
30
31 #include "gdcmArgMgr.h"
32
33 #include "bruker2dicom.h"
34
35 // ===================================================================================================
36 /**
37   * \brief   
38   *          - explores  the given root directory e.g. :
39   *            B67d1.Bp1
40   *              subject
41   *              AdjStatePerStudy
42   *              1
43   *                 acqp
44   *                 AdjStatePerScan
45   *                 fid
46   *                 imnd / method
47   *                 pulseprogram
48   *                 spnam0
49   *                 spnam1
50   *                 pdata
51   *                    1                // only 'native' images
52   *                       2dseq
53   *                       d3proc
54   *                       meta
55   *                       procs
56   *                       reco  <--
57   *                       roi
58   *                       CreatisComputedCartoFile
59   *                    2                // post processed images (if any)
60   *                       2dseq
61   *                       d3proc
62   *                       isa  <--
63   *                       meta
64   *                       procs
65   *                       roi                      ...                   
66   *                       roi
67   *                    3                // post processed images (if any)
68   *                       2dseq
69   *                       d3proc
70   *                       isa  <--
71   *                       meta
72   *                       procs
73   *                       roi
74   *                    ...        
75   *              2
76   *                 acqp
77   *                 fid
78   *                 ...
79   *                 pdata
80   *              3         
81   *                ...
82   *          - fills a single level Directory with the MHD files,
83   */  
84   
85
86 int main(int argc, char *argv[])
87 {
88    START_USAGE(usage)
89    " \n testBruker2Dicom : \n                                                 ",
90    " - explores the given directory, at the 3 levels,                         ",
91    " - fills an equivalent Directory with the MHD files or the DICOM files    ",
92    " usage: testBruker2Dicom dirin=rootDirectoryName                          ",
93    "                         dirout=outputDirectoryName                       ",
94    "                   [D] [M]                                                ",
95    "                   [{b|l}] b:BigEndian,l:LittleEndian default : l         ",
96    "                   [debug] [verbose] [listonly]                           ",
97    "                                                                          ",
98    "   D         : user wants to export as DICOM                              ",
99    "   M         : user wants to export as MHD                                ",   
100    "  debug      : developper wants to run the program in 'debug mode'        ",
101    FINISH_USAGE
102    
103    // ------------ Initialize Arguments Manager ----------------  
104    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
105   
106    if (argc == 1 || am->ArgMgrDefined("usage") )
107    {
108       am->ArgMgrUsage(usage); // Display 'usage'
109       delete am;
110       return 1;
111    }
112
113    // create the devilish object!
114    Bruker2Dicom b2d;
115       
116    const char *dirNamein;   
117    dirNamein  = am->ArgMgrGetString("dirin",".");
118
119    const char *dirNameout;   
120    dirNameout  = am->ArgMgrGetString("dirout",".");
121
122 // note : Big Endian / Little Endian pb not yet dealt with.
123 //        not a great issue, since everybody (?) works on Intell procs  
124    int b = am->ArgMgrDefined("b");
125    int l = am->ArgMgrDefined("l");
126
127    if (am->ArgMgrDefined("debug"))
128       GDCM_NAME_SPACE::Debug::DebugOn();
129
130    b2d.verbose  = am->ArgMgrDefined("verbose");      
131    int listonly = am->ArgMgrDefined("listonly");
132    
133    int dicom    = am->ArgMgrDefined("D");
134    int mhd      = am->ArgMgrDefined("M");
135    
136    if (dicom)
137       b2d.SetConvertModeToDicom();
138    if (mhd)
139       b2d.SetConvertModeToMhd();
140              
141    /* if unused Param we give up */
142    if ( am->ArgMgrPrintUnusedLabels() )
143    {
144       am->ArgMgrUsage(usage);
145       delete am;
146       return 1;
147    } 
148
149 // patientName : found in Bruker parameter files
150 // patientName  = am->ArgMgrGetString("patientname", "Patient^Name");
151
152 // b2d.day : unused  ...
153    b2d.day          = am->ArgMgrGetString("day", "You_forget_the_Day");
154       
155   
156
157    // ----------- End Arguments Manager ---------
158    
159
160    // ----- Begin Processing -----
161
162    b2d.SetInputDirectory(dirNamein);
163    b2d.SetOutputDirectory(dirNameout);
164
165    /// \TODO : *do* use exceptions in the methods!
166       
167    try {
168       b2d.Execute();
169    }
170    catch (int i)
171    {
172       std::cout << "Exception was thrown  (" << i << ") " << std::endl;
173    }
174    /*
175    catch (std::exception& e) {
176    std::cerr << "ERREUR: " << e.what() << "expected length: " << e.getExpectedLgt()
177              << " Found : " << e.getFoundLgt() << std::endl;
178    }
179   */
180
181
182
183  delete am;  // we don't need Argument Manager any longer
184
185
186