]> Creatis software - creaBruker.git/blob - lib/src1/bruker2dicom2.h
Added CMake configuration to enable CDash tests.
[creaBruker.git] / lib / src1 / bruker2dicom2.h
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 #ifndef BRUKER2DICOM2_H
28 #define BRUKER2DICOM2_H
29
30 #include <gdcmReader.h>
31 #include "gdcmDirectory.h"
32 #include <vtkGDCMImageReader.h>
33 #include <gdcmScanner.h>
34
35 #include "gdcmByteSwap.h"
36 #include "gdcmSwapCode.h"
37 #include "gdcmFilename.h"
38 #include "gdcmDataSet.h"
39
40 #include "gdcmImageWriter.h"
41 #include "gdcmImage.h"
42 #include "gdcmWriter.h"
43 #include "gdcmReader.h"
44 #include "gdcmUIDGenerator.h"
45 //
46 //#include "gdcmFile.h"
47 //#include "gdcmFileHelper.h"
48 //#include "gdcmCommon.h"
49 //#include "gdcmDebug.h"
50 //#include "gdcmUtil.h"
51 //#include "gdcmDirList.h"
52 //
53 //#include "gdcmArgMgr.h"
54 #include "brukerSystem.h"
55 #include "brukerdataset.h"
56 #include "brukerkspaceobject.h"
57 #include "brukerimage.h"
58 #include <string>
59 #include <iostream>
60 #include <sstream>
61
62   // file separator
63 #if defined(_WIN32)
64 #define VALID_FILE_SEPARATOR "\\"
65 #define INVALID_FILE_SEPARATOR "/"
66 #else
67 #define INVALID_FILE_SEPARATOR "\\"
68 #define VALID_FILE_SEPARATOR "/"
69 #endif
70
71 //class __declspec( dllexport ) Bruker2Dicom {
72 class /*creaBruker_EXPORT*/  Bruker2Dicom 
73 {
74
75 public:
76  /*! \brief Constructor
77 */
78   Bruker2Dicom () /* : verbose(0), mhd(0), dicom(0), day(O)*/ {};
79 /*! \brief Destructor
80 */
81   ~Bruker2Dicom (){};
82
83   void SetInputDirectory (const std::string &i) { InputDirName   = i;}
84   void SetOutputDirectory(const std::string &o) { OutputDirName  = o;}
85   void SetConvertModeToDicom()                  { dicom = 1; mhd = 0;}
86   void SetConvertModeToMhd()                    { dicom = 0; mhd = 1;}  
87   bool Execute();
88   
89   /* 
90   // For debugging pupose only.
91   //Don't need accessors : Attributes are 'public' 
92   
93   void SetVerbose(int v) { verbose = v;}
94   void SetMhd(int m)     { mhd = m;    }
95   void SetDicom(int d)   { dicom = d;  }
96   */     
97
98 private :
99
100 void MakeDicomImage(unsigned char *tabPixels, 
101               int X, 
102               int Y,
103               int nbFrames,
104               int pixelSize,
105               double spacingX, double spacingY, double sliceDistance, 
106               std::string dcmImageName,
107               const std::string &patientName,
108               const char *day,
109               std::string &studyUID,
110               std::string &serieUID,
111               std::string &studyDescr,
112               std::string &serieDescr,
113               std::string &strStudyTimeDate,
114               int imgNum, int  imagecontenttype//gdcm2 dont have such things, I think, as ImageContentTYpe 
115       );
116       
117 std::vector<BrukerImage> CreateImageSet ( );
118
119 void getImhDataType(BrukerFieldData &bDPT, 
120                     std::string &mhdDataPixelType, 
121                     int &pixelSize);
122                     
123 void cleanString(std::string &s);
124
125 bool CreateDirectory(const std::string &dirNameout);
126
127 int CheckUserDirectory(std::string &userDirName);
128 void DealWithMultiStudyDirectory(gdcm::Directory::FilenamesType &fileNames, const std::string &currentOutputDirName);
129 void DealWithSingleStudyDirectory (const std::string dirname,               const std::string currentOutputDirName) ;
130
131 void DealWithNiveau1(std::string level1Directory, std::string currentOutputDirName);
132 void DealWithNiveau2(std::string level2Directory, std::string currentOutputDirName);
133 void DealWithNiveau3(std::string &level3Directory, std::string &currentOutputDirName);
134                     
135 void dealWithCarto(gdcm::Directory::FilenamesType &fileNames, int NX, int NY, int nbSlices, 
136                    double fovX, double fovY, double sliceDistance,
137                    char *copyFile, std::string &currentOutputDirName, 
138                    char *outputMhdFileName, char *output2dseqCartoName);
139
140 const std::string createDirectory(const std::string &i_name,const std::string &i_dir);
141  std::string findFile(const std::string &i_dir, const std::string i_name);
142 public:
143
144 // these ones are for debugging only
145 // don't bbfy the accessors.
146
147    int verbose;
148    const char *day;
149        
150 private :
151    std::string InputDirName;
152    std::string OutputDirName;
153
154    bool subjectFound;
155    bool acqpFound;
156    
157    std::string subject_entry;
158    std::string subject_position;
159    std::string subject_date;
160    std::string subject_study_name;
161  
162    int mhd;
163    int dicom;
164      
165    int nbSlices;
166    BrukerDataSet br_subject;
167    BrukerDataSet br_acqp;
168    BrukerDataSet br_method;
169    BrukerDataSet br_d3proc;
170    BrukerDataSet br_isa;
171    BrukerDataSet br_reco;
172
173    std::vector<BrukerImage> imageSet;
174
175 // For DICOM images.
176
177    std::string strStudyUID; 
178    std::string strSerieUID; 
179    std::string strStudyDescr; 
180    std::string strSerieDescr;
181    std::string strStudyTimeDate;
182    std::string strPatientName;
183    std::string subject_name; // cleaned strPatientName
184  
185    int serieNumber;
186    int instanceNumber;      
187 };
188
189 #endif