]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
#3485 ShowNPionts for Multiple Groups
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
index 1a5a8dca32c971dab43839430aef052b5ff69c88..f7fa68f29570aefedf98041f7cb6a7350fc772f6 100644 (file)
@@ -1,15 +1,10 @@
 
 
-#include "vtkActor.h"
 #include "vtkSphereSource.h"
 #include "vtkRenderer.h"
 #include "vtkTextActor3D.h"
 
 
-#include "vtkProperty.h"
-#include "vtkPolyDataMapper.h"
-#include "vtkRenderWindow.h"
-#include <vtkTextProperty.h>
 
 #include <wx/button.h>
 #include <wx/sizer.h>
   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
   {
-       mmodelShowNPoints                               = new ModelShowNPoints();
+       // EED 2022-05-19
+    //  mmodelShowNPoints                               = new ModelShowNPoints();
+      mActualLstPoints=0;
+      ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
+      lstModelShowNPoints.push_back( modelShowNPoints );
+      lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
+      
+      
     mtype                                                      = type;
     SetType(mtype);
-    this->renderer                                     = NULL;
     wxPanel    *panel                                  = this;
     wxSizer *sizer                                     = NULL;
 
         sizer1->Add(btnDeleteAllPoints);
         sizer1->Add(spacer);
         sizer1->Add(textCtrl);
-        sdrOpacity = new wxSlider();
-        sdrRadio = new wxSlider();
+        sdrOpacity  = new wxSlider();
+        sdrRadio    = new wxSlider();
         txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
         sizer = sizer1;
        } // bbGetInputType 2
@@ -164,14 +165,29 @@ WidgetShowNPoints::~WidgetShowNPoints()
 //------------------------------------------------------------------------
 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
 {
-       return mmodelShowNPoints;
+    // EED 2022-05-19
+    // return mmodelShowNPoints;
+    return lstModelShowNPoints[ mActualLstPoints ];
+}
+
+// EED 2022-05-19
+//------------------------------------------------------------------------
+ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
+{
+    return lstViewShowNPoints[ mActualLstPoints ];
 }
 
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::SetRadio(double radio)
 {
-       GetModelShowNPoints()->SetRadio(radio);
+    // EED 2022-05-19
+    // GetModelShowNPoints()->SetRadio(radio);
+    int i,size = lstModelShowNPoints.size();
+    for (i=0;i<size;i++)
+    {
+        lstModelShowNPoints[i]->SetRadio( radio );
+    } // for i
        //NTU: For Slider
        sdrRadio->SetValue(radio);
 }
