]> Creatis software - creaMaracasVisu.git/commitdiff
2392 creaMaracasVisu Feature New Normal InsertPoint in showNPoints 2014-06-13 11:13
authorctorres <carlos.torres@creatis.insa-lyon.fr>
Fri, 13 Jun 2014 09:14:19 +0000 (11:14 +0200)
committerctorres <carlos.torres@creatis.insa-lyon.fr>
Fri, 13 Jun 2014 09:14:19 +0000 (11:14 +0200)
bbtk/src/bbmaracasvisuShowNPoints.cxx
bbtk/src/bbmaracasvisuShowNPoints.h

index 7c33f5d340c18a08ef325a8b5dfbd5eb1ffed1a6..b9d212e6f5a36c98ddc6f0e305570687a19da728 100644 (file)
@@ -51,6 +51,7 @@ namespace bbcreaMaracasVisu
                askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
                textCtrl                                                = new wxTextCtrl(panel, -1);
                wxButton *btnAddPoint                   = new wxButton( panel, -1, _T("Add Point"));
+               wxButton *btnInsertPoint                        = new wxButton( panel, -1, _T("Insert Point"));//CFT
                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"));
@@ -70,6 +71,7 @@ namespace bbcreaMaracasVisu
                //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
 
                Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
+               Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
                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);
@@ -85,6 +87,7 @@ namespace bbcreaMaracasVisu
                sizer1->Add(askPointLabel); // JPR
                sizer1->Add(textCtrl);
                sizer1->Add(btnAddPoint);
+               sizer1->Add(btnInsertPoint);//CFT
                sizer1->Add(btnSetPositionPoint);
                sizer1->Add(btnRenamePoint);
                sizer1->Add(btnErasePoint);
@@ -320,6 +323,94 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
        RefreshPoint(lstPointsX.size()-1);
 }
 
+//------------------------------------------------------------------------
+double WidgetShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT
+{
+    return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0));
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
+{
+       std::cout<<"WidgetShowNPoints::InsertPoint begin "<<std::endl;
+       std::vector<int> dTotal;
+       int pos = 0;
+       int a,b,res;
+       //Calcule distance for each pair of points
+       for(int i = 0; i<lstPointsX.size()-1 ; i++)
+       {
+               a = Distance(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]);
+               b = Distance(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]);
+               res = a + b;            
+               dTotal.push_back (res);         
+       }
+       //Gets the smallest distance 
+       int small = dTotal[0];
+       for (int j = 0; j < dTotal.size(); j++)
+  {
+      if(dTotal[j]<small)
+      {
+                     small=dTotal[j];
+                                       pos = j+1;
+      }
+  }
+
+       std::vector<int>::iterator it;
+       //Insert the point in the list of points
+       it = lstPointsX.begin();
+       lstPointsX.insert( it+pos, x );
+       it = lstPointsY.begin();
+       lstPointsY.insert( it+pos, y );
+       it = lstPointsZ.begin();
+       lstPointsZ.insert( it+pos, z );
+
+       std::string strLabel = CleanSpaces(  label );
+       
+       std::vector<std::string>::iterator itS;
+       itS = lstLabels.begin();
+       //Insert Label in list of labels
+       lstLabels.insert( itS+pos, strLabel );
+
+       // Sphere
+       vtkSphereSource *vtksphere              = vtkSphereSource::New();
+       vtksphere->SetThetaResolution (20);
+       vtksphere->SetPhiResolution (20);
+       vtksphere->SetRadius( mradio  );
+
+       //NTU: For updating points
+       std::vector<vtkSphereSource*>::iterator itSS;
+       itSS = lstSourceSphere.begin();
+       lstSourceSphere.insert( itSS+pos, vtksphere);
+
+       vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
+       sphereMapper->SetInput( vtksphere->GetOutput() );
+       vtkActor *sphereActor   = vtkActor::New();
+       sphereActor->SetMapper(sphereMapper);
+       sphereActor->SetOrigin(0, 0, 0);
+
+       std::vector<vtkActor*>::iterator itAS;
+       itAS = lstActorsSphere.begin();
+       lstActorsSphere.insert( itAS+pos, sphereActor);
+       if(renderer==NULL){
+               wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
+               dialog.ShowModal();             
+               return;
+       }
+       renderer->AddActor( sphereActor );
+
+       // Actor
+       vtkTextActor3D *textActor = vtkTextActor3D::New();
+
+       textActor->SetInput( strLabel.c_str()  );
+       renderer->AddActor( textActor );
+       std::vector<vtkTextActor3D*>::iterator itTA;
+       itTA = lstActorsText.begin();
+       lstActorsText.insert( itTA+pos , textActor);
+
+       RefreshPoint(pos);
+       std::cout<<"WidgetShowNPoints::InsertPoint end"<<std::endl;
+}
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 {
@@ -339,6 +430,28 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
        } // renderer
 }
 
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
+{
+       std::cout<<"WidgetShowNPoints::OnInsertPoint begin"<<std::endl;
+       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){
+                       InsertPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
+                       SetOutputBox();
+               } else {//mpoint.size
+                       printf("creaMaracasVisu::ShowNPoints (not match point) \n");
+               }
+       } // renderer
+       std::cout<<"WidgetShowNPoints::OnInsertPoint end"<<std::endl;
+}
+
+
 //------------------------------------------------------------------------
        void WidgetShowNPoints::SetOutputBox()
        {
index d9eccccd0c09ef45998adaac1691d59c7da683fc..5879aed318617f9c7d64f80c02d0bddc2c859a11 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef __bbcreaMaracasVisuShowNPoints_h_INCLUDED__
 #define __bbcreaMaracasVisuShowNPoints_h_INCLUDED__
 #include "bbtkWxBlackBox.h"
-
+#include <cmath>
 
 #include "vtkActor.h"
 #include "vtkSphereSource.h"
@@ -47,6 +47,7 @@ namespace bbcreaMaracasVisu
          WidgetShowNPoints( wxWindow *parent,  ShowNPoints *box);
          ~WidgetShowNPoints(); 
          void OnAddPoint(wxCommandEvent &event);   
+               void OnInsertPoint (wxCommandEvent& event);//CFT
          void OnSetPoint(wxCommandEvent& event);
          void OnRenamePoint(wxCommandEvent& event);
          void OnErasePoint(wxCommandEvent& event);
@@ -70,7 +71,8 @@ namespace bbcreaMaracasVisu
          std::vector<std::string> GetLstLabels();
 
          void AddPoint(int x, int y, int z, std::string label);
-
+               void InsertPoint(int x, int y, int z, std::string label);//CFT
+               double Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1);//CFT
 
   private: