]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourCrownWidget.cxx
#3418 creaMaracasVisu Feature New Normal - ManualPaint_model with openmp
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / ContourCrownWidget.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "ContourCrownWidget.h"
27
28 #include <vtkImageMapToColors.h>
29 #include <vtkImageActor.h>
30
31 #include "wxVtk2DBaseView.h"
32 #include "vtkLookupTable.h"
33
34 //----------------------------------------------------------------------
35   wxMaracasCoutourTool::wxMaracasCoutourTool(wxWindow *parent)
36     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
37   {
38         wxPanel *panel                  = this;
39     wxSizer *sizer                      = NULL;
40         
41         // Widget interface
42         wxButton *btnContourA   = new wxButton( panel, -1, _T("Crown Extern"));
43         wxButton *btnContourB   = new wxButton( panel, -1, _T("Crown Intern"));
44         wxButton *btnContourAB  = new wxButton( panel, -1, _T("Crown Extern and Intern"));
45
46 //JSTG 21-03-08 --------------------------------------------------------------------
47         wxButton *btnSaveContour                = new wxButton( panel, -1, _T("Save Contour"));
48         wxButton *btnSaveControlPoints  = new wxButton( panel, -1, _T("Save Control Points"));
49 //JSTG 11-04-08
50         wxButton *btnEreaseLastContour  = new wxButton( panel, -1, _T("Erease Last Contour"));
51         wxButton *btnEreaseLastCP               = new wxButton( panel, -1, _T("Erease Last Control Points"));
52 //----------------------------------------------------------------------------------
53
54         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(10); //Original Value = 10
55     sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
56     sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
57
58     Connect(btnContourA->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourA  );
59     Connect(btnContourB->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourB  );
60     Connect(btnContourAB->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourAB );
61
62 //JSTG 21-03-08 ---------------------------------------------------------------------
63         Connect(btnSaveContour->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnSaveContour );
64         Connect(btnSaveControlPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnSaveControlPoints );
65 //JSTG 11-04-08
66         Connect(btnEreaseLastContour->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::EreaseLastContour );
67         Connect(btnEreaseLastCP->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::EreaseLastCP );        
68 //-----------------------------------------------------------------------------------
69
70     sizer1->Add(btnContourA);
71     sizer1->Add(btnContourB);
72     sizer1->Add(btnContourAB);
73
74 //JSTG 21-03-08 --------------------
75         sizer1->Add(btnSaveContour);
76         sizer1->Add(btnSaveControlPoints);
77 //JSTG 11-04-08
78         sizer1->Add(btnEreaseLastContour);
79         sizer1->Add(btnEreaseLastCP);
80 //----------------------------------    
81         sizer = sizer1;
82         panel   ->      SetSizer(sizer);
83     panel       ->      SetAutoLayout(true);
84     panel       ->      Layout();  
85         
86 }
87
88   // ------------------------------------------------------------------------
89
90   wxMaracasCoutourTool::~wxMaracasCoutourTool()
91   {
92   }
93
94   // ------------------------------------------------------------------------
95   wxVtkBaseView *wxMaracasCoutourTool::GetWxVtkBaseView()
96         {
97                 return this->wxvtkbaseview;
98         }
99
100
101         // ------------------------------------------------------------------------
102 void wxMaracasCoutourTool::Init(wxVtkBaseView *wxvtkbaseview, vtkImageData* imagedata)
103 {
104     this->imagedata                     = imagedata;
105         this->wxvtkbaseview             = wxvtkbaseview;
106         
107         InitVtkImagesResult();
108         
109         vtkLookupTable *table = vtkLookupTable::New();
110         //       table->SetAlphaRange(128,255);
111         table->SetRange(0, 255); // image intensity range
112         //   table->SetValueRange(0.0, 1.0); // from black to white
113         table->SetValueRange(0.0, 255.0); // from black to white
114         
115         table->SetTableValue (0, 1.0 , 1.0 , 1.0 , 0.1 );
116         table->SetTableValue (255, 1.0 , 1.0 , 0.0 , 0.1);
117         
118         //       table->SetTableValue (0, 0.0 , 0.0 , 1.0 , 0.35 );
119         //       table->SetTableValue (255, 1.0 , 0.0 , 0.0 , 0.10);
120         
121         table->SetSaturationRange(0.0, 0.0); // no color saturation
122         table->SetRampToLinear();
123         table->Build();
124         
125         vtkImageMapToColors  *mapperImage       = vtkImageMapToColors::New();
126         vtkImageActor *actorImage                       = vtkImageActor::New();
127
128         mapperImage->SetLookupTable(table);
129
130
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
133         mapperImage->SetInput( imagedataMaskResult );
134         actorImage->SetInput( mapperImage->GetOutput() );
135 #else
136         mapperImage->SetInputData( imagedataMaskResult );
137         actorImage->SetInputData( mapperImage->GetOutput() );
138 #endif
139
140
141         actorImage->SetOpacity(1);
142         
143         wxvtkbaseview->GetRenderer()->AddActor(actorImage);     
144 }
145
146
147   // ------------------------------------------------------------------------
148   void wxMaracasCoutourTool::ConfigureVTK()
149   {
150           double spc[3];
151           this->imagedata->GetSpacing(spc);
152
153         // Contorno 1
154         _manContourControl_1    = new manualContourControler();
155         _mContourModel_1                = new manualContourModel();
156         _mViewContour_1                 = new manualViewContour();
157         _mViewContour_1->SetModel( _mContourModel_1 );
158         _mViewContour_1->SetWxVtkBaseView( this->wxvtkbaseview );
159         _mViewContour_1->SetRange( 2 );
160         _mViewContour_1->SetZ( 1000 );
161
162 //JSTG 18-06-07
163         _mContourModel_1->SetNumberOfPointsSpline(100);
164
165
166 //EED 3 oct 2006
167         _mViewContour_1->SetSpacing(spc);
168
169
170 //EED 3 oct 2006
171         _mViewContour_1->SetColorNormalContour(0, 0, 1);
172         _mViewContour_1->SetColorEditContour(0.5, 0.5, 0.5);
173
174
175         _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
176         ((vtkInteractorStyleBaseView*)this->wxvtkbaseview->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _manContourControl_1 );
177         _manContourControl_1->CreateNewManualContour();
178         _manContourControl_1->SetActive(false);
179         _mViewContour_1->RefreshContour();
180
181
182         // Contorno 2
183         _manContourControl_2    = new manualContourControler();
184         _mContourModel_2                = new manualContourModel();
185         _mViewContour_2                 = new manualViewContour();
186         _mViewContour_2->SetModel( _mContourModel_2 );
187         _mViewContour_2->SetWxVtkBaseView( this->wxvtkbaseview );
188         _mViewContour_2->SetRange( 2 );
189         _mViewContour_2->SetZ( 1000 );
190
191 //EED 3 oct 2006
192         _mViewContour_2->SetSpacing(spc);
193
194 //EED 3 oct 2006
195         _mViewContour_2->SetColorNormalContour(1, 0, 0);
196         _mViewContour_2->SetColorEditContour(0.5, 0.5, 0.5);
197
198
199         _manContourControl_2->SetModelView( _mContourModel_2 , _mViewContour_2 );
200         ((vtkInteractorStyleBaseView*)this->wxvtkbaseview->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _manContourControl_2 );
201         _manContourControl_2->CreateNewManualContour();
202         _manContourControl_2->SetActive(false);
203         _mViewContour_2->RefreshContour();
204
205 //      Refresh();      
206
207 //JSTG 16-06-08
208         _contprop = new ContourPropagation();
209  }
210
211 //JSTG 26-02-08 -------------------------------------------------------------------------------------------------------------
212   void wxMaracasCoutourTool::SetControlPoints(  std::vector<double> *InVectorX, 
213                                                                                                 std::vector<double> *InVectorY, 
214                                                                                                 std::vector<double> *InVectorZ )
215   {
216         int lstSize;
217         if (InVectorX!=NULL)
218         {
219                 int i,size=InVectorX->size();
220                 if (size!=0)
221                 {
222                         _mContourModel_1->DeleteAllPoints();
223                         _mViewContour_1->DeleteContour();
224
225                         for (i=0;i<size;i++)
226                         {
227                                 lstSize = _mContourModel_1->AddPoint( (*InVectorX)[i] , (*InVectorY)[i] , (*InVectorZ)[i] );
228                                 _mViewContour_1->AddPoint();
229                         }
230                         //_manContourControl_1->CreateNewManualContour();
231                         //_manContourControl_1->SetActive(true);
232                         _mViewContour_1->CreateNewContour();
233                         _mContourModel_1->UpdateSpline();
234                         _mViewContour_1->RefreshContour();
235                         //_mViewContour_1->Refresh ();
236                 } 
237          } 
238   }
239
240 // JSTG 26-02-08 ------------------------------------------------------------------------------
241   void wxMaracasCoutourTool::GetSplinePoints(   std::vector<double> *pLstContourX,
242                                                                                                 std::vector<double> *pLstContourY,
243                                                                                                 std::vector<double> *pLstContourZ  )
244   {
245           int i;
246           double x,y,z;
247           _mContourModel_1->UpdateSpline();
248           
249           for(i=0; i<_mContourModel_1->GetNumberOfPointsSpline(); i++)
250           {
251                 _mContourModel_1->GetSpline_i_Point( i, &x, &y, &z );
252                 pLstContourX->push_back(x);
253                 pLstContourY->push_back(y);
254                 //pLstContourY->push_back(z);                   //Fake Z -> For Visualization
255                 pLstContourZ->push_back(_zz);                   //True Z -> For processing
256           }
257   }
258 //---------------------------------------------------------------------------------------------
259
260 //------------------------------------------------------------------------
261 void wxMaracasCoutourTool::OnContourA(wxCommandEvent& event)
262 {
263         _manContourControl_1 -> SetActive(true);
264         _manContourControl_2 -> SetActive(false);
265 }
266 //------------------------------------------------------------------------
267 void wxMaracasCoutourTool::OnContourB(wxCommandEvent& event)
268 {
269         _manContourControl_1 -> SetActive(false);
270         _manContourControl_2 -> SetActive(true);
271 }
272 //------------------------------------------------------------------------
273 void wxMaracasCoutourTool::OnContourAB(wxCommandEvent& event)
274 {
275         _manContourControl_1 -> SetActive(true);
276         _manContourControl_2 -> SetActive(true);
277 }
278
279 //------------------------------------------------------------------------
280 void wxMaracasCoutourTool::GetMinMaxPoint(int *minPoint, 
281                                                                                   int *maxPoint, 
282                                                                                   manualViewBaseContour *manualviewbaseecontour,
283                                                                                   manualContourModel *manualcontourmodel
284                                                                                   )
285 {
286         int i;
287         //int   np  = manualviewbaseecontour->GetNumberOfPoints( );  // number of control points // JPRx
288
289 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
290         //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline
291         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
292 //------------------------------------------------------------------------------------------------------
293         
294 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
295         //double x,y,z,t;
296         double x,y,z;
297         //double delta=( double ) ( np  ) / ( double ) ( nps  );
298         manualcontourmodel->UpdateSpline();
299         for (i=0; i<nps; i++)
300         {
301                 //t= delta * (double)i;
302                 //manualcontourmodel->GetSplinePoint(t,x,y,z);
303                 manualcontourmodel->GetSpline_i_Point(i,&x,&y,&z);
304                 if (x<minPoint[0]){ minPoint[0]=(int)x; }
305                 if (y<minPoint[1]){ minPoint[1]=(int)y; }
306                 if (x>maxPoint[0]){ maxPoint[0]=(int)x; }
307                 if (y>maxPoint[1]){ maxPoint[1]=(int)y; }
308         }
309 //------------------------------------------------------------------------------------------------------
310 }
311
312 //------------------------------------------------------------------------
313
314 int wxMaracasCoutourTool::AnalisisContourInside(int x, 
315                                                                                                 int y, 
316                                                                                                 manualViewBaseContour *manualviewbaseecontour,
317                                                                                                 manualContourModel *manualcontourmodel
318                                                                                                 )
319 {
320         int result = 0;
321         int i;
322         int     np  = manualviewbaseecontour->GetNumberOfPoints( );  // number of control points
323
324 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
325         //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline
326         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
327         //double x1,y1,z1,x2,y2,z2,t;
328         double x1,y1,z1,x2,y2,z2;
329         double xx1, yy1,xx2, yy2;
330         //double delta=( double ) ( np  ) / ( double ) ( nps  );
331         manualcontourmodel->UpdateSpline();
332 //------------------------------------------------------------------------------------------------------
333         double d;
334         bool ok;
335         if (np>=2)
336         {
337 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
338                 nps--;
339                 //manualcontourmodel->GetSplinePoint(0,x1,y1,z1);
340                 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
341                 for (i=1; i<=nps; i++)
342                 {
343                         ok=false;
344                         //t= delta * (double)(i%nps);
345                         //manualcontourmodel->GetSplinePoint(t,x2,y2,z2);
346                         manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
347 //------------------------------------------------------------------------------------------------------
348                         //by triangle similarity
349                         if ( ((y1<y2)&&(y>=y1)&&(y<y2)) || ((y1>y2)&&(y<=y1)&&(y>y2)) )
350                         {
351                                 if (y1<y2) { xx1=x1; yy1=y1; xx2=x2; yy2=y2;} else { xx1=x2; yy1=y2; xx2=x1; yy2=y1; } 
352                                 d = ( fabs(xx2-xx1)*(y-yy1) ) / (yy2-yy1) ;
353                                 if (  ((xx1<xx2)&&(x<(xx1+d)))  ||  ((xx1>xx2)&&(x<(xx1-d)))  ) { result++; }
354                         }
355                         x1=x2; y1=y2; z1=z2;
356                 }
357         }
358         return result;
359 }
360
361 //------------------------------------------------------------------------
362
363
364 bool wxMaracasCoutourTool::isInside(int x, int y)
365 {
366         bool result=false;
367
368         int ext[6];
369         imagedataValueResult->GetExtent(ext);
370
371         if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3]))
372         {
373                 int numberLeftA=AnalisisContourInside(x,y,_mViewContour_1, _mContourModel_1); 
374                 int numberLeftB=AnalisisContourInside(x,y,_mViewContour_2, _mContourModel_2);
375                 if ( (numberLeftA+numberLeftB) % 2 ==1){        result = true;  } 
376         }
377
378         return result;
379 }
380
381 //------------------------------------------------------------------------
382
383 double wxMaracasCoutourTool::GetDataValue(int x, int y)
384 {
385         unsigned short *p;
386         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
387         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
388         //JSTG 13-03-08-----
389         _zz = z;
390         //------------------
391         p = (unsigned short *)imagedata->GetScalarPointer(x,y,z);
392         return (double)(*p);
393 }
394
395 //------------------------------------------------------------------------
396
397 void wxMaracasCoutourTool::PutVtkImageDataResultValue( int x, int y, double value )
398 {
399         unsigned short *pValue;
400         unsigned short *pMask;
401         pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,0);
402         pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,0);
403         *pMask  = 255;
404         *pValue = (unsigned short)value;
405 }
406
407 //------------------------------------------------------------------------
408 void wxMaracasCoutourTool::ResetImageResult()
409 {
410         unsigned short *pValue;
411         unsigned short *pMask;
412         pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,0);
413         pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,0);
414         
415         int ext[6];
416         imagedataValueResult->GetExtent(ext);
417
418         int i,size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 
419         for(i=0; i<size; i++)
420         {
421                 *pMask  = 0;
422                 *pValue = 0;
423                 pMask++;
424                 pValue++;
425         }
426 }
427 //------------------------------------------------------------------------
428
429 void wxMaracasCoutourTool::GetValuesInsideCrown(std::vector<double> *pLstValue,
430                                                                                                 std::vector<double> *pLstValuePosX,
431                                                                                                 std::vector<double> *pLstValuePosY,
432                                                                                                 std::vector<double> *pLstValuePosZ)
433 {
434   pLstValue->clear();
435   pLstValuePosX->clear();
436   pLstValuePosY->clear();
437   pLstValuePosZ->clear();
438   ResetImageResult();
439   
440         int minPoint[2];
441         int maxPoint[2];
442         int i,j;
443         double value;
444
445
446         minPoint[0]=999999;
447         minPoint[1]=999999;
448         maxPoint[0]=-999999;
449         maxPoint[1]=-999999;
450
451         GetMinMaxPoint(minPoint,maxPoint, _mViewContour_1, _mContourModel_1);
452         GetMinMaxPoint(minPoint,maxPoint, _mViewContour_2, _mContourModel_2);
453
454         for (j=minPoint[1]; j<maxPoint[1]; j++)
455         {
456                 for (i=minPoint[0]; i<maxPoint[0]; i++)
457                 {
458                         if (isInside(i,j)==true)
459                         {
460                                 value = GetDataValue(i,j);
461                                 PutVtkImageDataResultValue(i,j,  value );
462                                 pLstValue               -> push_back( value );
463                                 pLstValuePosX   -> push_back( i );
464                                 pLstValuePosY   -> push_back( j );
465                                 pLstValuePosZ   -> push_back( -1 );
466                         } // if
467                 } // for
468         } // for
469
470         imagedataValueResult->Modified();
471         imagedataMaskResult->Modified();
472 }
473
474 //------------------------------------------------------------------------
475
476 vtkImageData *wxMaracasCoutourTool::GetVtkImageValueResult()
477 {
478         return imagedataValueResult;
479 }
480 //------------------------------------------------------------------------
481 vtkImageData *wxMaracasCoutourTool::GetVtkImageMaskResult()
482 {
483         return imagedataMaskResult;
484 }
485 // ------------------------------------------------------------------------
486 void wxMaracasCoutourTool::InitVtkImagesResult()
487   {
488           int ext[6];
489           int newDim[3];
490           double spc[3];
491           int scalartype;
492
493           imagedata->GetSpacing(spc);
494           imagedata->GetExtent(ext);
495           newDim[0]=ext[1]-ext[0]+1;
496           newDim[1]=ext[3]-ext[2]+1;
497           newDim[2]=1;
498           scalartype = imagedata->GetScalarType();
499
500           imagedataValueResult = vtkImageData::New();
501 //        imagedataValueResult->SetScalarType(scalartype);
502           imagedataValueResult->SetSpacing(spc);
503           imagedataValueResult->SetDimensions( newDim );
504
505 //EED 2017-01-01 Migration VTK7
506 #if VTK_MAJOR_VERSION <= 5
507           imagedataValueResult->SetScalarTypeToUnsignedShort();
508           imagedataValueResult->AllocateScalars();
509 #else
510           imagedataValueResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
511 #endif
512
513
514           imagedataMaskResult  = vtkImageData::New();
515 //        imagedataMaskResult->SetScalarType(scalartype);
516           imagedataMaskResult->SetSpacing(spc);
517           imagedataMaskResult->SetDimensions( newDim );
518
519 //EED 2017-01-01 Migration VTK7
520 #if VTK_MAJOR_VERSION <= 5
521           imagedataMaskResult->SetScalarTypeToUnsignedShort();
522           imagedataMaskResult->AllocateScalars();
523 #else
524           imagedataMaskResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
525 #endif
526
527
528   }
529
530 //JSTG 21-03-08 -------------------------------------------------------------------
531 void wxMaracasCoutourTool::OnSaveContour(wxCommandEvent& event)
532 {
533         //For write the actual time and date
534         /*
535         time_t timer;
536         struct tm *tblock;
537         timer = time(NULL);
538         tblock = localtime(&timer);
539         */
540
541         FILE *fd;
542         
543         //WHERE CAN I MAKE THEM DELETE!!!
544         _mpoint = new manualPoint();
545
546         std::vector<double> tempX;
547         std::vector<double> tempY;
548         std::vector<double> tempZ;
549         tempX.clear();
550         tempY.clear();
551         tempZ.clear();
552
553         int size = _mContourModel_1->GetNumberOfPointsSpline();
554         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
555         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
556         double xx, yy, zz;
557
558         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","a");
559         //fprintf(fd,"Date %s", asctime(tblock) );
560         fprintf(fd,"\nPointsContour %d", size );
561         for(int i=0; i<size; i++)
562         {
563                 _mContourModel_1->GetSpline_i_Point(i,&xx,&yy,&zz);
564                 fprintf(fd,"\n%f %f %d",xx,yy,z);       //z -> Contain the true value || zz -> Contain the cheating value for visualitation 
565                 tempX.push_back(xx);
566                 tempY.push_back(yy);
567                 tempZ.push_back(z);
568         }
569         fclose(fd);
570
571 //JSTG 16-06-08
572         _contprop->appendContour(&tempX,&tempY,&tempZ);
573 }
574
575 //JSTG 21-03-08 --------------------------------------------------------------------
576 void wxMaracasCoutourTool::OnSaveControlPoints(wxCommandEvent& event)
577 {
578         //For write the actual time and date
579         /*
580         time_t timer;
581         struct tm *tblock;
582         timer = time(NULL);
583         tblock = localtime(&timer);
584         */
585         FILE *fd;
586         _mpoint = new manualPoint();
587         int size = _mContourModel_1->GetSizeLstPoints();
588         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
589         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
590
591         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","a");
592         //fprintf(fd,"Date %s", asctime(tblock) );
593         fprintf(fd,"\nNumberOfControlPoints %d", size );
594         for(int i=0; i<size; i++)
595         {
596                 _mpoint = _mContourModel_1->GetManualPoint(i);
597                 fprintf(fd,"\n%f %f %d",_mpoint->GetX(),_mpoint->GetY(),z);
598         }
599         fclose(fd);
600 }
601 //----------------------------------------------------------------------------------
602 void wxMaracasCoutourTool::EreaseLastContour(wxCommandEvent& event)
603 {
604         char firstline[30];
605         int     size = 0,i,j;
606         double x,y;
607         int z;          
608         
609         _tempCX.clear();
610         _tempCY.clear();
611         _tempCZ.clear();
612         _tempCPX.clear();
613         _tempCPY.clear();
614         _tempCPZ.clear();
615         _SizesC.clear();
616         _SizesCP.clear();
617
618         FILE* fd;
619         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
620         if(fd!=NULL)
621         {
622                 while(!feof(fd))        
623                 {
624 //              //fscanf(fd," %s %d",&firstline,&size); // JPRx
625                         fscanf(fd," %s %d",firstline,&size);
626
627                         _SizesC.push_back(size);
628                         for(j=0; j<size; j++)
629                         {
630                                 fscanf(fd,"%lf %lf %d",&x,&y,&z);
631                                 _tempCX.push_back(x);
632                                 _tempCY.push_back(y);
633                                 _tempCZ.push_back(z);
634                         }
635                 }
636         }
637         else
638         {
639                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
640         }
641         fclose(fd);
642
643         for(i=0; i<size; i++)
644         {
645                 _tempCX.pop_back();
646                 _tempCY.pop_back();
647                 _tempCZ.pop_back();
648         }
649         _SizesC.pop_back();
650         
651         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","w");
652         if(fd!=NULL)
653         {
654                 int cont = 0;
655                 for(i=0; i<(int)(_SizesC.size()); i++)
656                 {
657                         fprintf(fd,"\nNumberOfPoints %d", _SizesC[i] );
658                         for(j=0; j<_SizesC[i]; j++)
659                         {
660                                 fprintf(fd,"\n%f %f %d",_tempCX[j+cont],_tempCY[j+cont],_tempCZ[j+cont]);
661                         }
662                         cont = _SizesC[i];
663                 }
664         }
665         else
666         {
667                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
668         }
669         fclose(fd);
670
671 }
672 //----------------------------------------------------------------------------------
673 void wxMaracasCoutourTool::EreaseLastCP(wxCommandEvent& event)
674 {
675         char firstline[30];
676         int     size = 0,i,j;
677         double x,y;
678         int z;          
679         
680         _tempCX.clear();
681         _tempCY.clear();
682         _tempCZ.clear();
683         _tempCPX.clear();
684         _tempCPY.clear();
685         _tempCPZ.clear();
686         _SizesC.clear();
687         _SizesCP.clear();
688
689         FILE* fd;
690         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","r");
691         if(fd!=NULL)
692         {
693                 while(!feof(fd))        
694                 {
695                         //fscanf(fd,"");  // ?? JPRx
696                         //fscanf(fd," %s %d",&firstline,&size);// JPRx
697                         fscanf(fd," %s %d",firstline,&size); 
698                         _SizesC.push_back(size);
699                         for(j=0; j<size; j++)
700                         {
701                                 fscanf(fd,"%lf %lf %d",&x,&y,&z);
702                                 _tempCX.push_back(x);
703                                 _tempCY.push_back(y);
704                                 _tempCZ.push_back(z);
705                         }
706                 }
707         }
708         else
709         {
710                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
711         }
712         fclose(fd);
713
714         for(i=0; i<size; i++)
715         {
716                 _tempCX.pop_back();
717                 _tempCY.pop_back();
718                 _tempCZ.pop_back();
719         }
720         _SizesC.pop_back();
721         
722         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","w");
723         if(fd!=NULL)
724         {
725                 int cont = 0;
726                 for(i=0; i<(int)(_SizesC.size()); i++)
727                 {
728                         fprintf(fd,"\nNumberOfControlPoints %d", _SizesC[i] );
729                         for(j=0; j<_SizesC[i]; j++)
730                         {
731                                 fprintf(fd,"\n%f %f %d",_tempCX[j+cont],_tempCY[j+cont],_tempCZ[j+cont]);
732                         }
733                         cont = _SizesC[i];
734                 }
735         }
736         else
737         {
738                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
739         }
740         fclose(fd);
741 }
742 //----------------------------------------------------------------------------------