X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Fkernel_ManagerContour_NDimensions%2FKernelManagerContour.cxx;h=3f4a144a4ba9afb48eead9f98a17b6835b497922;hb=6c905248260709012e018c112dab06da8deecede;hp=93e21d5d355cc8489aa48fbafdbd75d595c1e139;hpb=a654abbc209ed3104e98553cb381ef1c2845937a;p=creaContours.git diff --git a/lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx b/lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx index 93e21d5..3f4a144 100644 --- a/lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx +++ b/lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx @@ -1,3 +1,28 @@ +/*# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ + //---------------------------------------------------------------------------------------------------------------- // Class definition include @@ -12,8 +37,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,77 +59,112 @@ KernelManagerContour::KernelManagerContour(){ **/ } -KernelManagerContour::KernelManagerContour(std::vector images){ +KernelManagerContour::KernelManagerContour(std::vector 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 KernelManagerContour::getVectImages(){ +std::vector KernelManagerContour::getVectImages() +{ return vectimages; } -void KernelManagerContour::setVectImages(std::vector vectimg){ - for(int i = 0; i < vectimg.size(); i++){ + +void KernelManagerContour::setVectImages(std::vector vectimg) +{ + double spc[3]; + std::vector 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); + +//EED 18 fev 2014 + change->SetOutputOrigin (0, 0, 0); - change->SetOutputSpacing(0.6,0.6,0.6); - 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::GetSpacing(double *vecspc, int iImage) +{ + vecspc[0]=vectimagesSpacing[iImage][0]; + vecspc[1]=vectimagesSpacing[iImage][1]; + vecspc[2]=vectimagesSpacing[iImage][2]; +} + + +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 * sourcesMap = new std::map(); std::map* sectionsMap = new std::map(); std::map* axesMap = new std::map(); - std::map* outlinesMap = new std::map(); + std::map* outlinesMap = new std::map(); - 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( 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 ); @@ -115,7 +181,7 @@ OutlineModelManager* KernelManagerContour::getOutlineModelManager(){ return modelManager; } -std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector instantVector){ +std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector instantVector){ return modelManager->createOutline( manModelContour, instantVector ); } @@ -128,7 +194,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; @@ -138,8 +204,8 @@ std::vector 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 KernelManagerContour::GetLstNameThings(){ return modelManager->GetLstNameThings(); @@ -153,7 +219,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; @@ -188,10 +254,13 @@ void KernelManagerContour::setInstant(std::vector vectInstant){ modelManager->setInstant(act); } -std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector &instantNoTouchData){ +std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector &instantNoTouchData) +{ return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData); } -manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){ + +manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName) +{ return modelManager->getOutlineByKeyName (cloneName )->getModel(); } @@ -199,16 +268,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--; @@ -216,9 +285,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; @@ -242,7 +311,7 @@ bool KernelManagerContour::onUndoSaveFile(std::string& filename){ filename = stundoredo + str + ".roi"; return true; - //saveFileWithContours(temp); + //saveFileWithContours(temp); } } @@ -254,55 +323,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 *vecX, std::vector *vecY, std::vector *vecZ, std::vector instants){ - if(isInitContourPropagation()){ - if (vecX->size()!=0){ - - int i,size=vecZ->size(); - int actualSlice = instants[1]; - for ( i=0 ; iappendContour(vecX , vecY , vecZ); - return intToString(actualSlice); - } - } +std::string KernelManagerContour::onSpreadAdd( std::vector *vecX, std::vector *vecY, std::vector *vecZ, std::vector instants) +{ + if (_contourPropagation==NULL) + { + _contourPropagation = new ContourPropagation(); + } + + if (vecX->size()!=0){ + + int i,size=vecZ->size(); + int actualSlice = instants[1]; + for ( i=0 ; iappendContour(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* vecCtrlPointX,std::vector* vecCtrlPointY,std::vector* vecCtrlPointZ, std::string& theName,int typeofcontour, std::vector tempVector){ - - +manualBaseModel* KernelManagerContour::GetPoints(int z,int type, std::vector* vecCtrlPointX,std::vector* vecCtrlPointY,std::vector* vecCtrlPointZ, std::string& theName,int typeofcontour, std::vector tempVector) +{ bool addedModel = false; - manualContourModel* manModelContour=NULL; + manualBaseModel* manModelContour=NULL; if (_contourPropagation->ifSliceKeyContourExist(z)==false){ @@ -311,9 +382,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); @@ -337,15 +408,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) @@ -371,6 +444,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; } @@ -378,20 +469,20 @@ std::vector KernelManagerContour::getOutlinesNameAtInstant(std::vec Instant instant(&tempvector); std::vector vectcont = modelManager->getOutlinesAtInstant( &instant ); std::vector 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 KernelManagerContour::getOutlinesAtInstant(Instant* instant ){ return modelManager->getOutlinesAtInstant(instant); } -std::vector KernelManagerContour::ExploseEachModel( std::vector lstManConMod ){ - std::vector lstTmp; - std::vector lstResult; +std::vector KernelManagerContour::ExploseEachModel( std::vector lstManConMod ){ + std::vector lstTmp; + std::vector lstResult; int j,jSize; int i,iSize=lstManConMod.size(); for (i=0;i& conc vtkImageData* KernelManagerContour::getImageAtInstant(std::vector inst){ int index = inst[5]-1; - if(index < vectimages.size()&&index!=_currentIndex){ + if(index < (int)(vectimages.size())&&index!=_currentIndex){ _currentIndex=index; return vectimages[index]; } @@ -427,4 +518,32 @@ std::string KernelManagerContour::getCurrentFileName(){ void KernelManagerContour::setCurrentFileName(std::string filenam){ this->filename = filenam; -} \ No newline at end of file +} + +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 + + +} + +