1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #ifndef __OsirixParser__
27 #define __OsirixParser__
32 #ifdef kernelParserOsirix_BUILD_SHARED
33 #define kernelParserOsirix_EXPORT __declspec( dllexport )
35 #define kernelParserOsirix_EXPORT __declspec( dllimport )
37 #define kernelParserOsirix_CDECL __cdecl
39 #define kernelParserOsirix_EXPORT
40 #define kernelParserOsirix_CDECL
41 #endif // defined(_WIN32)
43 //------------------------------------------------------------------------------------------------------------
45 //------------------------------------------------------------------------------------------------------------
50 #include <xercesc/parsers/XercesDOMParser.hpp>
51 #include <xercesc/dom/DOM.hpp>
52 #include <xercesc/dom/DOMErrorHandler.hpp>
53 #include <xercesc/dom/DOMLocator.hpp>
54 #include <xercesc/sax/HandlerBase.hpp>
55 #include <xercesc/util/XMLString.hpp>
56 #include <xercesc/util/PlatformUtils.hpp>
60 using namespace xercesc;
66 //------------------------------------------------------------------------------------------------------------
67 // Constructors & Destructors
68 //------------------------------------------------------------------------------------------------------------
72 ** Constructor for the parser, with the information of the pixel spacing and image dimensions
74 OsirixParser(std::string xsdfile = "", double* spacing = NULL, int* extent = NULL);
76 ** Desctructor by defect
80 int ParseFile(const char* xmlfile);
83 std::string getErrorLine();
85 std::string getContoursFileName();
87 // Return ROI as lists of points
88 const std::map<int, vector< vector<double> > >& getContoursMapMM() {
91 const std::map<int, vector< vector<double> > >& getContoursMapPX() {
96 const std::map<int, std::string>& getContoursNameMM() {
97 return contoursnameMM;
99 const std::map<int, std::string>& getContoursNamePX() {
100 return contoursnamePX;
107 std::string errorline;
110 std::string _roiname;
112 const char* OSIRIX_DICT;
113 const char* OSIRIX_KEY;
114 const char* OSIRIX_IMAGES;
115 const char* OSIRIX_ARRAY;
116 const char* OSIRIX_IMAGEINDEX;
117 const char* OSIRIX_INTEGER;
118 const char* OSIRIX_NUMBEROFROIS;
119 const char* OSIRIX_ROIS;
120 const char* OSIRIX_POINT_MM;
121 const char* OSIRIX_POINT_PX;
122 const char* OSIRIX_STRING;
123 const char* OSIRIX_NAME;
125 const char* CREACONTOUR;
126 const char* CREACONTOUR_VERSION;
127 const char* CREACONTOUR_IMAGEDIMENSIONS;
128 const char* CREACONTOUR_IMAGESPACING;
129 const char* CREACONTOUR_NUMBEROFCONTOURS;
131 const char* CREACONTOUR_INSTANT;
132 const char* CREACONTOUR_TYPEMODEL;
133 const char* CREACONTOUR_NUMBEROFCONTROLPOINTS;
134 const char* CREACONTOUR_TYPEVIEW;
136 const char* CREACONTOUR_NUMBEROFCONTOURSSTATIC;
138 std::string TEMPIMPORTOSIRIXFILE;
143 typedef vector< vector<double> > vectorXYZ;
144 std::map<int, vectorXYZ> contoursmapMM;
145 std::map<int, vectorXYZ> contoursmapPX;
147 std::map<int, std::string> contoursnameMM;
148 std::map<int, std::string> contoursnamePX;
150 void saveCreaContoursFormat();
152 void writeHeader(FILE* pFile);
153 void writeContours(FILE* pFile);
154 void writeContoursStatic(FILE* pFile);
156 void setErrorLine(DOMNodeList* list);
158 void getUserData(DOMElement* element);
160 void getData(DOMNodeList* list, std::vector<std::string>& vect, std::string tagname);
162 DOMNode* getLastNode(DOMNodeList* list);
164 void parseOSIRIX_DICT(DOMNodeList* list);
165 void parseOSIRIX_POINT_MM(DOMNodeList* list);
166 void parseOSIRIX_POINT_PX(DOMNodeList* list);
173 class OsirixParserErrorHandler : public ErrorHandler{
175 //------------------------------------------------------------------------------------------------------------
176 // Constructors & Destructors
177 //------------------------------------------------------------------------------------------------------------
181 ** Default Constructor
183 OsirixParserErrorHandler();
185 ** Desctructor by defect
187 ~OsirixParserErrorHandler();
189 virtual void warning (const SAXParseException &exc);
191 virtual void error (const SAXParseException &exc);
193 virtual void fatalError (const SAXParseException &exc);
195 virtual void resetErrors ();
197 std::string getErrorMsg();
202 std::string errormsg;