]> Creatis software - creaMaracasVisu.git/commitdiff
no message
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 5 Jul 2011 18:54:23 +0000 (18:54 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 5 Jul 2011 18:54:23 +0000 (18:54 +0000)
bbtk/src/bbmaracasvisuShowNPoints.cxx
bbtk/src/bbmaracasvisuShowNPoints.h

index d9e198e2b7202d10aba21e65f544d44a259514b1..8f434b06db9d059a434f4e1b5dca63f9cd0b225f 100644 (file)
@@ -14,22 +14,23 @@ namespace bbcreaMaracasVisu
   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent,  bbcreaMaracasVisu::ShowNPoints *box)
     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
   {
-    mbbShowNPoints                     = box;
-    this->renderer                     = NULL;
-    wxPanel    *panel                  = this;
-    wxSizer *sizer                     = NULL;
+    mbbShowNPoints                                     = box;
+    this->renderer                                     = NULL;
+    wxPanel    *panel                                  = this;
+    wxSizer *sizer                                     = NULL;
 
        // Widget interface
-       askPointLabel                           = new wxStaticText(panel, -1, _T("Point label :")); // JPR
-       textCtrl                                        = new wxTextCtrl(panel, -1);
-       wxButton *btnAddPoint           = new wxButton( panel, -1, _T("Add Point"));
-       wxButton *btnRenamePoint        = new wxButton( panel, -1, _T("Rename point"));
-       wxButton *btnEraseLastPoint     = new wxButton( panel, -1, _T("Erase Last point"));
-       wxButton *btnErasePoint         = new wxButton( panel, -1, _T("Erase point"));
-       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(" "));
+       askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
+       textCtrl                                                = new wxTextCtrl(panel, -1);
+       wxButton *btnAddPoint                   = new wxButton( panel, -1, _T("Add Point"));
+    wxButton *btnSetPositionPoint      = new wxButton( panel, -1, _T("Set nearest point"));
+       wxButton *btnRenamePoint                = new wxButton( panel, -1, _T("Rename point"));
+       wxButton *btnEraseLastPoint             = new wxButton( panel, -1, _T("Erase Last point"));
+       wxButton *btnErasePoint                 = new wxButton( panel, -1, _T("Erase point"));
+       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(" "));
 
        //NTU: Sliders for opacity and radio change
 
@@ -42,13 +43,14 @@ namespace bbcreaMaracasVisu
        wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
 //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
 
