]> Creatis software - creaMaracasVisu.git/commitdiff
bug view MPR
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 10 Jun 2009 11:43:30 +0000 (11:43 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 10 Jun 2009 11:43:30 +0000 (11:43 +0000)
bbtk/src/bbmaracasvisuShowNPoints.cxx
bbtk/src/bbmaracasvisuShowNPoints.h

index d5f702b87938dbe50a7f555e78b909196f45fe97..21cb59119c24f6b21d73e3bc97fe954ffb12c98a 100644 (file)
@@ -30,7 +30,7 @@ namespace bbcreaMaracasVisu
        wxButton *btnDeleteAllPoints    = new wxButton( panel, -1, _T("Delete all points"));
        wxButton *btnSavePoints                 = new wxButton( panel, -1, _T("Save points"));
        wxButton *btnLoadPoints                 = new wxButton( panel, -1, _T("Load points"));
-       txtNrPoints                                             = new wxStaticText(panel,-1, _T("Number of points: 0"));
+       txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
 
        wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); 
 //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
@@ -139,48 +139,53 @@ std::string WidgetShowNPoints::CleanSpaces(std::string ss)
        return ss;
 }
        
+//------------------------------------------------------------------------
+void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
+{
+       lstPointsX.push_back( x );
+       lstPointsY.push_back( y );
+       lstPointsZ.push_back( z );
+
+       std::string strLabel = CleanSpaces(  label );
+       
+       lstLabels.push_back( strLabel );
+       
+       // Sphere
+       vtkSphereSource *vtksphere              = vtkSphereSource::New();
+       vtksphere->SetThetaResolution (20);
+       vtksphere->SetPhiResolution (20);
+       vtksphere->SetRadius( mradio  ); 
+       vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
+       sphereMapper->SetInput( vtksphere->GetOutput() );
+       vtkActor *sphereActor   = vtkActor::New();
+       sphereActor->SetMapper(sphereMapper);
+       sphereActor->SetOrigin(0, 0, 0);
+       double spc[3];
+       mimage->GetSpacing(spc);
+       sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
+       sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
+       sphereActor->GetProperty()->SetOpacity( mopacity );
+       
+       lstActorsSphere.push_back(sphereActor);
+       renderer->AddActor( sphereActor );
+       
+       // Actor
+       vtkTextActor3D *textActor = vtkTextActor3D::New();
+       textActor->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+       textActor->SetInput( strLabel.c_str()  );
+       renderer->AddActor( textActor );
+       lstActorsText.push_back(textActor);
+       
+       SetOutputBox(); 
+       
+}
        
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 {
        if (this->renderer!=NULL){ 
                if (mpoint.size()==3){
-                       lstPointsX.push_back( mpoint[0] );
-                       lstPointsY.push_back( mpoint[1] );
-                       lstPointsZ.push_back( mpoint[2] );
-                       
-                       std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
-                       
-                       lstLabels.push_back( strLabel );
-
-                       // Sphere
-                       vtkSphereSource *vtksphere              = vtkSphereSource::New();
-                       vtksphere->SetThetaResolution (20);
-                       vtksphere->SetPhiResolution (20);
-                       vtksphere->SetRadius( mradio  ); 
-                       vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
-                       sphereMapper->SetInput( vtksphere->GetOutput() );
-                       vtkActor *sphereActor   = vtkActor::New();
-                       sphereActor->SetMapper(sphereMapper);
-                       sphereActor->SetOrigin(0, 0, 0);
-                       double spc[3];
-                       mimage->GetSpacing(spc);
-                       sphereActor->SetPosition( spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
-                       sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
-                       sphereActor->GetProperty()->SetOpacity( mopacity );
-
-                       lstActorsSphere.push_back(sphereActor);
-                       renderer->AddActor( sphereActor );
-                       
-                       // Actor
-                       vtkTextActor3D *textActor = vtkTextActor3D::New();
-                       textActor->SetPosition(  mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
-                       textActor->SetInput( strLabel.c_str()  );
-                       renderer->AddActor( textActor );
-                       lstActorsText.push_back(textActor);
-
-                       SetOutputBox(); 
-                       
+                       AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );                      
                } else {//mpoint.size
                        printf("creaMaracasVisu::ShowNPoints (not match point) \n");
                }
@@ -193,7 +198,7 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
        {
                renderer->GetRenderWindow()->Render();
                wxString strTmp;
-               strTmp.Printf("Number of points: %d", (int)(lstPointsX.size()) );
+               strTmp.Printf("Nbr of points: %d", (int)(lstPointsX.size()) );
                txtNrPoints->SetLabel(  strTmp );
                
                //--BBTK
@@ -210,34 +215,92 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
        //------------------------------------------------------------------------
        void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
        {
-               FILE *ff;
-               wxString filename="/Users/davila/Desktop/PDL_2/bbs/test.xls";
-               ff = fopen( (const char*) ( filename.mb_str() ) , "w+" );
-               if (ff!=NULL)
+               
+               wxFileDialog* FD = new wxFileDialog( 0, 
+                                                                                       _T("Save points .."),
+                                                                                       _T(""),
+                                                                                       _T(""),
+                                                                                       _T("(*.xls)|*.xls"),
+                                                                                        wxSAVE | wxOVERWRITE_PROMPT,
+                                                                                       wxDefaultPosition);
+               //EED
+               
+               int result_FD = FD->ShowModal();
+               
+               // This line is need it by windows //EED
+               FD->SetReturnCode( result_FD );
+               
+               if (FD->GetReturnCode()==wxID_OK)
                {
-                       int i , size = (int) (lstActorsSphere.size());
-                       fprintf(ff,"NumberOfPoints %d \n",size);
-                       fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
-                       int x, y, z;
-                       double value;
-                       for (i=0; i<size; i++)
+                       FILE *ff;
+                       std::string filename= (const char*) ( FD->GetPath().mb_str() );
+                       ff = fopen( filename.c_str() , "w+" );
+                       if (ff!=NULL)
                        {
-                               x=lstPointsX[i];
-                               y=lstPointsY[i];
-                               z=lstPointsZ[i];
-                               value= mimage->GetScalarComponentAsDouble(x,y,z,0);
-                               fprintf(ff,"%d\t %d\t %d\t %f\t %s\n", x , y , z , value  , lstLabels[i].c_str());
-                       } // for
-                       fclose(ff);
-               } else {   // else ff
-                       printf("WidgetShowNPoints::OnSavePoints  ...Error... creating file");
-               } //ff
+                               int i , size = (int) (lstActorsSphere.size());
+                               fprintf(ff,"NumberOfPoints %d \n",size);
+                               fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
+                               int x, y, z;
+                               double value;
+                               for (i=0; i<size; i++)
+                               {
+                                       x=lstPointsX[i];
+                                       y=lstPointsY[i];
+                                       z=lstPointsZ[i];
+                                       value= mimage->GetScalarComponentAsDouble(x,y,z,0);
+                                       fprintf(ff,"%d\t %d\t %d\t %f\t %s\n", x , y , z , value  , lstLabels[i].c_str());
+                               } // for
+                               fclose(ff);
+                       } else {   // else ff
+                               printf("WidgetShowNPoints::OnSavePoints  ...Error... creating file");
+                       } //ff
+               }       // dialog box
                
        }               
 
        //------------------------------------------------------------------------
        void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
        {
+               wxFileDialog* FD = new wxFileDialog( 0, 
+                                                                                       _T("Load points .."),
+                                                                                       _T(""),
+                                                                                       _T(""),
+                                                                                       _T("(*.xls)|*.xls"),
+                                                                                       wxOPEN | wxFILE_MUST_EXIST,
+                                                                                       wxDefaultPosition);
+               //EED
+               
+               int result_FD = FD->ShowModal();
+               
+               // This line is need it by windows //EED
+               FD->SetReturnCode( result_FD );
+               
+               if (FD->GetReturnCode()==wxID_OK)
+               {
+                       FILE *ff;
+                       std::string filename= (const char*) ( FD->GetPath().mb_str() );
+                       ff = fopen( filename.c_str() , "r+" );
+                       if (ff!=NULL)
+                       {
+                               int i,size;
+                               char chartmp[256];
+                               fscanf(ff," %s %d",chartmp,&size);
+                               fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp );
+
+                               float value;
+                               int x,y,z;
+                               for (i=0; i<size; i++)
+                               {
+                                       fscanf(ff," %d %d %d %f %s",&x,&y,&z,&value,chartmp );  // x,y,z,value,label
+                                       AddPoint(x,y,z, chartmp );                      
+                               }
+                               fclose(ff);
+                       } else {   // else ff
+                               printf("WidgetShowNPoints::OnLoadPoints  ...Error... reading file");
+                       } //ff
+               }       // dialog box
+               
+               
        }               
        
        int WidgetShowNPoints::GetNearestPoint()
index a203d1f9d03353c46ab7362c13ab1dd95351ecec..d95977ea09ce092390e129f2afbe7ec97dc9a094 100644 (file)
@@ -41,6 +41,7 @@ namespace bbcreaMaracasVisu
 
   private:
          
+         void                  AddPoint(int x, int y, int z, std::string label);
          std::string   CleanSpaces(std::string ss);
          int                   GetNearestPoint();
          void                  ErasePoint(int id);