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