]> Creatis software - creaMaracasVisu.git/commitdiff
#2982 creaMaracasVisu Feature New Normal - ShowNPoints_model
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 30 Jun 2016 00:50:06 +0000 (02:50 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 30 Jun 2016 00:50:06 +0000 (02:50 +0200)
bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx
bbtk/src/bbcreaMaracasVisuManualContourModel_Box.h
bbtk/src/bbmaracasvisuAxeVolume.cxx
bbtk/src/bbmaracasvisuAxeVolume.h
bbtk/src/bbmaracasvisuImageChangeInformation.cxx
bbtk/src/bbmaracasvisuShowNPoints.cxx
bbtk/src/bbmaracasvisuShowNPoints.h

index e1f639297815ece66af07687b09cdfcc11b507c1..0c59a4c75db8450b337051ab05fe5cac3261ea07 100644 (file)
@@ -74,7 +74,7 @@ void ManualContourModel_Box::bbUserSetDefaultValues()
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
    bbSetInputType(1);
-   bbSetInputOpenClose(true);
+   bbSetInputOpenClose(false);
    bbSetInputNbPoints(100);
   
 }
index 0786994ff1829dce00f483a35931ad074d546f25..9e34c0a5fafed781a3c9445b3e8ec6186b24e4c0 100644 (file)
@@ -41,8 +41,8 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ManualContourModel_Box,bbtk::AtomicBlackBox);
   BBTK_CATEGORY("empty");
 
   BBTK_INPUT(ManualContourModel_Box,Type,"(1 default) 1=spline, 2=rectangle, 3=circle, 4=bullEye, 6=Line, 7=points, 8=rotationTool, 10=polugon, 12=Spline3D",int,"");
-  BBTK_INPUT(ManualContourModel_Box,OpenClose,"(true default) true=open, fals=close",bool,"");
-  BBTK_INPUT(ManualContourModel_Box,NbPoints,"Number of points int the spline",int,"");
+  BBTK_INPUT(ManualContourModel_Box,OpenClose,"(false default) false=open, true=close",bool,"");
+  BBTK_INPUT(ManualContourModel_Box,NbPoints,"(100 default) Number of points int the spline",int,"");
   BBTK_INPUT(ManualContourModel_Box,LstControlPointsX,"List of control points",std::vector<double>,"");
   BBTK_INPUT(ManualContourModel_Box,LstControlPointsY,"List of control points",std::vector<double>,"");
   BBTK_INPUT(ManualContourModel_Box,LstControlPointsZ,"List of control points",std::vector<double>,"");
index 79e5ac0cf0fbfb4ccbed8ce1268a661ec33599f3..5cb228ef9c0c2a0ff2f333498d4e757e3381d632 100644 (file)
 
 #include "bbmaracasvisuAxeVolume.h"
 #include "bbcreaMaracasVisuPackage.h"
+
 namespace bbcreaMaracasVisu
 {
 
+
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AxeVolume)
 BBTK_BLACK_BOX_IMPLEMENTATION(AxeVolume,bbtk::AtomicBlackBox);
-void AxeVolume::Process()
+
+int AxeVolume::GetTypeFormat( std::string formatStr , vtkImageData* image )
 {
+       int outputformat = VTK_UNSIGNED_CHAR;
+       if (formatStr=="SAME")
+       {                                               
+               if (image!=NULL) outputformat = image->GetScalarType();
+       }
+       else if (formatStr=="VTK_BIT")                          outputformat = VTK_BIT;                         // 1
+       else if (formatStr=="VTK_CHAR")                         outputformat = VTK_CHAR;                        // 2
+       else if (formatStr=="VTK_SIGNED_CHAR")          outputformat = VTK_SIGNED_CHAR;         // 15
+       else if (formatStr=="VTK_UNSIGNED_CHAR")        outputformat = VTK_UNSIGNED_CHAR;       // 3
+       else if (formatStr=="VTK_SHORT")                        outputformat = VTK_SHORT;                       // 4
+       else if (formatStr=="VTK_UNSIGNED_SHORT")       outputformat = VTK_UNSIGNED_SHORT;      // 5
+       else if (formatStr=="VTK_INT")                          outputformat = VTK_INT;                 // 6
+       else if (formatStr=="VTK_UNSIGNED_INT")         outputformat = VTK_UNSIGNED_INT;        // 7
+       else if (formatStr=="VTK_LONG")                         outputformat = VTK_LONG;                // 8  
+       else if (formatStr=="VTK_UNSIGNED_LONG")        outputformat = VTK_UNSIGNED_LONG;       // 9
+       else if (formatStr=="VTK_FLOAT")                        outputformat = VTK_FLOAT;               // 10
+       else if (formatStr=="VTK_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11 
+       else if (formatStr=="MET_CHAR")                         outputformat = VTK_CHAR;                        // 2
+       else if (formatStr=="MET_UCHAR")                        outputformat = VTK_UNSIGNED_CHAR;       // 3
+       else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;                       // 4
+       else if (formatStr=="MET_USHORT")                       outputformat = VTK_UNSIGNED_SHORT;      // 5
+       else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;               // 4
+       else if (formatStr=="MET_FLOAT")                        outputformat = VTK_FLOAT;               // 10
+       else if (formatStr=="MET_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11  
+
+    return outputformat;
+}
 
-       printf("EED AxeVolume::Process start \n");
 
+void AxeVolume::Process()
+{
        if ( mimage!=NULL )
        {
                mimage->Delete();
@@ -53,23 +84,17 @@ void AxeVolume::Process()
     invSpc[1] = 1/spc[1];
     invSpc[2] = 1/spc[2];
 
+       int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
+
        mimage = vtkImageData::New();
        mimage->SetSpacing(bbGetInputIn()->GetSpacing());
        mimage->SetDimensions(bbGetInputIn()->GetDimensions());
        mimage->SetExtent(bbGetInputIn()->GetExtent());
        mimage->SetOrigin(bbGetInputIn()->GetOrigin());
-       //mimage->SetDimensions(sizeX,sizeY,sizeZ);
-       //mimage->SetOrigin(0,0,0);
-       //mimage->SetExtent( 0 , sizeX-1 , 0 , sizeY-1 , 0, sizeZ-1 );
-       //mimage->SetWholeExtent( 0 , sizeX-1 , 0 , sizeY-1 , 0, sizeZ-1 );
-       mimage->SetScalarTypeToUnsignedShort();
-       //mimage->SetSpacing(spc);
+       mimage->SetScalarType( outputformat );
        mimage->AllocateScalars();
-
-
-
        int i,j,k;
-       int sizeLstPointR       = bbGetInputlstPointR().size();
+    int sizeLstPointR  = bbGetInputlstPointR().size();
        int iAxe,sizeAxe        = bbGetInputlstPointX().size();
        double rx,ry,rz;
        double r,rr;
@@ -78,7 +103,6 @@ void AxeVolume::Process()
        double px,py,pz;
        double px1,py1,pz1;
        double px2,py2,pz2;
-
        // Clean image
        p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
        for ( i=0 ; i<sizeImage ; i++)
@@ -89,6 +113,7 @@ void AxeVolume::Process()
 
        for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
         {
+printf("AxeVolume %d/%d\n ",iAxe,sizeAxe);
                if (iAxe<sizeLstPointR)
                {
                        r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
@@ -121,26 +146,26 @@ void AxeVolume::Process()
                                ry      =       ry*ry;
                                for ( k=pz1 ; k<pz2 ; k++ )
                                {
-                                       if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) ){
-                                               p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
-                                               if (*p==0)
+                                       if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
+                                       {
+//                                             p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
+//                                             if (*p==0)
+                                               if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
                                                {
                                                        rz      =       k - pz;
                                                        rz      =       rz*rz;
                                                        if ( rx + ry + rz <= rr )
                                                        {
-                                                               *p=255;
+//                                                             *p=255;
+                                                               mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
                                                        }
                                                } // *p==0
-                                       } // inside point
+                                       } // if inside point
                                } //for k
                        } //for j
                } //for i
        } // for iAxe
     bbSetOutputOut( mimage );
-
-       printf("EED AxeVolume::Process end \n");
-
 }
 
 
