]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbmaracasvisuShowNPoints.cxx
#3096 creaMaracasVisu Feature New Normal - Box ShowNPoints_Reset
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuShowNPoints.cxx
index cf0a4de47774b00d88e415a94f4b0847ca056a78..440f361de35ba84b59ce86dfe3cac5b8ba35b140 100644 (file)
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
 #include "bbmaracasvisuShowNPoints.h"
 #include "bbcreaMaracasVisuPackage.h"
 
-#include "vtkProperty.h"
-#include "vtkSphereSource.h"
-#include "vtkPolyDataMapper.h"
-#include "vtkRenderWindow.h"
-#include "vtkTextActor3D.h"
 
 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;
-       
-
-       // Widget interface
-       textCtrl                                                = new wxTextCtrl(panel, -1);
-       wxButton *btnAddPoint                   = new wxButton( panel, -1, _T("Add 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"));
-
-
-       wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); 
-//    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
-
-    Connect(btnAddPoint->GetId()               , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
-    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);
-
-    sizer1->Add(textCtrl);
-       sizer1->Add(btnAddPoint);
-       sizer1->Add(btnErasePoint);
-    sizer1->Add(btnEraseLastPoint);
-    sizer1->Add(btnDeleteAllPoints);
-
-       sizer = sizer1;
-       panel   ->      SetSizer(sizer);
-    panel      ->      SetAutoLayout(true);
-    panel      ->      Layout();  
-       
-}
-
-
-//------------------------------------------------------------------------
-WidgetShowNPoints::~WidgetShowNPoints()
-{
-}
-
-void WidgetShowNPoints::SetRadio(double radio)
-{
-       mradio=radio;
-}
-
-//------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsX()
-{
-       return lstPointsX;
-}
-
 //------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsY()
-{
-       return lstPointsY;
-}
-
 //------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsZ()
-{
-       return lstPointsZ;
-}
-
 //------------------------------------------------------------------------
-       std::vector<std::string> WidgetShowNPoints::GetLstLabels()
-{
-       return lstLabels;
-}
-       
-       
-
-
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
+WidgetShowNPointsBox::WidgetShowNPointsBox(wxWindow *parent,  bbcreaMaracasVisu::ShowNPoints *box, int type)
+    : WidgetShowNPoints( parent, type)
 {
-       mpoint = ppoint;
+       mbbShowNPoints=box;
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetColour(std::vector<double> colour)
+WidgetShowNPointsBox::~WidgetShowNPointsBox()
 {
-       this->mcolour = colour;
 }
 
-//------------------------------------------------------------------------
-void WidgetShowNPoints::SetOpacity(double opacity)
-{
-       this->mopacity=opacity;
-}
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetImage(vtkImageData *image)
+void WidgetShowNPointsBox::UpdatePoints(wxCommandEvent &event)
 {
-       this->mimage=image;
-}
+printf("EED WidgetShowNPointsBox::UpdatePoints start\n");
+       WidgetShowNPoints::UpdatePoints(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
+       mbbShowNPoints->bbSetInputOpacity( GetOpacity() );
+       mbbShowNPoints->bbSetInputRadio( GetRadio() );
+       // EED 
+//     RefreshPoints();
+printf("EED WidgetShowNPointsBox::UpdatePoints end\n");
 
-//------------------------------------------------------------------------
-void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
-{
-       this->renderer  = renderer;
 }
 
 
-
 //------------------------------------------------------------------------
-void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
+void WidgetShowNPointsBox::SetOutputBox()
 {
-       if (this->renderer!=NULL){ 
-               if (mpoint.size()==3){
-                       lstPointsX.push_back( mpoint[0] );
-                       lstPointsY.push_back( mpoint[1] );
-                       lstPointsZ.push_back( mpoint[2] );
-                       lstLabels.push_back( (const char*) ( textCtrl->GetValue().mb_str() )  );
-
-                       // 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 );
+       WidgetShowNPoints::SetOutputBox();
 
-                       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( (const char*) ( textCtrl->GetValue().mb_str() )  );
-                       renderer->AddActor( textActor );
-                       lstActorsText.push_back(textActor);
-                       
-                       renderer->GetRenderWindow()->Render();
+//     wxString strTmp;
+//     strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
+//     txtNrPoints->SetLabel(  strTmp );
 
-                       SetOutputBox(); 
-                       
-               } else {//mpoint.size
-                       printf("creaMaracasVisu::ShowNPoints (not match point) \n");
-               }
-       } // renderer
+       //--BBTK
+       mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
+       mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
+       mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
+       mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
+       mbbShowNPoints->bbSignalOutputModification();
 }
 
-       void WidgetShowNPoints::SetOutputBox()
-       {
-               //--BBTK
-               mbbShowNPoints->bbSetOutputlstPointsX( GetLstPointsX() );
-               mbbShowNPoints->bbSetOutputlstPointsY( GetLstPointsY() );
-               mbbShowNPoints->bbSetOutputlstPointsZ( GetLstPointsZ() );
-               mbbShowNPoints->bbSetOutputlstLabels( GetLstLabels() );
-               mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));    
-               mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));    
-               mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));    
-               mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));    
-       }
-       
-       //------------------------------------------------------------------------
-       void WidgetShowNPoints::ErasePoint(int id)
-       {
-               if (this->renderer!=NULL){ 
-                       if (id>=0){
-                               renderer->RemoveActor( lstActorsSphere[id] );
-                               renderer->RemoveActor( lstActorsText[id] );
-                                lstActorsSphere[id]->Delete();
-                                lstActorsText[id]->Delete();
-                               lstActorsSphere.erase( lstActorsSphere.begin()+id );
-                               lstActorsText.erase( lstActorsText.begin()+id );
-                               
-                               lstPointsX.erase( lstPointsX.begin()+id );
-                               lstPointsY.erase( lstPointsY.begin()+id );
-                               lstPointsZ.erase( lstPointsZ.begin()+id );
-                               lstLabels.erase( lstLabels.begin()+id );
 
-                               renderer->GetRenderWindow()->Render();
-                               SetOutputBox(); 
 
-                       } // if id
-               } // if renderer
-       }
-       
-       //------------------------------------------------------------------------
-       void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
-       {
-               int id=-1;
-               int i, size=(int)(lstActorsSphere.size());
-               double spc[3];
-               mimage->GetSpacing(spc);
-               
-               for ( i=0  ; i<size; i++ )
-               {
-                       double rx =  spc[0]*(mpoint[0] - lstPointsX [i]);
-                       double ry =  spc[1]*(mpoint[1] - lstPointsY [i]);
-                       double rz =  spc[2]*(mpoint[2] - lstPointsZ [i]);
-                       if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
-                       {
-                               id=i;
-                       }       // if           
-               } // for
-               ErasePoint(id);
-       }
-       
-       //------------------------------------------------------------------------
-       void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
-       {
-               ErasePoint(lstActorsSphere.size()-1);
-       }
-       
-       
 //------------------------------------------------------------------------
