]> Creatis software - creaBruker.git/blob - lib/src1/bruker2dicom2.h
Feature #1767
[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 public:
75  /*! \brief Constructor
76 */
77   Bruker2Dicom () /* : verbose(0), mhd(0), dicom(0), day(O)*/ {};
78 /*! \brief Destructor
79 */
80   ~Bruker2Dicom (){};
81
82   void SetInputDirectory (const std::string &i) { InputDirName   = i;}
83   void SetOutputDirectory(const std::string &o) { OutputDirName  = o;}
84   void SetConvertModeToDicom()                  { dicom = 1; mhd = 0;}
85   void SetConvertModeToMhd()                    { dicom = 0; mhd = 1;}  
86   bool Execute();
87   
88   /* 
89   // For debugging pupose only.
90   //Don't need accessors : Attributes are 'public' 
91   
92   void SetVerbose(int v) { verbose = v;}
93   void SetMhd(int m)     { mhd = m;    }
94   void SetDicom(int d)   { dicom = d;  }
95   */     
96
97 private :
98
99 void MakeDicomImage(unsigned char *tabPixels, 
100               int X, 
101               int Y,
102               int nbFrames,
103               int pixelSize,
104               double spacingX, double spacingY, double sliceDistance, 
105               std::string dcmImageName,
106               const std::string &patientName,
107               const char *day,
108               std::string &studyUID,
109               std::string &serieUID,
110               std::string &studyDescr,
111               std::string &serieDescr,
112               std::string &strStudyTimeDate,
113               int imgNum, int  imagecontenttype//gdcm2 dont have such things, I think, as ImageContentTYpe 
114       );
115       
116 std::vector<BrukerImage> CreateImageSet ( );
117
118 void getImhDataType(BrukerFieldData &bDPT, 
119                     std::string &mhdDataPixelType, 
120                     int &pixelSize);
121                     
122 void cleanString(std::string &s);
123
124 bool CreateDirectory(const std::string &dirNameout);
125
126 int CheckUserDirectory(std::string &userDirName);
127 void DealWithMultiStudyDirectory(gdcm::Directory::FilenamesType &fileNames, const std::string &currentOutputDirName);
128 void DealWithSingleStudyDirectory (const std::string dirname,               const std::string currentOutputDirName) ;
129
130 void DealWithNiveau1(std::string level1Directory, std::string currentOutputDirName);
131 void DealWithNiveau2(std::string level2Directory, std::string currentOutputDirName);
132 void DealWithNiveau3(std::string &level3Directory, std::string &currentOutputDirName);
133                     
134 void dealWithCarto(gdcm::Directory::FilenamesType &fileNames, int NX, int NY, int nbSlices, 
135                    double fovX, double fovY, double sliceDistance,
136                    char *copyFile, std::string &currentOutputDirName, 
137                    char *outputMhdFileName, char *output2dseqCartoName);
138
139 const std::string createDirectory(const std::string &i_name,const std::string &i_dir);
140  std::string findFile(const std::string &i_dir, const std::string i_name);
141 public:
142
143 // these ones are for debugging only
144 // don't bbfy the accessors.
145
146    int verbose;
147    const char *day;
148        
149 private :
150    std::string InputDirName;
151    std::string OutputDirName;
152
153    bool subjectFound;
154    bool acqpFound;
155    
156    std::string subject_entry;
157    std::string subject_position;
158    std::string subject_date;
159    std::string subject_study_name;
160  
161    int mhd;
162    int dicom;
163      
164    int nbSlices;
165    BrukerDataSet br_subject;
166    BrukerDataSet br_acqp;
167    BrukerDataSet br_method;
168    BrukerDataSet br_d3proc;
169    BrukerDataSet br_isa;
170    BrukerDataSet br_reco;
171
172    std::vector<BrukerImage> imageSet;
173
174 // For DICOM images.
175
176    std::string strStudyUID; 
177    std::string strSerieUID; 
178    std::string strStudyDescr; 
179    std::string strSerieDescr;
180    std::string strStudyTimeDate;
181    std::string strPatientName;
182    std::string subject_name; // cleaned strPatientName
183  
184    int serieNumber;
185    int instanceNumber;      
186 };
187
188 #endif