@@ -148,6 +173,8 @@ void AxeVolume::Process()
        void AxeVolume::bbUserSetDefaultValues()
        {
                mimage=NULL;
+               bbSetInputOutputFormat("SAME");
+               bbSetInputValue(255);
        }
 
        //-----------------------------------------------------------------
index e420365628fc1841bf5a425f422ff9c494336c27..ca670c6610a6d56f065af10a2e9946d4aaff3365 100644 (file)
@@ -43,10 +43,17 @@ class /*BBTK_EXPORT*/ AxeVolume
   BBTK_DECLARE_INPUT( lstPointY , std::vector<double> );
   BBTK_DECLARE_INPUT( lstPointZ , std::vector<double> );
   BBTK_DECLARE_INPUT( lstPointR , std::vector<double> );
+  BBTK_DECLARE_INPUT( OutputFormat , std::string );
+  BBTK_DECLARE_INPUT( Value , double );
+
+
   BBTK_DECLARE_OUTPUT(Out,vtkImageData *);
   BBTK_PROCESS(Process);
   void Process();
 
+  int GetTypeFormat( std::string formatStr , vtkImageData* image );
+
+
 private:
   vtkImageData *mimage;
 };
@@ -61,6 +68,10 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(AxeVolume,bbtk::AtomicBlackBox);
   BBTK_INPUT(AxeVolume,lstPointY,"List of Y values", std::vector<double> ,"");
   BBTK_INPUT(AxeVolume,lstPointZ,"List of Z values", std::vector<double> ,"");
   BBTK_INPUT(AxeVolume,lstPointR,"List of Radius", std::vector<double> ,"");
+
+  BBTK_INPUT(AxeVolume,OutputFormat,"Image output format:  SAME (default), VTK_BIT, VTK_CHAR, VTK_SIGNED_CHAR, VTK_UNSIGNED_CHAR, VTK_SHORT, VTK_UNSIGNED_SHORT, VTK_INT, VTK_UNSIGNED_INT, VTK_LONG, VTK_UNSIGNED_LONG, VTK_FLOAT, VTK_DOUBLE",std::string,"");
+  BBTK_INPUT(AxeVolume,Value,"(255 default) Gray level in the output image", double ,"");
+
   BBTK_OUTPUT(AxeVolume,Out,"Result image",vtkImageData*,"");
 BBTK_END_DESCRIBE_BLACK_BOX(AxeVolume);
 }
index ed61f7630ec4b9b713be65fe7080722a0503038b..2c0e5108500a2cced85ddf2a6d121acb0420c5d4 100644 (file)
@@ -48,7 +48,8 @@ void ImageChangeInformation::Process()
                origin[2]=0.0;
                img->SetOrigin(origin);         
                mchange->SetInput( img );
-               mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
+//EED 2016 15 06
+//             mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
                mchange->SetOutputOrigin (0, 0, 0);
                mchange->SetOutputExtentStart(0,0,0);
                if (bbGetInputNewSpacing().size()==3)