-void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
-{
-       int id,size=lstActorsSphere.size();
-       for (id=size-1;id>=0;id--)
-       {
-               ErasePoint(id);
-       }
-               
-}
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+
 
 
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
 
+//-----------------------------------------------------------------
 void ShowNPoints::Process()
 {
-       if (mwxwidget!=NULL){
-               mwxwidget->SetRenderer( bbGetInputRenderer() );   
-               mwxwidget->SetPoint( bbGetInputIn() );   
-               mwxwidget->SetImage( bbGetInputImage() );   
-               mwxwidget->SetColour( bbGetInputColour() );   
-               mwxwidget->SetOpacity( bbGetInputOpacity() );   
-               mwxwidget->SetRadio( bbGetInputRadio() );   
+       if (mwxwidget!=NULL)
+       {
+               mwxwidget->SetRenderer( bbGetInputRenderer() );
+               mwxwidget->SetReferencePoint( bbGetInputIn() );
+               mwxwidget->SetImage( bbGetInputImage() );
+               mwxwidget->SetColour( bbGetInputColour() );
+               mwxwidget->SetOpacity( bbGetInputOpacity() );
+               mwxwidget->SetRadio( bbGetInputRadio() );
+
+               if ( mwxwidget->GetModelShowNPoints()->GetFirstTime()==true )
+               {
+                       mwxwidget->GetModelShowNPoints()->SetFirstTime(false);
+                       mwxwidget->SetInitLstPoints( bbGetInputInitLstPointsX() , bbGetInputInitLstPointsY() , bbGetInputInitLstPointsZ() , bbGetInputInitLstLabels() );
+               }
 
-               bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
-               bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
-               bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
-               bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
+               bbSetOutputlstPointsX( mwxwidget->GetModelShowNPoints()->GetLstPointsX() );
+               bbSetOutputlstPointsY( mwxwidget->GetModelShowNPoints()->GetLstPointsY() );
+               bbSetOutputlstPointsZ( mwxwidget->GetModelShowNPoints()->GetLstPointsZ() );
+               bbSetOutputlstLabels( mwxwidget->GetModelShowNPoints()->GetLstLabels() );
+               bbSetOutputWidgetShowNPoints( (WidgetShowNPoints*)mwxwidget );
        } // mwxwidget
 }
 
-
+//-----------------------------------------------------------------
 void ShowNPoints::CreateWidget(wxWindow* parent)
 {
-       mwxwidget = new WidgetShowNPoints( parent ,  this);
-       mwxwidget->SetPoint( bbGetInputIn() );
-
-       if (bbGetInputImage()==NULL)
-       {
-               printf("Missing Image  (ShowNPoints) \n");
-       }
-
-   bbSetOutputWidget( mwxwidget ); 
+       mwxwidget = new WidgetShowNPointsBox( parent, this, bbGetInputType() );
+    bbSetOutputWidget( mwxwidget );
 }
 
+//-----------------------------------------------------------------
 void ShowNPoints::bbUserSetDefaultValues()
 {
        mwxwidget = NULL;
-
-       bbSetInputRadio(0.5);
+       bbSetInputRadio(10);
        bbSetInputOpacity(1);
-       
        std::vector<double> colour;
        colour.push_back(1.0);
        colour.push_back(0.0);
        colour.push_back(0.0);
        bbSetInputColour(colour);
-
        bbSetInputImage(NULL);
+       bbSetInputType(0);
        bbSetInputRenderer(NULL);
+       bbSetOutputWidgetShowNPoints(NULL);
 }
-       
-       //-----------------------------------------------------------------     
+
+//-----------------------------------------------------------------
        void ShowNPoints::bbUserInitializeProcessing()
        {
        }
-       
-       //-----------------------------------------------------------------     
+
+//-----------------------------------------------------------------
        void ShowNPoints::bbUserFinalizeProcessing()
        {
        }
-       
-       //-----------------------------------------------------------------     
+
+//-----------------------------------------------------------------
 
 }
 // EO namespace bbcreaMaracasVisu
-
-