1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "KernelManagerContour.h"
33 KernelManagerContour::KernelManagerContour()
35 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
41 seconds = time (NULL);
43 stundoredo = "data/temp"+intToString(time);
45 _contourPropagation = NULL;
47 mkdir(stundoredo.c_str());
49 mkdir(stundoredo.c_str(),755);
51 stundoredo += "/cont";
57 KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std::string datadir,std::string tmpdir)
59 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
65 seconds = time (NULL);
67 stundoredo = tmpdir+"/temp"+intToString(time);
69 _contourPropagation = NULL;
71 mkdir(tmpdir.c_str());
72 mkdir(stundoredo.c_str());
74 mkdir(tmpdir.c_str(),755);
75 mkdir(stundoredo.c_str(),755);
77 stundoredo += "/cont";
81 setVectImages(images);
82 initializeEnvironment(datadir);
85 KernelManagerContour::~KernelManagerContour()
89 std::vector<vtkImageData*> KernelManagerContour::getVectImages()
95 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
98 std::vector<double> vectspc;
99 for(int i = 0; i < (int)(vectimg.size()); i++)
101 vtkImageData* img = vectimg[i];
102 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
103 //EED 2017-01-01 Migration VTK7
104 #if VTK_MAJOR_VERSION <= 5
105 change->SetInformationInput(img);
106 change->SetInputConnection(img->GetProducerPort());
108 change->SetInputData(img);
110 img->GetSpacing(spc);
111 // change->SetOutputSpacing(1,1,1);
113 change->SetOutputOrigin (0, 0, 0);
116 vectspc.push_back(spc[0]);
117 vectspc.push_back(spc[1]);
118 vectspc.push_back(spc[2]);
119 vectimagesSpacing.push_back(vectspc);
120 vectimg[i] = change->GetOutput();
122 vectimages = vectimg;
125 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
127 vecspc[0]=vectimagesSpacing[iImage][0];
128 vecspc[1]=vectimagesSpacing[iImage][1];
129 vecspc[2]=vectimagesSpacing[iImage][2];
132 void KernelManagerContour::initializeEnvironment(std::string datadir)
135 std::string conceptsFN = datadir+"holaConceptsFile.cf";
136 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
137 std::string imageSectionsFN = "";
138 std::string axeThingsFN = "";
140 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
141 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
142 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
143 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
145 for(int i = 0; i < (int)(vectimages.size()); i++)
147 vtkImageData* selectedimage = vectimages[i];
148 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
149 std::string imgstring = "Source Image "+intToString(i+1);
150 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
153 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
154 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
155 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
156 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
157 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
158 //Creating the objects to manage
159 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
160 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
163 vtkImageData* KernelManagerContour::getSourceImage()
165 return imageSource->getSourceImage();
168 OutlineModelManager* KernelManagerContour::getOutlineModelManager()
173 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector)
175 return modelManager->createOutline( manModelContour, instantVector );
178 std::string KernelManagerContour::intToString(int num)
188 char temp = k % 10 + 48;
190 result = temp + result;
196 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic()
198 return modelManager->GetLstNameThingsStatic();
201 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name )
203 modelManager->SaveThingName(pFile, pFileData, name);
206 std::vector<std::string> KernelManagerContour::GetLstNameThings()
208 return modelManager->GetLstNameThings();
211 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
212 // return modelManager->IsPartOfStaticList(keyName);
215 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName)
217 return modelManager->IsPartOfStaticList(theKeyName) == -1;
220 void KernelManagerContour::deleteCModel(std::string theKeyName)
222 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
223 modelManager->removeOutline( theKeyName );
227 void KernelManagerContour::removeAllOutlines()
229 modelManager->removeAllOutlines();
232 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines()
234 return modelManager->getActualInstantOutlines();
237 int KernelManagerContour::getNamesWrappingSize()
239 return getActualInstantOutlines().size();
242 std::string KernelManagerContour::getNameWrapping(int i)
244 return getActualInstantOutlines()[i]->getKeyName();
247 void KernelManagerContour::setInstant(Instant * theInstant)
249 modelManager->setInstant(theInstant);
250 //_actualInstant = theInstant;
253 Instant * KernelManagerContour::getCurrentInstant()
255 return modelManager->getInstant();
258 void KernelManagerContour::setInstant(std::vector<int> vectInstant)
260 Instant* act = new Instant ( &vectInstant );
261 modelManager->setInstant(act);
264 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
266 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
269 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
271 return modelManager->getOutlineByKeyName (cloneName )->getModel();
274 bool KernelManagerContour::onRedo(std::string& filename)
280 std::string str = intToString(inundo);
281 filename = stundoredo + str + ".roi";
288 bool KernelManagerContour::onUndo(std::string& filename)
295 //itoa(inundo, str, 10);
296 std::string str = intToString(inundo);
297 filename = stundoredo + str + ".roi";
298 return true;//loadState(temp);
303 std::string KernelManagerContour::saveState()
306 std::string str = intToString(inundo);
307 std::string temp = stundoredo + str + ".roi";
312 bool KernelManagerContour::onUndoSaveFile(std::string& filename)
319 //itoa(inundo, str, 10);
320 std::string str = intToString(inundo);
321 filename = stundoredo + str + ".roi";
323 //saveFileWithContours(temp);
329 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
331 modelManager->ChangeContourOfList(keyName, instant);
334 void KernelManagerContour ::resetAppend()
336 if (_contourPropagation!=NULL)
338 _contourPropagation->resetAppend();
343 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
345 if (_contourPropagation==NULL)
347 _contourPropagation = new ContourPropagation();
351 int i,size=vecZ->size();
352 int actualSlice = instants[1];
353 for ( i=0 ; i<size ; i++ )
355 (*vecZ)[i] = actualSlice;
357 _contourPropagation->appendContour(vecX , vecY , vecZ);
358 return intToString(actualSlice);
363 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
365 if (_contourPropagation!=NULL)
367 _contourPropagation->getMaxMinZ(minZ, maxZ);
371 void KernelManagerContour::CalculeSplinePropagation()
373 _contourPropagation->setInterpolationNumber(100);
374 _contourPropagation->CalculeSplinePropagation();
377 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)
379 bool addedModel = false;
380 manualBaseModel* manModelContour=NULL;
381 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
383 manModelContour = factoryManualContourModel( typeofcontour );
384 int idTmp = _contourPropagation->FindIdWithZ(z);
385 if (type==0) // Initial Points
387 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
389 if (type==1) // Automatique Method
391 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
393 if (type==2) // sampling
395 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
397 //--------------------------------------------------------------------
398 int sizeCtrPt = vecCtrlPointX->size();
399 for (int j=0 ; j<sizeCtrPt ; j++)
401 //JSTG_16-07-08_----------------------------------------------------------------
402 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
403 //--------------------------------------------------------------------
406 theName = modelManager->createOutline( manModelContour, tempVector );
407 addedModel = theName.compare("") != 0;
410 manModelContour = NULL;
412 }// ifSliceKeyContourExist
413 return manModelContour;
416 manualBaseModel *KernelManagerContour::factoryManualContourModel(int typeContour)
418 manualBaseModel *manModelContour=NULL;
419 // Creating the model
420 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
424 manModelContour = new manualContourModel();
429 manModelContour = new manualContourModel();
434 manModelContour = new manualContourModelRoi();
439 manModelContour = new manualContourModelCircle();
444 manModelContour = new manualContourModelLine();
449 manModelContour = new manualBaseModel();
454 manModelContour = new manualContourModelPolygon();
456 return manModelContour;
459 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
460 Instant instant(&tempvector);
461 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
462 std::vector<std::string> vectname;
463 for(int i = 0; i < (int)(vectcont.size()); i++){
464 ContourThing **contourthing = vectcont[i];
465 vectname.push_back((*contourthing)->getName());
470 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
471 return modelManager->getOutlinesAtInstant(instant);
474 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
475 std::vector<manualBaseModel*> lstTmp;
476 std::vector<manualBaseModel*> lstResult;
478 int i,iSize=lstManConMod.size();
479 for (i=0;i<iSize;i++)
481 lstTmp = lstManConMod[i]->ExploseModel();
483 for (j=0;j<jSize;j++)
485 lstResult.push_back( lstTmp[j] );
491 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
492 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
496 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
497 int index = inst[5]-1;
499 if(index < (int)(vectimages.size())&&index!=_currentIndex){
501 return vectimages[index];
506 std::string KernelManagerContour::getCurrentFileName(){
510 void KernelManagerContour::setCurrentFileName(std::string filenam){
511 this->filename = filenam;
514 std::string KernelManagerContour::parseOsirixFile(std::string filename){
517 #ifdef ParserOsirix_BUILD
518 vtkImageData* sourceimage;
523 xsdfile.append("\\XML\\osirixschema.xsd");
525 sourceimage = getSourceImage();
526 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
528 if(p.ParseFile(filename.c_str())!= 0){
532 return p.getContoursFileName();