index c0edbf2b31ea9774d7f2db40028d46eec4f0ae51..488a3a4142400a9b15ce8cefb59106bb4a8e44cb 100644 (file)
 namespace bbcreaMaracasVisu
 {
 
+//----------------------------------------------------------------------
+ModelShowNPoints::ModelShowNPoints()
+{
+}
+//----------------------------------------------------------------------
+
+ModelShowNPoints::~ModelShowNPoints()
+{
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::SetRadio(double radio)
+{
+       mradio =  radio;
+}
+
+
+//------------------------------------------------------------------------
+double ModelShowNPoints::GetRadio()
+{
+       return mradio;
+}
+
+
+//------------------------------------------------------------------------
+std::vector<int> ModelShowNPoints::GetLstPointsX()
+{
+       return lstPointsX;
+}
+
+//------------------------------------------------------------------------
+std::vector<int> ModelShowNPoints::GetLstPointsY()
+{
+       return lstPointsY;
+}
+
+//------------------------------------------------------------------------
+std::vector<int> ModelShowNPoints::GetLstPointsZ()
+{
+       return lstPointsZ;
+}
+
+//------------------------------------------------------------------------
+std::vector<std::string> ModelShowNPoints::GetLstLabels()
+{
+       return lstLabels;
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::SetReferencePoint(std::vector<int> ppoint)
+{
+       mReferencePoint = ppoint;
+}
+
+//------------------------------------------------------------------------
+std::vector<int> ModelShowNPoints::GetReferencePoint()
+{
+       return mReferencePoint;
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::SetImage(vtkImageData *image)
+{
+       this->mimage=image;
+}
+
+
+//------------------------------------------------------------------------
+std::string ModelShowNPoints::CleanSpaces(std::string ss)
+{
+       int i;
+       while( (i=ss.find(32))>=0 )
+       {
+               ss.replace(i,1,"_");
+       }
+       return ss;
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z)
+{
+       *x=lstPointsX[id];
+       *y=lstPointsY[id];
+       *z=lstPointsZ[id];
+}
+
+//------------------------------------------------------------------------
+std::string ModelShowNPoints::GetIdLabel(int id)
+{
+       return lstLabels[id];
+}
+
+//------------------------------------------------------------------------
+vtkImageData *ModelShowNPoints::GetImage()
+{
+       return mimage;
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::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 );
+}
+
+//------------------------------------------------------------------------
+double ModelShowNPoints::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));
+}
+
+//------------------------------------------------------------------------
+int ModelShowNPoints::InsertPoint(int x, int y, int z, std::string label)
+{
+       if(lstPointsX.size()>1)
+       {
+               std::vector<int> dTotal;
+               int pos = 1;
+               int a,b,res;
+               
+               //Calcule distance for each pair of points
+               for(int i = 0; i<(int)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 smallTMP = dTotal[0];
+               for (int j = 0; j < (int) dTotal.size(); j++)
+               {
+                         if(dTotal[j]<smallTMP)
+                         {
+                                         smallTMP=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 );
+               return pos;
+       } else {
+               return -1;
+       }// if size lst X
+
+}
+
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::SavePoints(std::string filename)
+{
+       std::string tmpLabel;
+       FILE *ff;
+       ff = fopen( filename.c_str() , "w+" );
+       if (ff!=NULL)
+       {
+               int i , size = (int) (lstPointsX.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);
+                       if (lstLabels[i]!="") 
+                       {
+                               tmpLabel=lstLabels[i];
+                       } else{
+                               tmpLabel="<_VOID_>";
+                       }
+                       fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value  , tmpLabel.c_str());
+               } // for
+               fclose(ff);
+       } else {   // else ff
+               printf("ModelShowNPoints::SavePoints  ...Error... creating file");
+       } //ff
+}
+
+//------------------------------------------------------------------------
+int ModelShowNPoints::ReadPoints(std::string filename)
+{
+       int i,size;
+       char chartmp[256];
+       FILE *ff;
+       ff = fopen( filename.c_str() , "r+" );
+       if (ff!=NULL)
+       {
+               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
+                       if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
+                       AddPoint(x,y,z, chartmp );
+               }
+               fclose(ff);
+       } else {   // else ff
+               printf("ModelShowNPoints::LoadPoints  ...Error... reading file");
+       } //ff
+       return size;
+}
+
+//------------------------------------------------------------------------
+int ModelShowNPoints::GetNearestPoint()
+{
+       int id=-1;
+       int i, size=(int)(lstPointsX.size());
+       double radioMin=10000000;       
+       for ( i=0  ; i<size; i++ )
+       {
+               double rx =  mReferencePoint[0] - lstPointsX [i];
+               double ry =  mReferencePoint[1] - lstPointsY [i];
+               double rz =  mReferencePoint[2] - lstPointsZ [i];
+               double radio = rx*rx + ry*ry + rz*rz;
+               if ( radio <= radioMin)
+               {
+                       radioMin=radio;
+                       id=i;
+               }       // if
+       } // for                        
+       return id;
+}
+
+//------------------------------------------------------------------------
+int ModelShowNPoints::GetLstPointsSize()
+{
+       return lstPointsX.size();
+}
+
+//------------------------------------------------------------------------
+void ModelShowNPoints::SetPointId_mReferencePoint(int id)
+{
+       lstPointsX[id] = mReferencePoint[0];
+       lstPointsY[id] = mReferencePoint[1];
+       lstPointsZ[id] = mReferencePoint[2];            
+}
+
+
+//------------------------------------------------------------------------     
+int ModelShowNPoints::IdInsidePoint()
+{
+       int id=-1;
+       int i, size=(int)(lstPointsX.size());
+       double spc[3];
+       if(mimage ==NULL)
+       {
+               printf("WidgetShowNPoints::IdInsidePoint  image not set\n");
+               return -1;
+       }else{
+               mimage->GetSpacing(spc);
+               for ( i=0  ; i<size; i++ )
+               {
+                       double rx =  spc[0]*(mReferencePoint[0] - lstPointsX [i]);
+                       double ry =  spc[1]*(mReferencePoint[1] - lstPointsY [i]);
+                       double rz =  spc[2]*(mReferencePoint[2] - lstPointsZ [i]);
+                       if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
+                       {
+                               id=i;
+                       }       // if
+               } // for
+               return id;
+       } // if
+}
+
+//------------------------------------------------------------------------     
+int ModelShowNPoints::RenamePoint(std::string label)
+{
+       int id=IdInsidePoint();
+       if (id>=0)
+       {
+               std::string strLabel = CleanSpaces( label );
+               lstLabels[id] = strLabel;
+       }
+       return id;
+}
+
+//----------------------------------------------------------------------
+void ModelShowNPoints::ErasePoint(int id)
+{
+       lstPointsX.erase( lstPointsX.begin()+id );
+       lstPointsY.erase( lstPointsY.begin()+id );
+       lstPointsZ.erase( lstPointsZ.begin()+id );
+       lstLabels.erase( lstLabels.begin()+id );
+}
+
+
+
+//----------------------------------------------------------------------
+//----------------------------------------------------------------------
+//----------------------------------------------------------------------
+//----------------------------------------------------------------------
 //----------------------------------------------------------------------
   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent,  bbcreaMaracasVisu::ShowNPoints *box)
     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
   {
+       mmodelShowNPoints                               = new ModelShowNPoints();
     mbbShowNPoints                                     = box;
     this->renderer                                     = NULL;
     wxPanel    *panel                                  = this;
@@ -51,7 +366,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 *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"));
@@ -110,11 +425,11 @@ namespace bbcreaMaracasVisu
                  txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
 
                  //NTU: Sliders for opacity and radio change
-                 wxStaticText* txOpacity               = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
-                 sdrOpacity                                    = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-                 wxStaticText* txRadio                 = new wxStaticText(this, -1, wxString(_T("  Points Radio  ")));
-                 sdrRadio                                              = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-                 wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
+                 wxStaticText* txOpacity                       = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
+                 sdrOpacity                                            = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+                 wxStaticText* txRadio                         = new wxStaticText(this, -1, wxString(_T("  Points Radio  ")));
+                 sdrRadio                                                      = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+                 wxFlexGridSizer *sizer1                       = new wxFlexGridSizer(1);
                  Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
                  Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
                  Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
@@ -128,38 +443,33 @@ namespace bbcreaMaracasVisu
                  sizer = sizer1;
          }
     
