KernelManagerContour.cxx

Go to the documentation of this file.
00001 
00002 //----------------------------------------------------------------------------------------------------------------
00003 // Class definition include
00004 //----------------------------------------------------------------------------------------------------------------
00005 #include "KernelManagerContour.h"
00006 
00007 
00008 KernelManagerContour::KernelManagerContour(){
00009 
00010 
00014         inredo = 0;
00015         inundo = 0;
00016 
00017         time_t seconds;
00018         seconds = time (NULL);
00019         int time = seconds;
00020 
00021 
00022         stundoredo = "data/temp"+intToString(time);
00023         _currentIndex = 0;
00024 
00025         _contourPropagation = NULL;
00026 #if(WIN32)
00027                 mkdir(stundoredo.c_str());
00028 #else
00029                 mkdir(stundoredo.c_str(),755);
00030 #endif
00031         stundoredo += "/cont";
00036 }
00037 KernelManagerContour::KernelManagerContour(std::vector<vtkImageData*> images,std::string datadir,std::string tmpdir)
00038 {
00039 
00040 
00044         inredo = 0;
00045         inundo = 0;
00046 
00047         time_t seconds;
00048         seconds = time (NULL);
00049         int time = seconds;
00050 
00051 
00052         stundoredo = tmpdir+"/temp"+intToString(time);
00053         _currentIndex = 0;
00054 
00055         _contourPropagation = NULL;
00056 #if(WIN32)
00057         mkdir(tmpdir.c_str());
00058         mkdir(stundoredo.c_str());
00059 #else
00060         mkdir(tmpdir.c_str(),755);
00061         mkdir(stundoredo.c_str(),755);
00062 #endif
00063         stundoredo += "/cont";
00067         setVectImages(images);        
00068         initializeEnvironment(datadir);
00069 
00070 }
00071 
00072 KernelManagerContour::~KernelManagerContour()
00073 {
00074 }
00075 
00076 std::vector<vtkImageData*> KernelManagerContour::getVectImages()
00077 {
00078         return vectimages;
00079 }
00080 
00081 
00082 void KernelManagerContour::setVectImages(std::vector<vtkImageData*> vectimg)
00083 {
00084         double spc[3];
00085         std::vector<double> vectspc;
00086         
00087         for(int i = 0; i < (int)(vectimg.size()); i++){
00088                 vtkImageData* img = vectimg[i];
00089                 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
00090                 change->SetInformationInput(img);
00091                 change->SetInputConnection(img->GetProducerPort());
00092 
00093                 img->GetSpacing(spc);
00094                 change->SetOutputSpacing(1,1,1);
00095                 change->Update();
00096 
00097                 vectspc.clear();
00098                 vectspc.push_back(spc[0]);
00099                 vectspc.push_back(spc[1]);
00100                 vectspc.push_back(spc[2]);
00101                 vectimagesSpacing.push_back(vectspc);
00102                 vectimg[i] = change->GetOutput();
00103         }
00104 
00105         vectimages = vectimg;
00106 }
00107 
00108 
00109 void KernelManagerContour::GetSpacing(double *vecspc, int iImage)
00110 {
00111         vecspc[0]=vectimagesSpacing[iImage][0];
00112         vecspc[1]=vectimagesSpacing[iImage][1];
00113         vecspc[2]=vectimagesSpacing[iImage][2];
00114 }
00115 
00116 
00117 void KernelManagerContour::initializeEnvironment(std::string datadir){
00118         _datadir = datadir;
00119         std::string conceptsFN                  =  datadir+"holaConceptsFile.cf";
00120         std::string imageSourcesFN              =  datadir+"holaImagesInstantsFile.of";
00121         std::string imageSectionsFN             = "";
00122         std::string axeThingsFN                 = "";
00123 
00124         std::map<std::string, ImageSourceThing *> * sourcesMap          = new std::map<std::string, ImageSourceThing *>();
00125         std::map<std::string, ImageSectionThing *>* sectionsMap         = new std::map<std::string, ImageSectionThing *>();
00126         std::map<std::string, AxeThing *>* axesMap                                      = new std::map<std::string, AxeThing *>();
00127         std::map<std::string, ContourThing *>* outlinesMap                      = new std::map<std::string, ContourThing *>();
00128 
00129         for(int i = 0; i < (int)(vectimages.size()); i++){
00130                 vtkImageData* selectedimage = vectimages[i];
00131                 ImageSourceThing * thing                                                                        = new ImageSourceThing(selectedimage);
00132                 std::string imgstring = "Source Image "+intToString(i+1);
00133                 sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( imgstring, thing));
00134         }
00135 
00136 
00137         OutlineModelBuilder * _builder                                                          = new OutlineModelBuilder( conceptsFN ,datadir);
00138         _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
00139         _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );
00140         _builder->buildAxe_Envornment(axeThingsFN, axesMap );
00141         _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
00142 
00143         //Creating the objects to manage
00144         modelManager                            = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv() );
00145 
00146         imageSource     = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
00147 
00148 }
00149 vtkImageData* KernelManagerContour::getSourceImage(){
00150         return imageSource->getSourceImage();
00151 }
00152 OutlineModelManager* KernelManagerContour::getOutlineModelManager(){
00153         return modelManager;
00154 }
00155 
00156 std::string KernelManagerContour::createOutline(manualBaseModel * manModelContour,std::vector<int> instantVector){
00157         return modelManager->createOutline( manModelContour, instantVector );
00158 }
00159 
00160 std::string KernelManagerContour::intToString(int num){
00161         std::string result;
00162         if(num == 0){
00163                 result = "0";
00164         }else{
00165                 int k=num;
00166                 while (k > 0){
00167                         char temp = k % 10 + 48;
00168                         k = k / 10;
00169                         result = temp + result;
00170                 }
00171         }
00172         return result;
00173 }
00174 
00175 std::vector<std::string> KernelManagerContour::GetLstNameThingsStatic(){
00176         return modelManager->GetLstNameThingsStatic();
00177 }
00178 
00179 void KernelManagerContour::SaveThingName(FILE* pFile, FILE *pFileData, std::string name ){
00180         modelManager->SaveThingName(pFile, pFileData, name);
00181 }
00182 std::vector<std::string> KernelManagerContour::GetLstNameThings(){
00183         return modelManager->GetLstNameThings();
00184 }
00185 //int KernelManagerContour::IsPartOfStaticList(std::string keyName ){
00186 //      return modelManager->IsPartOfStaticList(keyName);
00187 //}
00188 
00189 bool KernelManagerContour::IsPartOfStaticList(std::string theKeyName){
00190         return modelManager->IsPartOfStaticList(theKeyName) == -1;
00191 }
00192 
00193 void KernelManagerContour::deleteCModel(std::string theKeyName){
00194         manualBaseModel* cModel         = modelManager->getOutlineByKeyName(theKeyName)->getModel();
00195         modelManager->removeOutline( theKeyName );
00196 
00197         delete cModel;
00198 }
00199 
00200 void KernelManagerContour::removeAllOutlines(){
00201         modelManager->removeAllOutlines();
00202 }
00203 
00204 std::vector<NameWrapper *> KernelManagerContour::getActualInstantOutlines(){
00205         return modelManager->getActualInstantOutlines();
00206 }
00207 
00208 int KernelManagerContour::getNamesWrappingSize(){
00209         return getActualInstantOutlines().size();
00210 }
00211 
00212 std::string KernelManagerContour::getNameWrapping(int i){
00213         return getActualInstantOutlines()[i]->getKeyName();
00214 }
00215 
00216 void KernelManagerContour::setInstant(Instant * theInstant){
00217         modelManager->setInstant(theInstant);
00218         //_actualInstant = theInstant;
00219 }
00220 
00221 Instant * KernelManagerContour::getCurrentInstant(){
00222         return modelManager->getInstant();
00223 }
00224 void KernelManagerContour::setInstant(std::vector<int> vectInstant){
00225         Instant* act = new Instant ( &vectInstant );
00226         modelManager->setInstant(act);
00227 }
00228 
00229 std::string KernelManagerContour::createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData)
00230 {
00231         return modelManager->createCopyContourOf(anExistingKName, instantNoTouchData);
00232 }
00233 
00234 manualBaseModel* KernelManagerContour::getOutlineByKeyName(std::string cloneName)
00235 {
00236         return modelManager->getOutlineByKeyName (cloneName )->getModel();
00237 }
00238 
00239 bool KernelManagerContour::onRedo(std::string& filename){
00240         if(inredo > 0){
00241                 inredo--;
00242                 inundo++;
00243                 std::string str = intToString(inundo);
00244                 filename = stundoredo + str + ".roi";
00245                 //loadState(temp);
00246                 return true;
00247         }
00248         return false;
00249 }
00250 
00251 bool KernelManagerContour::onUndo(std::string& filename){
00252         if(inundo>0){
00253                 inredo++;
00254                 inundo--;
00255 
00256                 //char str[9000];
00257                 //itoa(inundo, str, 10);
00258                 std::string str = intToString(inundo);
00259 
00260 
00261                 filename = stundoredo + str + ".roi";
00262 
00263                 return true;//loadState(temp);
00264         }
00265         return false;
00266 }
00267 
00268 std::string KernelManagerContour::saveState(){
00269         inredo=0;
00270         std::string str = intToString(inundo);
00271         std::string temp = stundoredo + str + ".roi";
00272         inundo++;
00273         return temp;
00274 }
00275 
00276 bool KernelManagerContour::onUndoSaveFile(std::string& filename){
00277         if(inundo>0){
00278                 if(inredo==0){
00279 
00280                         //char str[9000];
00281                         //itoa(inundo, str, 10);
00282                         std::string str = intToString(inundo);
00283 
00284                         filename = stundoredo + str + ".roi";
00285                         return true;
00286                         //saveFileWithContours(temp);
00287 
00288                 }
00289         }
00290         return false;
00291 }
00292 
00293 void KernelManagerContour :: changeContourOfManager(std::string keyName, Instant *instant)
00294 {
00295         modelManager->ChangeContourOfList(keyName, instant);
00296 }
00297 
00298 void KernelManagerContour ::resetAppend()
00299 {
00300     if (_contourPropagation!=NULL)
00301         {
00302                 _contourPropagation->resetAppend();
00303         }
00304 }
00305 
00306 
00307 std::string KernelManagerContour::onSpreadAdd( std::vector<double> *vecX, std::vector<double> *vecY, std::vector<double> *vecZ, std::vector<int> instants)
00308 {
00309     if (_contourPropagation==NULL)
00310     {
00311                 _contourPropagation = new ContourPropagation();
00312     }
00313 
00314     if (vecX->size()!=0){
00315 
00316         int i,size=vecZ->size();
00317         int actualSlice = instants[1];
00318         for ( i=0 ; i<size ; i++ )
00319         {
00320             (*vecZ)[i] = actualSlice;
00321         } // for
00322 
00323         _contourPropagation->appendContour(vecX , vecY , vecZ);
00324         return intToString(actualSlice);
00325     }
00326         return "";
00327 }
00328 
00329 
00330 void KernelManagerContour::getMaxMinZ(double *minZ,double *maxZ)
00331 {
00332     if (_contourPropagation!=NULL)
00333         {
00334                 _contourPropagation->getMaxMinZ(minZ, maxZ);
00335         }
00336 }
00337 
00338 
00339 void KernelManagerContour::CalculeSplinePropagation()
00340 {
00341         _contourPropagation->setInterpolationNumber(100);
00342         _contourPropagation->CalculeSplinePropagation();
00343 }
00344 
00345 manualBaseModel* 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)
00346 {
00347         bool addedModel = false;
00348         manualBaseModel* manModelContour=NULL;
00349 
00350         if (_contourPropagation->ifSliceKeyContourExist(z)==false){
00351 
00352                 manModelContour = factoryManualContourModel( typeofcontour );
00353 
00354                 int idTmp = _contourPropagation->FindIdWithZ(z);
00355 
00356                 if (type==0) // Initial Points
00357                 {
00358                         _contourPropagation->GetInitialControlPoints( idTmp , vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
00359                 }
00360                 if (type==1)  // Automatique Method
00361                 {
00362                         _contourPropagation->GetControlPoints( idTmp  ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
00363                 }
00364                 if (type==2)  // sampling
00365                 {
00366                         _contourPropagation->GetControlPoints( idTmp , 20.0 ,vecCtrlPointX,vecCtrlPointY,vecCtrlPointZ);
00367                 }
00368 //--------------------------------------------------------------------
00369                 int sizeCtrPt = vecCtrlPointX->size();
00370                 for (int j=0 ; j<sizeCtrPt ; j++)
00371                 {
00372 //JSTG_16-07-08_----------------------------------------------------------------
00373                         manModelContour->AddPoint( (*vecCtrlPointX)[j] , (*vecCtrlPointY)[j] , -900  );
00374 //--------------------------------------------------------------------
00375                 } // for j
00376 
00377                 tempVector[1]=z;
00378                 theName = modelManager->createOutline( manModelContour, tempVector );
00379                 addedModel = theName.compare("") != 0;
00380                 if(!addedModel){
00381                         manModelContour = NULL;
00382                 }
00383 
00384         }// ifSliceKeyContourExist
00385         return manModelContour;
00386 }
00387 
00388 manualBaseModel * KernelManagerContour::factoryManualContourModel(int typeContour)
00389 {
00390         manualBaseModel *manModelContour=NULL;
00391 
00392         // Creating the model
00393         // NOTE: The view and the controler are created in the wxVtkBaseView_SceneManager class, configureViewControlTo method
00394 
00395         // spline
00396         if (typeContour==0)
00397         {
00398                 manModelContour = new manualContourModel();
00399         }
00400 
00401         // spline
00402         if (typeContour==1)
00403         {
00404                 manModelContour = new manualContourModel();
00405         }
00406 
00407         // rectangle
00408         if (typeContour==2)
00409         {
00410                 manModelContour = new manualContourModelRoi();
00411         }
00412 
00413         // circle
00414         if (typeContour==3)
00415         {
00416                 manModelContour = new manualContourModelCircle();
00417         }
00418 
00419         // line
00420         if (typeContour==6)
00421         {
00422                 manModelContour = new manualContourModelLine();
00423         }
00424 
00425         // points
00426         if (typeContour==7)
00427         {
00428                 manModelContour = new manualBaseModel();
00429         }
00430 
00431         // polygon
00432         if (typeContour==10)
00433         {
00434                 manModelContour = new manualContourModelPolygon();
00435         }
00436 
00437         return manModelContour;
00438 }
00439 
00440 std::vector<std::string> KernelManagerContour::getOutlinesNameAtInstant(std::vector<int> tempvector){
00441         Instant instant(&tempvector);
00442         std::vector<ContourThing**> vectcont = modelManager->getOutlinesAtInstant( &instant );
00443         std::vector<std::string> vectname;
00444         for(int i = 0; i < (int)(vectcont.size()); i++){
00445                 ContourThing **contourthing = vectcont[i];
00446                 vectname.push_back((*contourthing)->getName());
00447         }
00448     return vectname;
00449 }
00450 
00451 std::vector<ContourThing**> KernelManagerContour::getOutlinesAtInstant(Instant* instant ){
00452         return modelManager->getOutlinesAtInstant(instant);
00453 }
00454 
00455 std::vector<manualBaseModel*> KernelManagerContour::ExploseEachModel( std::vector<manualBaseModel*> lstManConMod ){
00456         std::vector<manualBaseModel*> lstTmp;
00457         std::vector<manualBaseModel*> lstResult;
00458         int j,jSize;
00459         int i,iSize=lstManConMod.size();
00460         for (i=0;i<iSize;i++)
00461         {
00462                 lstTmp = lstManConMod[i]->ExploseModel();
00463                 jSize=lstTmp.size();
00464                 for (j=0;j<jSize;j++)
00465                 {
00466                         lstResult.push_back( lstTmp[j] );
00467                 }
00468         }
00469         return lstResult;
00470 }
00471 
00472 void KernelManagerContour::getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect){
00473         modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
00474 }
00475 
00476 
00477 vtkImageData* KernelManagerContour::getImageAtInstant(std::vector<int> inst){
00478         int index = inst[5]-1;
00479 
00480         if(index < (int)(vectimages.size())&&index!=_currentIndex){
00481                 _currentIndex=index;
00482                 return vectimages[index];
00483         }
00484         return NULL;
00485 }
00486 
00487 std::string KernelManagerContour::getCurrentFileName(){
00488         return filename;
00489 }
00490 
00491 void KernelManagerContour::setCurrentFileName(std::string filenam){
00492         this->filename = filenam;
00493 }
00494 
00495 std::string KernelManagerContour::parseOsirixFile(std::string filename){
00496 
00497 
00498 #ifdef ParserOsirix_BUILD
00499         vtkImageData* sourceimage;
00500         std::string xsdfile;
00501 
00502         xsdfile = _datadir;
00503 
00504         xsdfile.append("\\XML\\osirixschema.xsd");
00505 
00506         sourceimage = getSourceImage();
00507         OsirixParser p(xsdfile.c_str(), sourceimage->GetSpacing(), sourceimage->GetExtent());
00508 
00509         if(p.ParseFile(filename.c_str())!= 0){
00510 
00511         }
00512 
00513         return p.getContoursFileName();
00514 #else
00515         return "";
00516 #endif
00517 
00518 
00519 }
00520 
00521 

Generated on Wed Jun 27 23:28:33 2012 for creaContours_lib by  doxygen 1.5.7.1