]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/ParserOsirix/OsirixParser.h
346cd7adf44f65fcc34d8cb68ccff80d3de36ef5
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / ParserOsirix / OsirixParser.h
1 #ifndef __OsirixParser__
2 #define __OsirixParser__
3
4
5 #if defined(_WIN32)
6 #include "Windows.h"
7   #ifdef kernelParserOsirix_BUILD_SHARED
8     #define kernelParserOsirix_EXPORT __declspec( dllexport )
9   #else
10     #define kernelParserOsirix_EXPORT __declspec( dllimport )
11   #endif
12   #define kernelParserOsirix_CDECL __cdecl
13 #else
14   #define kernelParserOsirix_EXPORT
15   #define kernelParserOsirix_CDECL
16 #endif // defined(_WIN32)
17
18 //------------------------------------------------------------------------------------------------------------
19 // Includes
20 //------------------------------------------------------------------------------------------------------------
21
22 #include <iostream>
23 #include <vector>
24 #include <map>
25 #include <xercesc/parsers/XercesDOMParser.hpp>
26 #include <xercesc/dom/DOM.hpp>
27 #include <xercesc/dom/DOMErrorHandler.hpp>
28 #include <xercesc/dom/DOMLocator.hpp>
29 #include <xercesc/sax/HandlerBase.hpp>
30 #include <xercesc/util/XMLString.hpp>
31 #include <xercesc/util/PlatformUtils.hpp>
32
33
34 using namespace std;
35 using namespace xercesc;
36
37
38
39 class OsirixParser{
40
41 //------------------------------------------------------------------------------------------------------------
42 // Constructors & Destructors
43 //------------------------------------------------------------------------------------------------------------
44 public:
45
46         /**
47         ** Constructor for the parser, with the information of the pixel spacing and image dimensions
48         **/
49         OsirixParser(std::string xsdfile = "", double* spacing = NULL, int* extent = NULL);
50         /**
51         ** Desctructor by defect
52         **/
53         ~OsirixParser();        
54
55         int ParseFile(const char* xmlfile);
56         
57         
58         std::string getErrorLine();
59
60         std::string getContoursFileName();
61
62         // Return ROI as lists of points
63         const std::map<int, vector< vector<double> > >& getContoursMapMM() {
64           return contoursmapMM;
65         }
66         const std::map<int, vector< vector<double> > >& getContoursMapPX() {
67           return contoursmapPX;
68         }
69
70         // Return ROI names
71         const std::map<int, std::string>& getContoursNameMM() {
72           return contoursnameMM;
73         }
74         const std::map<int, std::string>& getContoursNamePX() {
75           return contoursnamePX;
76         }
77
78 private:
79
80         std::string schema;
81
82         std::string errorline;  
83
84         int _imageindex;
85         std::string _roiname;
86
87         const char* OSIRIX_DICT;
88         const char* OSIRIX_KEY;
89         const char* OSIRIX_IMAGES;
90         const char* OSIRIX_ARRAY;
91         const char* OSIRIX_IMAGEINDEX;
92         const char* OSIRIX_INTEGER;
93         const char* OSIRIX_NUMBEROFROIS;
94         const char* OSIRIX_ROIS;
95         const char* OSIRIX_POINT_MM;
96         const char* OSIRIX_POINT_PX;
97         const char* OSIRIX_STRING;              
98         const char* OSIRIX_NAME;
99
100         const char* CREACONTOUR;
101         const char* CREACONTOUR_VERSION;
102         const char* CREACONTOUR_IMAGEDIMENSIONS;
103         const char* CREACONTOUR_IMAGESPACING;
104         const char* CREACONTOUR_NUMBEROFCONTOURS;
105
106         const char* CREACONTOUR_INSTANT;
107         const char* CREACONTOUR_TYPEMODEL;
108         const char* CREACONTOUR_NUMBEROFCONTROLPOINTS;
109         const char* CREACONTOUR_TYPEVIEW;       
110         
111         const char* CREACONTOUR_NUMBEROFCONTOURSSTATIC;
112
113         std::string TEMPIMPORTOSIRIXFILE;
114
115         double _spacing[3];
116         int _extent[6];
117
118         typedef vector< vector<double> > vectorXYZ;
119         std::map<int, vectorXYZ> contoursmapMM; 
120         std::map<int, vectorXYZ> contoursmapPX;
121
122         std::map<int, std::string> contoursnameMM;
123         std::map<int, std::string> contoursnamePX;
124
125         void saveCreaContoursFormat();
126
127         void writeHeader(FILE* pFile);
128         void writeContours(FILE* pFile);
129         void writeContoursStatic(FILE* pFile);
130
131         void setErrorLine(DOMNodeList* list);   
132
133         void getUserData(DOMElement* element);  
134
135         void getData(DOMNodeList* list, std::vector<std::string>& vect, std::string tagname);
136
137         DOMNode* getLastNode(DOMNodeList* list);
138
139         void parseOSIRIX_DICT(DOMNodeList* list);
140         void parseOSIRIX_POINT_MM(DOMNodeList* list);
141         void parseOSIRIX_POINT_PX(DOMNodeList* list);
142
143         
144
145         
146 };
147
148 class OsirixParserErrorHandler : public ErrorHandler{
149
150 //------------------------------------------------------------------------------------------------------------
151 // Constructors & Destructors
152 //------------------------------------------------------------------------------------------------------------
153 public:
154
155         /**
156         ** Default Constructor
157         **/
158         OsirixParserErrorHandler();
159         /**
160         ** Desctructor by defect
161         **/
162         ~OsirixParserErrorHandler();    
163
164         virtual void    warning (const SAXParseException &exc);         
165
166         virtual void    error (const SAXParseException &exc);           
167
168         virtual void    fatalError (const SAXParseException &exc);              
169
170         virtual void    resetErrors ();
171
172         std::string getErrorMsg();
173
174 private:
175
176         
177         std::string errormsg;
178
179         
180
181         
182         
183 };
184 #endif