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