]> Creatis software - creaContours.git/blobdiff - lib/kernel_ManagerContour_NDimensions/ParserOsirix/OsirixParser.cxx
export contours data
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / ParserOsirix / OsirixParser.cxx
index 4c36214c9b7774b60deb4a6ebf8ba586ecd72453..447c9ddf3bd755abddf9a97f7c0b08ee0e1e2d83 100644 (file)
@@ -3,7 +3,6 @@
 // Class definition include
 //----------------------------------------------------------------------------------------------------------------
 #include "OsirixParser.h"
-
 #include <stdio.h>
 
 
@@ -22,6 +21,7 @@ OsirixParser::OsirixParser(std::string xsdfile, double* spacing, int* extent)
        OSIRIX_POINT_MM = "Point_mm";
        OSIRIX_POINT_PX = "Point_px";
        OSIRIX_STRING = "string";
+       OSIRIX_NAME = "Name";
 
        if(spacing != NULL){
                _spacing[0] = spacing[0];
@@ -65,6 +65,7 @@ OsirixParser::OsirixParser(std::string xsdfile, double* spacing, int* extent)
        /*STATICCONTOURS*/
        CREACONTOUR_NUMBEROFCONTOURSSTATIC = "NumberOfContoursStatic";
 
+        TEMPIMPORTOSIRIXFILE = "";
 
 #ifdef WIN32
 
@@ -77,7 +78,15 @@ OsirixParser::OsirixParser(std::string xsdfile, double* spacing, int* extent)
        TEMPIMPORTOSIRIXFILE.append("\\data\\TEMPIMPORTOSIRIXFILE.roi");
        
 #else
-       TEMPIMPORTOSIRIXFILE = "./data/TEMPIMPORTOSIRIXFILE";
+        char * pPath;
+        pPath = getenv ("HOME");
+
+        if(pPath){
+            TEMPIMPORTOSIRIXFILE.append(pPath);
+        }else{
+            TEMPIMPORTOSIRIXFILE.append(".");
+        }
+        TEMPIMPORTOSIRIXFILE.append("/.creaContourDataTemp/TEMPIMPORTOSIRIXFILE.roi");
 #endif
        
 }
@@ -223,6 +232,8 @@ void OsirixParser::parseOSIRIX_DICT(DOMNodeList* list){
        imageindex = OSIRIX_IMAGEINDEX;
        osirixinteger = OSIRIX_INTEGER;
        
+       std::string osirixstring = OSIRIX_STRING;
+       std::string osirixname = OSIRIX_NAME;
        
 
        for(i = 0; i < (int)(list->getLength()); i++){
@@ -250,6 +261,13 @@ void OsirixParser::parseOSIRIX_DICT(DOMNodeList* list){
                                if(childnode1 != NULL && osirixinteger.compare(XMLString::transcode(childnode1->getNodeName())) == 0){
                                        _imageindex = atoi(XMLString::transcode(childnode1->getTextContent()));                                         
                                }                               
+                       } else if(osirixname.compare(temp) == 0) {
+                         // keep information about the name of the ROI
+                               childnode1 = childlist->item(j+2);
+                               if(childnode1 != NULL && osirixstring.compare(XMLString::transcode(childnode1->getNodeName())) == 0){
+                                 char* roiname = XMLString::transcode(childnode1->getTextContent());
+                                 _roiname = string(roiname);
+                               }
                        }
                }               
        }
@@ -299,6 +317,7 @@ void OsirixParser::parseOSIRIX_POINT_MM(DOMNodeList* list){
                vectorxyz.push_back(*vectory);
                vectorxyz.push_back(*vectorz);
                contoursmapMM.insert(pair<int, vectorXYZ>(contoursmapMM.size(), vectorxyz));
+               contoursnameMM.insert(pair<int, string>(contoursnameMM.size(), _roiname));
        }
 }
 
@@ -342,6 +361,7 @@ void OsirixParser::parseOSIRIX_POINT_PX(DOMNodeList* list){
                vectorxyz.push_back(*vectory);  
                vectorxyz.push_back(*vectorz);  
                contoursmapPX.insert(pair<int, vectorXYZ>(contoursmapPX.size(), vectorxyz));
+               contoursnamePX.insert(pair<int, string>(contoursnamePX.size(), _roiname));
        }       
 }
                
@@ -411,7 +431,8 @@ void OsirixParser::writeContours(FILE* pFile){
                        fprintf(pFile, CREACONTOUR_NUMBEROFCONTROLPOINTS);
                        fprintf(pFile, " %d\n", vectz.size());
                        for(i = 0; i < vectx.size(); i++){
-                               fprintf(pFile, "%f %f 900.00\n", vectx[i]/ _spacing[0],dimy - vecty[i]/ _spacing[1]);
+                         fprintf(pFile, "%f %f 900.00\n", vectx[i]/ _spacing[0], dimy - vecty[i]/ _spacing[1]);
+                         // fprintf(pFile, "%f %f %f\n", vectx[i] , vecty[i], vectz[i]);
                        }               
                        fprintf(pFile, CREACONTOUR_TYPEVIEW);
                        fprintf(pFile, " 1\n");
@@ -470,12 +491,20 @@ void      OsirixParserErrorHandler::error (const SAXParseException &exc){
        char c[1000];
        errormsg = "Column ";
 //     errormsg +=     itoa(exc.getColumnNumber(),c,10);
+#ifdef WIN32
        sprintf_s(c,"%d",(int)(exc.getColumnNumber()));
+#else
+       sprintf(c,"%d",(int)(exc.getColumnNumber()));
+#endif
        errormsg +=     std::string(c);
 
        errormsg += " Line ";
 //     errormsg +=     itoa(exc.getLineNumber(),c,10);
+#ifdef WIN32
        sprintf_s(c,"%d",(int)(exc.getLineNumber()));
+#else
+       sprintf(c,"%d",(int)(exc.getLineNumber()));
+#endif
        errormsg +=     std::string(c);
 
        errormsg += " ";
@@ -487,12 +516,20 @@ void      OsirixParserErrorHandler::fatalError (const SAXParseException &exc){
        char c[1000];
        errormsg = "Column ";
 //     errormsg +=     itoa(exc.getColumnNumber(),c,10);
+#ifdef WIN32
        sprintf_s(c,"%d",(int)(exc.getColumnNumber()));
+#else
+       sprintf(c,"%d",(int)(exc.getColumnNumber()));
+#endif
        errormsg +=     std::string(c);
 
        errormsg += " Line ";
 //     errormsg +=     itoa(exc.getLineNumber(),c,10);
+#ifdef WIN32
        sprintf_s(c,"%d",(int)(exc.getLineNumber()));
+#else
+       sprintf(c,"%d",(int)(exc.getLineNumber()));
+#endif
        errormsg +=     std::string(c);
 
        errormsg += " ";