@@ -179,61 +195,77 @@ void WidgetShowNPoints::SetRadio(double radio)
 //------------------------------------------------------------------------
 void WidgetShowNPoints::SetColour(std::vector<double> colour)
 {
-       this->mcolour = colour;
+    // EED 2022-05-19
+    //this->mcolour = colour;
+    int i,size = lstViewShowNPoints.size();
+    for (i=0 ; i<size ; i++)
+    {
+        lstViewShowNPoints[i]->mcolour = colour;
+    } // for i
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::SetImage(vtkImageData* image)
 {
-       GetModelShowNPoints()->SetImage(image);
+    // EED 2022-05-19
+       //GetModelShowNPoints()->SetImage(image);
+    int i,size = lstModelShowNPoints.size();
+    for (i=0 ; i<size ; i++)
+    {
+        lstModelShowNPoints[i]->SetImage(image);
+    } // for i
 }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::SetOpacity(double opacity)
 {
-       this->mopacity=opacity;
+    // EED 2022-05-19
+       //this->mopacity=opacity;
+    int i,size = lstViewShowNPoints.size();
+    for (i=0 ; i<size ; i++)
+    {
+        lstViewShowNPoints[i]->mopacity = opacity;
+    } // for i
        //NTU: For Slider
-       sdrOpacity->SetValue(this->mopacity*100.0);
+       sdrOpacity->SetValue( opacity*100.0 );
 }
 
 
 //------------------------------------------------------------------------
 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
 {
-       this->renderer  = renderer;
+    // EED 2022-05-19
+       //this->renderer        = renderer;
+    int i,size = lstViewShowNPoints.size();
+    for (i=0 ; i<size ; i++)
+    {
+        lstViewShowNPoints[i]->renderer = renderer;
+    } // for i
 }
-       
+
+/* EED 2022-05-19
 //------------------------------------------------------------------------
        
 void WidgetShowNPoints::RefreshPoint(int id)
 {
        double spc[3];
-
-//EED 2016/06/17
-//     mimage->GetSpacing(spc);
-//     int x = lstPointsX[id];
-//     int y = lstPointsY[id];
-//     int z = lstPointsZ[id];
        int x,y,z;
        GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
        GetModelShowNPoints()->GetImage()->GetSpacing(spc);
        std::string label       = GetModelShowNPoints()->GetIdLabel(id);
        double radio            = GetModelShowNPoints()->GetRadio();
-
-       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 );
-       lstSourceSphere[id]->SetRadius( radio );
-
+    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 );
+    lstSourceSphere[id]->SetRadius( radio );
 //EED 2017-01-01 Migration VTK7
 #if VTK_MAJOR_VERSION <= 5
        // ..
 #else
-       lstSourceSphere[id]->Update();
+    lstSourceSphere[id]->Update();
 #endif
-
-       lstActorsText[id]->SetInput( label.c_str()  );
-       lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
+    lstActorsText[id]->SetInput( label.c_str()  );
+    lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
 }
 
 //------------------------------------------------------------------------
@@ -284,39 +316,47 @@ void WidgetShowNPoints::AddVtkPoint()
        renderer->AddActor( textActor );
        lstActorsText.push_back(textActor);
 }
+ */
 
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
 {
        GetModelShowNPoints()->AddPoint(x,y,z, label );
-       AddVtkPoint();
-       RefreshPoint(lstActorsSphere.size()-1);
+    // EED 2022-05-19
+    //AddVtkPoint();
+    //RefreshPoint(lstActorsSphere.size()-1);
+    GetViewShowNPoints()->AddPoint();
 }
 
-
-
 //------------------------------------------------------------------------
 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
 {
+    // EED 2022-05-19
+       //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
+       //{
+    //    AddVtkPoint();
+       //} else {
+       //      AddPoint(x,y,z,label);
+       //}
+       //RefreshPoints();
+    if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
+    {
+        GetViewShowNPoints()->AddVtkPoint();
+    } else {
+        AddPoint(x,y,z,label);
+    }
+    GetViewShowNPoints()->RefreshPoints();
 
-//--
-       if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
-       {
-               AddVtkPoint();
-       } else {
-               AddPoint(x,y,z,label);
-       }
-       RefreshPoints();
-       //end if
 }
 
-
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 {      
-       if (this->renderer==NULL)
-       { 
+    // EED 2022-05-19
+       //if (this->renderer==NULL)
+    if (GetViewShowNPoints()->renderer==NULL)
+       {
                return;
        }
 
@@ -325,7 +365,9 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
        {
                AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
                SetOutputBox();
-               renderer->GetRenderWindow()->Render();
+        // EED 2022-05-19
+        //renderer->GetRenderWindow()->Render();
+        GetViewShowNPoints()->Render();
        } else {//mpoint.size
                printf("creaMaracasVisu::ShowNPoints (not match point) \n");
        }
@@ -334,8 +376,10 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
 {      
-       if (this->renderer==NULL)
-       { 
+    // EED 2022-05-19
+    //if (this->renderer==NULL)
+    if (GetViewShowNPoints()->renderer==NULL)
+       {
                return;
        }
 
@@ -356,7 +400,7 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
 //EED          renderer->GetRenderWindow()->Render();
                wxString strTmp;
                strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
-               txtNrPoints->SetLabel(  strTmp );
+               txtNrPoints->SetLabel( strTmp );
                //--BBTK
 
 //EED 2017-06-03
@@ -391,13 +435,9 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                                             wxDefaultPosition);
 #endif
 
-
-
                int result_FD = FD->ShowModal();
-               
                // This line is need it by windows //EED
                FD->SetReturnCode( result_FD );
-
                if (FD->GetReturnCode()==wxID_OK)
                {
                        std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
@@ -440,12 +480,15 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                        int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
                        for (i=0;i<numberPointsRead;i++)
                        {
-                               AddVtkPoint();
+                // EED 2022-05-19
+                //AddVtkPoint();
+                GetViewShowNPoints()->AddVtkPoint();
                        }// for
                        SetOutputBox();
-                       RefreshPoints();
+            // EED 2022-05-19
+                       //RefreshPoints();
+            GetViewShowNPoints()->RefreshPoints();
                }       // dialog box
-
        }
 
        //------------------------------------------------------------------------
@@ -462,8 +505,11 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                if (id>=0)
                {
                        GetModelShowNPoints()->SetPointId_mReferencePoint(id);
-                       RefreshPoint(id);
-                       renderer->GetRenderWindow()->Render();
+            // EED 2022-05-19
+                       //RefreshPoint(id);
+                       //renderer->GetRenderWindow()->Render();
+            GetViewShowNPoints()->RefreshPoint(id);
+            GetViewShowNPoints()->Render();
                } // if id
                SetOutputBox();
        }
@@ -474,27 +520,34 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
                if (id>=0)
                {
-                       lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
-                       SetOutputBox();
-                       renderer->GetRenderWindow()->Render();
+            // EED 2022-05-19
+                       //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
+                       //renderer->GetRenderWindow()->Render();
+            GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
+            GetViewShowNPoints()->Render();
+            SetOutputBox();
                }
        }
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::ErasePoint(int id)
        {
-               if (this->renderer!=NULL)
+        // EED 2022-05-19
+               //if (this->renderer!=NULL)
+        if (GetViewShowNPoints()->renderer!=NULL)
                {
                        if (id>=0)
                        {
-                               renderer->RemoveActor( lstActorsSphere[id] );
-                               renderer->RemoveActor( lstActorsText[id] );
-                               lstActorsSphere[id]->Delete();
-                               lstActorsText[id]->Delete();
-                               lstSourceSphere[id]->Delete();
-                               lstActorsSphere.erase( lstActorsSphere.begin()+id );
-                               lstActorsText.erase( lstActorsText.begin()+id );
-                               lstSourceSphere.erase( lstSourceSphere.begin()+id );
+                // EED 2022-05-19
+                               //renderer->RemoveActor( lstActorsSphere[id] );
+                               //renderer->RemoveActor( lstActorsText[id] );
+                               //lstActorsSphere[id]->Delete();
+                               //lstActorsText[id]->Delete();
+                               //lstSourceSphere[id]->Delete();
+                               //lstActorsSphere.erase( lstActorsSphere.begin()+id );
+                               //lstActorsText.erase( lstActorsText.begin()+id );
+                               //lstSourceSphere.erase( lstSourceSphere.begin()+id );
+                GetViewShowNPoints()->ErasePoint(id);
                                GetModelShowNPoints()->ErasePoint(id);
                        } // if id
                } // if renderer
@@ -505,27 +558,37 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
        {
                ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
                SetOutputBox();
-               renderer->GetRenderWindow()->Render();
+        // EED 2022-05-19
+               //renderer->GetRenderWindow()->Render();
+        GetViewShowNPoints()->Render();
        }
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
        {
-               ErasePoint(lstActorsSphere.size()-1);
-               SetOutputBox();
-               renderer->GetRenderWindow()->Render();
+        // EED 2022-05-19
+        //ErasePoint( lstActorsSphere.size()-1 );
+        //renderer->GetRenderWindow()->Render();
+        int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
+        ErasePoint( id );
+        GetViewShowNPoints()->Render();
+        SetOutputBox();
        }
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::DeleteAllPoints()
 {
-       int id,size=lstActorsSphere.size();
+    // EED 2022-05-19
+       //int id,size=lstActorsSphere.size();
+    int id,size=GetViewShowNPoints()->lstActorsSphere.size();
        for (id=size-1;id>=0;id--)
        {
                ErasePoint(id);
        }
        SetOutputBox();
-       renderer->GetRenderWindow()->Render();
+    // EED 2022-05-19
+       //renderer->GetRenderWindow()->Render();
+    GetViewShowNPoints()->Render();
 }
 
 //------------------------------------------------------------------------
@@ -539,18 +602,20 @@ void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
 //------------------------------------------------------------------------
 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
 {
-       //Difference in Radio for text placement
-//     double radio=GetModelShowNPoints()->GetRadio();
-       this->mopacity = sdrOpacity->GetValue()/100.0;
-       GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
-//     radio = sdrRadio->GetValue();
-       //NTU refresh the inputs
-
-//EED 2017-06-03
-//     mbbShowNPoints->bbSetInputOpacity(this->mopacity);
-//     mbbShowNPoints->bbSetInputRadio( radio );
-       // EED 
-       RefreshPoints();
+    // EED 2022-05-19
+       //this->mopacity = sdrOpacity->GetValue()/100.0;
+    //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
+    //RefreshPoints();
+
+    double opacity  = sdrOpacity->GetValue()/100.0;
+    double radio    = sdrRadio->GetValue();
+    int i,size      = lstViewShowNPoints.size();
+    for (i=0 ; i<size ; i++)
+    {
+        lstViewShowNPoints[i]->mopacity = opacity;
+        lstModelShowNPoints[i]->SetRadio( radio ) ;
+    } // for i
+    GetViewShowNPoints()->RefreshPoints();
 }
 
 //------------------------------------------------------------------------
@@ -562,23 +627,21 @@ void  WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
 //------------------------------------------------------------------------
 void  WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX,  std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
 {
-       if (this->renderer==NULL)
-       { 
+    // EED 2022-05-19
+       //if (this->renderer==NULL)
+    if (GetViewShowNPoints()->renderer==NULL)
+       {
                return;
        }
-
        int i,sizeX,sizeY,sizeZ,sizeLabels;
        sizeX=(int)initLstPointsX.size();
        sizeY=(int)initLstPointsY.size();
        sizeZ=(int)initLstPointsZ.size();
        sizeLabels=(int)initLstLabels.size();
-
        int x,y,z;
        std::string label;
-
        if ( (sizeX==sizeY) && (sizeX==sizeZ) )
        {
-
                for (i=0;i<sizeX;i++)
                {
                        x               = initLstPointsX[i];
@@ -594,9 +657,9 @@ void  WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX,  std
                } // for i
                //      SetOutputBox(); 
                //      renderer->GetRenderWindow()->Render();
-
        } // if size
 }
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::SetType(int type)
 {
@@ -615,11 +678,8 @@ double WidgetShowNPoints::GetRadio()
 {
        return sdrRadio->GetValue();
 }
-
 //------------------------------------------------------------------------
 double WidgetShowNPoints::GetOpacity()
 {
-       return mopacity;
+       return sdrOpacity->GetValue()/100;
 }
-
-