]> Creatis software - creaBruker.git/blob - appli/testBruker2Dicom/testBruker2Dicom.cxx
b81541029e6a5ffd421633b0ae322f73fca95c6f
[creaBruker.git] / appli / testBruker2Dicom / testBruker2Dicom.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: testBruker2Dicom.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/12/14 14:08:08 $
7   Version:   $Revision: 1.6 $
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 (holding a FULL Bruker exam), 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    "                                                                          ",   
103    "  REMARK :                                                                ",   
104    "         If you were supplied  an *incomplete* Bruker exam                ",
105    "        (e.g. only the '2' serie) put it a 'root' directory,              ",
106    "         and run this test using this 'root' directory as 'dirin'         ",   
107    FINISH_USAGE
108    
109    // ------------ Initialize Arguments Manager ----------------  
110    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
111   
112    if (argc == 1 || am->ArgMgrDefined("usage") )
113    {
114       am->ArgMgrUsage(usage); // Display 'usage'
115       delete am;
116       return 1;
117    }
118
119    // create the devilish object!
120    Bruker2Dicom b2d;
121       
122    const char *dirNamein;   
123    dirNamein  = am->ArgMgrGetString("dirin",".");
124
125    const char *dirNameout;   
126    dirNameout  = am->ArgMgrGetString("dirout",".");
127
128 // note : Big Endian / Little Endian pb not yet dealt with.
129 //        not a great issue, since everybody (?) works on Intell procs  
130    int b = am->ArgMgrDefined("b");
131    int l = am->ArgMgrDefined("l");
132
133    if (am->ArgMgrDefined("debug"))
134       GDCM_NAME_SPACE::Debug::DebugOn();
135
136    b2d.verbose  = am->ArgMgrDefined("verbose");      
137    int listonly = am->ArgMgrDefined("listonly");
138    
139    int dicom    = am->ArgMgrDefined("D");
140    int mhd      = am->ArgMgrDefined("M");
141    
142    if (dicom)
143       b2d.SetConvertModeToDicom();
144    if (mhd)
145       b2d.SetConvertModeToMhd();
146              
147    /* if unused Param we give up */
148    if ( am->ArgMgrPrintUnusedLabels() )
149    {
150       am->ArgMgrUsage(usage);
151       delete am;
152       return 1;
153    } 
154
155 // patientName : found in Bruker parameter files
156 // patientName  = am->ArgMgrGetString("patientname", "Patient^Name");
157
158 // b2d.day : unused  ...
159    b2d.day          = am->ArgMgrGetString("day", "You_forget_the_Day");
160       
161  delete am;  // we don't need Argument Manager any longer  
162
163    // ----------- End Arguments Manager ---------
164    
165
166    // ----- Begin Processing -----
167
168    b2d.SetInputDirectory(dirNamein);
169    b2d.SetOutputDirectory(dirNameout);
170
171    /// \TODO : *do* use exceptions in the methods!
172       
173    try {
174       b2d.Execute();
175    }
176    catch (int i)
177    {
178       std::cout << "Exception was thrown  (" << i << ") " << std::endl;
179    }
180    /*
181    catch (std::exception& e) {
182    std::cerr << "ERREUR: " << e.what() << "expected length: " << e.getExpectedLgt()
183              << " Found : " << e.getFoundLgt() << std::endl;
184    }
185   */
186
187    catch (BrukerHopelessException &e)
188    {
189       std::cout << "And Hopless Exception was thrown  (" << e.what() << ") " << std::endl;
190    }
191
192
193
194
195