-        if (mbbShowNPoints->bbGetInputType() == 2) {
-            askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
-            
-            wxButton *btnAddPoint = new wxButton(panel, -1,        _T("      Add  Point      "));
-            wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
-            wxStaticText* spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
-            textCtrl = new wxTextCtrl(panel, -1);
-            
-            wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
-
-            Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
-            Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
-            
-            sizer1->Add(askPointLabel); 
-            sizer1->Add(btnAddPoint);
-            sizer1->Add(btnDeleteAllPoints);
-            sizer1->Add(spacer);
-            sizer1->Add(textCtrl);
-            
-            sdrOpacity = new wxSlider();
-            sdrRadio = new wxSlider();
-            
-            txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));  
-            
-            sizer = sizer1;
-        } 
-         if (sizer!=NULL)
-         {
-                 panel->SetSizer(sizer);
-                 panel->SetAutoLayout(true);
-                 panel->Layout();
-         }
+    if (mbbShowNPoints->bbGetInputType() == 2) 
+       {
+               askPointLabel                                           = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
+       wxButton                *btnAddPoint            = new wxButton(panel, -1,        _T("      Add  Point      "));
+        wxButton               *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
+        wxStaticText   *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
+                                        textCtrl                       = new wxTextCtrl(panel, -1);
+        wxFlexGridSizer *sizer1                        = new wxFlexGridSizer(1);
+        Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
+        Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
+        sizer1->Add(askPointLabel); 
+        sizer1->Add(btnAddPoint);
+        sizer1->Add(btnDeleteAllPoints);
+        sizer1->Add(spacer);
+        sizer1->Add(textCtrl);
+        sdrOpacity = new wxSlider();
+        sdrRadio = new wxSlider();
+        txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
+        sizer = sizer1;
+       } // bbGetInputType 2
+
+       if (sizer!=NULL)
+       {
+               panel->SetSizer(sizer);
+               panel->SetAutoLayout(true);
+               panel->Layout();
+       } // if sizer
 }
 
 //------------------------------------------------------------------------
@@ -168,47 +478,30 @@ WidgetShowNPoints::~WidgetShowNPoints()
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetRadio(double radio)
-{
-       this->mradio=radio;
-       //NTU: For Slider
-       sdrRadio->SetValue(this->mradio);
-}
-
-//------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsX()
-{
-       return lstPointsX;
-}
-
-//------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsY()
+ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
 {
-       return lstPointsY;
+       return mmodelShowNPoints;
 }
 
-//------------------------------------------------------------------------
-std::vector<int> WidgetShowNPoints::GetLstPointsZ()
-{
-       return lstPointsZ;
-}
 
 //------------------------------------------------------------------------
-       std::vector<std::string> WidgetShowNPoints::GetLstLabels()
+void WidgetShowNPoints::SetRadio(double radio)
 {
-       return lstLabels;
+       GetModelShowNPoints()->SetRadio(radio);
+       //NTU: For Slider
+       sdrRadio->SetValue(radio);
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
+void WidgetShowNPoints::SetColour(std::vector<double> colour)
 {
-       mpoint = ppoint;
+       this->mcolour = colour;
 }
 
 //------------------------------------------------------------------------
-void WidgetShowNPoints::SetColour(std::vector<double> colour)
+void WidgetShowNPoints::SetImage(vtkImageData* image)
 {
-       this->mcolour = colour;
+       GetModelShowNPoints()->SetImage(image);
 }
 
 //------------------------------------------------------------------------
@@ -219,90 +512,66 @@ void WidgetShowNPoints::SetOpacity(double opacity)
        sdrOpacity->SetValue(this->mopacity*100.0);
 }
 
