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);
72 KernelManagerContour::~KernelManagerContour()
76 std::vector<vtkImageData*> KernelManagerContour::getVectImages()
82 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
85 std::vector<double> vectspc;
87 for(int i = 0; i < (int)(vectimg.size()); i++){
88 vtkImageData* img = vectimg[i];
89 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
90 change->SetInformationInput(img);
91 change->SetInputConnection(img->GetProducerPort());
94 change->SetOutputSpacing(1,1,1);
98 vectspc.push_back(spc[0]);
99 vectspc.push_back(spc[1]);
100 vectspc.push_back(spc[2]);
101 vectimagesSpacing.push_back(vectspc);
102 vectimg[i] = change->GetOutput();
105 vectimages = vectimg;
109 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
111 vecspc[0]=vectimagesSpacing[iImage][0];
112 vecspc[1]=vectimagesSpacing[iImage][1];
113 vecspc[2]=vectimagesSpacing[iImage][2];
117 void KernelManagerContour::initializeEnvironment(std::string datadir){
119 std::string conceptsFN = datadir+"holaConceptsFile.cf";
120 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
121 std::string imageSectionsFN = "";
122 std::string axeThingsFN = "";
124 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
125 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
126 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
127 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
129 for(int i = 0; i < (int)(vectimages.size()); i++){
130 vtkImageData* selectedimage = vectimages[i];
131 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
132 std::string imgstring = "Source Image "+intToString(i+1);
133 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
137 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
138 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
139 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
140 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
141 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
143 //Creating the objects to manage
144 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
146 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
149 vtkImageData* KernelManagerContour::getSourceImage(){
150 return imageSource->getSourceImage();
152 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
156 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
157 return modelManager->createOutline( manModelContour, instantVector );
160 std::string KernelManagerContour::intToString(int num){
167 char temp = k % 10 + 48;
169 result = temp + result;
175 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
176 return modelManager->GetLstNameThingsStatic();
179 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
180 modelManager->SaveThingName(pFile, pFileData, name);
182 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
183 return modelManager->GetLstNameThings();
185 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
186 // return modelManager->IsPartOfStaticList(keyName);
189 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
190 return modelManager->IsPartOfStaticList(theKeyName) == -1;
193 void KernelManagerContour::deleteCModel(std::string theKeyName){
194 manualBaseModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
195 modelManager->removeOutline( theKeyName );
200 void KernelManagerContour::removeAllOutlines(){
201 modelManager->removeAllOutlines();
204 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
205 return modelManager->getActualInstantOutlines();
208 int KernelManagerContour::getNamesWrappingSize(){
209 return getActualInstantOutlines().size();
212 std::string KernelManagerContour::getNameWrapping(int i){
213 return getActualInstantOutlines()[i]->getKeyName();
216 void KernelManagerContour::setInstant(Instant * theInstant){
217 modelManager->setInstant(theInstant);
218 //_actualInstant = theInstant;
221 Instant * KernelManagerContour::getCurrentInstant(){
222 return modelManager->getInstant();
224 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
225 Instant* act = new Instant ( &vectInstant );
226 modelManager->setInstant(act);
229 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
231 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
234 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
236 return modelManager->getOutlineByKeyName (cloneName )->getModel();
239 bool KernelManagerContour::onRedo(std::string& filename){
243 std::string str = intToString(inundo);
244 filename = stundoredo + str + ".roi";
251 bool KernelManagerContour::onUndo(std::string& filename){
257 //itoa(inundo, str, 10);
258 std::string str = intToString(inundo);
261 filename = stundoredo + str + ".roi";
263 return true;//loadState(temp);
268 std::string KernelManagerContour::saveState(){
270 std::string str = intToString(inundo);
271 std::string temp = stundoredo + str + ".roi";
276 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
281 //itoa(inundo, str, 10);
282 std::string str = intToString(inundo);
284 filename = stundoredo + str + ".roi";
286 //saveFileWithContours(temp);
293 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
295 modelManager->ChangeContourOfList(keyName, instant);
298 void KernelManagerContour ::resetAppend()
300 if (_contourPropagation!=NULL)
302 _contourPropagation->resetAppend();
307 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
309 if (_contourPropagation==NULL)
311 _contourPropagation = new ContourPropagation();
314 if (vecX->size()!=0){
316 int i,size=vecZ->size();
317 int actualSlice = instants[1];
318 for ( i=0 ; i<size ; i++ )
320 (*vecZ)[i] = actualSlice;
323 _contourPropagation->appendContour(vecX , vecY , vecZ);
324 return intToString(actualSlice);
330 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
332 if (_contourPropagation!=NULL)
334 _contourPropagation->getMaxMinZ(minZ, maxZ);
339 void KernelManagerContour::CalculeSplinePropagation()
341 _contourPropagation->setInterpolationNumber(100);
342 _contourPropagation->CalculeSplinePropagation();
345 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)
347 bool addedModel = false;
348 manualBaseModel* manModelContour=NULL;
350 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
352 manModelContour = factoryManualContourModel( typeofcontour );
354 int idTmp = _contourPropagation->FindIdWithZ(z);
356 if (type==0) // Initial Points
358 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
360 if (type==1) // Automatique Method
362 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
364 if (type==2) // sampling
366 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
368 //--------------------------------------------------------------------
369 int sizeCtrPt = vecCtrlPointX->size();
370 for (int j=0 ; j<sizeCtrPt ; j++)
372 //JSTG_16-07-08_----------------------------------------------------------------
373 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , 900 );
374 //--------------------------------------------------------------------
378 theName = modelManager->createOutline( manModelContour, tempVector );
379 addedModel = theName.compare("") != 0;
381 manModelContour = NULL;
384 }// ifSliceKeyContourExist
385 return manModelContour;
388 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
390 manualBaseModel *manModelContour=NULL;
392 // Creating the model
393 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
398 manModelContour = new manualContourModel();
404 manModelContour = new manualContourModel();
410 manModelContour = new manualContourModelRoi();
416 manModelContour = new manualContourModelCircle();
422 manModelContour = new manualContourModelLine();
428 manModelContour = new manualBaseModel();
434 manModelContour = new manualContourModelPolygon();
437 return manModelContour;
440 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
441 Instant instant(&tempvector);
442 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
443 std::vector<std::string> vectname;
444 for(int i = 0; i < (int)(vectcont.size()); i++){
445 ContourThing **contourthing = vectcont[i];
446 vectname.push_back((*contourthing)->getName());
451 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
452 return modelManager->getOutlinesAtInstant(instant);
455 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
456 std::vector<manualBaseModel*> lstTmp;
457 std::vector<manualBaseModel*> lstResult;
459 int i,iSize=lstManConMod.size();
460 for (i=0;i<iSize;i++)
462 lstTmp = lstManConMod[i]->ExploseModel();
464 for (j=0;j<jSize;j++)
466 lstResult.push_back( lstTmp[j] );
472 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
473 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
477 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
478 int index = inst[5]-1;
480 if(index < (int)(vectimages.size())&&index!=_currentIndex){
482 return vectimages[index];
487 std::string KernelManagerContour::getCurrentFileName(){
491 void KernelManagerContour::setCurrentFileName(std::string filenam){
492 this->filename = filenam;
495 std::string KernelManagerContour::parseOsirixFile(std::string filename){
498 #ifdef ParserOsirix_BUILD
499 vtkImageData* sourceimage;
504 xsdfile.append("\\XML\\osirixschema.xsd");
506 sourceimage = getSourceImage();
507 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
509 if(p.ParseFile(filename.c_str())!= 0){
513 return p.getContoursFileName();