]> Creatis software - creaContours.git/blobdiff - lib/kernel_ManagerContour_NDimensions/KernelManagerContour.cxx
#3140 creaContours Feature New Normal - branch vtk7itk4wx3
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / KernelManagerContour.cxx
index 633d43859b37f1dc24b26e9bd276723efb62deb1..3edce32a41f4b4b81d45ad16beb41ba2bd6779b5 100644 (file)
 #include "KernelManagerContour.h"
 
 
-KernelManagerContour::KernelManagerContour(){
-
-
+KernelManagerContour::KernelManagerContour()
+{
 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
 **
 **/
-       inredo = 0;
-       inundo = 0;
-
+       inredo                          = 0;
+       inundo                          = 0;
        time_t seconds;
-       seconds = time (NULL);
-       int time = seconds;
-
-
-       stundoredo = "data/temp"+intToString(time);
-       _currentIndex = 0;
-
+       seconds                         = time (NULL);
+       int time                        = seconds;
+       stundoredo                      = "data/temp"+intToString(time);
+       _currentIndex           = 0;
        _contourPropagation = NULL;
 #if(WIN32)
                mkdir(stundoredo.c_str());
@@ -57,26 +52,20 @@ KernelManagerContour::KernelManagerContour(){
 /**
 **  FINISH PERSISTANCE
 **/
-
 }
+
 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;
-
+       inredo          = 0;
+       inundo          = 0;
        time_t seconds;
-       seconds = time (NULL);
-       int time = seconds;
-
-
+       seconds         = time (NULL);
+       int time        = seconds;
        stundoredo = tmpdir+"/temp"+intToString(time);
        _currentIndex = 0;
-
        _contourPropagation = NULL;
 #if(WIN32)
        mkdir(tmpdir.c_str());
@@ -91,7 +80,6 @@ KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std
 **/
        setVectImages(images);        
        initializeEnvironment(datadir);
-
 }
 
 KernelManagerContour::~KernelManagerContour()
@@ -108,12 +96,10 @@ void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
 {
        double spc[3];
        std::vector<double> vectspc;
-       
-       for(int i = 0; i < (int)(vectimg.size()); i++){
+       for(int i = 0; i < (int)(vectimg.size()); i++)
+       {
                vtkImageData* img = vectimg[i];
                vtkImageChangeInformation* change = vtkImageChangeInformation::New();
-
-
 //EED 2017-01-01 Migration VTK7
 #if VTK_MAJOR_VERSION <= 5
                change->SetInformationInput(img);
@@ -121,27 +107,21 @@ void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
 #else
                change->SetInputData(img);
 #endif
-
                img->GetSpacing(spc);
                change->SetOutputSpacing(1,1,1);
-
 //EED 18 fev 2014
                change->SetOutputOrigin (0, 0, 0);
-
                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();
-       }
-
+       } // for i
        vectimages = vectimg;
 }
 
-
 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
 {
        vecspc[0]=vectimagesSpacing[iImage][0];
@@ -149,8 +129,8 @@ void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
        vecspc[2]=vectimagesSpacing[iImage][2];
 }
 
-
-void KernelManagerContour::initializeEnvironment(std::string datadir){
+void KernelManagerContour::initializeEnvironment(std::string datadir)
+{
        _datadir = datadir;
        std::string conceptsFN                  =  datadir+"holaConceptsFile.cf";
        std::string imageSourcesFN              =  datadir+"holaImagesInstantsFile.of";
@@ -162,102 +142,121 @@ void KernelManagerContour::initializeEnvironment(std::string datadir){
        std::map<std::string, AxeThing *>* axesMap                                      = new std::map<std::string, AxeThing *>();
        std::map<std::string, ContourThing *>* outlinesMap                      = new std::map<std::string, ContourThing *>();
 
-       for(int i = 0; i < (int)(vectimages.size()); i++){
+       for(int i = 0; i < (int)(vectimages.size()); i++)
+       {
                vtkImageData* selectedimage = vectimages[i];
-               ImageSourceThing * thing                                                                        = new ImageSourceThing(selectedimage);
+               ImageSourceThing * thing                                                                = new ImageSourceThing(selectedimage);
                std::string imgstring = "Source Image "+intToString(i+1);
                sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
-       }
-
+       } // for
 
        OutlineModelBuilder * _builder                                                          = new OutlineModelBuilder( conceptsFN ,datadir);
        _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
        _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
        _builder->buildAxe_Envornment(axeThingsFN, axesMap );
        _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
-
        //Creating the objects to manage
        modelManager                            = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv() );
-
        imageSource     = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
-
 }
-vtkImageData* KernelManagerContour::getSourceImage(){
+
+vtkImageData* KernelManagerContour::getSourceImage()
+{
        return imageSource->getSourceImage();
 }
-OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
+
+OutlineModelManager* KernelManagerContour::getOutlineModelManager()
+{
        return modelManager;
 }
 
-std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
+std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector)
+{
        return modelManager->createOutline( manModelContour, instantVector );
 }
 
-std::string KernelManagerContour::intToString(int num){
+std::string KernelManagerContour::intToString(int num)
+{
        std::string result;
-       if(num == 0){
+       if(num == 0)
+       {
                result = "0";
        }else{
                int k=num;
-               while (k > 0){
+               while (k > 0)
+               {
                        char temp = k % 10 + 48;
                        k = k / 10;
                        result = temp + result;
-               }
-       }
+               } // while
+       } // if num
        return result;
 }
 
-std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
+std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic()
+{
        return modelManager->GetLstNameThingsStatic();
 }
 
-void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
+void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name )
+{
        modelManager->SaveThingName(pFile, pFileData, name);
 }
-std::vector<std::string> KernelManagerContour::GetLstNameThings(){
+
+std::vector<std::string> KernelManagerContour::GetLstNameThings()
+{
        return modelManager->GetLstNameThings();
 }
+
 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
 //     return modelManager->IsPartOfStaticList(keyName);
 //}
 
-bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
+bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName)
+{
        return modelManager->IsPartOfStaticList(theKeyName) == -1;
 }
 
-void KernelManagerContour::deleteCModel(std::string theKeyName){
+void KernelManagerContour::deleteCModel(std::string theKeyName)
+{
        manualBaseModel* cModel         = modelManager->getOutlineByKeyName(theKeyName)->getModel();
        modelManager->removeOutline( theKeyName );
-
        delete cModel;
 }
 
-void KernelManagerContour::removeAllOutlines(){
+void KernelManagerContour::removeAllOutlines()
+{
        modelManager->removeAllOutlines();
 }
 
-std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
+std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines()
+{
        return modelManager->getActualInstantOutlines();
 }
 
-int KernelManagerContour::getNamesWrappingSize(){
+int KernelManagerContour::getNamesWrappingSize()
+{
        return getActualInstantOutlines().size();
 }
 
-std::string KernelManagerContour::getNameWrapping(int i){
+std::string KernelManagerContour::getNameWrapping(int i)
+{
        return getActualInstantOutlines()[i]->getKeyName();
 }
 
-void KernelManagerContour::setInstant(Instant * theInstant){
+void KernelManagerContour::setInstant(Instant * theInstant)
+{
        modelManager->setInstant(theInstant);
        //_actualInstant = theInstant;
 }
 
-Instant * KernelManagerContour::getCurrentInstant(){
+Instant * KernelManagerContour::getCurrentInstant()
+{
        return modelManager->getInstant();
 }
-void KernelManagerContour::setInstant(std::vector<int> vectInstant){
+
+void KernelManagerContour::setInstant(std::vector<int> vectInstant)
+{
        Instant* act = new Instant ( &vectInstant );
        modelManager->setInstant(act);
 }
@@ -272,36 +271,37 @@ manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName
        return modelManager->getOutlineByKeyName (cloneName )->getModel();
 }
 
-bool KernelManagerContour::onRedo(std::string& filename){
-       if(inredo > 0){
+bool KernelManagerContour::onRedo(std::string& filename)
+{
+       if(inredo > 0)
+       {
                inredo--;
                inundo++;
                std::string str = intToString(inundo);
                filename = stundoredo + str + ".roi";
                //loadState(temp);
                return true;
-       }
+       } // inredo
        return false;
 }
 
-bool KernelManagerContour::onUndo(std::string& filename){
-       if(inundo>0){
+bool KernelManagerContour::onUndo(std::string& filename)
+{
+       if(inundo>0)
+       {
                inredo++;
                inundo--;
-
                //char str[9000];
                //itoa(inundo, str, 10);
                std::string str = intToString(inundo);
-
-
                filename = stundoredo + str + ".roi";
-
                return true;//loadState(temp);
        }
        return false;
 }
 
-std::string KernelManagerContour::saveState(){
+std::string KernelManagerContour::saveState()
+{
        inredo=0;
        std::string str = intToString(inundo);
        std::string temp = stundoredo + str + ".roi";
@@ -309,20 +309,20 @@ std::string KernelManagerContour::saveState(){
        return temp;
 }
 
-bool KernelManagerContour::onUndoSaveFile(std::string& filename){
-       if(inundo>0){
-               if(inredo==0){
-
+bool KernelManagerContour::onUndoSaveFile(std::string& filename)
+{
+       if(inundo>0)
+       {
+               if(inredo==0)
+               {
                        //char str[9000];
                        //itoa(inundo, str, 10);
                        std::string str = intToString(inundo);
-
                        filename = stundoredo + str + ".roi";
                        return true;
                        //saveFileWithContours(temp);
-
-               }
-       }
+               }  // if inundo  ==0
+       }  // if inundo > 0
        return false;
 }
 
@@ -346,23 +346,20 @@ std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::v
     {
                _contourPropagation = new ContourPropagation();
     }
-
-    if (vecX->size()!=0){
-
+    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 (_contourPropagation!=NULL)
@@ -371,7 +368,6 @@ void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
        }
 }
 
-
 void KernelManagerContour::CalculeSplinePropagation()
 {
        _contourPropagation->setInterpolationNumber(100);
@@ -382,13 +378,10 @@ manualBaseModel* KernelManagerContour::GetPoints(int z,int type, std::vector<dou
 {
        bool addedModel = false;
        manualBaseModel* manModelContour=NULL;
-
-       if (_contourPropagation->ifSliceKeyContourExist(z)==false){
-
+       if (_contourPropagation->ifSliceKeyContourExist(z)==false)
+       {
                manModelContour = factoryManualContourModel( typeofcontour );
-
                int idTmp = _contourPropagation->FindIdWithZ(z);
-
                if (type==0) // Initial Points
                {
                        _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
@@ -409,67 +402,57 @@ manualBaseModel* KernelManagerContour::GetPoints(int z,int type, std::vector<dou
                        manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900  );
 //--------------------------------------------------------------------
                } // for j
-
                tempVector[1]=z;
                theName = modelManager->createOutline( manModelContour, tempVector );
                addedModel = theName.compare("") != 0;
-               if(!addedModel){
+               if(!addedModel)
+               {
                        manModelContour = NULL;
                }
-
        }// ifSliceKeyContourExist
        return manModelContour;
 }
 
-manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
+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)
        {
                manModelContour = new manualContourModel();
        }
-
        // spline
        if (typeContour==1)
        {
                manModelContour = new manualContourModel();
        }
-
        // rectangle
        if (typeContour==2)
        {
                manModelContour = new manualContourModelRoi();
        }
-
        // circle
        if (typeContour==3)
        {
                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;
 }