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
63 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 = "";
139 std::map<std::string, ImageSourceThing *> *sourcesMap = new std::map<std::string, ImageSourceThing *>();
140 std::map<std::string, ImageSectionThing *> *sectionsMap = new std::map<std::string, ImageSectionThing *>();
141 std::map<std::string, AxeThing *> *axesMap = new std::map<std::string, AxeThing *>();
142 std::map<std::string, ContourThing *> *outlinesMap = new std::map<std::string, ContourThing *>();
143 for(int i = 0; i < (int)(vectimages.size()); i++)
145 vtkImageData *selectedimage = vectimages[i];
146 ImageSourceThing *thing = new ImageSourceThing(selectedimage);
147 std::string imgstring = "Source Image "+intToString(i+1);
148 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
150 OutlineModelBuilder *_builder = new OutlineModelBuilder( conceptsFN ,datadir);
151 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
152 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
153 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
154 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
155 //Creating the objects to manage
156 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
157 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
160 vtkImageData* KernelManagerContour::getSourceImage()
162 return imageSource->getSourceImage();
165 OutlineModelManager* KernelManagerContour::getOutlineModelManager()
170 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector)
172 return modelManager->createOutline( manModelContour, instantVector );
175 std::string KernelManagerContour::intToString(int num)
185 char temp = k % 10 + 48;
187 result = temp + result;
193 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic()
195 return modelManager->GetLstNameThingsStatic();
198 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name )
200 modelManager->SaveThingName(pFile, pFileData, name);
203 std::vector<std::string> KernelManagerContour::GetLstNameThings()
205 return modelManager->GetLstNameThings();
208 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
209 // return modelManager->IsPartOfStaticList(keyName);
212 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName)
214 return modelManager->IsPartOfStaticList(theKeyName) == -1;
217 void KernelManagerContour::deleteCModel(std::string theKeyName)
219 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
220 modelManager->removeOutline( theKeyName );
224 void KernelManagerContour::removeAllOutlines()
226 modelManager->removeAllOutlines();
229 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines()
231 return modelManager->getActualInstantOutlines();
234 int KernelManagerContour::getNamesWrappingSize()
236 return getActualInstantOutlines().size();
239 std::string KernelManagerContour::getNameWrapping(int i)
241 return getActualInstantOutlines()[i]->getKeyName();
244 void KernelManagerContour::setInstant(Instant * theInstant)
246 modelManager->setInstant(theInstant);
247 //_actualInstant = theInstant;
250 Instant * KernelManagerContour::getCurrentInstant()
252 return modelManager->getInstant();
255 void KernelManagerContour::setInstant(std::vector<int> vectInstant)
257 Instant* act = new Instant ( &vectInstant );
258 modelManager->setInstant(act);
261 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
263 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
266 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
268 return modelManager->getOutlineByKeyName (cloneName )->getModel();
271 bool KernelManagerContour::onRedo(std::string& filename)
277 std::string str = intToString(inundo);
278 filename = stundoredo + str + ".roi";
285 bool KernelManagerContour::onUndo(std::string& filename)
292 //itoa(inundo, str, 10);
293 std::string str = intToString(inundo);
294 filename = stundoredo + str + ".roi";
295 return true;//loadState(temp);
300 std::string KernelManagerContour::saveState()
303 std::string str = intToString(inundo);
304 std::string temp = stundoredo + str + ".roi";
309 bool KernelManagerContour::onUndoSaveFile(std::string& filename)
316 //itoa(inundo, str, 10);
317 std::string str = intToString(inundo);
318 filename = stundoredo + str + ".roi";
320 //saveFileWithContours(temp);
326 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
328 modelManager->ChangeContourOfList(keyName, instant);
331 void KernelManagerContour ::resetAppend()
333 if (_contourPropagation!=NULL)
335 _contourPropagation->resetAppend();
340 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
342 if (_contourPropagation==NULL)
344 _contourPropagation = new ContourPropagation();
348 int i,size=vecZ->size();
349 int actualSlice = instants[1];
350 for ( i=0 ; i<size ; i++ )
352 (*vecZ)[i] = actualSlice;
354 _contourPropagation->appendContour(vecX , vecY , vecZ);
355 return intToString(actualSlice);
360 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
362 if (_contourPropagation!=NULL)
364 _contourPropagation->getMaxMinZ(minZ, maxZ);
368 void KernelManagerContour::CalculeSplinePropagation()
370 _contourPropagation->setInterpolationNumber(100);
371 _contourPropagation->CalculeSplinePropagation();
374 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)
376 bool addedModel = false;
377 manualBaseModel* manModelContour=NULL;
378 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
380 manModelContour = factoryManualContourModel( typeofcontour );
381 int idTmp = _contourPropagation->FindIdWithZ(z);
382 if (type==0) // Initial Points
384 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
386 if (type==1) // Automatique Method
388 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
390 if (type==2) // sampling
392 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
394 //--------------------------------------------------------------------
395 int sizeCtrPt = vecCtrlPointX->size();
396 for (int j=0 ; j<sizeCtrPt ; j++)
398 //JSTG_16-07-08_----------------------------------------------------------------
399 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
400 //--------------------------------------------------------------------
403 theName = modelManager->createOutline( manModelContour, tempVector );
404 addedModel = theName.compare("") != 0;
407 manModelContour = NULL;
409 }// ifSliceKeyContourExist
410 return manModelContour;
413 manualBaseModel *KernelManagerContour::factoryManualContourModel(int typeContour)
415 manualBaseModel *manModelContour=NULL;
416 // Creating the model
417 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
421 manModelContour = new manualContourModel();
426 manModelContour = new manualContourModel();
431 manModelContour = new manualContourModelRoi();
436 manModelContour = new manualContourModelCircle();
441 manModelContour = new manualContourModelLine();
446 manModelContour = new manualBaseModel();
451 manModelContour = new manualContourModelPolygon();
453 return manModelContour;
456 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
457 Instant instant(&tempvector);
458 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
459 std::vector<std::string> vectname;
460 for(int i = 0; i < (int)(vectcont.size()); i++){
461 ContourThing **contourthing = vectcont[i];
462 vectname.push_back((*contourthing)->getName());
467 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
468 return modelManager->getOutlinesAtInstant(instant);
471 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
472 std::vector<manualBaseModel*> lstTmp;
473 std::vector<manualBaseModel*> lstResult;
475 int i,iSize=lstManConMod.size();
476 for (i=0;i<iSize;i++)
478 lstTmp = lstManConMod[i]->ExploseModel();
480 for (j=0;j<jSize;j++)
482 lstResult.push_back( lstTmp[j] );
488 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
489 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
493 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst)
495 int index = inst[5]-1;
497 if(index < (int)(vectimages.size())&&index!=_currentIndex)
500 return vectimages[index];
505 std::string KernelManagerContour::getCurrentFileName()
510 void KernelManagerContour::setCurrentFileName(std::string filenam)
512 this->filename = filenam;
515 std::string KernelManagerContour::parseOsirixFile(std::string filename)
519 #ifdef ParserOsirix_BUILD
520 vtkImageData* sourceimage;
525 xsdfile.append("\\XML\\osirixschema.xsd");
527 sourceimage = getSourceImage();
528 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
530 if(p.ParseFile(filename.c_str())!= 0){
534 return p.getContoursFileName();