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());
118 img->GetSpacing(spc);
119 change->SetOutputSpacing(1,1,1);
123 vectspc.push_back(spc[0]);
124 vectspc.push_back(spc[1]);
125 vectspc.push_back(spc[2]);
126 vectimagesSpacing.push_back(vectspc);
127 vectimg[i] = change->GetOutput();
130 vectimages = vectimg;
134 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
136 vecspc[0]=vectimagesSpacing[iImage][0];
137 vecspc[1]=vectimagesSpacing[iImage][1];
138 vecspc[2]=vectimagesSpacing[iImage][2];
142 void KernelManagerContour::initializeEnvironment(std::string datadir){
144 std::string conceptsFN = datadir+"holaConceptsFile.cf";
145 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
146 std::string imageSectionsFN = "";
147 std::string axeThingsFN = "";
149 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
150 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
151 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
152 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
154 for(int i = 0; i < (int)(vectimages.size()); i++){
155 vtkImageData* selectedimage = vectimages[i];
156 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
157 std::string imgstring = "Source Image "+intToString(i+1);
158 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
162 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
163 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
164 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
165 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
166 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
168 //Creating the objects to manage
169 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
171 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
174 vtkImageData* KernelManagerContour::getSourceImage(){
175 return imageSource->getSourceImage();
177 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
181 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
182 return modelManager->createOutline( manModelContour, instantVector );
185 std::string KernelManagerContour::intToString(int num){
192 char temp = k % 10 + 48;
194 result = temp + result;
200 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
201 return modelManager->GetLstNameThingsStatic();
204 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
205 modelManager->SaveThingName(pFile, pFileData, name);
207 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
208 return modelManager->GetLstNameThings();
210 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
211 // return modelManager->IsPartOfStaticList(keyName);
214 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
215 return modelManager->IsPartOfStaticList(theKeyName) == -1;
218 void KernelManagerContour::deleteCModel(std::string theKeyName){
219 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
220 modelManager->removeOutline( theKeyName );
225 void KernelManagerContour::removeAllOutlines(){
226 modelManager->removeAllOutlines();
229 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
230 return modelManager->getActualInstantOutlines();
233 int KernelManagerContour::getNamesWrappingSize(){
234 return getActualInstantOutlines().size();
237 std::string KernelManagerContour::getNameWrapping(int i){
238 return getActualInstantOutlines()[i]->getKeyName();
241 void KernelManagerContour::setInstant(Instant * theInstant){
242 modelManager->setInstant(theInstant);
243 //_actualInstant = theInstant;
246 Instant * KernelManagerContour::getCurrentInstant(){
247 return modelManager->getInstant();
249 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
250 Instant* act = new Instant ( &vectInstant );
251 modelManager->setInstant(act);
254 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
256 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
259 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
261 return modelManager->getOutlineByKeyName (cloneName )->getModel();
264 bool KernelManagerContour::onRedo(std::string& filename){
268 std::string str = intToString(inundo);
269 filename = stundoredo + str + ".roi";
276 bool KernelManagerContour::onUndo(std::string& filename){
282 //itoa(inundo, str, 10);
283 std::string str = intToString(inundo);
286 filename = stundoredo + str + ".roi";
288 return true;//loadState(temp);
293 std::string KernelManagerContour::saveState(){
295 std::string str = intToString(inundo);
296 std::string temp = stundoredo + str + ".roi";
301 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
306 //itoa(inundo, str, 10);
307 std::string str = intToString(inundo);
309 filename = stundoredo + str + ".roi";
311 //saveFileWithContours(temp);
318 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
320 modelManager->ChangeContourOfList(keyName, instant);
323 void KernelManagerContour ::resetAppend()
325 if (_contourPropagation!=NULL)
327 _contourPropagation->resetAppend();
332 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
334 if (_contourPropagation==NULL)
336 _contourPropagation = new ContourPropagation();
339 if (vecX->size()!=0){
341 int i,size=vecZ->size();
342 int actualSlice = instants[1];
343 for ( i=0 ; i<size ; i++ )
345 (*vecZ)[i] = actualSlice;
348 _contourPropagation->appendContour(vecX , vecY , vecZ);
349 return intToString(actualSlice);
355 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
357 if (_contourPropagation!=NULL)
359 _contourPropagation->getMaxMinZ(minZ, maxZ);
364 void KernelManagerContour::CalculeSplinePropagation()
366 _contourPropagation->setInterpolationNumber(100);
367 _contourPropagation->CalculeSplinePropagation();
370 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)
372 bool addedModel = false;
373 manualBaseModel* manModelContour=NULL;
375 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
377 manModelContour = factoryManualContourModel( typeofcontour );
379 int idTmp = _contourPropagation->FindIdWithZ(z);
381 if (type==0) // Initial Points
383 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
385 if (type==1) // Automatique Method
387 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
389 if (type==2) // sampling
391 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
393 //--------------------------------------------------------------------
394 int sizeCtrPt = vecCtrlPointX->size();
395 for (int j=0 ; j<sizeCtrPt ; j++)
397 //JSTG_16-07-08_----------------------------------------------------------------
398 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
399 //--------------------------------------------------------------------
403 theName = modelManager->createOutline( manModelContour, tempVector );
404 addedModel = theName.compare("") != 0;
406 manModelContour = NULL;
409 }// ifSliceKeyContourExist
410 return manModelContour;
413 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
415 manualBaseModel *manModelContour=NULL;
417 // Creating the model
418 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
423 manModelContour = new manualContourModel();
429 manModelContour = new manualContourModel();
435 manModelContour = new manualContourModelRoi();
441 manModelContour = new manualContourModelCircle();
447 manModelContour = new manualContourModelLine();
453 manModelContour = new manualBaseModel();
459 manModelContour = new manualContourModelPolygon();
462 return manModelContour;
465 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
466 Instant instant(&tempvector);
467 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
468 std::vector<std::string> vectname;
469 for(int i = 0; i < (int)(vectcont.size()); i++){
470 ContourThing **contourthing = vectcont[i];
471 vectname.push_back((*contourthing)->getName());
476 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
477 return modelManager->getOutlinesAtInstant(instant);
480 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
481 std::vector<manualBaseModel*> lstTmp;
482 std::vector<manualBaseModel*> lstResult;
484 int i,iSize=lstManConMod.size();
485 for (i=0;i<iSize;i++)
487 lstTmp = lstManConMod[i]->ExploseModel();
489 for (j=0;j<jSize;j++)
491 lstResult.push_back( lstTmp[j] );
497 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
498 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
502 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
503 int index = inst[5]-1;
505 if(index < (int)(vectimages.size())&&index!=_currentIndex){
507 return vectimages[index];
512 std::string KernelManagerContour::getCurrentFileName(){
516 void KernelManagerContour::setCurrentFileName(std::string filenam){
517 this->filename = filenam;
520 std::string KernelManagerContour::parseOsirixFile(std::string filename){
523 #ifdef ParserOsirix_BUILD
524 vtkImageData* sourceimage;
529 xsdfile.append("\\XML\\osirixschema.xsd");
531 sourceimage = getSourceImage();
532 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
534 if(p.ParseFile(filename.c_str())!= 0){
538 return p.getContoursFileName();