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);
211 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
212 return modelManager->getOutlineByKeyName (cloneName )->getModel();
215 bool KernelManagerContour::onRedo(std::string& filename){
219 std::string str = intToString(inundo);
220 filename = stundoredo + str + ".roi";
227 bool KernelManagerContour::onUndo(std::string& filename){
233 //itoa(inundo, str, 10);
234 std::string str = intToString(inundo);
237 filename = stundoredo + str + ".roi";
239 return true;//loadState(temp);
244 std::string KernelManagerContour::saveState(){
246 std::string str = intToString(inundo);
247 std::string temp = stundoredo + str + ".roi";
252 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
257 //itoa(inundo, str, 10);
258 std::string str = intToString(inundo);
260 filename = stundoredo + str + ".roi";
262 //saveFileWithContours(temp);
269 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
271 modelManager->ChangeContourOfList(keyName, instant);
274 void KernelManagerContour ::resetAppend(){
275 if(isInitContourPropagation()){
276 _contourPropagation->resetAppend();
280 bool KernelManagerContour::isInitContourPropagation(){
281 if(_contourPropagation == NULL){
282 _contourPropagation = new ContourPropagation();
290 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
291 if(isInitContourPropagation()){
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){
309 if(isInitContourPropagation()){
310 _contourPropagation->getMaxMinZ(minZ, maxZ);
313 void KernelManagerContour::CalculeSplinePropagation(){
314 _contourPropagation->setInterpolationNumber(100);
315 _contourPropagation->CalculeSplinePropagation();
318 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){
321 bool addedModel = false;
322 manualBaseModel* manModelContour=NULL;
324 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
326 manModelContour = factoryManualContourModel( typeofcontour );
328 int idTmp = _contourPropagation->FindIdWithZ(z);
330 if (type==0) // Initial Points
332 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
334 if (type==1) // Automatique Method
336 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
338 if (type==2) // sampling
340 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
342 //--------------------------------------------------------------------
343 int sizeCtrPt = vecCtrlPointX->size();
344 for (int j=0 ; j<sizeCtrPt ; j++)
346 //JSTG_16-07-08_----------------------------------------------------------------
347 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , 900 );
348 //--------------------------------------------------------------------
352 theName = modelManager->createOutline( manModelContour, tempVector );
353 addedModel = theName.compare("") != 0;
355 manModelContour = NULL;
358 }// ifSliceKeyContourExist
359 return manModelContour;
362 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
364 manualBaseModel *manModelContour=NULL;
366 // Creating the model
367 // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
372 manModelContour = new manualContourModel();
378 manModelContour = new manualContourModel();
384 manModelContour = new manualContourModelRoi();
390 manModelContour = new manualContourModelCircle();
396 manModelContour = new manualContourModelLine();
402 manModelContour = new manualBaseModel();
408 manModelContour = new manualContourModelPolygon();
411 return manModelContour;
414 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
415 Instant instant(&tempvector);
416 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
417 std::vector<std::string> vectname;
418 for(int i = 0; i < (int)(vectcont.size()); i++){
419 ContourThing **contourthing = vectcont[i];
420 vectname.push_back((*contourthing)->getName());
425 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
426 return modelManager->getOutlinesAtInstant(instant);
429 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
430 std::vector<manualBaseModel*> lstTmp;
431 std::vector<manualBaseModel*> lstResult;
433 int i,iSize=lstManConMod.size();
434 for (i=0;i<iSize;i++)
436 lstTmp = lstManConMod[i]->ExploseModel();
438 for (j=0;j<jSize;j++)
440 lstResult.push_back( lstTmp[j] );
446 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
447 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
451 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
452 int index = inst[5]-1;
454 if(index < (int)(vectimages.size())&&index!=_currentIndex){
456 return vectimages[index];
461 std::string KernelManagerContour::getCurrentFileName(){
465 void KernelManagerContour::setCurrentFileName(std::string filenam){
466 this->filename = filenam;
469 std::string KernelManagerContour::parseOsirixFile(std::string filename){
472 #ifdef ParserOsirix_BUILD
473 vtkImageData* sourceimage;
478 xsdfile.append("\\XML\\osirixschema.xsd");
480 sourceimage = getSourceImage();
481 OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
483 if(p.ParseFile(filename.c_str())!= 0){
487 return p.getContoursFileName();