]> Creatis software - creaContours.git/blobdiff - lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx
no message
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / KernelManagerContour.cxx
index b62a9b6412460900abb61748bfa4f3f40e29cfa6..236a515ea6e34341c95379b9a716230e8e5e72d8 100644 (file)
@@ -12,8 +12,14 @@ KernelManagerContour::KernelManagerContour(){
 **
 **/
        inredo = 0;
-       inundo = 0;     
-       stundoredo = "data/temp";
+       inundo = 0;
+
+       time_t seconds;
+       seconds = time (NULL);
+       int time = seconds;
+
+
+       stundoredo = "data/temp"+intToString(time);
        _currentIndex = 0;
 
        _contourPropagation = NULL;
@@ -28,63 +34,98 @@ KernelManagerContour::KernelManagerContour(){
 **/
 
 }
-KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images){
+KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std::string datadir,std::string tmpdir)
+{
 
 
 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
 **
 **/
        inredo = 0;
-       inundo = 0;     
-       stundoredo = "data/temp";
+       inundo = 0;
+
+       time_t seconds;
+       seconds = time (NULL);
+       int time = seconds;
+
+
+       stundoredo = tmpdir+"/temp"+intToString(time);
        _currentIndex = 0;
 
        _contourPropagation = NULL;
 #if(WIN32)
-               mkdir(stundoredo.c_str());
+       mkdir(tmpdir.c_str());
+       mkdir(stundoredo.c_str());
 #else
-               mkdir(stundoredo.c_str(),755);
+       mkdir(tmpdir.c_str(),755);
+       mkdir(stundoredo.c_str(),755);
 #endif
        stundoredo += "/cont";
 /**
 **  FINISH PERSISTANCE
 **/
-       setVectImages(images);
-       initializeEnvironment();
+       setVectImages(images);        
+       initializeEnvironment(datadir);
 
 }
