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();
115 change->SetInformationInput(img);
116 change->SetInputConnection(img->GetProducerPort());
117 img->GetSpacing(spc);
118 change->SetOutputSpacing(1,1,1);
121 change->SetOutputOrigin (0, 0, 0);
126 vectspc.push_back(spc[0]);
127 vectspc.push_back(spc[1]);
128 vectspc.push_back(spc[2]);
129 vectimagesSpacing.push_back(vectspc);
130 vectimg[i] = change->GetOutput();
133 vectimages = vectimg;
137 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
139 vecspc[0]=vectimagesSpacing[iImage][0];
140 vecspc[1]=vectimagesSpacing[iImage][1];
141 vecspc[2]=vectimagesSpacing[iImage][2];
145 void KernelManagerContour::initializeEnvironment(std::string datadir){
147 std::string conceptsFN = datadir+"holaConceptsFile.cf";
148 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
149 std::string imageSectionsFN = "";
150 std::string axeThingsFN = "";
152 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
153 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
154 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
155 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
157 for(int i = 0; i < (int)(vectimages.size()); i++){
158 vtkImageData* selectedimage = vectimages[i];
159 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
160 std::string imgstring = "Source Image "+intToString(i+1);
161 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
165 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
166 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
167 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
168 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
169 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
171 //Creating the objects to manage
172 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
174 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
177 vtkImageData* KernelManagerContour::getSourceImage(){
178 return imageSource->getSourceImage();
180 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
184 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
185 return modelManager->createOutline( manModelContour, instantVector );
188 std::string KernelManagerContour::intToString(int num){
195 char temp = k % 10 + 48;
197 result = temp + result;
203 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
204 return modelManager->GetLstNameThingsStatic();
207 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
208 modelManager->SaveThingName(pFile, pFileData, name);
210 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
211 return modelManager->GetLstNameThings();
213 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
214 // return modelManager->IsPartOfStaticList(keyName);
217 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
218 return modelManager->IsPartOfStaticList(theKeyName) == -1;
221 void KernelManagerContour::deleteCModel(std::string theKeyName){
222 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
223 modelManager->removeOutline( theKeyName );
228 void KernelManagerContour::removeAllOutlines(){
229 modelManager->removeAllOutlines();
232 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
233 return modelManager->getActualInstantOutlines();
236 int KernelManagerContour::getNamesWrappingSize(){
237 return getActualInstantOutlines().size();
240 std::string KernelManagerContour::getNameWrapping(int i){
241 return getActualInstantOutlines()[i]->getKeyName();
244 void KernelManagerContour::setInstant(Instant * theInstant){
245 modelManager->setInstant(theInstant);
246 //_actualInstant = theInstant;
249 Instant * KernelManagerContour::getCurrentInstant(){
250 return modelManager->getInstant();
252 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
253 Instant* act = new Instant ( &vectInstant );
254 modelManager->setInstant(act);
257 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
259 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
262 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
264 return modelManager->getOutlineByKeyName (cloneName )->getModel();
267 bool KernelManagerContour::onRedo(std::string& filename){
271 std::string str = intToString(inundo);
272 filename = stundoredo + str + ".roi";
279 bool KernelManagerContour::onUndo(std::string& filename){
285 //itoa(inundo, str, 10);
286 std::string str = intToString(inundo);
289 filename = stundoredo + str + ".roi";
291 return true;//loadState(temp);
296 std::string KernelManagerContour::saveState(){
298 std::string str = intToString(inundo);
299 std::string temp = stundoredo + str + ".roi";
304 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
309 //itoa(inundo, str, 10);
310 std::string str = intToString(inundo);
312 filename = stundoredo + str + ".roi";
314 //saveFileWithContours(temp);
321 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
323 modelManager->ChangeContourOfList(keyName, instant);
326 void KernelManagerContour ::resetAppend()
328 if (_contourPropagation!=NULL)
330 _contourPropagation->resetAppend();
335 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
337 if (_contourPropagation==NULL)
339 _contourPropagation = new ContourPropagation();
342 if (vecX->size()!=0){
344 int i,size=vecZ->size();
345 int actualSlice = instants[1];
346 for ( i=0 ; i<size ; i++ )
348 (*vecZ)[i] = actualSlice;
351 _contourPropagation->appendContour(vecX , vecY , vecZ);
352 return intToString(actualSlice);
358 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
360 if (_contourPropagation!=NULL)
362 _contourPropagation->getMaxMinZ(minZ, maxZ);
367 void KernelManagerContour::CalculeSplinePropagation()
369 _contourPropagation->setInterpolationNumber(100);
370 _contourPropagation->CalculeSplinePropagation();
373 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)
375 bool addedModel = false;
376 manualBaseModel* manModelContour=NULL;
378 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
380 manModelContour = factoryManualContourModel( typeofcontour );
382 int idTmp = _contourPropagation->FindIdWithZ(z);
384 if (type==0) // Initial Points
386 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
388 if (type==1) // Automatique Method
390 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
392 if (type==2) // sampling
394 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
396 //--------------------------------------------------------------------
397 int sizeCtrPt = vecCtrlPointX->size();
398 for (int j=0 ; j<sizeCtrPt ; j++)
400 //JSTG_16-07-08_----------------------------------------------------------------
401 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
402 //--------------------------------------------------------------------
406 theName = modelManager->createOutline( manModelContour, tempVector );
407 addedModel = theName.compare("") != 0;
409 manModelContour = NULL;
412 }// ifSliceKeyContourExist
413 return manModelContour;
416 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
418 manualBaseModel *manModelContour=NULL;
420 // Creating the model
421 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
426 manModelContour = new manualContourModel();
432 manModelContour = new manualContourModel();
438 manModelContour = new manualContourModelRoi();
444 manModelContour = new manualContourModelCircle();
450 manModelContour = new manualContourModelLine();
456 manModelContour = new manualBaseModel();
462 manModelContour = new manualContourModelPolygon();
465 return manModelContour;
468 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
469 Instant instant(&tempvector);
470 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
471 std::vector<std::string> vectname;
472 for(int i = 0; i < (int)(vectcont.size()); i++){
473 ContourThing **contourthing = vectcont[i];
474 vectname.push_back((*contourthing)->getName());
479 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
480 return modelManager->getOutlinesAtInstant(instant);
483 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
484 std::vector<manualBaseModel*> lstTmp;
485 std::vector<manualBaseModel*> lstResult;
487 int i,iSize=lstManConMod.size();
488 for (i=0;i<iSize;i++)
490 lstTmp = lstManConMod[i]->ExploseModel();
492 for (j=0;j<jSize;j++)
494 lstResult.push_back( lstTmp[j] );
500 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
501 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
505 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
506 int index = inst[5]-1;
508 if(index < (int)(vectimages.size())&&index!=_currentIndex){
510 return vectimages[index];
515 std::string KernelManagerContour::getCurrentFileName(){
519 void KernelManagerContour::setCurrentFileName(std::string filenam){
520 this->filename = filenam;
523 std::string KernelManagerContour::parseOsirixFile(std::string filename){
526 #ifdef ParserOsirix_BUILD
527 vtkImageData* sourceimage;
532 xsdfile.append("\\XML\\osirixschema.xsd");
534 sourceimage = getSourceImage();
535 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
537 if(p.ParseFile(filename.c_str())!= 0){
541 return p.getContoursFileName();