OsirixParser.h
Go to the documentation of this file.00001 #ifndef __OsirixParser__
00002 #define __OsirixParser__
00003
00004
00005 #if defined(_WIN32)
00006 #include "Windows.h"
00007 #ifdef kernelParserOsirix_BUILD_SHARED
00008 #define kernelParserOsirix_EXPORT __declspec( dllexport )
00009 #else
00010 #define kernelParserOsirix_EXPORT __declspec( dllimport )
00011 #endif
00012 #define kernelParserOsirix_CDECL __cdecl
00013 #else
00014 #define kernelParserOsirix_EXPORT
00015 #define kernelParserOsirix_CDECL
00016 #endif // defined(_WIN32)
00017
00018
00019
00020
00021
00022 #include <iostream>
00023 #include <vector>
00024 #include <map>
00025 #include <xercesc/parsers/XercesDOMParser.hpp>
00026 #include <xercesc/dom/DOM.hpp>
00027 #include <xercesc/dom/DOMErrorHandler.hpp>
00028 #include <xercesc/dom/DOMLocator.hpp>
00029 #include <xercesc/sax/HandlerBase.hpp>
00030 #include <xercesc/util/XMLString.hpp>
00031 #include <xercesc/util/PlatformUtils.hpp>
00032
00033
00034 using namespace std;
00035 using namespace xercesc;
00036
00037
00038
00039 class OsirixParser{
00040
00041
00042
00043
00044 public:
00045
00049 OsirixParser(std::string xsdfile = "", double* spacing = NULL, int* extent = NULL);
00053 ~OsirixParser();
00054
00055 int ParseFile(const char* xmlfile);
00056
00057
00058 std::string getErrorLine();
00059
00060 std::string getContoursFileName();
00061
00062
00063 const std::map<int, vector< vector<double> > >& getContoursMapMM() {
00064 return contoursmapMM;
00065 }
00066 const std::map<int, vector< vector<double> > >& getContoursMapPX() {
00067 return contoursmapPX;
00068 }
00069
00070
00071 const std::map<int, std::string>& getContoursNameMM() {
00072 return contoursnameMM;
00073 }
00074 const std::map<int, std::string>& getContoursNamePX() {
00075 return contoursnamePX;
00076 }
00077
00078 private:
00079
00080 std::string schema;
00081
00082 std::string errorline;
00083
00084 int _imageindex;
00085 std::string _roiname;
00086
00087 const char* OSIRIX_DICT;
00088 const char* OSIRIX_KEY;
00089 const char* OSIRIX_IMAGES;
00090 const char* OSIRIX_ARRAY;
00091 const char* OSIRIX_IMAGEINDEX;
00092 const char* OSIRIX_INTEGER;
00093 const char* OSIRIX_NUMBEROFROIS;
00094 const char* OSIRIX_ROIS;
00095 const char* OSIRIX_POINT_MM;
00096 const char* OSIRIX_POINT_PX;
00097 const char* OSIRIX_STRING;
00098 const char* OSIRIX_NAME;
00099
00100 const char* CREACONTOUR;
00101 const char* CREACONTOUR_VERSION;
00102 const char* CREACONTOUR_IMAGEDIMENSIONS;
00103 const char* CREACONTOUR_IMAGESPACING;
00104 const char* CREACONTOUR_NUMBEROFCONTOURS;
00105
00106 const char* CREACONTOUR_INSTANT;
00107 const char* CREACONTOUR_TYPEMODEL;
00108 const char* CREACONTOUR_NUMBEROFCONTROLPOINTS;
00109 const char* CREACONTOUR_TYPEVIEW;
00110
00111 const char* CREACONTOUR_NUMBEROFCONTOURSSTATIC;
00112
00113 std::string TEMPIMPORTOSIRIXFILE;
00114
00115 double _spacing[3];
00116 int _extent[6];
00117
00118 typedef vector< vector<double> > vectorXYZ;
00119 std::map<int, vectorXYZ> contoursmapMM;
00120 std::map<int, vectorXYZ> contoursmapPX;
00121
00122 std::map<int, std::string> contoursnameMM;
00123 std::map<int, std::string> contoursnamePX;
00124
00125 void saveCreaContoursFormat();
00126
00127 void writeHeader(FILE* pFile);
00128 void writeContours(FILE* pFile);
00129 void writeContoursStatic(FILE* pFile);
00130
00131 void setErrorLine(DOMNodeList* list);
00132
00133 void getUserData(DOMElement* element);
00134
00135 void getData(DOMNodeList* list, std::vector<std::string>& vect, std::string tagname);
00136
00137 DOMNode* getLastNode(DOMNodeList* list);
00138
00139 void parseOSIRIX_DICT(DOMNodeList* list);
00140 void parseOSIRIX_POINT_MM(DOMNodeList* list);
00141 void parseOSIRIX_POINT_PX(DOMNodeList* list);
00142
00143
00144
00145
00146 };
00147
00148 class OsirixParserErrorHandler : public ErrorHandler{
00149
00150
00151
00152
00153 public:
00154
00158 OsirixParserErrorHandler();
00162 ~OsirixParserErrorHandler();
00163
00164 virtual void warning (const SAXParseException &exc);
00165
00166 virtual void error (const SAXParseException &exc);
00167
00168 virtual void fatalError (const SAXParseException &exc);
00169
00170 virtual void resetErrors ();
00171
00172 std::string getErrorMsg();
00173
00174 private:
00175
00176
00177 std::string errormsg;
00178
00179
00180
00181
00182
00183 };
00184 #endif