00001
00002
00003
00004
00005 #include "OutlineModelManager.h"
00006
00007
00008
00009
00012
00013
00014
00015
00016
00017
00018 OutlineModelManager :: OutlineModelManager( SomeEnvironment<ImageSourceThing *> *imSourceEnv, SomeEnvironment<ImageSectionThing *> *imSectionEnv, SomeEnvironment<AxeThing *> *axesEnv, SomeEnvironment<ContourThing *> *contourEnv )
00019 {
00020 actualInstant = NULL;
00021 imageSourceEnvironment = imSourceEnv;
00022 imagesSectionEnvironment = imSectionEnv;
00023 axesEnvironment = axesEnv;
00024 outlinesEnvironment = contourEnv;
00025
00026 workSpace = new ContourWorkspace(this);
00027 keyGenerator = * new PrefixMaxKeyGenerator();
00028 counterIdKey = 0;
00029
00030 actualInstantWrapping = new InstantMembersNameList();
00031 changeSourceImage = true;
00032
00033 bool allOK = keyGenerator.addKeyThing("Axes", "Axe");
00034 allOK &= keyGenerator.addKeyThing("Image Sources", "Image source");
00035 allOK &= keyGenerator.addKeyThing("Image Sections", "Image section");
00036 allOK &= keyGenerator.addKeyThing("Outlines", "Outline");
00037
00038 }
00039
00040
00041
00042
00043 OutlineModelManager :: ~OutlineModelManager()
00044 {
00045 clean();
00046 delete actualInstant;
00047 delete workSpace;
00048 delete actualInstantWrapping;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 ContourWorkspace * OutlineModelManager :: createWorkSpace()
00061 {
00062 workSpace = new ContourWorkspace(this);
00063 return workSpace;
00064 }
00065
00066
00067
00068
00069
00070 void OutlineModelManager :: setWorkSpace( ContourWorkspace * aWorkSpace )
00071 {
00072 workSpace = aWorkSpace;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082 bool OutlineModelManager :: executeCommand_OutlineModel(std::string outKName, CommandObject * theCommand, bool fromRegistration)
00083 {
00084 ContourThing * theOutline = *outlinesEnvironment->getThingByName( outKName );
00085 if(!fromRegistration)
00086 {
00087 CommandObject * undoCommand = theOutline->getUndoCommandOf( theCommand );
00088 workSpace->callRegisterCommand(theCommand, undoCommand);
00089 }
00090 return theOutline->executeCommand( theCommand );
00091 }
00092
00093
00094
00095
00096
00097
00098 bool OutlineModelManager :: executeCommand(CommandObject * theCommand, bool fromRegistration)
00099 {
00100 bool executedCom = true;
00101
00102
00103
00104
00105
00106
00107
00108 return executedCom;
00109 }
00110
00111
00112
00113
00114
00115
00116 bool OutlineModelManager :: executeCommandsQueue(std::deque<CommandObject *> executionQueue, bool fromRegistration)
00117 {
00118 bool executedComs = executionQueue.size()>0 ? true : false;
00119 while( executionQueue.size()>0 )
00120 {
00121 CommandObject * aCmmand = executionQueue.front();
00122 executedComs &= executeCommand(aCmmand, fromRegistration);
00123 executionQueue.pop_front();
00124 }
00125 return executedComs;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 bool OutlineModelManager :: setUserConcepts(std::string conceptsScript)
00135 {
00136 bool allOK = true;
00137 int endSub;
00138 std::string::size_type equalIndex = conceptsScript.find("=", 0);
00139 std::string::size_type nextIndex = 0;
00140 while( equalIndex != std::string::npos && allOK)
00141 {
00142 endSub = equalIndex;
00143 std::string concept = conceptsScript.substr( 0, endSub );
00144 conceptsScript.erase( 0, endSub+1 );
00145 std::cout << "C: " << concept <<std::endl;
00146 nextIndex = conceptsScript.find(";", 0);
00147 std::string cSize;
00148 if(nextIndex != std::string::npos)
00149 {
00150 endSub = nextIndex;
00151 cSize = conceptsScript.substr( 0, endSub );
00152 conceptsScript.erase( 0, endSub+1 );
00153 }
00154 else
00155 {
00156 endSub = conceptsScript.size();
00157 cSize = conceptsScript.substr( 0, endSub );
00158 conceptsScript.erase( 0, endSub );
00159 }
00160 int intReturn = atoi(cSize.c_str());
00161 std::cout << "SZ: "<<intReturn <<std::endl;
00162 equalIndex = conceptsScript.find("=", 0);
00163 if( intReturn>0 )
00164 allOK &= addUserConcept(concept, intReturn);
00165 else
00166 allOK = false;
00167 }
00168 return allOK;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 bool OutlineModelManager :: addUserConcept(std::string theConceptName, int conceptSize)
00178 {
00179 bool allOK = axesEnvironment->addConcept(theConceptName, conceptSize);
00180 allOK &= imagesSectionEnvironment->addConcept(theConceptName, conceptSize);
00181 allOK &= imageSourceEnvironment->addConcept(theConceptName, conceptSize);
00182 allOK &= outlinesEnvironment->addConcept(theConceptName, conceptSize);
00183 return allOK;
00184 }
00185
00192 std::vector<NameWrapper *> OutlineModelManager :: getActualInstantOutlines ()
00193 {
00194 return actualInstantWrapping->getOutlinesNamesVector();
00195 }
00196
00197
00198 void OutlineModelManager :: ChangeContourOfList(std::string keyName, Instant *instant)
00199 {
00200 int ispartofstaticlist = IsPartOfStaticList(keyName);
00201 if (ispartofstaticlist==-1)
00202 {
00203 staticContourLst.push_back( this->outlinesEnvironment->getThingByName(keyName) );
00204 this->outlinesEnvironment->removeThingFromInstant(keyName, instant);
00205 } else {
00206 ContourThing **contourthing = staticContourLst[ispartofstaticlist];
00207 this->outlinesEnvironment->addInstantToThing ( keyName , instant );
00208 staticContourLst.erase( staticContourLst.begin()+ispartofstaticlist );
00209 }
00210 }
00211
00212
00219 std::vector<ContourThing**> OutlineModelManager :: getOutlinesAtInstant(Instant * anInstant, bool ifAnnotate)
00220 {
00221 std::vector<std::string> kNamesVector;
00222 std::vector<ContourThing **> outlinesVector;
00223 outlinesEnvironment->getThings( kNamesVector, outlinesVector, anInstant);
00224
00225
00226 int i,sizeStaticContourLst = staticContourLst.size();
00227 for ( i=0 ; i<sizeStaticContourLst ; i++ )
00228 {
00229 ContourThing **contourthing = staticContourLst[i];
00230 outlinesVector.push_back( contourthing );
00231 kNamesVector.push_back( (*contourthing)->getName() );
00232 }
00233
00234 if (ifAnnotate)
00235 {
00236 annotateOutlinesWrap(kNamesVector, outlinesVector);
00237 }
00238 return outlinesVector;
00239 }
00240
00241
00242 std::vector<std::string> OutlineModelManager :: GetLstNameThingsStatic()
00243 {
00244 std::vector<std::string> result;
00245 int i,sizeStaticContourLst = staticContourLst.size();
00246 for ( i=0 ; i<sizeStaticContourLst ; i++ )
00247 {
00248 ContourThing **contourthing = staticContourLst[i];
00249 result.push_back( (*contourthing)->getName() );
00250 }
00251 return result;
00252 }
00253
00254 std::vector<std::string> OutlineModelManager :: GetLstNameThings()
00255 {
00256 std::vector<std::string> kNamesVector;
00257 std::vector<ContourThing **> outlinesVector;
00258 std::vector<Instant *> lstInstants = getOutlineInstants();
00259 int i,sizeLstInstants = lstInstants.size();
00260 Instant *instant;
00261 for ( i=0 ; i<sizeLstInstants ; i++ )
00262 {
00263 instant = lstInstants[i];
00264 outlinesEnvironment->getThings( kNamesVector, outlinesVector, instant);
00265 }
00266 return kNamesVector;
00267 }
00268
00269
00275 std::vector<ContourThing*> OutlineModelManager :: getOutlinesFromGroup(std::string aGroupName)
00276 {
00277 std::vector<ContourThing *> outlinesVector;
00278 std::map< std::string,OutlineGroup * >::iterator iterP = outlineGroups.find(aGroupName);
00279 if ( iterP != outlineGroups.end() )
00280 {
00281 std::vector<std::string> kNamesVector = iterP->second->getGroupOutlinesNames();
00282 for(int i=0; i<kNamesVector.size();i++)
00283 {
00284 ContourThing * outlineI = getOutlineByKeyName(kNamesVector[i]);
00285 outlinesVector.push_back(outlineI);
00286 }
00287 }
00288 return outlinesVector;
00289 }
00290
00296 bool OutlineModelManager :: addOutlinesGroup( std::string theOutlineName, OutlineGroup * theGroup )
00297 {
00298 outlineGroups.insert(std::pair <std::string, OutlineGroup *> ( theOutlineName, theGroup ));
00299
00300 std::map<std::string, OutlineGroup *> :: iterator iter;
00301 iter = outlineGroups.find( theOutlineName );
00302 bool ifAdded = iter->first.compare( theOutlineName ) == 0;
00303 return ifAdded;
00304 }
00305
00306
00307
00308
00309
00310 ContourThing* OutlineModelManager :: getOutlineByKeyName(std::string outKName)
00311 {
00312 return *(outlinesEnvironment->getThingByName(outKName));
00313 }
00314
00315
00316
00317
00318
00319
00320 ImageSourceThing* OutlineModelManager ::getImageSourceThingByKeyName(std::string iSeourceKName)
00321 {
00322 return *(imageSourceEnvironment->getThingByName(iSeourceKName));
00323 }
00324
00325
00326
00327
00328
00329
00330 ImageSectionThing* OutlineModelManager ::getImageSectionThingByKeyName(std::string iSectionName)
00331 {
00332 return *(imagesSectionEnvironment->getThingByName(iSectionName));
00333 }
00334
00335
00336
00337
00338
00339
00340
00341 std::string OutlineModelManager :: createOutline(manualBaseModel * model, std::vector<int> theInstantData, std::string aName)
00342 {
00343 ContourThing * theOutline = new ContourThing ( model );
00344 theOutline->setName(aName);
00345 return addOutline( theOutline, new Instant( &theInstantData ) );
00346 }
00347
00348
00349
00350
00351
00352
00353
00354 bool OutlineModelManager :: createAxe(std::string aDescription, Instant * theInstantData)
00355 {
00356 AxeThing * theAxe = new AxeThing ();
00357 theAxe->setDescription(aDescription);
00358 return addAxe(theAxe, theInstantData);
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 bool OutlineModelManager :: createImageSource(std::string aSource, Instant * theInstantData)
00368 {
00369
00370
00371 return NULL;
00372 }
00373
00374
00375
00376
00377
00378
00379
00380 bool OutlineModelManager :: createImageSection(std::string aSecImageData, Instant * theInstantData)
00381 {
00382
00383
00384 return NULL;
00385 }
00386
00387
00388
00389
00390
00391
00392
00393 std::string OutlineModelManager :: addOutline( ContourThing * theOutline, Instant * theInstantData)
00394 {
00395 std::string kName;
00396
00397
00398
00399
00400 counterIdKey++;
00401 bool added = keyGenerator.generateKeyOf( "Outlines", counterIdKey , kName );
00402
00403 if( theOutline->getName().compare("")==0 )
00404 {
00405 theOutline->setName(kName);
00406 }
00407 added &= outlinesEnvironment->addThingWithInstant(kName,theOutline, theInstantData);
00408 if( added )
00409 return kName;
00410 else
00411 return "";
00412 }
00413
00414
00415 int OutlineModelManager::IsPartOfStaticList(std::string ss)
00416 {
00417 int iBack=-1;
00418 int i, size = staticContourLst.size();
00419 for( i=0 ; i<size ; i++ )
00420 {
00421 ContourThing **contourthing = staticContourLst[i];
00422 if ((*contourthing)->getName() == ss)
00423 {
00424 iBack=i;
00425 }
00426 }
00427 return iBack;
00428 }
00429
00430
00431
00432
00433
00434
00435 void OutlineModelManager :: removeOutline( std::string ss )
00436 {
00437 outlinesEnvironment->removeThing( ss );
00438 }
00439
00440
00441 void OutlineModelManager :: removeAllOutlines()
00442 {
00443
00444 staticContourLst.clear();
00445
00446
00447 std::vector< ContourThing **> thingsVector;
00448 outlinesEnvironment->getThingsOfEnvironment( &thingsVector );
00449 int i,sizeThingVector = thingsVector.size();
00450 for(i=0;i<sizeThingVector;i++)
00451 {
00452 ContourThing ** contourthing = thingsVector[i];
00453 removeOutline( (*contourthing)->getName() );
00454 }
00455 }
00456
00457
00458
00459
00460
00461
00462
00463
00464 bool OutlineModelManager :: addAxe( AxeThing * theAxe , Instant * theInstantData)
00465 {
00466 std::string kName;
00467 bool added = keyGenerator.generateKeyOf("Axes", axesEnvironment->getNumberOfThings(),kName);
00468 added &= axesEnvironment->addThingWithInstant(kName,theAxe, theInstantData);
00469 return added;
00470 }
00471
00472
00473
00474
00475
00476
00477
00478 bool OutlineModelManager :: addImageSource(ImageSourceThing * imageSource, Instant * theInstantData)
00479 {
00480 std::string kName;
00481 bool added = keyGenerator.generateKeyOf("Image Sources", imageSourceEnvironment->getNumberOfThings(),kName);
00482 added &= imageSourceEnvironment->addThingWithInstant(kName,imageSource, theInstantData );
00483 return added;
00484 }
00485
00486
00487
00488
00489
00490
00491
00492 bool OutlineModelManager :: addImageSection(ImageSectionThing * imageSection, Instant * theInstantData)
00493 {
00494 std::string kName;
00495 bool added = keyGenerator.generateKeyOf("Image Sections", imagesSectionEnvironment->getNumberOfThings(),kName);
00496 added &= imagesSectionEnvironment->addThingWithInstant(kName, imageSection, theInstantData);
00497 return added;
00498 }
00499
00500
00501
00502
00503
00504
00505 void OutlineModelManager :: annotateOutlineWrap(std::string kOutlineName, std::string theRealName)
00506 {
00507 actualInstantWrapping -> addOutlineName(kOutlineName, theRealName);
00508 }
00509
00510
00511
00512
00513
00514
00515 void OutlineModelManager :: annotateOutlinesWrap(std::vector<std::string> kNamesVector, std::vector<ContourThing **> theOutlinesVector)
00516 {
00517 actualInstantWrapping ->clean();
00518 for(int i=0; i<kNamesVector.size(); i++)
00519 {
00520 ContourThing * anOutline = *theOutlinesVector[i];
00521 actualInstantWrapping -> addOutlineName( kNamesVector[i], anOutline->getName() );
00522 }
00523 }
00524
00525
00526
00527
00528
00529
00530 void OutlineModelManager :: annotateActualOutlineWrap(std::string actualKeyOutline, std::string theRealName)
00531 {
00532 actualInstantWrapping -> setActualOutline(actualKeyOutline, theRealName);
00533 }
00534
00535
00536
00537
00538
00539
00540 void OutlineModelManager :: annotateActualAxeWrap(std::string actualKeyAxe, std::string theRealName)
00541 {
00542 actualInstantWrapping -> setActualAxeWrap(actualKeyAxe, theRealName);
00543 }
00544
00545
00546
00547
00548
00549
00550 void OutlineModelManager :: annotateActualSectionImageWrap(std::string actualKeyImage, std::string theRealName)
00551 {
00552 actualInstantWrapping -> setActualSectionImageNamesWrapp(actualKeyImage, theRealName);
00553 }
00554
00555
00556
00557
00558
00559
00560 void OutlineModelManager :: annotateActualSourceImageWrap(std::string actualKeyImage, std::string theRealName)
00561 {
00562 actualInstantWrapping -> setActualSourceImageNamesWrapp(actualKeyImage, theRealName);
00563 }
00564
00565
00566
00567
00568
00569
00570 void OutlineModelManager :: setInstant(Instant * newActualInstantData)
00571 {
00572 actualInstant = newActualInstantData;
00573 updateToActualInstant();
00574 }
00575
00576 Instant* OutlineModelManager :: getInstant()
00577 {
00578 return actualInstant;
00579 }
00580
00581
00582
00583
00584
00585
00586 AxeThing * OutlineModelManager :: getAxeByKeyName(std::string axeKName)
00587 {
00588 return *axesEnvironment->getThingByName(axeKName);
00589 }
00590
00591
00592
00593
00594
00595
00596 std::vector<Instant *> OutlineModelManager :: getOutlineInstantsByName(std::string thekName)
00597 {
00598 return *outlinesEnvironment->getInstantsOfThing(thekName);
00599 }
00600
00601
00602
00603
00604
00605 std::vector<Instant *> OutlineModelManager :: getOutlineInstants()
00606 {
00607 return *outlinesEnvironment->getExistingInstants();
00608 }
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 bool OutlineModelManager :: includeOutlineInstant(std::string outKName,Instant * anInstantData)
00619 {
00620 return outlinesEnvironment->addInstantToThing(outKName,anInstantData);
00621 }
00622
00623
00624
00625
00626
00627
00628
00629 bool OutlineModelManager :: includeAxeInstant(std::string axeKName,Instant * anInstantData)
00630 {
00631 return axesEnvironment->addInstantToThing( axeKName,anInstantData );
00632 }
00633
00634
00635
00636
00637
00638
00639
00640 bool OutlineModelManager :: includeImageSectionInstant(std::string imaKName,Instant * anInstantData)
00641 {
00642 return imagesSectionEnvironment->addInstantToThing( imaKName,anInstantData );
00643 }
00644
00645
00646
00647
00648
00649
00650
00651 bool OutlineModelManager :: includeImageSourceInstant(std::string imaKName,Instant * anInstantData)
00652 {
00653 return imageSourceEnvironment->addInstantToThing( imaKName,anInstantData );
00654 }
00655
00656
00657
00658
00659
00660
00661 void OutlineModelManager :: getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect)
00662 {
00663 if( outlinesEnvironment != NULL )
00664 {
00665
00666 outlinesEnvironment->getConceptsInformation(conceptNameVect, conceptSizeVect);
00667 }
00668 }
00669
00670
00671
00672
00673
00674
00675 ContourWorkspace * OutlineModelManager :: getContourWorkspace()
00676 {
00677 return workSpace;
00678 }
00679
00680
00681
00682
00683
00684 void OutlineModelManager :: clean()
00685 {
00686
00687
00688
00689
00690 outlineGroups.clear();
00691 actualInstantWrapping->clean();
00692 keyGenerator.clear();
00693
00694 }
00695
00696
00697
00698
00699 void OutlineModelManager :: updateToActualInstant()
00700 {
00701 Instant * longInstant = actualInstant;
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 std::vector<ContourThing ** > vect = getOutlinesAtInstant( longInstant );
00735
00736 }
00737
00738
00739
00740
00741
00742 bool OutlineModelManager :: setAutomaticConcepts()
00743 {
00744 axeConcept = "Axe";
00745 axeDepthConcept = "Axe Depth";
00746 int axeC_size = 10;
00747 int axeDepthC_size = INT_MAX;
00748
00749 bool allOK = axesEnvironment->addConcept(axeConcept, axeC_size);
00750 allOK &= imagesSectionEnvironment->addConcept(axeConcept, axeC_size);
00751 allOK &= outlinesEnvironment->addConcept(axeConcept, axeC_size);
00752
00753 allOK &= imagesSectionEnvironment->addConcept(axeDepthConcept, axeDepthC_size);
00754 allOK &= outlinesEnvironment->addConcept(axeDepthConcept, axeDepthC_size);
00755
00756
00757
00758
00759
00760
00761 return allOK;
00762 }
00763
00764
00765 std::string OutlineModelManager :: createCopyContourOf( std::string anExistingKName, std::vector<int> &instantNoTouchData )
00766 {
00767 manualBaseModel * manModelContour = getOutlineByKeyName( anExistingKName )->getModel()->Clone();
00768 return createOutline( manModelContour, instantNoTouchData );
00769 }
00770
00771 void OutlineModelManager::SaveThingName( FILE *pFile, FILE *pFileData, std::string nameThing )
00772 {
00773 std::vector< Instant * > *lstInstants;
00774 lstInstants = outlinesEnvironment->getInstantsOfThing( nameThing );
00775 Instant *instant = (*lstInstants)[0];
00776 std::vector<int> *vecInst =instant->getInstant();
00777 int i,sizeVecInst = vecInst->size();
00778 fprintf(pFile,"Instant ");
00779 for ( i=0 ; i<sizeVecInst ; i++ )
00780 {
00781 fprintf(pFile,"%d ",(*vecInst)[i]);
00782 }
00783 fprintf(pFile,"\n");
00784 ContourThing *contourthing = *outlinesEnvironment->getThingByName(nameThing);
00785 contourthing->getModel()->Save(pFile);
00786 contourthing->getModel()->SaveData(pFileData);
00787 }
00788