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){
66 void KernelManagerContour::initializeEnvironment(){
67 std::string conceptsFN = "data/holaConceptsFile.cf";
68 std::string imageSourcesFN = "data/holaImagesInstantsFile.of";
69 std::string imageSectionsFN = "";
70 std::string axeThingsFN = "";
72 std::map<std::string, ImageSourceThing *> * sourcesMap = new std::map<std::string, ImageSourceThing *>();
73 std::map<std::string, ImageSectionThing *>* sectionsMap = new std::map<std::string, ImageSectionThing *>();
74 std::map<std::string, AxeThing *>* axesMap = new std::map<std::string, AxeThing *>();
75 std::map<std::string, ContourThing *>* outlinesMap = new std::map<std::string, ContourThing *>();
77 for(int i = 0; i < vectimages.size(); i++){
78 vtkImageData* selectedimage = vectimages[i];
79 ImageSourceThing * thing = new ImageSourceThing(selectedimage);
80 std::string imgstring = "Source Image "+intToString(i+1);
81 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
85 OutlineModelBuilder * _builder = new OutlineModelBuilder( conceptsFN );
86 _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
87 _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
88 _builder->buildAxe_Envornment(axeThingsFN, axesMap );
89 _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
91 //Creating the objects to manage
92 modelManager = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv() );
94 imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
97 vtkImageData* KernelManagerContour::getSourceImage(){
98 return imageSource->getSourceImage();
100 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
104 std::string KernelManagerContour::createOutline(manualContourModel * manModelContour,std::vector<int> instantVector){
105 return modelManager->createOutline( manModelContour, instantVector );
108 std::string KernelManagerContour::intToString(int num){
115 char temp = k % 10 + 48;
117 result = temp + result;
123 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
124 return modelManager->GetLstNameThingsStatic();
127 void KernelManagerContour::SaveThingName(FILE* pFile, std::string name ){
128 modelManager->SaveThingName(pFile, name);
130 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
131 return modelManager->GetLstNameThings();
133 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
134 // return modelManager->IsPartOfStaticList(keyName);
137 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
138 return modelManager->IsPartOfStaticList(theKeyName) == -1;
141 void KernelManagerContour::deleteCModel(std::string theKeyName){
142 manualContourModel* cModel = modelManager->getOutlineByKeyName(theKeyName)->getModel();
143 modelManager->removeOutline( theKeyName );
148 void KernelManagerContour::removeAllOutlines(){
149 modelManager->removeAllOutlines();
152 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
153 return modelManager->getActualInstantOutlines();
156 int KernelManagerContour::getNamesWrappingSize(){
157 return getActualInstantOutlines().size();
160 std::string KernelManagerContour::getNameWrapping(int i){
161 return getActualInstantOutlines()[i]->getKeyName();
164 void KernelManagerContour::setInstant(Instant * theInstant){
165 modelManager->setInstant(theInstant);
166 //_actualInstant = theInstant;
169 Instant * KernelManagerContour::getCurrentInstant(){
170 return modelManager->getInstant();
172 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
173 Instant* act = new Instant ( &vectInstant );
174 modelManager->setInstant(act);
177 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData){
178 return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
180 manualContourModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName){
181 return modelManager->getOutlineByKeyName (cloneName )->getModel();
184 bool KernelManagerContour::onRedo(std::string& filename){
188 std::string str = intToString(inundo);
189 filename = stundoredo + str + ".roi";
196 bool KernelManagerContour::onUndo(std::string& filename){
202 //itoa(inundo, str, 10);
203 std::string str = intToString(inundo);
206 filename = stundoredo + str + ".roi";
208 return true;//loadState(temp);
213 std::string KernelManagerContour::saveState(){
215 std::string str = intToString(inundo);
216 std::string temp = stundoredo + str + ".roi";
221 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
226 //itoa(inundo, str, 10);
227 std::string str = intToString(inundo);
229 filename = stundoredo + str + ".roi";
231 //saveFileWithContours(temp);
238 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
240 modelManager->ChangeContourOfList(keyName, instant);
243 void KernelManagerContour ::resetAppend(){
244 if(isInitContourPropagation()){
245 _contourPropagation->resetAppend();
249 bool KernelManagerContour::isInitContourPropagation(){
250 if(_contourPropagation == NULL){
251 _contourPropagation = new ContourPropagation();
259 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants){
260 if(isInitContourPropagation()){
261 if (vecX->size()!=0){
263 int i,size=vecZ->size();
264 int actualSlice = instants[1];
265 for ( i=0 ; i<size ; i++ )
267 (*vecZ)[i] = actualSlice;
270 _contourPropagation->appendContour(vecX , vecY , vecZ);
271 return intToString(actualSlice);
277 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ){
278 if(isInitContourPropagation()){
279 _contourPropagation->getMaxMinZ(minZ, maxZ);
282 void KernelManagerContour::CalculeSplinePropagation(){
283 _contourPropagation->setInterpolationNumber(100);
284 _contourPropagation->CalculeSplinePropagation();
287 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){
290 bool addedModel = false;
291 manualContourModel* manModelContour=NULL;
293 if (_contourPropagation->ifSliceKeyContourExist(z)==false){
295 manModelContour = factoryManualContourModel( typeofcontour );
297 int idTmp = _contourPropagation->FindIdWithZ(z);
299 if (type==0) // Initial Points
301 _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
303 if (type==1) // Automatique Method
305 _contourPropagation->GetControlPoints( idTmp ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
307 if (type==2) // sampling
309 _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
311 //--------------------------------------------------------------------
312 int sizeCtrPt = vecCtrlPointX->size();
313 for (int j=0 ; j<sizeCtrPt ; j++)
315 //JSTG_16-07-08_----------------------------------------------------------------
316 manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900 );
317 //--------------------------------------------------------------------
321 theName = modelManager->createOutline( manModelContour, tempVector );
322 addedModel = theName.compare("") != 0;
324 manModelContour = NULL;
327 }// ifSliceKeyContourExist
328 return manModelContour;
332 manualContourModel * KernelManagerContour::factoryManualContourModel(int typeContour)
334 manualContourModel *manModelContour=NULL;
339 manModelContour = new manualContourModel();
345 manModelContour = new manualContourModel();
351 manModelContour = new manualContourModelRoi();
357 manModelContour = new manualContourModelCircle();
360 return manModelContour;
363 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
364 Instant instant(&tempvector);
365 std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
366 std::vector<std::string> vectname;
367 for(int i = 0; i < vectcont.size(); i++){
368 ContourThing **contourthing = vectcont[i];
369 vectname.push_back((*contourthing)->getName());
374 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
375 return modelManager->getOutlinesAtInstant(instant);
378 std::vector<manualContourModel*> KernelManagerContour::ExploseEachModel( std::vector<manualContourModel*> lstManConMod ){
379 std::vector<manualContourModel*> lstTmp;
380 std::vector<manualContourModel*> lstResult;
382 int i,iSize=lstManConMod.size();
383 for (i=0;i<iSize;i++)
385 lstTmp = lstManConMod[i]->ExploseModel();
387 for (j=0;j<jSize;j++)
389 lstResult.push_back( lstTmp[j] );
395 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
396 modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
400 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
401 int index = inst[5]-1;
403 if(index < vectimages.size()&&index!=_currentIndex){
405 return vectimages[index];