-         Connect(btnAddPoint->GetId()           , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
-         Connect(btnRenamePoint->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
-         Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
-         Connect(btnErasePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
-         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
-         Connect(btnSavePoints->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
-         Connect(btnLoadPoints->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
+         Connect(btnAddPoint->GetId()                  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
+         Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
+         Connect(btnRenamePoint->GetId()               , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
+         Connect(btnEraseLastPoint->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
+         Connect(btnErasePoint->GetId()                , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
+         Connect(btnDeleteAllPoints->GetId()   , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
+         Connect(btnSavePoints->GetId()                , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
+         Connect(btnLoadPoints->GetId()                , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
 
          //NTU: Slider events
          Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
@@ -57,6 +59,7 @@ namespace bbcreaMaracasVisu
          sizer1->Add(askPointLabel); // JPR
          sizer1->Add(textCtrl);
          sizer1->Add(btnAddPoint);
+         sizer1->Add(btnSetPositionPoint);
          sizer1->Add(btnRenamePoint);
          sizer1->Add(btnErasePoint);
          sizer1->Add(btnEraseLastPoint);
@@ -155,6 +158,26 @@ std::string WidgetShowNPoints::CleanSpaces(std::string ss)
        return ss;
 }
 
+       
+//------------------------------------------------------------------------
+       
+void WidgetShowNPoints::RefreshPoint(int id)
+{
+       int x = lstPointsX[id];
+       int y = lstPointsY[id];
+       int z = lstPointsZ[id];
+       
+       double spc[3];
+       mimage->GetSpacing(spc);
+       
+       lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
+       lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
+       lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
+       
+       lstActorsText[id]->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+}
+       
+       
 //------------------------------------------------------------------------
 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
 {
@@ -181,6 +204,9 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
        vtkActor *sphereActor   = vtkActor::New();
        sphereActor->SetMapper(sphereMapper);
        sphereActor->SetOrigin(0, 0, 0);
+       
+       
+/*EED Borrame
        double spc[3];
        if(mimage==NULL){
                wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
@@ -191,7 +217,8 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
        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);
        if(renderer==NULL){
                wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
@@ -202,17 +229,28 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
 
        // Actor
        vtkTextActor3D *textActor = vtkTextActor3D::New();
+/* EED Borrame 
        textActor->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+*/ 
        textActor->SetInput( strLabel.c_str()  );
        renderer->AddActor( textActor );
        lstActorsText.push_back(textActor);
 
+       RefreshPoint(lstPointsX.size()-1);
+       
+       
        SetOutputBox();
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 {
+       if(mimage==NULL){
+               wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
+               dialog.ShowModal();
+               return;
+       }
+       
        if (this->renderer!=NULL){
                if (mpoint.size()==3){
                        AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
@@ -333,6 +371,58 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 //------------------------------------------------------------------------
 
        int WidgetShowNPoints::GetNearestPoint()
+       {
+               int id=-1;
+               int i, size=(int)(lstActorsSphere.size());
+               double radioMin=10000000;
+               
+               if(mimage ==NULL){                      
+                       wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
+                       diag->ShowModal();
+                       return -1;
+               }else{
+                       
+                       for ( i=0  ; i<size; i++ )
+                       {
+                               double rx =  mpoint[0] - lstPointsX [i];
+                               double ry =  mpoint[1] - lstPointsY [i];
+                               double rz =  mpoint[2] - lstPointsZ [i];
+                               double radio = rx*rx + ry*ry + rz*rz;
+                               if ( radio <= radioMin)
+                               {
+                                       radioMin=radio;
+                                       id=i;
+                               }       // if
+                       } // for
+                       
+                       return id;
+               }
+       }
+
+       
+       //------------------------------------------------------------------------
+       void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
+       {
+               int id=GetNearestPoint();
+               if (id>=0)
+               {
+                       printf("WidgetShowNPoints::OnSetPoint \n");
+                       lstPointsX[id] = mpoint[0];
+                       lstPointsY[id] = mpoint[1];
+                       lstPointsZ[id] = mpoint[2];             
+                       RefreshPoint(id);
+                       /*EED Borrame
+                        this->lstActorsSphere[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
+                        this->lstActorsText[id]->SetPosition(  spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
+                        */ 
+               } // if id
+               SetOutputBox();
+       }
+       
+       
+       //------------------------------------------------------------------------
+       
+       int WidgetShowNPoints::IdInsidePoint()
        {
                int id=-1;
                int i, size=(int)(lstActorsSphere.size());
@@ -361,10 +451,11 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
                }
        }
 
+       
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
        {
-               int id=GetNearestPoint();
+               int id=IdInsidePoint();
                if (id>=0)
                {
                        std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
@@ -402,7 +493,7 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
        {
-               ErasePoint( GetNearestPoint() );
+               ErasePoint( IdInsidePoint() );
        }
 
 //------------------------------------------------------------------------
index c890f13066389ef4fcaf16b8cee25f1da2b6d9cf..fd2d8487b73a7ee68a42e40256d52e57d3099aa4 100644 (file)
@@ -22,15 +22,17 @@ namespace bbcreaMaracasVisu
          WidgetShowNPoints( wxWindow *parent,  ShowNPoints *box);
          ~WidgetShowNPoints(); 
          void OnAddPoint(wxCommandEvent &event);   
+         void OnSetPoint(wxCommandEvent& event);
          void OnRenamePoint(wxCommandEvent& event);
          void OnErasePoint(wxCommandEvent& event);
          void OnEraseLastPoint(wxCommandEvent &event);   
          void OnDeleteAllPoints(wxCommandEvent &event);   
          void OnSavePoints(wxCommandEvent &event);   
          void OnLoadPoints(wxCommandEvent &event);
-
          void UpdatePoints(wxCommandEvent &event);
          
+         void RefreshPoint(int id);
+         
          void SetPoint(std::vector<int> ppoint);
          void SetColour(std::vector<double> colour);
          void SetOpacity(double opacity);
@@ -47,6 +49,7 @@ namespace bbcreaMaracasVisu
          void                  AddPoint(int x, int y, int z, std::string label);
          std::string           CleanSpaces(std::string ss);
          int                   GetNearestPoint();
+         int                                   IdInsidePoint();
          void                  ErasePoint(int id);
          void                  SetOutputBox();