-//------------------------------------------------------------------------
-void WidgetShowNPoints::SetImage(vtkImageData *image)
-{
-       this->mimage=image;
-}
 
 //------------------------------------------------------------------------
 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
 {
        this->renderer  = renderer;
 }
-
-//------------------------------------------------------------------------
-
-std::string WidgetShowNPoints::CleanSpaces(std::string ss)
-{
-       int i;
-       while( (i=ss.find(32))>=0 )
-       {
-               ss.replace(i,1,"_");
-       }
-       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);
-       
+
+//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 );
-       
-       lstActorsText[id]->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+       lstSourceSphere[id]->SetRadius( radio );
+
+       lstActorsText[id]->SetInput( label.c_str()  );
+       lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
 }
-       
-       
+
 //------------------------------------------------------------------------
-void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
+void WidgetShowNPoints::RefreshPoints()
 {
-       lstPointsX.push_back( x );
-       lstPointsY.push_back( y );
-       lstPointsZ.push_back( z );
-
-       std::string strLabel = CleanSpaces(  label );
-
-       lstLabels.push_back( strLabel );
+       int id,size=lstActorsSphere.size();
+       for (id=0;id<size;id++)
+       {
+               RefreshPoint(id);
+       } // for
+       renderer->GetRenderWindow()->Render();
+}
 
+//------------------------------------------------------------------------
+void WidgetShowNPoints::AddVtkPoint()
+{
        // Sphere
-       vtkSphereSource *vtksphere              = vtkSphereSource::New();
+       vtkSphereSource *vtksphere = vtkSphereSource::New();
        vtksphere->SetThetaResolution (20);
        vtksphere->SetPhiResolution (20);
-       vtksphere->SetRadius( mradio  );
-
+       vtksphere->SetRadius( 1 );
        //NTU: For updating points
-
        lstSourceSphere.push_back(vtksphere);
-
        vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
        sphereMapper->SetInput( vtksphere->GetOutput() );
        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);
-               dialog.ShowModal();
-               return;
-       }
-       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);
        if(renderer==NULL){
                wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
@@ -310,71 +579,33 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
                return;
        }
        renderer->AddActor( sphereActor );
-
        // Actor
        vtkTextActor3D *textActor = vtkTextActor3D::New();
-/* EED Borrame 
-       textActor->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
-*/ 
-       textActor->SetInput( strLabel.c_str()  );
+//     textActor->SetInput( strLabel.c_str()  );
        renderer->AddActor( textActor );
        lstActorsText.push_back(textActor);
-
-       RefreshPoint(lstPointsX.size()-1);
 }
 
+
 //------------------------------------------------------------------------
-double WidgetShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT
+void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
 {
-    return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0));
+       GetModelShowNPoints()->AddPoint(x,y,z, label );
+       AddVtkPoint();
+       RefreshPoint(lstActorsSphere.size()-1);
 }
 
+
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
 {
-       std::cout<<"WidgetShowNPoints::InsertPoint begin "<<std::endl;
 
-       if(lstPointsX.size()>1)
-       {
-               std::vector<int> dTotal;
-               int pos = 1;
-               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 smallTMP = dTotal[0];
-               for (int j = 0; j < dTotal.size(); j++)
-               {
-                         if(dTotal[j]<smallTMP)
-                         {
-                                         smallTMP=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 );
 
+//--
+       if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
+       {
+/*
                // Sphere
                vtkSphereSource *vtksphere              = vtkSphereSource::New();
                vtksphere->SetThetaResolution (20);
@@ -410,76 +641,71 @@ void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
                std::vector<vtkTextActor3D*>::iterator itTA;
                itTA = lstActorsText.begin();
                lstActorsText.insert( itTA+pos , textActor);
+*/
 
-               RefreshPoint(pos);
-       }//end if
-       std::cout<<"WidgetShowNPoints::InsertPoint end"<<std::endl;
+               AddVtkPoint();
+       } else {
+               AddPoint(x,y,z,label);
+       }
+       RefreshPoints();
+       //end if
 }
 
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
-{
-       if(mimage==NULL){
-               wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
-               dialog.ShowModal();
+{      
+       if (this->renderer==NULL)
+       { 
                return;
        }
-       
-       if (this->renderer!=NULL){
-               if (mpoint.size()==3){
-                       AddPoint(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::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
+       if (point.size()==3)
+       {
+               AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
+               SetOutputBox();
+               renderer->GetRenderWindow()->Render();
+       } else {//mpoint.size
+               printf("creaMaracasVisu::ShowNPoints (not match point) \n");
+       }
 }
 
 //------------------------------------------------------------------------
 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();
+{      
+       if (this->renderer==NULL)
+       { 
                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;
+
+       std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
+       if (point.size()==3)
+       {
+               InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
+               SetOutputBox();
+       } else {//mpoint.size
+               printf("creaMaracasVisu::ShowNPoints (not match point) \n");
+       }
 }
 
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::SetOutputBox()
        {
-               renderer->GetRenderWindow()->Render();
+//EED          renderer->GetRenderWindow()->Render();
                wxString strTmp;
-               strTmp.Printf(_T("Nbr of points: %d"), (int)(lstPointsX.size()) );
+               strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
                txtNrPoints->SetLabel(  strTmp );
-
                //--BBTK
-               mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX );
-               mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY );
-               mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ );
-               mbbShowNPoints->bbSetOutputlstLabels( lstLabels );
-
+               mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
+               mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
+               mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
+               mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
                mbbShowNPoints->bbSignalOutputModification();
-
-//EED 07/07/2014
-//             mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
-//             mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
-//             mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
-//             mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
        }
 
+
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
        {
@@ -493,44 +719,18 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                //EED
 
                int result_FD = FD->ShowModal();
-               std::string tmpLabel;
                
                // 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() , "w+" );
-                       if (ff!=NULL)
-                       {
-                               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);
-                                       if (lstLabels[i]!="") 
-                                       {
-                                               tmpLabel=lstLabels[i];
-                                       } else{
-                                           tmpLabel="<_VOID_>";
-                                       }
-                                       fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value  , tmpLabel.c_str());
-                               } // for
-                               fclose(ff);
-                       } else {   // else ff
-                               printf("WidgetShowNPoints::OnSavePoints  ...Error... creating file");
-                       } //ff
+                       std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
+                       GetModelShowNPoints()->SavePoints( filename );
                }       // dialog box
        }
 
