HistogramDialog.cxx

Go to the documentation of this file.
00001 #include "HistogramDialog.h"
00002 #include <vector>
00003 
00004 // IMPLEMENT_CLASS(HistogramDialog, wxDialog)
00005 
00006 
00007 //id for events
00008 enum {
00009     ID_SAVE  = 108,
00010         ID_LOAD,
00011         ID_REFRESH
00012 };
00013 
00014 //-------------------------
00015 //Constructor
00016 //-------------------------
00017 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type)
00018 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE   ,_T("dialogBox"))
00019 {
00020 
00021         _ctfun=NULL;
00022         _tfun=NULL;
00023 
00024         SetBackgroundColour(wxColour(255,255,255));
00025         /*
00026         Pointers
00027         */
00028         wxvtkmpr3Dview=NULL;
00029         wxvtkclipping3Dview=NULL;
00030         
00031         /*
00032          Histogram
00033         */
00034         
00035         histogramW=new HistogramWidget(this, -1, wxPoint(0,0), wxSize(400,400),wxNO_BORDER ,imageData,type);
00036         
00037         refreshed=false;
00038 
00039         /*
00040         Buttons
00041         */
00042         okBtn = new wxButton(this,wxID_OK ,_T("OK"));
00043         cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel"));
00044         
00045         saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
00046         loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
00047         refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
00048         
00049         Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData       );
00050         Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData       );
00051         Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn      );
00052         
00053         //-------------------
00054         //GUI
00055         //-------------------
00056         
00057         //Upper Box
00058         wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
00059         //Including components for plotter control
00060         upper_box->Add( histogramW, 4, wxGROW);
00061         
00062 
00063         //bottom Sizer
00064         wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
00065         bottomBox->Add( okBtn, wxSizerFlags().Center());
00066         bottomBox->AddSpacer(40);
00067         bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
00068         bottomBox->AddSpacer(40);
00069         bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
00070         bottomBox->AddSpacer(40);
00071         bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
00072         bottomBox->AddSpacer(40);
00073         bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
00074         //Sizer
00075         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00076         sizer->Add(upper_box,1,wxEXPAND);       
00077     sizer->Add(bottomBox,0,wxCENTER);
00078         SetAutoLayout( TRUE );
00079         SetSizer( sizer );
00080         SetBestSize(wxSize(600,600));
00081 }
00082 
00083 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title)
00084 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE   ,_T("dialogBox")){
00085         _ctfun=NULL;
00086         _tfun=NULL;
00087 
00088         SetBackgroundColour(wxColour(255,255,255));
00089         /*
00090         Pointers
00091         */
00092         wxvtkmpr3Dview=NULL;
00093         wxvtkclipping3Dview=NULL;
00094         
00095         /*
00096          Histogram
00097         */
00098         
00099         histogramW=new HistogramWidget(this, -1);
00100         
00101         refreshed=false;
00102 
00103         /*
00104         Buttons
00105         */
00106         okBtn = new wxButton(this,wxID_OK ,_T("OK"));
00107         cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel"));
00108         
00109         saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
00110         loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
00111         refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
00112         
00113         Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData       );
00114         Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData       );
00115         Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn      );
00116         
00117         //-------------------
00118         //GUI
00119         //-------------------
00120         
00121         //Upper Box
00122         wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
00123         //Including components for plotter control
00124         upper_box->Add( histogramW, 4, wxGROW);
00125         
00126 
00127         //bottom Sizer
00128         wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
00129         bottomBox->Add( okBtn, wxSizerFlags().Center());
00130         bottomBox->AddSpacer(40);
00131         bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
00132         bottomBox->AddSpacer(40);
00133         bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
00134         bottomBox->AddSpacer(40);
00135         bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
00136         bottomBox->AddSpacer(40);
00137         bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
00138         //Sizer
00139         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00140         sizer->Add(upper_box,1,wxEXPAND);       
00141     sizer->Add(bottomBox,0,wxCENTER);
00142         SetAutoLayout( TRUE );
00143         SetSizer( sizer );
00144         SetBestSize(wxSize(600,600));
00145 }
00146 
00147 //-----------------------
00148 //Handling events
00149 //-----------------------
00150 
00151 void HistogramDialog::OnSaveData(wxCommandEvent& event)
00152 {
00153         wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1,  -1);//wxFileSelector(_T("Save Data"),wxSAVE);
00154         std::ofstream file;
00155         if(nameF.CompareTo( _T("/0") )>0)
00156                 file.open( (const char*)(nameF.mb_str()) );
00157 
00158         if(file.is_open())
00159         {
00160                 file << "<histogram Data>" << std::endl;
00161                 //histograms points
00162                 /*
00163                 file << "       <histogramPoints>" << std::endl;
00164                 int histogramS=histogramW->getHistogramSize();
00165                 int i=0;        
00166                 while(i<histogramS)
00167                 {
00168                         file << "               <HistogramPoint>" << std::endl;
00169                         file << "                       <greyValue>" << i << "</greyValue>" <<std::endl;
00170                         file << "                       <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
00171                         file << "               </HistogramPoint>" << std::endl;
00172                         i++;
00173                 }
00174                 file << "       </histogramPoints>" << std::endl;
00175                 */
00176                 //points transference Function
00177                 file << " <TransferenceFunction>"<< std::endl;
00178                 int tfPointS=histogramW->getSizeTransferenceFunction();
00179                 int i=0;
00180                 int gv,in;
00181                 while(i<tfPointS)
00182                 {
00183                         
00184                         histogramW->getTransferenceFunctionPoint(i,gv,in);
00185                         file << "               <Transferencepoint>" << std::endl;
00186                         file << "                       <greyValue>" << gv << "</greyValue>" <<std::endl;
00187                         file << "                       <intensity>" << in << "</intensity> "<<std::endl;
00188                         file << "               </Transferencepoint>" << std::endl;
00189                         i++;
00190                 }
00191                 file << "       </TransferenceFunction>"<< std::endl;
00192                 //colorPoints
00193                 file << "       <Colors>"<< std::endl;
00194                 int ctfPointS=histogramW->getSizeBarColor();
00195 
00196                 i=0;
00197                 int red,green,blue;
00198                 while(i<ctfPointS)
00199                 {
00200                         
00201                         histogramW->getDataBarColorPoint(i,gv,red,green,blue);
00202                         file << "               <greyValueRGBpoint>" << std::endl;
00203                         file << "                       <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
00204                         file << "                       <red>" << red << "</red>" <<std::endl;
00205                         file << "                       <green>" << green << "</green>" <<std::endl;
00206                         file << "                       <blue>" << blue << "</blue>" <<std::endl;
00207                         file << "               </greyValueRGBpoint>" << std::endl;
00208                         i++;
00209                 }
00210 
00211                 file << "       </Colors>"<< std::endl;
00212                 file << "</histogram Data>" << std::endl;
00213         }
00214         file.close();
00215 }
00216 
00217 void HistogramDialog::OnLoadData(wxCommandEvent& event)
00218 {
00219         wxString nameF=wxFileSelector(_T("Load Data") );
00220         //std::string line;
00221         std::ifstream file;
00222         if(nameF.CompareTo( _T("/0") )>0)
00223                 file.open(  (const char*) (nameF.mb_str()) );
00224         
00225         bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false;  // JPRx
00226         int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
00227         if(file.is_open())
00228         {
00229                 //-------------
00230                 erasePointsTransferenceFunction();
00231                 eraseColorPoints();
00232                 //--------------
00233         
00234                 //std::getline(file,line);
00235                 //int i=0;  // JPRx
00236                 while(!file.eof())
00237                 {
00238                         std::string line;
00239                         std::getline(file,line);
00240                         //int a=line.find("histogram Data");
00241                         if( (int)(line.find("histogram Data"))!=-1)
00242                         {
00243                                 histogramReading=true;
00244                         
00245                         }
00246                         /*
00247                         else if(line.find("histogramPoints")!=0 && histogramReading)
00248                         {
00249                                 histogramPoints=true;
00250                         }
00251                         else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
00252                         {
00253 
00254                         }
00255                         else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
00256                         {
00257                                 int pos1=line.find(">");
00258                                 int pos2=line.find("<",pos+1);
00259                                 std::string x=line.substr(pos1+1,pos2-1);
00260                                 gv=atoi(x.c_str());
00261                         }
00262                         else if(line.find("number")!=0 && histogramReading && histogramPoints)
00263                         {
00264                                 int pos1=line.find(">");
00265                                 int pos2=line.find("<",pos+1);
00266                                 std::string x=line.substr(pos1+1,pos2-1);
00267                                 nP=atoi(x.c_str());
00268                                 //add to the histogram
00269                                 //histogramW->addPointToTransferenceFunction(gc,in);
00270                         }
00271                         */
00272                         else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
00273                         {
00274                                 tf=true;
00275                         }
00276                         else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
00277                         {
00278                                 tfp=true;
00279                         }
00280                         else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
00281                         {
00282                                 int pos1=line.find(">");
00283                                 int pos2=line.find("<",pos1+1);
00284                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00285                                 gv=atoi(x.c_str());
00286                                 
00287                         }
00288                         else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
00289                         {
00290                                 int pos1=line.find(">");
00291                                 int pos2=line.find("<",pos1+1);
00292                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00293                                 in=atoi(x.c_str());
00294                                 histogramW->addPointToTransferenceFunction(gv,in);
00295                                 tfp=false;
00296                                 
00297                         }
00298                         else if( (int)(line.find("Colors"))!=-1 && histogramReading)
00299                         {
00300                                 ctf=true;
00301                         }
00302                         
00303                         else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
00304                         {
00305                                 ctfp=true;
00306                                 
00307                         }
00308                         else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
00309                         {
00310                                 int pos1=line.find(">");
00311                                 int pos2=line.find("<",pos1+1);
00312                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00313                                 gv=atoi(x.c_str());
00314                                 
00315                         }
00316                         else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
00317                         {
00318                                 int pos1=line.find(">");
00319                                 int pos2=line.find("<",pos1+1);
00320                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00321                                 red=atoi(x.c_str());
00322                                 
00323                         }
00324                         else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
00325                         {
00326                                 int pos1=line.find(">");
00327                                 int pos2=line.find("<",pos1+1);
00328                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00329                                 gr=atoi(x.c_str());
00330                         }
00331                         else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
00332                         {
00333                                 int pos1=line.find(">");
00334                                 int pos2=line.find("<",pos1+1);
00335                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00336                                 bl=atoi(x.c_str());
00337                                 histogramW->addColorPoint(gv,red,gr,bl);
00338                                 ctfp=false;
00339                         }
00340                         line.clear();
00341              }
00342      }
00343         
00344         file.close();
00345         histogramW->updatePlotter();
00346 }
00347 /*
00348  On refresh btn
00349 */
00350 
00351 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
00352 {
00353         refreshed=true;
00354                         
00355                         int i=0,xi,yi,r,g,b;
00356                         
00357                         // -- TransferenceFunction --
00358                         int nPointsTF=getSizeTransferenceFunction();
00359 
00360                         if(nPointsTF>0)
00361                         {
00362 
00363                                 int nTFPoints=getSizeTransferenceFunction();
00364                                 i=0;
00365                                 while(i<nTFPoints)
00366                                 {
00367                                         getTransferenceFunctionPoint(i,xi,yi);
00368                                         _tfun->AddPoint( xi , yi/100.0 );
00369                                         i++;
00370                                 }
00371                         }
00372                         //-- Color bar --
00373                         //clean colors
00374                         int nPointsCTF=getSizeBarColor();
00375                         if(nPointsCTF>0)
00376                         {                       
00377                                 _ctfun->RemoveAllPoints();
00378                                 
00379                                 int nCTFpoints=getSizeBarColor();
00380                                 i=0;    
00381                                 while(i<nCTFpoints)
00382                                 {
00383                                         getDataBarColorPoint(i,xi,r,g,b);
00384                                         _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
00385                                         i++;
00386                                 }
00387                         }
00388 
00389 //EED Borrame
00390 
00391         /*
00392          NOTE I NEED THE UPDATE
00393         */
00394         //if it was call from the clipping ctnrl panel
00395         if(wxvtkclipping3Dview!=NULL)
00396         {
00397                 wxvtkclipping3Dview->Refresh();
00398 
00399         }
00400         else if(wxvtkmpr3Dview!=NULL)
00401         {
00402                 wxvtkmpr3Dview->Refresh();
00403 
00404         }
00405 }
00406 
00407 
00408 //-----------------------
00409 //Methods
00410 //-----------------------
00411 
00412 /*
00413                 get number of points of the transference function
00414         */
00415         int HistogramDialog::getSizeTransferenceFunction()
00416         {
00417                 return histogramW->getSizeTransferenceFunction();
00418                 
00419         }
00420         /*
00421                 get number of points of the barColor
00422         */
00423         int HistogramDialog::getSizeBarColor()
00424         {
00425                 return histogramW->getSizeBarColor();
00426         }
00427         /*
00428                 get a point of the transference function
00429         */
00430         void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
00431         {
00432                 histogramW->getTransferenceFunctionPoint(index,x,y);
00433         }
00434         /*
00435                 get a  color int the bqr color
00436         */
00437         void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
00438         {
00439                 histogramW->getDataBarColorPoint(index,x,red,green,blue);
00440         }
00441         /*
00442                 get a point of the Histogram
00443                 given the grey value
00444         */
00445         int HistogramDialog::getHistogramPoint(int gValue)
00446         {
00447                 return histogramW->getHistogramPoint(gValue);
00448         }
00449 
00450         //--------------------
00451         // bar Information
00452         //---------------------
00453         /*
00454          Get the porcentage of the positions of 
00455          the min,max and actual in the bar range
00456         */
00457         float HistogramDialog::getMaxShowedPorcentage()
00458         {
00459                 return histogramW->getMaxShowedPorcentage();
00460         }
00461         float HistogramDialog::getMinShowedPorcentage()
00462         {
00463                 return histogramW->getMinShowedPorcentage();
00464         }
00465         float HistogramDialog::getActualShowedPorcentage()
00466         {
00467                 return histogramW->getActualShowedPorcentage();
00468         }
00469         //---------------------------------------
00470         // setting data in transferences function
00471         // and in bar color
00472         //----------------------------------------
00473         bool  HistogramDialog::addPointToTransferenceFunction(double x, double y)
00474         {
00475                 return histogramW->addPointToTransferenceFunction(x,y);
00476         }
00477         bool  HistogramDialog::addColorPoint(double x,int red,int green, int blue)
00478         {
00479                 return histogramW->addColorPoint(x,red,green,blue);
00480         }
00481         //------------------------
00482         //Erase data
00483         //------------------------
00484         
00485         /*
00486          Erase all the points that are in the transference function
00487         */
00488         void HistogramDialog::erasePointsTransferenceFunction()
00489         {
00490                 histogramW->erasePointsTransferenceFunction();
00491         }
00492         /*
00493         Erase the  color points in the plotter
00494         */
00495         void HistogramDialog::eraseColorPoints()
00496         {
00497                 histogramW->eraseColorPoints();
00498         }
00499 
00500         //-------------------
00501         // Getter and setters
00502         //-------------------
00503 
00504         void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
00505         {
00506                 _ctfun=cf;
00507         
00508         }
00509         void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
00510         {
00511                 _tfun=tf;
00512         }
00513 
00514         bool HistogramDialog::getRefreshed()
00515         {
00516                 return refreshed;
00517         }
00518         
00519         void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
00520         {
00521                 volumeMapper=volMapper;
00522         }
00523         void HistogramDialog::setVolume(vtkVolume* vol)
00524         {
00525                 newvol=vol;     
00526         }
00527         void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
00528         {
00529                 wxvtkmpr3Dview=wxvtkmpr3Dview1;
00530         }
00531         void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
00532         {
00533                 wxvtkclipping3Dview=wxvtkclipping3Dview1;
00534         }
00535 
00536 
00537         void  HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
00538         {
00539                 histogramW->setTransferenceFunctionHasPoints(hasPoints);
00540         }
00541         void  HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
00542         {
00543                 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
00544         }
00545 
00546         //--------------------
00547         // plotter Information
00548         //---------------------
00549         void  HistogramDialog::updatePlotter()
00550         {
00551                 histogramW->updatePlotter();
00552         }
00553 
00554 
00558         void HistogramDialog::initializeHistogram(vtkImageData* img){
00559                 histogramW->initializeHistogram(img);
00560         }
00564         void HistogramDialog::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
00565 
00566                 histogramW->GetValuesPointsFunction(greylevel, value);
00567         }
00568 
00573 void HistogramDialog::GetValuesColorPointsFunction(std::vector<double>& greylevel,
00574                                                                 std::vector<double>& red,
00575                                                                 std::vector<double>& green,
00576                                                                 std::vector<double>& blue)
00577 {
00578         histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue);
00579 }
00580 
00581 void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){
00582         _tfun = _opac;
00583         _ctfun = _color;        
00584 }

Generated on Wed Jul 29 16:35:29 2009 for creaMaracasVisu_lib by  doxygen 1.5.3