-KernelManagerContour::~KernelManagerContour(){
+
+KernelManagerContour::~KernelManagerContour()
+{
 }
 
-std::vector<vtkImageData*> KernelManagerContour::getVectImages(){
+std::vector<vtkImageData*> KernelManagerContour::getVectImages()
+{
        return vectimages;
 }
-void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg){
+void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
+{
+       double spc[3];
+       std::vector<double> vectspc;
+       
+       for(int i = 0; i < (int)(vectimg.size()); i++){
+               vtkImageData* img = vectimg[i];
+               vtkImageChangeInformation* change = vtkImageChangeInformation::New();
+               change->SetInformationInput(img);
+               change->SetInputConnection(img->GetProducerPort());
+
+               img->GetSpacing(spc);
+               change->SetOutputSpacing(1,1,1);
+               change->Update();
+
+               vectspc.clear();
+               vectspc.push_back(spc[0]);
+               vectspc.push_back(spc[1]);
+               vectspc.push_back(spc[2]);
+               vectimagesSpacing.push_back(vectspc);
+               vectimg[i] = change->GetOutput();
+       }
+
        vectimages = vectimg;
 }
 
-void KernelManagerContour::initializeEnvironment(){
-       std::string conceptsFN                  =  "data/holaConceptsFile.cf";
-       std::string imageSourcesFN              = "data/holaImagesInstantsFile.of";
+void KernelManagerContour::initializeEnvironment(std::string datadir){
+       _datadir = datadir;
+       std::string conceptsFN                  =  datadir+"holaConceptsFile.cf";
+       std::string imageSourcesFN              =  datadir+"holaImagesInstantsFile.of";
        std::string imageSectionsFN             = "";
        std::string axeThingsFN                 = "";
 
        std::map<std::string, ImageSourceThing *> * sourcesMap          = new std::map<std::string, ImageSourceThing *>();
        std::map<std::string, ImageSectionThing *>* sectionsMap         = new std::map<std::string, ImageSectionThing *>();
        std::map<std::string, AxeThing *>* axesMap                                      = new std::map<std::string, AxeThing *>();
-       std::map<std::string, ContourThing *>* outlinesMap                      = new std::map<std::string, ContourThing *>();  
+       std::map<std::string, ContourThing *>* outlinesMap                      = new std::map<std::string, ContourThing *>();
 
-       for(int i = 0; i < vectimages.size(); i++){
+       for(int i = 0; i < (int)(vectimages.size()); i++){
                vtkImageData* selectedimage = vectimages[i];
                ImageSourceThing * thing                                                                        = new ImageSourceThing(selectedimage);
                std::string imgstring = "Source Image "+intToString(i+1);
                sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
        }
-       
 
-       OutlineModelBuilder * _builder                                                          = new OutlineModelBuilder( conceptsFN );
+
+       OutlineModelBuilder * _builder                                                          = new OutlineModelBuilder( conceptsFN ,datadir);
        _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
-       _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );         
+       _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
        _builder->buildAxe_Envornment(axeThingsFN, axesMap );
        _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
 
@@ -101,7 +142,7 @@ OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
        return modelManager;
 }
 
-std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector<int> instantVector){
+std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
        return modelManager->createOutline( manModelContour, instantVector );
 }
 
@@ -114,7 +155,7 @@ std::string KernelManagerContour::intToString(int num){
                while (k > 0){
                        char temp = k % 10 + 48;
                        k = k / 10;
-                       result = temp + result; 
+                       result = temp + result;
                }
        }
        return result;
@@ -124,8 +165,8 @@ std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
        return modelManager->GetLstNameThingsStatic();
 }
 
-void KernelManagerContour::SaveThingName(FILE* pFile, std::string name ){
-       modelManager->SaveThingName(pFile, name);
+void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
+       modelManager->SaveThingName(pFile, pFileData, name);
 }
 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
        return modelManager->GetLstNameThings();
@@ -139,7 +180,7 @@ bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
 }
 
 void KernelManagerContour::deleteCModel(std::string theKeyName){
-       manualContourModel* cModel              = modelManager->getOutlineByKeyName(theKeyName)->getModel();
+       manualBaseModel* cModel         = modelManager->getOutlineByKeyName(theKeyName)->getModel();
        modelManager->removeOutline( theKeyName );
 
        delete cModel;
@@ -174,10 +215,13 @@ void KernelManagerContour::setInstant(std::vector<int> vectInstant){
        modelManager->setInstant(act);
 }
 
-std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData){
+std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
+{
        return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
 }
-manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
+
+manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
+{
        return modelManager->getOutlineByKeyName (cloneName )->getModel();
 }
 
@@ -185,16 +229,16 @@ bool KernelManagerContour::onRedo(std::string& filename){
        if(inredo > 0){
                inredo--;
                inundo++;
-               std::string str = intToString(inundo);        
-               filename = stundoredo + str + ".roi";   
-               //loadState(temp);              
+               std::string str = intToString(inundo);
+               filename = stundoredo + str + ".roi";
+               //loadState(temp);
                return true;
        }
        return false;
 }
 
 bool KernelManagerContour::onUndo(std::string& filename){
-       if(inundo>0){           
+       if(inundo>0){
                inredo++;
                inundo--;
 
@@ -202,9 +246,9 @@ bool KernelManagerContour::onUndo(std::string& filename){
                //itoa(inundo, str, 10);
                std::string str = intToString(inundo);
 
-        
+
                filename = stundoredo + str + ".roi";
-       
+
                return true;//loadState(temp);
        }
        return false;
@@ -228,7 +272,7 @@ bool KernelManagerContour::onUndoSaveFile(std::string& filename){
 
                        filename = stundoredo + str + ".roi";
                        return true;
-                       //saveFileWithContours(temp);                           
+                       //saveFileWithContours(temp);
 
                }
        }
@@ -240,55 +284,57 @@ void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant
        modelManager->ChangeContourOfList(keyName, instant);
 }
 
-void KernelManagerContour ::resetAppend(){
-       if(isInitContourPropagation()){
+void KernelManagerContour ::resetAppend()
+{
+    if (_contourPropagation!=NULL)
+       {
                _contourPropagation->resetAppend();
-       }       
-}
-
-bool KernelManagerContour::isInitContourPropagation(){
-       if(_contourPropagation == NULL){
-               _contourPropagation = new ContourPropagation();
-       }else{
-               return true;
        }
-       return false;
-
 }
 
-std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
-       if(isInitContourPropagation()){
-               if (vecX->size()!=0){
-                       
-                       int i,size=vecZ->size();
-                       int actualSlice = instants[1];
-                       for ( i=0 ; i<size ; i++ )
-                       {
-                               (*vecZ)[i] = actualSlice;
-                       } // for
 
-                       _contourPropagation->appendContour(vecX , vecY , vecZ);
-                       return intToString(actualSlice);                
-               }
-       }
+std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
+{
+    if (_contourPropagation==NULL)
+    {
+               _contourPropagation = new ContourPropagation();
+    }
+
+    if (vecX->size()!=0){
+
+        int i,size=vecZ->size();
+        int actualSlice = instants[1];
+        for ( i=0 ; i<size ; i++ )
+        {
+            (*vecZ)[i] = actualSlice;
+        } // for
+
+        _contourPropagation->appendContour(vecX , vecY , vecZ);
+        return intToString(actualSlice);
+    }
        return "";
 }
 
-void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ){
-       if(isInitContourPropagation()){
+
+void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
+{
+    if (_contourPropagation!=NULL)
+       {
                _contourPropagation->getMaxMinZ(minZ, maxZ);
        }
 }
-void KernelManagerContour::CalculeSplinePropagation(){
+
+
+void KernelManagerContour::CalculeSplinePropagation()
+{
        _contourPropagation->setInterpolationNumber(100);
        _contourPropagation->CalculeSplinePropagation();
 }
 
-manualContourModel* KernelManagerContour::GetPoints(int z,int type, std::vector<double>* vecCtrlPointX,std::vector<double>* vecCtrlPointY,std::vector<double>* vecCtrlPointZ, std::string& theName,int typeofcontour, std::vector<int> tempVector){
-    
-       
+manualBaseModel* KernelManagerContour::GetPoints(int z,int type, std::vector<double>* vecCtrlPointX,std::vector<double>* vecCtrlPointY,std::vector<double>* vecCtrlPointZ, std::string& theName,int typeofcontour, std::vector<int> tempVector)
+{
        bool addedModel = false;
-       manualContourModel* manModelContour=NULL;
+       manualBaseModel* manModelContour=NULL;
 
        if (_contourPropagation->ifSliceKeyContourExist(z)==false){
 
@@ -297,9 +343,9 @@ manualContourModel* KernelManagerContour::GetPoints(int z,int type, std::vector<
                int idTmp = _contourPropagation->FindIdWithZ(z);
 
                if (type==0) // Initial Points
-               {   
+               {
                        _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
-               } 
+               }
                if (type==1)  // Automatique Method
                {
                        _contourPropagation->GetControlPoints( idTmp  ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
@@ -313,7 +359,7 @@ manualContourModel* KernelManagerContour::GetPoints(int z,int type, std::vector<
                for (int j=0 ; j<sizeCtrPt ; j++)
                {
 //JSTG_16-07-08_----------------------------------------------------------------
-                       manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900  );
+                       manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , 900  );
 //--------------------------------------------------------------------
                } // for j
 
@@ -323,15 +369,17 @@ manualContourModel* KernelManagerContour::GetPoints(int z,int type, std::vector<
                if(!addedModel){
                        manModelContour = NULL;
                }
-               
+
        }// ifSliceKeyContourExist
        return manModelContour;
-
 }
 
-manualContourModel * KernelManagerContour::factoryManualContourModel(int typeContour)
-{      
-       manualContourModel *manModelContour=NULL;
+manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
+{
+       manualBaseModel *manModelContour=NULL;
+
+       // Creating the model
+       // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
 
        // spline
        if (typeContour==0)
@@ -357,6 +405,24 @@ manualContourModel * KernelManagerContour::factoryManualContourModel(int typeCon
                manModelContour = new manualContourModelCircle();
        }
 
+       // line
+       if (typeContour==6)
+       {
+               manModelContour = new manualContourModelLine();
+       }
+
+       // points
+       if (typeContour==7)
+       {
+               manModelContour = new manualBaseModel();
+       }
+
+       // polygon
+       if (typeContour==10)
+       {
+               manModelContour = new manualContourModelPolygon();
+       }
+
        return manModelContour;
 }
 
@@ -364,20 +430,20 @@ std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vec
        Instant instant(&tempvector);
        std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
        std::vector<std::string> vectname;
-       for(int i = 0; i < vectcont.size(); i++){
+       for(int i = 0; i < (int)(vectcont.size()); i++){
                ContourThing **contourthing = vectcont[i];
                vectname.push_back((*contourthing)->getName());
        }
-    return vectname;   
+    return vectname;
 }
 
 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
        return modelManager->getOutlinesAtInstant(instant);
 }
 
-std::vector<manualContourModel*> KernelManagerContour::ExploseEachModel( std::vector<manualContourModel*> lstManConMod ){
-       std::vector<manualContourModel*> lstTmp;
-       std::vector<manualContourModel*> lstResult;
+std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
+       std::vector<manualBaseModel*> lstTmp;
+       std::vector<manualBaseModel*> lstResult;
        int j,jSize;
        int i,iSize=lstManConMod.size();
        for (i=0;i<iSize;i++)
@@ -400,9 +466,45 @@ void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conc
 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
        int index = inst[5]-1;
 
-       if(index < vectimages.size()&&index!=_currentIndex){
+       if(index < (int)(vectimages.size())&&index!=_currentIndex){
                _currentIndex=index;
                return vectimages[index];
        }
        return NULL;
-}
\ No newline at end of file
+}
+
+std::string KernelManagerContour::getCurrentFileName(){
+       return filename;
+}
+
+void KernelManagerContour::setCurrentFileName(std::string filenam){
+       this->filename = filenam;
+}
+
+std::string KernelManagerContour::parseOsirixFile(std::string filename){
+
+
+#ifdef ParserOsirix_BUILD
+       vtkImageData* sourceimage;
+       std::string xsdfile;
+
+       xsdfile = _datadir;
+
+       xsdfile.append("\\XML\\osirixschema.xsd");
+
+       sourceimage = getSourceImage();
+       OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
+
+       if(p.ParseFile(filename.c_str())!= 0){
+
+       }
+
+       return p.getContoursFileName();
+#else
+       return "";
+#endif
+
+
+}
+
+