2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "KernelManagerContour.h"
8 KernelManagerContour::KernelManagerContour(){
11 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
18 seconds = time (NULL);
22 stundoredo = "data/temp"+intToString(time);
25 _contourPropagation = NULL;
27 mkdir(stundoredo.c_str());
29 mkdir(stundoredo.c_str(),755);
31 stundoredo += "/cont";
37 KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std::string datadir,std::string tmpdir)
41 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
48 seconds = time (NULL);
52 stundoredo = tmpdir+"/temp"+intToString(time);
55 _contourPropagation = NULL;
57 mkdir(tmpdir.c_str());
58 mkdir(stundoredo.c_str());
60 mkdir(tmpdir.c_str(),755);
61 mkdir(stundoredo.c_str(),755);
63 stundoredo += "/cont";
67 setVectImages(images);
68 initializeEnvironment(datadir);
71 KernelManagerContour::~KernelManagerContour(){
74 std::vector<vtkImageData*> KernelManagerContour::getVectImages(){
77 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg){
79 for(int i = 0; i < (int)(vectimg.size()); i++){
80 vtkImageData* img = vectimg[i];
81 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
82 change->SetInformationInput(img);
83 change->SetInputConnection(img->GetProducerPort());
85 change->SetOutputSpacing(1,1,1);
89 vectimg[i] = change->GetOutput();
95 void KernelManagerContour::initializeEnvironment(std::string datadir){
97 std::string conceptsFN = datadir+"holaConceptsFile.cf";
98 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
99 std::string imageSectionsFN = "";
100 std::string axeThingsFN = "";
102 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
103 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
104 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
105 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
107 for(int i = 0; i < (int)(vectimages.size()); i++){
108 vtkImageData* selectedimage = vectimages[i];
109 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
110 std::string imgstring = "Source Image "+intToString(i+1);
111 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
115 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
116 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
117 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
118 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
119 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
121 //Creating the objects to manage
122 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
124 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
127 vtkImageData* KernelManagerContour::getSourceImage(){
128 return imageSource->getSourceImage();
130 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
134 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
135 return modelManager->createOutline( manModelContour, instantVector );
138 std::string KernelManagerContour::intToString(int num){
145 char temp = k % 10 + 48;
147 result = temp + result;
153 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
154 return modelManager->GetLstNameThingsStatic();
157 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
158 modelManager->SaveThingName(pFile, pFileData, name);
160 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
161 return modelManager->GetLstNameThings();
163 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
164 // return modelManager->IsPartOfStaticList(keyName);
167 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
168 return modelManager->IsPartOfStaticList(theKeyName) == -1;
171 void KernelManagerContour::deleteCModel(std::string theKeyName){
172 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
173 modelManager->removeOutline( theKeyName );
178 void KernelManagerContour::removeAllOutlines(){
179 modelManager->removeAllOutlines();
182 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
183 return modelManager->getActualInstantOutlines();
186 int KernelManagerContour::getNamesWrappingSize(){
187 return getActualInstantOutlines().size();
190 std::string KernelManagerContour::getNameWrapping(int i){
191 return getActualInstantOutlines()[i]->getKeyName();
194 void KernelManagerContour::setInstant(Instant * theInstant){
195 modelManager->setInstant(theInstant);
196 //_actualInstant = theInstant;
199 Instant * KernelManagerContour::getCurrentInstant(){
200 return modelManager->getInstant();
202 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
203 Instant* act = new Instant ( &vectInstant );
204 modelManager->setInstant(act);
207 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
209 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
212 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
214 return modelManager->getOutlineByKeyName (cloneName )->getModel();
217 bool KernelManagerContour::onRedo(std::string& filename){
221 std::string str = intToString(inundo);
222 filename = stundoredo + str + ".roi";
229 bool KernelManagerContour::onUndo(std::string& filename){
235 //itoa(inundo, str, 10);
236 std::string str = intToString(inundo);
239 filename = stundoredo + str + ".roi";
241 return true;//loadState(temp);
246 std::string KernelManagerContour::saveState(){
248 std::string str = intToString(inundo);
249 std::string temp = stundoredo + str + ".roi";
254 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
259 //itoa(inundo, str, 10);
260 std::string str = intToString(inundo);
262 filename = stundoredo + str + ".roi";
264 //saveFileWithContours(temp);
271 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
273 modelManager->ChangeContourOfList(keyName, instant);
276 void KernelManagerContour ::resetAppend()
278 if (_contourPropagation!=NULL)
280 _contourPropagation->resetAppend();
285 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
287 if (_contourPropagation==NULL)
289 _contourPropagation = new ContourPropagation();
292 if (vecX->size()!=0){
294 int i,size=vecZ->size();
295 int actualSlice = instants[1];
296 for ( i=0 ; i<size ; i++ )
298 (*vecZ)[i] = actualSlice;
301 _contourPropagation->appendContour(vecX , vecY , vecZ);
302 return intToString(actualSlice);
308 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
310 if (_contourPropagation!=NULL)
312 _contourPropagation->getMaxMinZ(minZ, maxZ);
317 void KernelManagerContour::CalculeSplinePropagation()
319 _contourPropagation->setInterpolationNumber(100);
320 _contourPropagation->CalculeSplinePropagation();
323 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)
325 bool addedModel = false;
326 manualBaseModel* manModelContour=NULL;
328 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
330 manModelContour = factoryManualContourModel( typeofcontour );
332 int idTmp = _contourPropagation->FindIdWithZ(z);
334 if (type==0) // Initial Points
336 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
338 if (type==1) // Automatique Method
340 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
342 if (type==2) // sampling
344 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
346 //--------------------------------------------------------------------
347 int sizeCtrPt = vecCtrlPointX->size();
348 for (int j=0 ; j<sizeCtrPt ; j++)
350 //JSTG_16-07-08_----------------------------------------------------------------
351 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , 900 );
352 //--------------------------------------------------------------------
356 theName = modelManager->createOutline( manModelContour, tempVector );
357 addedModel = theName.compare("") != 0;
359 manModelContour = NULL;
362 }// ifSliceKeyContourExist
363 return manModelContour;
366 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
368 manualBaseModel *manModelContour=NULL;
370 // Creating the model
371 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
376 manModelContour = new manualContourModel();
382 manModelContour = new manualContourModel();
388 manModelContour = new manualContourModelRoi();
394 manModelContour = new manualContourModelCircle();
400 manModelContour = new manualContourModelLine();
406 manModelContour = new manualBaseModel();
412 manModelContour = new manualContourModelPolygon();
415 return manModelContour;
418 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
419 Instant instant(&tempvector);
420 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
421 std::vector<std::string> vectname;
422 for(int i = 0; i < (int)(vectcont.size()); i++){
423 ContourThing **contourthing = vectcont[i];
424 vectname.push_back((*contourthing)->getName());
429 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
430 return modelManager->getOutlinesAtInstant(instant);
433 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
434 std::vector<manualBaseModel*> lstTmp;
435 std::vector<manualBaseModel*> lstResult;
437 int i,iSize=lstManConMod.size();
438 for (i=0;i<iSize;i++)
440 lstTmp = lstManConMod[i]->ExploseModel();
442 for (j=0;j<jSize;j++)
444 lstResult.push_back( lstTmp[j] );
450 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
451 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
455 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
456 int index = inst[5]-1;
458 if(index < (int)(vectimages.size())&&index!=_currentIndex){
460 return vectimages[index];
465 std::string KernelManagerContour::getCurrentFileName(){
469 void KernelManagerContour::setCurrentFileName(std::string filenam){
470 this->filename = filenam;
473 std::string KernelManagerContour::parseOsirixFile(std::string filename){
476 #ifdef ParserOsirix_BUILD
477 vtkImageData* sourceimage;
482 xsdfile.append("\\XML\\osirixschema.xsd");
484 sourceimage = getSourceImage();
485 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
487 if(p.ParseFile(filename.c_str())!= 0){
491 return p.getContoursFileName();