2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "KernelManagerContour.h"
8 KernelManagerContour::KernelManagerContour(){
11 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
16 stundoredo = "data/temp";
19 _contourPropagation = NULL;
21 mkdir(stundoredo.c_str());
23 mkdir(stundoredo.c_str(),755);
25 stundoredo += "/cont";
31 KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images){
34 /**THIS ALL SHOULD BE IN AN OTHER LIB CALLED PERSISTANCE
39 stundoredo = "data/temp";
42 _contourPropagation = NULL;
44 mkdir(stundoredo.c_str());
46 mkdir(stundoredo.c_str(),755);
48 stundoredo += "/cont";
52 setVectImages(images);
53 initializeEnvironment();
56 KernelManagerContour::~KernelManagerContour(){
59 std::vector<vtkImageData*> KernelManagerContour::getVectImages(){
62 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg){
64 for(int i = 0; i < vectimg.size(); i++){
65 vtkImageData* img = vectimg[i];
66 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
67 change->SetInformationInput(img);
68 change->SetInputConnection(img->GetProducerPort());
70 change->SetOutputSpacing(0.6,0.6,0.6);
74 vectimg[i] = change->GetOutput();
80 void KernelManagerContour::initializeEnvironment(){
81 std::string conceptsFN = "data/holaConceptsFile.cf";
82 std::string imageSourcesFN = "data/holaImagesInstantsFile.of";
83 std::string imageSectionsFN = "";
84 std::string axeThingsFN = "";
86 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
87 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
88 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
89 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
91 for(int i = 0; i < vectimages.size(); i++){
92 vtkImageData* selectedimage = vectimages[i];
93 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
94 std::string imgstring = "Source Image "+intToString(i+1);
95 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
99 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN );
100 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
101 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
102 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
103 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
105 //Creating the objects to manage
106 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
108 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
111 vtkImageData* KernelManagerContour::getSourceImage(){
112 return imageSource->getSourceImage();
114 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
118 std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector<int> instantVector){
119 return modelManager->createOutline( manModelContour, instantVector );
122 std::string KernelManagerContour::intToString(int num){
129 char temp = k % 10 + 48;
131 result = temp + result;
137 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
138 return modelManager->GetLstNameThingsStatic();
141 void KernelManagerContour::SaveThingName(FILE* pFile, std::string name ){
142 modelManager->SaveThingName(pFile, name);
144 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
145 return modelManager->GetLstNameThings();
147 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
148 // return modelManager->IsPartOfStaticList(keyName);
151 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
152 return modelManager->IsPartOfStaticList(theKeyName) == -1;
155 void KernelManagerContour::deleteCModel(std::string theKeyName){
156 manualContourModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
157 modelManager->removeOutline( theKeyName );
162 void KernelManagerContour::removeAllOutlines(){
163 modelManager->removeAllOutlines();
166 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
167 return modelManager->getActualInstantOutlines();
170 int KernelManagerContour::getNamesWrappingSize(){
171 return getActualInstantOutlines().size();
174 std::string KernelManagerContour::getNameWrapping(int i){
175 return getActualInstantOutlines()[i]->getKeyName();
178 void KernelManagerContour::setInstant(Instant * theInstant){
179 modelManager->setInstant(theInstant);
180 //_actualInstant = theInstant;
183 Instant * KernelManagerContour::getCurrentInstant(){
184 return modelManager->getInstant();
186 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
187 Instant* act = new Instant ( &vectInstant );
188 modelManager->setInstant(act);
191 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData){
192 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
194 manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
195 return modelManager->getOutlineByKeyName (cloneName )->getModel();
198 bool KernelManagerContour::onRedo(std::string& filename){
202 std::string str = intToString(inundo);
203 filename = stundoredo + str + ".roi";
210 bool KernelManagerContour::onUndo(std::string& filename){
216 //itoa(inundo, str, 10);
217 std::string str = intToString(inundo);
220 filename = stundoredo + str + ".roi";
222 return true;//loadState(temp);
227 std::string KernelManagerContour::saveState(){
229 std::string str = intToString(inundo);
230 std::string temp = stundoredo + str + ".roi";
235 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
240 //itoa(inundo, str, 10);
241 std::string str = intToString(inundo);
243 filename = stundoredo + str + ".roi";
245 //saveFileWithContours(temp);
252 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
254 modelManager->ChangeContourOfList(keyName, instant);
257 void KernelManagerContour ::resetAppend(){
258 if(isInitContourPropagation()){
259 _contourPropagation->resetAppend();
263 bool KernelManagerContour::isInitContourPropagation(){
264 if(_contourPropagation == NULL){
265 _contourPropagation = new ContourPropagation();
273 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
274 if(isInitContourPropagation()){
275 if (vecX->size()!=0){
277 int i,size=vecZ->size();
278 int actualSlice = instants[1];
279 for ( i=0 ; i<size ; i++ )
281 (*vecZ)[i] = actualSlice;
284 _contourPropagation->appendContour(vecX , vecY , vecZ);
285 return intToString(actualSlice);
291 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ){
292 if(isInitContourPropagation()){
293 _contourPropagation->getMaxMinZ(minZ, maxZ);
296 void KernelManagerContour::CalculeSplinePropagation(){
297 _contourPropagation->setInterpolationNumber(100);
298 _contourPropagation->CalculeSplinePropagation();
301 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){
304 bool addedModel = false;
305 manualContourModel* manModelContour=NULL;
307 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
309 manModelContour = factoryManualContourModel( typeofcontour );
311 int idTmp = _contourPropagation->FindIdWithZ(z);
313 if (type==0) // Initial Points
315 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
317 if (type==1) // Automatique Method
319 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
321 if (type==2) // sampling
323 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
325 //--------------------------------------------------------------------
326 int sizeCtrPt = vecCtrlPointX->size();
327 for (int j=0 ; j<sizeCtrPt ; j++)
329 //JSTG_16-07-08_----------------------------------------------------------------
330 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
331 //--------------------------------------------------------------------
335 theName = modelManager->createOutline( manModelContour, tempVector );
336 addedModel = theName.compare("") != 0;
338 manModelContour = NULL;
341 }// ifSliceKeyContourExist
342 return manModelContour;
346 manualContourModel * KernelManagerContour::factoryManualContourModel(int typeContour)
348 manualContourModel *manModelContour=NULL;
353 manModelContour = new manualContourModel();
359 manModelContour = new manualContourModel();
365 manModelContour = new manualContourModelRoi();
371 manModelContour = new manualContourModelCircle();
374 return manModelContour;
377 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
378 Instant instant(&tempvector);
379 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
380 std::vector<std::string> vectname;
381 for(int i = 0; i < vectcont.size(); i++){
382 ContourThing **contourthing = vectcont[i];
383 vectname.push_back((*contourthing)->getName());
388 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
389 return modelManager->getOutlinesAtInstant(instant);
392 std::vector<manualContourModel*> KernelManagerContour::ExploseEachModel( std::vector<manualContourModel*> lstManConMod ){
393 std::vector<manualContourModel*> lstTmp;
394 std::vector<manualContourModel*> lstResult;
396 int i,iSize=lstManConMod.size();
397 for (i=0;i<iSize;i++)
399 lstTmp = lstManConMod[i]->ExploseModel();
401 for (j=0;j<jSize;j++)
403 lstResult.push_back( lstTmp[j] );
409 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
410 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
414 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
415 int index = inst[5]-1;
417 if(index < vectimages.size()&&index!=_currentIndex){
419 return vectimages[index];
424 std::string KernelManagerContour::getCurrentFileName(){
428 void KernelManagerContour::setCurrentFileName(std::string filenam){
429 this->filename = filenam;