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 < 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){
96 std::string conceptsFN = datadir+"holaConceptsFile.cf";
97 std::string imageSourcesFN = datadir+"holaImagesInstantsFile.of";
98 std::string imageSectionsFN = "";
99 std::string axeThingsFN = "";
101 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
102 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
103 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
104 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
106 for(int i = 0; i < vectimages.size(); i++){
107 vtkImageData* selectedimage = vectimages[i];
108 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
109 std::string imgstring = "Source Image "+intToString(i+1);
110 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
114 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN ,datadir);
115 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
116 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
117 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
118 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
120 //Creating the objects to manage
121 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
123 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
126 vtkImageData* KernelManagerContour::getSourceImage(){
127 return imageSource->getSourceImage();
129 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
133 std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector<int> instantVector){
134 return modelManager->createOutline( manModelContour, instantVector );
137 std::string KernelManagerContour::intToString(int num){
144 char temp = k % 10 + 48;
146 result = temp + result;
152 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
153 return modelManager->GetLstNameThingsStatic();
156 void KernelManagerContour::SaveThingName(FILE* pFile, std::string name ){
157 modelManager->SaveThingName(pFile, name);
159 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
160 return modelManager->GetLstNameThings();
162 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
163 // return modelManager->IsPartOfStaticList(keyName);
166 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
167 return modelManager->IsPartOfStaticList(theKeyName) == -1;
170 void KernelManagerContour::deleteCModel(std::string theKeyName){
171 manualContourModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
172 modelManager->removeOutline( theKeyName );
177 void KernelManagerContour::removeAllOutlines(){
178 modelManager->removeAllOutlines();
181 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
182 return modelManager->getActualInstantOutlines();
185 int KernelManagerContour::getNamesWrappingSize(){
186 return getActualInstantOutlines().size();
189 std::string KernelManagerContour::getNameWrapping(int i){
190 return getActualInstantOutlines()[i]->getKeyName();
193 void KernelManagerContour::setInstant(Instant * theInstant){
194 modelManager->setInstant(theInstant);
195 //_actualInstant = theInstant;
198 Instant * KernelManagerContour::getCurrentInstant(){
199 return modelManager->getInstant();
201 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
202 Instant* act = new Instant ( &vectInstant );
203 modelManager->setInstant(act);
206 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
208 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
210 manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
211 return modelManager->getOutlineByKeyName (cloneName )->getModel();
214 bool KernelManagerContour::onRedo(std::string& filename){
218 std::string str = intToString(inundo);
219 filename = stundoredo + str + ".roi";
226 bool KernelManagerContour::onUndo(std::string& filename){
232 //itoa(inundo, str, 10);
233 std::string str = intToString(inundo);
236 filename = stundoredo + str + ".roi";
238 return true;//loadState(temp);
243 std::string KernelManagerContour::saveState(){
245 std::string str = intToString(inundo);
246 std::string temp = stundoredo + str + ".roi";
251 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
256 //itoa(inundo, str, 10);
257 std::string str = intToString(inundo);
259 filename = stundoredo + str + ".roi";
261 //saveFileWithContours(temp);
268 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
270 modelManager->ChangeContourOfList(keyName, instant);
273 void KernelManagerContour ::resetAppend(){
274 if(isInitContourPropagation()){
275 _contourPropagation->resetAppend();
279 bool KernelManagerContour::isInitContourPropagation(){
280 if(_contourPropagation == NULL){
281 _contourPropagation = new ContourPropagation();
289 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
290 if(isInitContourPropagation()){
291 if (vecX->size()!=0){
293 int i,size=vecZ->size();
294 int actualSlice = instants[1];
295 for ( i=0 ; i<size ; i++ )
297 (*vecZ)[i] = actualSlice;
300 _contourPropagation->appendContour(vecX , vecY , vecZ);
301 return intToString(actualSlice);
307 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ){
308 if(isInitContourPropagation()){
309 _contourPropagation->getMaxMinZ(minZ, maxZ);
312 void KernelManagerContour::CalculeSplinePropagation(){
313 _contourPropagation->setInterpolationNumber(100);
314 _contourPropagation->CalculeSplinePropagation();
317 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){
320 bool addedModel = false;
321 manualContourModel* manModelContour=NULL;
323 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
325 manModelContour = factoryManualContourModel( typeofcontour );
327 int idTmp = _contourPropagation->FindIdWithZ(z);
329 if (type==0) // Initial Points
331 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
333 if (type==1) // Automatique Method
335 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
337 if (type==2) // sampling
339 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
341 //--------------------------------------------------------------------
342 int sizeCtrPt = vecCtrlPointX->size();
343 for (int j=0 ; j<sizeCtrPt ; j++)
345 //JSTG_16-07-08_----------------------------------------------------------------
346 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
347 //--------------------------------------------------------------------
351 theName = modelManager->createOutline( manModelContour, tempVector );
352 addedModel = theName.compare("") != 0;
354 manModelContour = NULL;
357 }// ifSliceKeyContourExist
358 return manModelContour;
362 manualContourModel * KernelManagerContour::factoryManualContourModel(int typeContour)
364 manualContourModel *manModelContour=NULL;
369 manModelContour = new manualContourModel();
375 manModelContour = new manualContourModel();
381 manModelContour = new manualContourModelRoi();
387 manModelContour = new manualContourModelCircle();
393 manModelContour = new manualContourModelLine();
396 return manModelContour;
399 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
400 Instant instant(&tempvector);
401 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
402 std::vector<std::string> vectname;
403 for(int i = 0; i < vectcont.size(); i++){
404 ContourThing **contourthing = vectcont[i];
405 vectname.push_back((*contourthing)->getName());
410 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
411 return modelManager->getOutlinesAtInstant(instant);
414 std::vector<manualContourModel*> KernelManagerContour::ExploseEachModel( std::vector<manualContourModel*> lstManConMod ){
415 std::vector<manualContourModel*> lstTmp;
416 std::vector<manualContourModel*> lstResult;
418 int i,iSize=lstManConMod.size();
419 for (i=0;i<iSize;i++)
421 lstTmp = lstManConMod[i]->ExploseModel();
423 for (j=0;j<jSize;j++)
425 lstResult.push_back( lstTmp[j] );
431 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
432 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
436 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
437 int index = inst[5]-1;
439 if(index < vectimages.size()&&index!=_currentIndex){
441 return vectimages[index];
446 std::string KernelManagerContour::getCurrentFileName(){
450 void KernelManagerContour::setCurrentFileName(std::string filenam){
451 this->filename = filenam;