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){
40 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
47 seconds = time (NULL);
51 stundoredo = tmpdir+"/temp"+intToString(time);
54 _contourPropagation = NULL;
56 mkdir(tmpdir.c_str());
57 mkdir(stundoredo.c_str());
59 mkdir(tmpdir.c_str(),755);
60 mkdir(stundoredo.c_str(),755);
62 stundoredo += "/cont";
66 setVectImages(images);
67 initializeEnvironment(datadir);
70 KernelManagerContour::~KernelManagerContour(){
73 std::vector<vtkImageData*> KernelManagerContour::getVectImages(){
76 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg){
78 for(int i = 0; i < vectimg.size(); i++){
79 vtkImageData* img = vectimg[i];
80 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
81 change->SetInformationInput(img);
82 change->SetInputConnection(img->GetProducerPort());
84 change->SetOutputSpacing(1,1,1);
88 vectimg[i] = change->GetOutput();
94 void KernelManagerContour::initializeEnvironment(std::string datadir){
95 std::string conceptsFN = datadir+"holaConceptsFile.cf";
96 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
97 std::string imageSectionsFN = "";
98 std::string axeThingsFN = "";
100 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
101 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
102 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
103 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
105 for(int i = 0; i < vectimages.size(); i++){
106 vtkImageData* selectedimage = vectimages[i];
107 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
108 std::string imgstring = "Source Image "+intToString(i+1);
109 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
113 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
114 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
115 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
116 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
117 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
119 //Creating the objects to manage
120 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
122 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
125 vtkImageData* KernelManagerContour::getSourceImage(){
126 return imageSource->getSourceImage();
128 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
132 std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector<int> instantVector){
133 return modelManager->createOutline( manModelContour, instantVector );
136 std::string KernelManagerContour::intToString(int num){
143 char temp = k % 10 + 48;
145 result = temp + result;
151 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
152 return modelManager->GetLstNameThingsStatic();
155 void KernelManagerContour::SaveThingName(FILE* pFile, std::string name ){
156 modelManager->SaveThingName(pFile, name);
158 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
159 return modelManager->GetLstNameThings();
161 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
162 // return modelManager->IsPartOfStaticList(keyName);
165 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
166 return modelManager->IsPartOfStaticList(theKeyName) == -1;
169 void KernelManagerContour::deleteCModel(std::string theKeyName){
170 manualContourModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
171 modelManager->removeOutline( theKeyName );
176 void KernelManagerContour::removeAllOutlines(){
177 modelManager->removeAllOutlines();
180 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
181 return modelManager->getActualInstantOutlines();
184 int KernelManagerContour::getNamesWrappingSize(){
185 return getActualInstantOutlines().size();
188 std::string KernelManagerContour::getNameWrapping(int i){
189 return getActualInstantOutlines()[i]->getKeyName();
192 void KernelManagerContour::setInstant(Instant * theInstant){
193 modelManager->setInstant(theInstant);
194 //_actualInstant = theInstant;
197 Instant * KernelManagerContour::getCurrentInstant(){
198 return modelManager->getInstant();
200 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
201 Instant* act = new Instant ( &vectInstant );
202 modelManager->setInstant(act);
205 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
207 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
209 manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
210 return modelManager->getOutlineByKeyName (cloneName )->getModel();
213 bool KernelManagerContour::onRedo(std::string& filename){
217 std::string str = intToString(inundo);
218 filename = stundoredo + str + ".roi";
225 bool KernelManagerContour::onUndo(std::string& filename){
231 //itoa(inundo, str, 10);
232 std::string str = intToString(inundo);
235 filename = stundoredo + str + ".roi";
237 return true;//loadState(temp);
242 std::string KernelManagerContour::saveState(){
244 std::string str = intToString(inundo);
245 std::string temp = stundoredo + str + ".roi";
250 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
255 //itoa(inundo, str, 10);
256 std::string str = intToString(inundo);
258 filename = stundoredo + str + ".roi";
260 //saveFileWithContours(temp);
267 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
269 modelManager->ChangeContourOfList(keyName, instant);
272 void KernelManagerContour ::resetAppend(){
273 if(isInitContourPropagation()){
274 _contourPropagation->resetAppend();
278 bool KernelManagerContour::isInitContourPropagation(){
279 if(_contourPropagation == NULL){
280 _contourPropagation = new ContourPropagation();
288 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
289 if(isInitContourPropagation()){
290 if (vecX->size()!=0){
292 int i,size=vecZ->size();
293 int actualSlice = instants[1];
294 for ( i=0 ; i<size ; i++ )
296 (*vecZ)[i] = actualSlice;
299 _contourPropagation->appendContour(vecX , vecY , vecZ);
300 return intToString(actualSlice);
306 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ){
307 if(isInitContourPropagation()){
308 _contourPropagation->getMaxMinZ(minZ, maxZ);
311 void KernelManagerContour::CalculeSplinePropagation(){
312 _contourPropagation->setInterpolationNumber(100);
313 _contourPropagation->CalculeSplinePropagation();
316 manualContourModel* 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){
319 bool addedModel = false;
320 manualContourModel* manModelContour=NULL;
322 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
324 manModelContour = factoryManualContourModel( typeofcontour );
326 int idTmp = _contourPropagation->FindIdWithZ(z);
328 if (type==0) // Initial Points
330 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
332 if (type==1) // Automatique Method
334 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
336 if (type==2) // sampling
338 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
340 //--------------------------------------------------------------------
341 int sizeCtrPt = vecCtrlPointX->size();
342 for (int j=0 ; j<sizeCtrPt ; j++)
344 //JSTG_16-07-08_----------------------------------------------------------------
345 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
346 //--------------------------------------------------------------------
350 theName = modelManager->createOutline( manModelContour, tempVector );
351 addedModel = theName.compare("") != 0;
353 manModelContour = NULL;
356 }// ifSliceKeyContourExist
357 return manModelContour;
361 manualContourModel * KernelManagerContour::factoryManualContourModel(int typeContour)
363 manualContourModel *manModelContour=NULL;
368 manModelContour = new manualContourModel();
374 manModelContour = new manualContourModel();
380 manModelContour = new manualContourModelRoi();
386 manModelContour = new manualContourModelCircle();
392 manModelContour = new manualContourModelLine();
395 return manModelContour;
398 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
399 Instant instant(&tempvector);
400 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
401 std::vector<std::string> vectname;
402 for(int i = 0; i < vectcont.size(); i++){
403 ContourThing **contourthing = vectcont[i];
404 vectname.push_back((*contourthing)->getName());
409 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
410 return modelManager->getOutlinesAtInstant(instant);
413 std::vector<manualContourModel*> KernelManagerContour::ExploseEachModel( std::vector<manualContourModel*> lstManConMod ){
414 std::vector<manualContourModel*> lstTmp;
415 std::vector<manualContourModel*> lstResult;
417 int i,iSize=lstManConMod.size();
418 for (i=0;i<iSize;i++)
420 lstTmp = lstManConMod[i]->ExploseModel();
422 for (j=0;j<jSize;j++)
424 lstResult.push_back( lstTmp[j] );
430 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
431 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
435 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
436 int index = inst[5]-1;
438 if(index < vectimages.size()&&index!=_currentIndex){
440 return vectimages[index];
445 std::string KernelManagerContour::getCurrentFileName(){
449 void KernelManagerContour::setCurrentFileName(std::string filenam){
450 this->filename = filenam;