creaContours_lib
OsirixParser.h
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
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
8 #
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.
15 #
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
20 # liability.
21 #
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 # ------------------------------------------------------------------------ */
25 
26 #ifndef __OsirixParser__
27 #define __OsirixParser__
28 
29 
30 #if defined(_WIN32)
31 #include "Windows.h"
32  #ifdef kernelParserOsirix_BUILD_SHARED
33  #define kernelParserOsirix_EXPORT __declspec( dllexport )
34  #else
35  #define kernelParserOsirix_EXPORT __declspec( dllimport )
36  #endif
37  #define kernelParserOsirix_CDECL __cdecl
38 #else
39  #define kernelParserOsirix_EXPORT
40  #define kernelParserOsirix_CDECL
41 #endif // defined(_WIN32)
42 
43 //------------------------------------------------------------------------------------------------------------
44 // Includes
45 //------------------------------------------------------------------------------------------------------------
46 
47 #include <iostream>
48 #include <vector>
49 #include <map>
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>
57 
58 
59 using namespace std;
60 using namespace xercesc;
61 
62 
63 
65 
66 //------------------------------------------------------------------------------------------------------------
67 // Constructors & Destructors
68 //------------------------------------------------------------------------------------------------------------
69 public:
70 
74  OsirixParser(std::string xsdfile = "", double* spacing = NULL, int* extent = NULL);
78  ~OsirixParser();
79 
80  int ParseFile(const char* xmlfile);
81 
82 
83  std::string getErrorLine();
84 
85  std::string getContoursFileName();
86 
87  // Return ROI as lists of points
88  const std::map<int, vector< vector<double> > >& getContoursMapMM() {
89  return contoursmapMM;
90  }
91  const std::map<int, vector< vector<double> > >& getContoursMapPX() {
92  return contoursmapPX;
93  }
94 
95  // Return ROI names
96  const std::map<int, std::string>& getContoursNameMM() {
97  return contoursnameMM;
98  }
99  const std::map<int, std::string>& getContoursNamePX() {
100  return contoursnamePX;
101  }
102 
103 private:
104 
105  std::string schema;
106 
107  std::string errorline;
108 
110  std::string _roiname;
111 
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;
124 
125  const char* CREACONTOUR;
126  const char* CREACONTOUR_VERSION;
130 
131  const char* CREACONTOUR_INSTANT;
134  const char* CREACONTOUR_TYPEVIEW;
135 
137 
138  std::string TEMPIMPORTOSIRIXFILE;
139 
140  double _spacing[3];
141  int _extent[6];
142 
143  typedef vector< vector<double> > vectorXYZ;
144  std::map<int, vectorXYZ> contoursmapMM;
145  std::map<int, vectorXYZ> contoursmapPX;
146 
147  std::map<int, std::string> contoursnameMM;
148  std::map<int, std::string> contoursnamePX;
149 
150  void saveCreaContoursFormat();
151 
152  void writeHeader(FILE* pFile);
153  void writeContours(FILE* pFile);
154  void writeContoursStatic(FILE* pFile);
155 
156  void setErrorLine(DOMNodeList* list);
157 
158  void getUserData(DOMElement* element);
159 
160  void getData(DOMNodeList* list, std::vector<std::string>& vect, std::string tagname);
161 
162  DOMNode* getLastNode(DOMNodeList* list);
163 
164  void parseOSIRIX_DICT(DOMNodeList* list);
165  void parseOSIRIX_POINT_MM(DOMNodeList* list);
166  void parseOSIRIX_POINT_PX(DOMNodeList* list);
167 
168 
169 
170 
171 };
172 
173 class OsirixParserErrorHandler : public ErrorHandler{
174 
175 //------------------------------------------------------------------------------------------------------------
176 // Constructors & Destructors
177 //------------------------------------------------------------------------------------------------------------
178 public:
179 
188 
189  virtual void warning (const SAXParseException &exc);
190 
191  virtual void error (const SAXParseException &exc);
192 
193  virtual void fatalError (const SAXParseException &exc);
194 
195  virtual void resetErrors ();
196 
197  std::string getErrorMsg();
198 
199 private:
200 
201 
202  std::string errormsg;
203 
204 
205 
206 
207 
208 };
209 #endif