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