]> Creatis software - creaBruker.git/blob - appli/testBruker2Dicom/testBruker2Dicom.cxx
Throw and catch exception *everywhere* (hope it's enough!)
[creaBruker.git] / appli / testBruker2Dicom / testBruker2Dicom.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: testBruker2Dicom.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/06/19 15:51:44 $
7   Version:   $Revision: 1.5 $
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 #include "brukerexception.h"
35
36 // ===================================================================================================
37 /**
38   * \brief   
39   *          - explores  the given root directory e.g. :
40   *            B67d1.Bp1
41   *              subject
42   *              AdjStatePerStudy
43   *              1
44   *                 acqp
45   *                 AdjStatePerScan
46   *                 fid
47   *                 imnd / method
48   *                 pulseprogram
49   *                 spnam0
50   *                 spnam1
51   *                 pdata
52   *                    1                // only 'native' images
53   *                       2dseq
54   *                       d3proc
55   *                       meta
56   *                       procs
57   *                       reco  <--
58   *                       roi
59   *                       CreatisComputedCartoFile
60   *                    2                // post processed images (if any)
61   *                       2dseq
62   *                       d3proc
63   *                       isa  <--
64   *                       meta
65   *                       procs
66   *                       roi                      ...                   
67   *                       roi
68   *                    3                // post processed images (if any)
69   *                       2dseq
70   *                       d3proc
71   *                       isa  <--
72   *                       meta
73   *                       procs
74   *                       roi
75   *                    ...        
76   *              2
77   *                 acqp
78   *                 fid
79   *                 ...
80   *                 pdata
81   *              3         
82   *                ...
83   *          - fills a single level Directory with the MHD files,
84   */  
85   
86
87 int main(int argc, char *argv[])
88 {
89    START_USAGE(usage)
90    " \n testBruker2Dicom : \n                                                 ",
91    " - explores the given directory, at the 3 levels,                         ",
92    " - fills an equivalent Directory with the MHD files or the DICOM files    ",
93    " usage: testBruker2Dicom dirin=rootDirectoryName                          ",
94    "                         dirout=outputDirectoryName                       ",
95    "                   [D] [M]                                                ",
96    "                   [{b|l}] b:BigEndian,l:LittleEndian default : l         ",
97    "                   [debug] [verbose] [listonly]                           ",
98    "                                                                          ",
99    "   D         : user wants to export as DICOM                              ",
100    "   M         : user wants to export as MHD                                ",   
101    "  debug      : developper wants to run the program in 'debug mode'        ",
102    FINISH_USAGE
103    
104    // ------------ Initialize Arguments Manager ----------------  
105    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
106   
107    if (argc == 1 || am->ArgMgrDefined("usage") )
108    {
109       am->ArgMgrUsage(usage); // Display 'usage'
110       delete am;
111       return 1;
112    }
113
114    // create the devilish object!
115    Bruker2Dicom b2d;
116       
117    const char *dirNamein;   
118    dirNamein  = am->ArgMgrGetString("dirin",".");
119
120    const char *dirNameout;   
121    dirNameout  = am->ArgMgrGetString("dirout",".");
122
123 // note : Big Endian / Little Endian pb not yet dealt with.
124 //        not a great issue, since everybody (?) works on Intell procs  
125    int b = am->ArgMgrDefined("b");
126    int l = am->ArgMgrDefined("l");
127
128    if (am->ArgMgrDefined("debug"))
129       GDCM_NAME_SPACE::Debug::DebugOn();
130
131    b2d.verbose  = am->ArgMgrDefined("verbose");      
132    int listonly = am->ArgMgrDefined("listonly");
133    
134    int dicom    = am->ArgMgrDefined("D");
135    int mhd      = am->ArgMgrDefined("M");
136    
137    if (dicom)
138       b2d.SetConvertModeToDicom();
139    if (mhd)
140       b2d.SetConvertModeToMhd();
141              
142    /* if unused Param we give up */
143    if ( am->ArgMgrPrintUnusedLabels() )
144    {
145       am->ArgMgrUsage(usage);
146       delete am;
147       return 1;
148    } 
149
150 // patientName : found in Bruker parameter files
151 // patientName  = am->ArgMgrGetString("patientname", "Patient^Name");
152
153 // b2d.day : unused  ...
154    b2d.day          = am->ArgMgrGetString("day", "You_forget_the_Day");
155       
156  delete am;  // we don't need Argument Manager any longer  
157
158    // ----------- End Arguments Manager ---------
159    
160
161    // ----- Begin Processing -----
162
163    b2d.SetInputDirectory(dirNamein);
164    b2d.SetOutputDirectory(dirNameout);
165
166    /// \TODO : *do* use exceptions in the methods!
167       
168    try {
169       b2d.Execute();
170    }
171    catch (int i)
172    {
173       std::cout << "Exception was thrown  (" << i << ") " << std::endl;
174    }
175    /*
176    catch (std::exception& e) {
177    std::cerr << "ERREUR: " << e.what() << "expected length: " << e.getExpectedLgt()
178              << " Found : " << e.getFoundLgt() << std::endl;
179    }
180   */
181
182    catch (BrukerHopelessException &e)
183    {
184       std::cout << "And Hopless Exception was thrown  (" << e.what() << ") " << std::endl;
185    }
186
187
188
189
190