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 //-----------------------
00084 //Handling events
00085 //-----------------------
00086 
00087 void HistogramDialog::OnSaveData(wxCommandEvent& event)
00088 {
00089         wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1,  -1);//wxFileSelector(_T("Save Data"),wxSAVE);
00090         std::ofstream file;
00091         if(nameF.CompareTo( _T("/0") )>0)
00092                 file.open( (const char*)(nameF.mb_str()) );
00093 
00094         if(file.is_open())
00095         {
00096                 file << "<histogram Data>" << std::endl;
00097                 //histograms points
00098                 /*
00099                 file << "       <histogramPoints>" << std::endl;
00100                 int histogramS=histogramW->getHistogramSize();
00101                 int i=0;        
00102                 while(i<histogramS)
00103                 {
00104                         file << "               <HistogramPoint>" << std::endl;
00105                         file << "                       <greyValue>" << i << "</greyValue>" <<std::endl;
00106                         file << "                       <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
00107                         file << "               </HistogramPoint>" << std::endl;
00108                         i++;
00109                 }
00110                 file << "       </histogramPoints>" << std::endl;
00111                 */
00112                 //points transference Function
00113                 file << " <TransferenceFunction>"<< std::endl;
00114                 int tfPointS=histogramW->getSizeTransferenceFunction();
00115                 int i=0;
00116                 int gv,in;
00117                 while(i<tfPointS)
00118                 {
00119                         
00120                         histogramW->getTransferenceFunctionPoint(i,gv,in);
00121                         file << "               <Transferencepoint>" << std::endl;
00122                         file << "                       <greyValue>" << gv << "</greyValue>" <<std::endl;
00123                         file << "                       <intensity>" << in << "</intensity> "<<std::endl;
00124                         file << "               </Transferencepoint>" << std::endl;
00125                         i++;
00126                 }
00127                 file << "       </TransferenceFunction>"<< std::endl;
00128                 //colorPoints
00129                 file << "       <Colors>"<< std::endl;
00130                 int ctfPointS=histogramW->getSizeBarColor();
00131 
00132                 i=0;
00133                 int red,green,blue;
00134                 while(i<ctfPointS)
00135                 {
00136                         
00137                         histogramW->getDataBarColorPoint(i,gv,red,green,blue);
00138                         file << "               <greyValueRGBpoint>" << std::endl;
00139                         file << "                       <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
00140                         file << "                       <red>" << red << "</red>" <<std::endl;
00141                         file << "                       <green>" << green << "</green>" <<std::endl;
00142                         file << "                       <blue>" << blue << "</blue>" <<std::endl;
00143                         file << "               </greyValueRGBpoint>" << std::endl;
00144                         i++;
00145                 }
00146 
00147                 file << "       </Colors>"<< std::endl;
00148                 file << "</histogram Data>" << std::endl;
00149         }
00150         file.close();
00151 }
00152 
00153 void HistogramDialog::OnLoadData(wxCommandEvent& event)
00154 {
00155         wxString nameF=wxFileSelector(_T("Load Data") );
00156         //std::string line;
00157         std::ifstream file;
00158         if(nameF.CompareTo( _T("/0") )>0)
00159                 file.open(  (const char*) (nameF.mb_str()) );
00160         
00161         bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false;  // JPRx
00162         int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
00163         if(file.is_open())
00164         {
00165                 //-------------
00166                 erasePointsTransferenceFunction();
00167                 eraseColorPoints();
00168                 //--------------
00169         
00170                 //std::getline(file,line);
00171                 //int i=0;  // JPRx
00172                 while(!file.eof())
00173                 {
00174                         std::string line;
00175                         std::getline(file,line);
00176                         //int a=line.find("histogram Data");
00177                         if( (int)(line.find("histogram Data"))!=-1)
00178                         {
00179                                 histogramReading=true;
00180                         
00181                         }
00182                         /*
00183                         else if(line.find("histogramPoints")!=0 && histogramReading)
00184                         {
00185                                 histogramPoints=true;
00186                         }
00187                         else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
00188                         {
00189 
00190                         }
00191                         else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
00192                         {
00193                                 int pos1=line.find(">");
00194                                 int pos2=line.find("<",pos+1);
00195                                 std::string x=line.substr(pos1+1,pos2-1);
00196                                 gv=atoi(x.c_str());
00197                         }
00198                         else if(line.find("number")!=0 && histogramReading && histogramPoints)
00199                         {
00200                                 int pos1=line.find(">");
00201                                 int pos2=line.find("<",pos+1);
00202                                 std::string x=line.substr(pos1+1,pos2-1);
00203                                 nP=atoi(x.c_str());
00204                                 //add to the histogram
00205                                 //histogramW->addPointToTransferenceFunction(gc,in);
00206                         }
00207                         */
00208                         else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
00209                         {
00210                                 tf=true;
00211                         }
00212                         else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
00213                         {
00214                                 tfp=true;
00215                         }
00216                         else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
00217                         {
00218                                 int pos1=line.find(">");
00219                                 int pos2=line.find("<",pos1+1);
00220                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00221                                 gv=atoi(x.c_str());
00222                                 
00223                         }
00224                         else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
00225                         {
00226                                 int pos1=line.find(">");
00227                                 int pos2=line.find("<",pos1+1);
00228                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00229                                 in=atoi(x.c_str());
00230                                 histogramW->addPointToTransferenceFunction(gv,in);
00231                                 tfp=false;
00232                                 
00233                         }
00234                         else if( (int)(line.find("Colors"))!=-1 && histogramReading)
00235                         {
00236                                 ctf=true;
00237                         }
00238                         
00239                         else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
00240                         {
00241                                 ctfp=true;
00242                                 
00243                         }
00244                         else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
00245                         {
00246                                 int pos1=line.find(">");
00247                                 int pos2=line.find("<",pos1+1);
00248                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00249                                 gv=atoi(x.c_str());
00250                                 
00251                         }
00252                         else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
00253                         {
00254                                 int pos1=line.find(">");
00255                                 int pos2=line.find("<",pos1+1);
00256                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00257                                 red=atoi(x.c_str());
00258                                 
00259                         }
00260                         else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
00261                         {
00262                                 int pos1=line.find(">");
00263                                 int pos2=line.find("<",pos1+1);
00264                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00265                                 gr=atoi(x.c_str());
00266                         }
00267                         else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
00268                         {
00269                                 int pos1=line.find(">");
00270                                 int pos2=line.find("<",pos1+1);
00271                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
00272                                 bl=atoi(x.c_str());
00273                                 histogramW->addColorPoint(gv,red,gr,bl);
00274                                 ctfp=false;
00275                         }
00276                         line.clear();
00277              }
00278      }
00279         
00280         file.close();
00281         histogramW->updatePlotter();
00282 }
00283 /*
00284  On refresh btn
00285 */
00286 
00287 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
00288 {
00289         refreshed=true;
00290                         
00291                         int i=0,xi,yi,r,g,b;
00292                         
00293                         // -- TransferenceFunction --
00294                         int nPointsTF=getSizeTransferenceFunction();
00295 
00296                         if(nPointsTF>0)
00297                         {
00298 
00299                                 int nTFPoints=getSizeTransferenceFunction();
00300                                 i=0;
00301                                 while(i<nTFPoints)
00302                                 {
00303                                         getTransferenceFunctionPoint(i,xi,yi);
00304                                         _tfun->AddPoint( xi , yi/100.0 );
00305                                         i++;
00306                                 }
00307                         }
00308                         //-- Color bar --
00309                         //clean colors
00310                         int nPointsCTF=getSizeBarColor();
00311                         if(nPointsCTF>0)
00312                         {                       
00313                                 _ctfun->RemoveAllPoints();
00314                                 
00315                                 int nCTFpoints=getSizeBarColor();
00316                                 i=0;    
00317                                 while(i<nCTFpoints)
00318                                 {
00319                                         getDataBarColorPoint(i,xi,r,g,b);
00320                                         _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
00321                                         i++;
00322                                 }
00323                         }
00324 
00325 //EED Borrame
00326 
00327         /*
00328          NOTE I NEED THE UPDATE
00329         */
00330         //if it was call from the clipping ctnrl panel
00331         if(wxvtkclipping3Dview!=NULL)
00332         {
00333                 wxvtkclipping3Dview->Refresh();
00334 
00335         }
00336         else if(wxvtkmpr3Dview!=NULL)
00337         {
00338                 wxvtkmpr3Dview->Refresh();
00339 
00340         }
00341 }
00342 
00343 
00344 //-----------------------
00345 //Methods
00346 //-----------------------
00347 
00348 /*
00349                 get number of points of the transference function
00350         */
00351         int HistogramDialog::getSizeTransferenceFunction()
00352         {
00353                 return histogramW->getSizeTransferenceFunction();
00354                 
00355         }
00356         /*
00357                 get number of points of the barColor
00358         */
00359         int HistogramDialog::getSizeBarColor()
00360         {
00361                 return histogramW->getSizeBarColor();
00362         }
00363         /*
00364                 get a point of the transference function
00365         */
00366         void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
00367         {
00368                 histogramW->getTransferenceFunctionPoint(index,x,y);
00369         }
00370         /*
00371                 get a  color int the bqr color
00372         */
00373         void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
00374         {
00375                 histogramW->getDataBarColorPoint(index,x,red,green,blue);
00376         }
00377         /*
00378                 get a point of the Histogram
00379                 given the grey value
00380         */
00381         int HistogramDialog::getHistogramPoint(int gValue)
00382         {
00383                 return histogramW->getHistogramPoint(gValue);
00384         }
00385 
00386         //--------------------
00387         // bar Information
00388         //---------------------
00389         /*
00390          Get the porcentage of the positions of 
00391          the min,max and actual in the bar range
00392         */
00393         float HistogramDialog::getMaxShowedPorcentage()
00394         {
00395                 return histogramW->getMaxShowedPorcentage();
00396         }
00397         float HistogramDialog::getMinShowedPorcentage()
00398         {
00399                 return histogramW->getMinShowedPorcentage();
00400         }
00401         float HistogramDialog::getActualShowedPorcentage()
00402         {
00403                 return histogramW->getActualShowedPorcentage();
00404         }
00405         //---------------------------------------
00406         // setting data in transferences function
00407         // and in bar color
00408         //----------------------------------------
00409         bool  HistogramDialog::addPointToTransferenceFunction(double x, double y)
00410         {
00411                 return histogramW->addPointToTransferenceFunction(x,y);
00412         }
00413         bool  HistogramDialog::addColorPoint(double x,int red,int green, int blue)
00414         {
00415                 return histogramW->addColorPoint(x,red,green,blue);
00416         }
00417         //------------------------
00418         //Erase data
00419         //------------------------
00420         
00421         /*
00422          Erase all the points that are in the transference function
00423         */
00424         void HistogramDialog::erasePointsTransferenceFunction()
00425         {
00426                 histogramW->erasePointsTransferenceFunction();
00427         }
00428         /*
00429         Erase the  color points in the plotter
00430         */
00431         void HistogramDialog::eraseColorPoints()
00432         {
00433                 histogramW->eraseColorPoints();
00434         }
00435 
00436         //-------------------
00437         // Getter and setters
00438         //-------------------
00439 
00440         void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
00441         {
00442                 _ctfun=cf;
00443         
00444         }
00445         void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
00446         {
00447                 _tfun=tf;
00448         }
00449 
00450         bool HistogramDialog::getRefreshed()
00451         {
00452                 return refreshed;
00453         }
00454         
00455         void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
00456         {
00457                 volumeMapper=volMapper;
00458         }
00459         void HistogramDialog::setVolume(vtkVolume* vol)
00460         {
00461                 newvol=vol;     
00462         }
00463         void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
00464         {
00465                 wxvtkmpr3Dview=wxvtkmpr3Dview1;
00466         }
00467         void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
00468         {
00469                 wxvtkclipping3Dview=wxvtkclipping3Dview1;
00470         }
00471 
00472 
00473         void  HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
00474         {
00475                 histogramW->setTransferenceFunctionHasPoints(hasPoints);
00476         }
00477         void  HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
00478         {
00479                 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
00480         }
00481 
00482         //--------------------
00483         // plotter Information
00484         //---------------------
00485         void  HistogramDialog::updatePlotter()
00486         {
00487                 histogramW->updatePlotter();
00488         }
00489 
00490 

Generated on Fri Jun 12 00:08:33 2009 for creaMaracasVisu by  doxygen 1.5.7.1