+
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
        {
@@ -541,168 +741,74 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
                                              _T("(*.xls)|*.xls"),
                                              wxOPEN | wxFILE_MUST_EXIST,
                                              wxDefaultPosition);
+               int i;
                //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)
+
+                       std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
+                       int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
+                       for (i=0;i<numberPointsRead;i++)
                        {
-                               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
-                                       if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
-                                       AddPoint(x,y,z, chartmp );
-                               }
-                               SetOutputBox();
-                               fclose(ff);
-                       } else {   // else ff
-                               printf("WidgetShowNPoints::OnLoadPoints  ...Error... reading file");
-                       } //ff
+                               AddVtkPoint();
+                       }// for
+                       SetOutputBox();
+                       RefreshPoints();
                }       // dialog box
 
-
        }
 
-//------------------------------------------------------------------------
-
-       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();
+               int id=GetModelShowNPoints()->GetNearestPoint();
                if((id==-1) && (mbbShowNPoints->bbGetInputType()==1))
                {
                        id=0;
                        AddPoint(0,0,0,"");
                        SetOutputBox();
                }
-               
-               
+       
                if (id>=0)
                {
-                       printf("WidgetShowNPoints::OnSetPoint \n");
-                       lstPointsX[id] = mpoint[0];
-                       lstPointsY[id] = mpoint[1];
-                       lstPointsZ[id] = mpoint[2];             
+                       GetModelShowNPoints()->SetPointId_mReferencePoint(id);
                        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] );
-                        */ 
+                       renderer->GetRenderWindow()->Render();
                } // if id
                SetOutputBox();
        }
        
-       
-       //------------------------------------------------------------------------
-       
-       int WidgetShowNPoints::IdInsidePoint()
-       {
-               int id=-1;
-               int i, size=(int)(lstActorsSphere.size());
-               double spc[3];
-
-               if(mimage ==NULL){                      
-                       wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
-                       diag->ShowModal();
-                       return -1;
-               }else{
-
-                       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
-
-                       return id;
-               }
-       }
-
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
        {
-               int id=IdInsidePoint();
+               int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
                if (id>=0)
                {
-                       std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
-                       lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
-                       lstActorsText[id]->SetInput(  lstLabels[id].c_str() );
+                       lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
                        SetOutputBox();
+                       renderer->GetRenderWindow()->Render();
                }
        }
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::ErasePoint(int id)
        {
-               if (this->renderer!=NULL){
-                       if (id>=0){
+               if (this->renderer!=NULL)
+               {
+                       if (id>=0)
+                       {
                                renderer->RemoveActor( lstActorsSphere[id] );
                                renderer->RemoveActor( lstActorsText[id] );
-                                lstActorsSphere[id]->Delete();
-                                lstActorsText[id]->Delete();
-                                lstSourceSphere[id]->Delete();
+                               lstActorsSphere[id]->Delete();
+                               lstActorsText[id]->Delete();
+                               lstSourceSphere[id]->Delete();
                                lstActorsSphere.erase( lstActorsSphere.begin()+id );
                                lstActorsText.erase( lstActorsText.begin()+id );
                                lstSourceSphere.erase( lstSourceSphere.begin()+id );
-
-                               lstPointsX.erase( lstPointsX.begin()+id );
-                               lstPointsY.erase( lstPointsY.begin()+id );
-                               lstPointsZ.erase( lstPointsZ.begin()+id );
-                               lstLabels.erase( lstLabels.begin()+id );
-
-                               SetOutputBox();
-
+                               GetModelShowNPoints()->ErasePoint(id);
                        } // if id
                } // if renderer
        }
@@ -710,13 +816,17 @@ void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
        {
-               ErasePoint( IdInsidePoint() );
+               ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
+               SetOutputBox();
+               renderer->GetRenderWindow()->Render();
        }
 
 //------------------------------------------------------------------------
        void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
        {
                ErasePoint(lstActorsSphere.size()-1);
+               SetOutputBox();
+               renderer->GetRenderWindow()->Render();
        }
 
 //------------------------------------------------------------------------
@@ -727,6 +837,8 @@ void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
        {
                ErasePoint(id);
        }
+       SetOutputBox();
+       renderer->GetRenderWindow()->Render();
 }
 
 //NTU: Method for updating points opacity and Radio
@@ -735,31 +847,65 @@ void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
 {
        //Difference in Radio for text placement
-       int difradio = sdrRadio->GetValue() - this->mradio;
-       
+       double radio=GetModelShowNPoints()->GetRadio();
        this->mopacity = sdrOpacity->GetValue()/100.0;
-       this->mradio = sdrRadio->GetValue();
-       
+       GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
+       radio = sdrRadio->GetValue();
        //NTU refresh the inputs
        mbbShowNPoints->bbSetInputOpacity(this->mopacity);
-       mbbShowNPoints->bbSetInputRadio(this->mradio);
+       mbbShowNPoints->bbSetInputRadio( radio );
+       // EED 
+       RefreshPoints();
+}
 
-       int size = (int) this->lstActorsSphere.size();
-       int i;
-       for(i = 0; i < size; i ++)
-       {
-               this->lstSourceSphere[i]->SetRadius(mradio);
-               this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity);
-               this->lstActorsText[i]->GetTextProperty()->SetOpacity(mopacity);
-               this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]);
+//------------------------------------------------------------------------
+void  WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
+{
+       GetModelShowNPoints()->SetReferencePoint(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)
+       { 
+               return;
        }
 
-       //NTU: For updating
-//EED  SetOutputBox();
-        renderer->GetRenderWindow()->Render();
+       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];
+                       y               = initLstPointsY[i];
+                       z               = initLstPointsZ[i];
+                       if (i<sizeLabels) 
+                       {
+                               label   = initLstLabels[i];
+                       } else {
+                               label="";
+                       }
+                       AddPoint( x,y,z,label );
+               } // for i
+               //      SetOutputBox(); 
+               //      renderer->GetRenderWindow()->Render();
+
+       } // if size
 }
 
