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