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(){
36 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
43 seconds = time (NULL);
47 stundoredo = "data/temp"+intToString(time);
50 _contourPropagation = NULL;
52 mkdir(stundoredo.c_str());
54 mkdir(stundoredo.c_str(),755);
56 stundoredo += "/cont";
62 KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std::string datadir,std::string tmpdir)
66 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
73 seconds = time (NULL);
77 stundoredo = tmpdir+"/temp"+intToString(time);
80 _contourPropagation = NULL;
82 mkdir(tmpdir.c_str());
83 mkdir(stundoredo.c_str());
85 mkdir(tmpdir.c_str(),755);
86 mkdir(stundoredo.c_str(),755);
88 stundoredo += "/cont";
92 setVectImages(images);
93 initializeEnvironment(datadir);
97 KernelManagerContour::~KernelManagerContour()
101 std::vector<vtkImageData*> KernelManagerContour::getVectImages()
107 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
110 std::vector<double> vectspc;
112 for(int i = 0; i < (int)(vectimg.size()); i++){
113 vtkImageData* img = vectimg[i];
114 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
117 //EED 2017-01-01 Migration VTK7
118 #if VTK_MAJOR_VERSION <= 5
119 change->SetInformationInput(img);
120 change->SetInputConnection(img->GetProducerPort());
122 change->SetInputData(img);
125 img->GetSpacing(spc);
126 change->SetOutputSpacing(1,1,1);
129 change->SetOutputOrigin (0, 0, 0);
134 vectspc.push_back(spc[0]);
135 vectspc.push_back(spc[1]);
136 vectspc.push_back(spc[2]);
137 vectimagesSpacing.push_back(vectspc);
138 vectimg[i] = change->GetOutput();
141 vectimages = vectimg;
145 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
147 vecspc[0]=vectimagesSpacing[iImage][0];
148 vecspc[1]=vectimagesSpacing[iImage][1];
149 vecspc[2]=vectimagesSpacing[iImage][2];
153 void KernelManagerContour::initializeEnvironment(std::string datadir){
155 std::string conceptsFN = datadir+"holaConceptsFile.cf";
156 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
157 std::string imageSectionsFN = "";
158 std::string axeThingsFN = "";
160 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
161 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
162 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
163 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
165 for(int i = 0; i < (int)(vectimages.size()); i++){
166 vtkImageData* selectedimage = vectimages[i];
167 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
168 std::string imgstring = "Source Image "+intToString(i+1);
169 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
173 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
174 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
175 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
176 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
177 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
179 //Creating the objects to manage
180 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
182 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
185 vtkImageData* KernelManagerContour::getSourceImage(){
186 return imageSource->getSourceImage();
188 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
192 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
193 return modelManager->createOutline( manModelContour, instantVector );
196 std::string KernelManagerContour::intToString(int num){
203 char temp = k % 10 + 48;
205 result = temp + result;
211 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
212 return modelManager->GetLstNameThingsStatic();
215 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
216 modelManager->SaveThingName(pFile, pFileData, name);
218 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
219 return modelManager->GetLstNameThings();
221 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
222 // return modelManager->IsPartOfStaticList(keyName);
225 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
226 return modelManager->IsPartOfStaticList(theKeyName) == -1;
229 void KernelManagerContour::deleteCModel(std::string theKeyName){
230 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
231 modelManager->removeOutline( theKeyName );
236 void KernelManagerContour::removeAllOutlines(){
237 modelManager->removeAllOutlines();
240 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
241 return modelManager->getActualInstantOutlines();
244 int KernelManagerContour::getNamesWrappingSize(){
245 return getActualInstantOutlines().size();
248 std::string KernelManagerContour::getNameWrapping(int i){
249 return getActualInstantOutlines()[i]->getKeyName();
252 void KernelManagerContour::setInstant(Instant * theInstant){
253 modelManager->setInstant(theInstant);
254 //_actualInstant = theInstant;
257 Instant * KernelManagerContour::getCurrentInstant(){
258 return modelManager->getInstant();
260 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
261 Instant* act = new Instant ( &vectInstant );
262 modelManager->setInstant(act);
265 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
267 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
270 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
272 return modelManager->getOutlineByKeyName (cloneName )->getModel();
275 bool KernelManagerContour::onRedo(std::string& filename){
279 std::string str = intToString(inundo);
280 filename = stundoredo + str + ".roi";
287 bool KernelManagerContour::onUndo(std::string& filename){
293 //itoa(inundo, str, 10);
294 std::string str = intToString(inundo);
297 filename = stundoredo + str + ".roi";
299 return true;//loadState(temp);
304 std::string KernelManagerContour::saveState(){
306 std::string str = intToString(inundo);
307 std::string temp = stundoredo + str + ".roi";
312 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
317 //itoa(inundo, str, 10);
318 std::string str = intToString(inundo);
320 filename = stundoredo + str + ".roi";
322 //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();
350 if (vecX->size()!=0){
352 int i,size=vecZ->size();
353 int actualSlice = instants[1];
354 for ( i=0 ; i<size ; i++ )
356 (*vecZ)[i] = actualSlice;
359 _contourPropagation->appendContour(vecX , vecY , vecZ);
360 return intToString(actualSlice);
366 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
368 if (_contourPropagation!=NULL)
370 _contourPropagation->getMaxMinZ(minZ, maxZ);
375 void KernelManagerContour::CalculeSplinePropagation()
377 _contourPropagation->setInterpolationNumber(100);
378 _contourPropagation->CalculeSplinePropagation();
381 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)
383 bool addedModel = false;
384 manualBaseModel* manModelContour=NULL;
386 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
388 manModelContour = factoryManualContourModel( typeofcontour );
390 int idTmp = _contourPropagation->FindIdWithZ(z);
392 if (type==0) // Initial Points
394 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
396 if (type==1) // Automatique Method
398 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
400 if (type==2) // sampling
402 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
404 //--------------------------------------------------------------------
405 int sizeCtrPt = vecCtrlPointX->size();
406 for (int j=0 ; j<sizeCtrPt ; j++)
408 //JSTG_16-07-08_----------------------------------------------------------------
409 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
410 //--------------------------------------------------------------------
414 theName = modelManager->createOutline( manModelContour, tempVector );
415 addedModel = theName.compare("") != 0;
417 manModelContour = NULL;
420 }// ifSliceKeyContourExist
421 return manModelContour;
424 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
426 manualBaseModel *manModelContour=NULL;
428 // Creating the model
429 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
434 manModelContour = new manualContourModel();
440 manModelContour = new manualContourModel();
446 manModelContour = new manualContourModelRoi();
452 manModelContour = new manualContourModelCircle();
458 manModelContour = new manualContourModelLine();
464 manModelContour = new manualBaseModel();
470 manModelContour = new manualContourModelPolygon();
473 return manModelContour;
476 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
477 Instant instant(&tempvector);
478 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
479 std::vector<std::string> vectname;
480 for(int i = 0; i < (int)(vectcont.size()); i++){
481 ContourThing **contourthing = vectcont[i];
482 vectname.push_back((*contourthing)->getName());
487 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
488 return modelManager->getOutlinesAtInstant(instant);
491 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
492 std::vector<manualBaseModel*> lstTmp;
493 std::vector<manualBaseModel*> lstResult;
495 int i,iSize=lstManConMod.size();
496 for (i=0;i<iSize;i++)
498 lstTmp = lstManConMod[i]->ExploseModel();
500 for (j=0;j<jSize;j++)
502 lstResult.push_back( lstTmp[j] );
508 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
509 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
513 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
514 int index = inst[5]-1;
516 if(index < (int)(vectimages.size())&&index!=_currentIndex){
518 return vectimages[index];
523 std::string KernelManagerContour::getCurrentFileName(){
527 void KernelManagerContour::setCurrentFileName(std::string filenam){
528 this->filename = filenam;
531 std::string KernelManagerContour::parseOsirixFile(std::string filename){
534 #ifdef ParserOsirix_BUILD
535 vtkImageData* sourceimage;
540 xsdfile.append("\\XML\\osirixschema.xsd");
542 sourceimage = getSourceImage();
543 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
545 if(p.ParseFile(filename.c_str())!= 0){
549 return p.getContoursFileName();