+
+
+
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
 
@@ -769,17 +915,22 @@ void ShowNPoints::Process()
        if (mwxwidget!=NULL)
        {
                mwxwidget->SetRenderer( bbGetInputRenderer() );
-               mwxwidget->SetPoint( bbGetInputIn() );
+               mwxwidget->SetReferencePoint( bbGetInputIn() );
                mwxwidget->SetImage( bbGetInputImage() );
                mwxwidget->SetColour( bbGetInputColour() );
                mwxwidget->SetOpacity( bbGetInputOpacity() );
                mwxwidget->SetRadio( bbGetInputRadio() );
 
-               bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
-               bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
-               bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
-               bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
+               if (firsttime==true)
+               {
+                       firsttime=false;
+                       mwxwidget->SetInitLstPoints( bbGetInputInitLstPointsX() , bbGetInputInitLstPointsY() , bbGetInputInitLstPointsZ() , bbGetInputInitLstLabels() );
+               }
 
+               bbSetOutputlstPointsX( mwxwidget->GetModelShowNPoints()->GetLstPointsX() );
+               bbSetOutputlstPointsY( mwxwidget->GetModelShowNPoints()->GetLstPointsY() );
+               bbSetOutputlstPointsZ( mwxwidget->GetModelShowNPoints()->GetLstPointsZ() );
+               bbSetOutputlstLabels( mwxwidget->GetModelShowNPoints()->GetLstLabels() );
        } // mwxwidget
 }
 
@@ -793,6 +944,7 @@ void ShowNPoints::CreateWidget(wxWindow* parent)
 //-----------------------------------------------------------------
 void ShowNPoints::bbUserSetDefaultValues()
 {
+       firsttime = true;
        mwxwidget = NULL;
 
        bbSetInputRadio(10);
index 5879aed318617f9c7d64f80c02d0bddc2c859a11..df37ddb87ffbffe476e4d402f5ec57325ccfae9b 100644 (file)
 namespace bbcreaMaracasVisu
 {
 
+  class ModelShowNPoints
+  {
+       public:
+         ModelShowNPoints();
+         ~ModelShowNPoints(); 
+         std::vector<int>                      GetLstPointsX();
+         std::vector<int>                      GetLstPointsY();
+         std::vector<int>                      GetLstPointsZ();
+         void                                          GetIdPoint(int id, int *x, int *y, int *z);
+         std::string                           GetIdLabel(int id);
+         std::vector<std::string>      GetLstLabels();
+         void                                          AddPoint(int x, int y, int z, std::string label);
+         double                                        Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1);
+         int                                           InsertPoint(int x, int y, int z, std::string label);
+         void                                          SavePoints(std::string filename);
+         int                                           ReadPoints(std::string filename);
+         int                                           GetNearestPoint();
+
+         int                                           GetLstPointsSize();
+         void                                          SetPointId_mReferencePoint(int id);
+         int                                           IdInsidePoint();
+
+         void                                          SetReferencePoint(std::vector<int> ppoint);
+         std::vector<int>                      GetReferencePoint();
+         void                                          SetImage(vtkImageData *image);
+         std::string                           CleanSpaces(std::string ss);
+         vtkImageData*                         GetImage();
+         void                                          SetRadio(double radio);
+         double                                        GetRadio();
+         int                                           RenamePoint(std::string label);
+         void                                          ErasePoint(int id);
+
+       private:
+         std::vector<int>              lstPointsX;
+         std::vector<int>              lstPointsY;
+         std::vector<int>              lstPointsZ;
+         std::vector<std::string>      lstLabels;
+         std::vector<int>                      mReferencePoint;
+         double                                mradio;
+         vtkImageData                          *mimage;
+
+  };
+
+
   class ShowNPoints;
 
   //--------------------------------------------------------------------------
@@ -47,7 +91,7 @@ namespace bbcreaMaracasVisu
          WidgetShowNPoints( wxWindow *parent,  ShowNPoints *box);
          ~WidgetShowNPoints(); 
          void OnAddPoint(wxCommandEvent &event);   
-               void OnInsertPoint (wxCommandEvent& event);//CFT
+         void OnInsertPoint (wxCommandEvent& event);//CFT
          void OnSetPoint(wxCommandEvent& event);
          void OnRenamePoint(wxCommandEvent& event);
          void OnErasePoint(wxCommandEvent& event);
@@ -59,35 +103,29 @@ namespace bbcreaMaracasVisu
          
          void RefreshPoint(int id);
          
-         void SetPoint(std::vector<int> ppoint);
          void SetColour(std::vector<double> colour);
          void SetOpacity(double opacity);
          void SetRadio(double radio);
          void SetImage(vtkImageData *image);
          void SetRenderer(vtkRenderer *renderer);
-         std::vector<int> GetLstPointsX();
-         std::vector<int> GetLstPointsY();
-         std::vector<int> GetLstPointsZ();
-         std::vector<std::string> GetLstLabels();
+         void SetReferencePoint(std::vector<int> point);
 
          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
+         void InsertPoint(int x, int y, int z, std::string label);//CFT
 
-  private:
+         ModelShowNPoints* GetModelShowNPoints();
+         void RefreshPoints();
+         void AddVtkPoint();
+         void SetInitLstPoints( std::vector<int> initLstPointsX,  std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels );
 
-         std::string           CleanSpaces(std::string ss);
-         int                   GetNearestPoint();
-         int                                   IdInsidePoint();
-         void                  ErasePoint(int id);
-         void                  SetOutputBox();
+
+  private:
+         void                                  ErasePoint(int id);
+         void                                  SetOutputBox();
 
          ShowNPoints                   *mbbShowNPoints;
          vtkRenderer                   *renderer;
-         std::vector<int>              lstPointsX;
-         std::vector<int>              lstPointsY;
-         std::vector<int>              lstPointsZ;
-         std::vector<std::string>      lstLabels;
+
          std::vector<vtkActor*>        lstActorsSphere;//NTU changed from prop3D to Actor
          std::vector<vtkTextActor3D*>  lstActorsText;
 
@@ -95,17 +133,16 @@ namespace bbcreaMaracasVisu
 
          std::vector<vtkSphereSource*> lstSourceSphere;
 
-         std::vector<int>      mpoint;
-         vtkImageData          *mimage;
-         std::vector<double>   mcolour;
-         double                mopacity;
-         double                mradio;
-         wxStaticText          *askPointLabel;
-         wxTextCtrl            *textCtrl;
-         wxStaticText          *txtNrPoints;
-         wxSlider              *sdrOpacity;
-         wxSlider              *sdrRadio;
+         std::vector<double>                   mcolour;
+         double                                mopacity;
+         wxStaticText                          *askPointLabel;
+         wxTextCtrl                            *textCtrl;
+         wxStaticText                          *txtNrPoints;
+         wxSlider                              *sdrOpacity;
+         wxSlider                              *sdrRadio;
 
+         ModelShowNPoints                              *mmodelShowNPoints;
+               
   };
 
 class /*BBTK_EXPORT*/ ShowNPoints
@@ -119,7 +156,12 @@ class /*BBTK_EXPORT*/ ShowNPoints
   BBTK_DECLARE_INPUT(Colour, std::vector<double> );
   BBTK_DECLARE_INPUT(Opacity, double );
   BBTK_DECLARE_INPUT(Radio, double );
+  BBTK_DECLARE_INPUT(InitLstPointsX, std::vector<int> );
+  BBTK_DECLARE_INPUT(InitLstPointsY, std::vector<int> );
+  BBTK_DECLARE_INPUT(InitLstPointsZ, std::vector<int> );
+  BBTK_DECLARE_INPUT(InitLstLabels, std::vector<std::string> );
   BBTK_DECLARE_INPUT(Type, int );
+
   BBTK_DECLARE_OUTPUT( lstPointsX, std::vector<int> );
   BBTK_DECLARE_OUTPUT( lstPointsY, std::vector<int> );
   BBTK_DECLARE_OUTPUT( lstPointsZ, std::vector<int> );
@@ -131,6 +173,7 @@ class /*BBTK_EXPORT*/ ShowNPoints
 
 private:
        WidgetShowNPoints *mwxwidget; 
+       bool firsttime;
 };
 
 BBTK_BEGIN_DESCRIBE_BLACK_BOX(ShowNPoints,bbtk::WxBlackBox);
@@ -138,17 +181,24 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ShowNPoints,bbtk::WxBlackBox);
   BBTK_AUTHOR("Eduardo DAVILA");
   BBTK_DESCRIPTION("widget that shows N moints in 3D (vtkActors)");
   BBTK_CATEGORY("widgetVtk");
+
   BBTK_INPUT(ShowNPoints,In,"One Point",std::vector<int>,"");
   BBTK_INPUT(ShowNPoints,Renderer,"Renderer",vtkRenderer*,"");
   BBTK_INPUT(ShowNPoints,Image,"vktkImageData",vtkImageData*,"");
   BBTK_INPUT(ShowNPoints,Colour,"Colour of the actor",std::vector<double>,"colour");
   BBTK_INPUT(ShowNPoints,Opacity,"Opacity of the actor 0..1 (default 1)",double,"");
   BBTK_INPUT(ShowNPoints,Radio,"Radio of the spheres 1..50 (default 10)",double,"");
+  BBTK_INPUT(ShowNPoints,InitLstPointsX,"Initial lst of points X",std::vector<int>,"");
+  BBTK_INPUT(ShowNPoints,InitLstPointsY,"Initial lst of points Y",std::vector<int>,"");
+  BBTK_INPUT(ShowNPoints,InitLstPointsZ,"Initial lst of points Z",std::vector<int>,"");
+  BBTK_INPUT(ShowNPoints,InitLstLabels,"Initial lst of labels",std::vector<std::string>,"");
   BBTK_INPUT(ShowNPoints,Type,"Type of the widget. 0(default): N-points, 1:Just one point",int,"");
+
   BBTK_OUTPUT(ShowNPoints , lstPointsX , " list of points X ", std::vector<int> ,"");
   BBTK_OUTPUT(ShowNPoints , lstPointsY , " list of points Y ", std::vector<int> ,"");
   BBTK_OUTPUT(ShowNPoints , lstPointsZ , " list of points Z ", std::vector<int> ,"");
   BBTK_OUTPUT(ShowNPoints , lstLabels , " list of labels ", std::vector<std::string> ,"");
+
 BBTK_END_DESCRIBE_BLACK_BOX(ShowNPoints);
 }
 // EO namespace bbcreaMaracasVisu