ContourCrownWidget.cxx

Go to the documentation of this file.
00001 
00002 #include "ContourCrownWidget.h"
00003 
00004 #include <vtkImageMapToColors.h>
00005 #include <vtkImageActor.h>
00006 
00007 #include "wxVtk2DBaseView.h"
00008 #include "vtkLookupTable.h"
00009 
00010 //----------------------------------------------------------------------
00011   wxMaracasCoutourTool::wxMaracasCoutourTool(wxWindow *parent, wxVtkBaseView *wxvtkbaseview, vtkImageData* imagedata)
00012     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
00013   {
00014 //EED    this->mbbtkContourCrown        = contourcrown;
00015     this->imagedata                     = imagedata;
00016         this->wxvtkbaseview             = wxvtkbaseview;
00017         wxPanel *panel                  = this;
00018     wxSizer *sizer                      = NULL;
00019         
00020         InitVtkImagesResult();
00021 
00022          vtkLookupTable *table = vtkLookupTable::New();
00023 //       table->SetAlphaRange(128,255);
00024      table->SetRange(0, 255); // image intensity range
00025 //   table->SetValueRange(0.0, 1.0); // from black to white
00026      table->SetValueRange(0.0, 255.0); // from black to white
00027 
00028          table->SetTableValue (0, 1.0 , 1.0 , 1.0 , 0.1 );
00029          table->SetTableValue (255, 1.0 , 1.0 , 0.0 , 0.1);
00030 
00031 //       table->SetTableValue (0, 0.0 , 0.0 , 1.0 , 0.35 );
00032 //       table->SetTableValue (255, 1.0 , 0.0 , 0.0 , 0.10);
00033 
00034      table->SetSaturationRange(0.0, 0.0); // no color saturation
00035      table->SetRampToLinear();
00036      table->Build();
00037 
00038         vtkImageMapToColors  *mapperImage = vtkImageMapToColors::New();
00039         mapperImage->SetLookupTable(table);
00040         mapperImage->SetInput( imagedataMaskResult );
00041         vtkImageActor *actorImage       = vtkImageActor::New();
00042         actorImage->SetInput( mapperImage->GetOutput() );
00043         actorImage->SetOpacity(1);
00044 
00045         wxvtkbaseview->GetRenderer()->AddActor(actorImage);
00046 
00047         // Widget interface
00048         wxButton *btnContourA   = new wxButton( panel, -1, _T("Crown Extern"));
00049         wxButton *btnContourB   = new wxButton( panel, -1, _T("Crown Intern"));
00050         wxButton *btnContourAB  = new wxButton( panel, -1, _T("Crown Extern and Intern"));
00051 
00052 //JSTG 21-03-08 --------------------------------------------------------------------
00053         wxButton *btnSaveContour                = new wxButton( panel, -1, _T("Save Contour"));
00054         wxButton *btnSaveControlPoints  = new wxButton( panel, -1, _T("Save Control Points"));
00055 //JSTG 11-04-08
00056         wxButton *btnEreaseLastContour  = new wxButton( panel, -1, _T("Erease Last Contour"));
00057         wxButton *btnEreaseLastCP               = new wxButton( panel, -1, _T("Erease Last Control Points"));
00058 //----------------------------------------------------------------------------------
00059 
00060         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(10); //Original Value = 10
00061     sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
00062     sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
00063 
00064     Connect(btnContourA->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourA  );
00065     Connect(btnContourB->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourB  );
00066     Connect(btnContourAB->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnContourAB );
00067 
00068 //JSTG 21-03-08 ---------------------------------------------------------------------
00069         Connect(btnSaveContour->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnSaveContour );
00070         Connect(btnSaveControlPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::OnSaveControlPoints );
00071 //JSTG 11-04-08
00072         Connect(btnEreaseLastContour->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::EreaseLastContour );
00073         Connect(btnEreaseLastCP->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxMaracasCoutourTool::EreaseLastCP );        
00074 //-----------------------------------------------------------------------------------
00075 
00076     sizer1->Add(btnContourA);
00077     sizer1->Add(btnContourB);
00078     sizer1->Add(btnContourAB);
00079 
00080 //JSTG 21-03-08 --------------------
00081         sizer1->Add(btnSaveContour);
00082         sizer1->Add(btnSaveControlPoints);
00083 //JSTG 11-04-08
00084         sizer1->Add(btnEreaseLastContour);
00085         sizer1->Add(btnEreaseLastCP);
00086 //----------------------------------    
00087         sizer = sizer1;
00088         panel   ->      SetSizer(sizer);
00089     panel       ->      SetAutoLayout(true);
00090     panel       ->      Layout();  
00091         
00092 }
00093 
00094   // ------------------------------------------------------------------------
00095 
00096   wxMaracasCoutourTool::~wxMaracasCoutourTool()
00097   {
00098   }
00099 
00100   // ------------------------------------------------------------------------
00101   wxVtkBaseView *wxMaracasCoutourTool::GetWxVtkBaseView()
00102         {
00103                 return this->wxvtkbaseview;
00104         }
00105 
00106 
00107   // ------------------------------------------------------------------------
00108 
00109   void wxMaracasCoutourTool::ConfigureVTK()
00110   {
00111           double spc[3];
00112           this->imagedata->GetSpacing(spc);
00113 
00114         // Contorno 1
00115         _manContourControl_1    = new manualContourControler();
00116         _mContourModel_1                = new manualContourModel();
00117         _mViewContour_1                 = new manualViewContour();
00118         _mViewContour_1->SetModel( _mContourModel_1 );
00119         _mViewContour_1->SetWxVtkBaseView( this->wxvtkbaseview );
00120         _mViewContour_1->SetRange( 2 );
00121         _mViewContour_1->SetZ( 1000 );
00122 
00123 //JSTG 18-06-07
00124         _mContourModel_1->SetNumberOfPointsSpline(100);
00125 
00126 
00127 //EED 3 oct 2006
00128         _mViewContour_1->SetSpacing(spc);
00129 
00130 
00131 //EED 3 oct 2006
00132         _mViewContour_1->SetColorNormalContour(0, 0, 1);
00133         _mViewContour_1->SetColorEditContour(0.5, 0.5, 0.5);
00134 
00135 
00136         _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
00137         ((vtkInteractorStyleBaseView*)this->wxvtkbaseview->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _manContourControl_1 );
00138         _manContourControl_1->CreateNewManualContour();
00139         _manContourControl_1->SetActive(false);
00140         _mViewContour_1->RefreshContour();
00141 
00142 
00143         // Contorno 2
00144         _manContourControl_2    = new manualContourControler();
00145         _mContourModel_2                = new manualContourModel();
00146         _mViewContour_2                 = new manualViewContour();
00147         _mViewContour_2->SetModel( _mContourModel_2 );
00148         _mViewContour_2->SetWxVtkBaseView( this->wxvtkbaseview );
00149         _mViewContour_2->SetRange( 2 );
00150         _mViewContour_2->SetZ( 1000 );
00151 
00152 //EED 3 oct 2006
00153         _mViewContour_2->SetSpacing(spc);
00154 
00155 //EED 3 oct 2006
00156         _mViewContour_2->SetColorNormalContour(1, 0, 0);
00157         _mViewContour_2->SetColorEditContour(0.5, 0.5, 0.5);
00158 
00159 
00160         _manContourControl_2->SetModelView( _mContourModel_2 , _mViewContour_2 );
00161         ((vtkInteractorStyleBaseView*)this->wxvtkbaseview->GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _manContourControl_2 );
00162         _manContourControl_2->CreateNewManualContour();
00163         _manContourControl_2->SetActive(false);
00164         _mViewContour_2->RefreshContour();
00165 
00166 //      Refresh();      
00167 
00168 //JSTG 16-06-08
00169         _contprop = new ContourPropagation();
00170  }
00171 
00172 //JSTG 26-02-08 -------------------------------------------------------------------------------------------------------------
00173   void wxMaracasCoutourTool::SetControlPoints(  std::vector<double> *InVectorX, 
00174                                                                                                 std::vector<double> *InVectorY, 
00175                                                                                                 std::vector<double> *InVectorZ )
00176   {
00177         int lstSize;
00178         if (InVectorX!=NULL)
00179         {
00180                 int i,size=InVectorX->size();
00181                 if (size!=0)
00182                 {
00183                         _mContourModel_1->DeleteAllPoints();
00184                         _mViewContour_1->DeleteContour();
00185 
00186                         for (i=0;i<size;i++)
00187                         {
00188                                 lstSize = _mContourModel_1->AddPoint( (*InVectorX)[i] , (*InVectorY)[i] , (*InVectorZ)[i] );
00189                                 _mViewContour_1->AddPoint();
00190                         }
00191                         //_manContourControl_1->CreateNewManualContour();
00192                         //_manContourControl_1->SetActive(true);
00193                         _mViewContour_1->CreateNewContour();
00194                         _mContourModel_1->UpdateSpline();
00195                         _mViewContour_1->RefreshContour();
00196                         //_mViewContour_1->Refresh ();
00197                 } 
00198          } 
00199   }
00200 
00201 // JSTG 26-02-08 ------------------------------------------------------------------------------
00202   void wxMaracasCoutourTool::GetSplinePoints(   std::vector<double> *pLstContourX,
00203                                                                                                 std::vector<double> *pLstContourY,
00204                                                                                                 std::vector<double> *pLstContourZ  )
00205   {
00206           int i;
00207           double x,y,z;
00208           _mContourModel_1->UpdateSpline();
00209           
00210           for(i=0; i<_mContourModel_1->GetNumberOfPointsSpline(); i++)
00211           {
00212                 _mContourModel_1->GetSpline_i_Point( i, &x, &y, &z );
00213                 pLstContourX->push_back(x);
00214                 pLstContourY->push_back(y);
00215                 //pLstContourY->push_back(z);                   //Fake Z -> For Visualization
00216                 pLstContourZ->push_back(_zz);                   //True Z -> For processing
00217           }
00218   }
00219 //---------------------------------------------------------------------------------------------
00220 
00221 //------------------------------------------------------------------------
00222 void wxMaracasCoutourTool::OnContourA(wxCommandEvent& event)
00223 {
00224         _manContourControl_1 -> SetActive(true);
00225         _manContourControl_2 -> SetActive(false);
00226 }
00227 //------------------------------------------------------------------------
00228 void wxMaracasCoutourTool::OnContourB(wxCommandEvent& event)
00229 {
00230         _manContourControl_1 -> SetActive(false);
00231         _manContourControl_2 -> SetActive(true);
00232 }
00233 //------------------------------------------------------------------------
00234 void wxMaracasCoutourTool::OnContourAB(wxCommandEvent& event)
00235 {
00236         _manContourControl_1 -> SetActive(true);
00237         _manContourControl_2 -> SetActive(true);
00238 }
00239 
00240 //------------------------------------------------------------------------
00241 void wxMaracasCoutourTool::GetMinMaxPoint(int *minPoint, 
00242                                                                                   int *maxPoint, 
00243                                                                                   manualViewBaseContour *manualviewbaseecontour,
00244                                                                                   manualContourModel *manualcontourmodel
00245                                                                                   )
00246 {
00247         int i;
00248         //int   np  = manualviewbaseecontour->GetNumberOfPoints( );  // number of control points // JPRx
00249 
00250 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
00251         //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline
00252         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
00253 //------------------------------------------------------------------------------------------------------
00254         
00255 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
00256         //double x,y,z,t;
00257         double x,y,z;
00258         //double delta=( double ) ( np  ) / ( double ) ( nps  );
00259         manualcontourmodel->UpdateSpline();
00260         for (i=0; i<nps; i++)
00261         {
00262                 //t= delta * (double)i;
00263                 //manualcontourmodel->GetSplinePoint(t,x,y,z);
00264                 manualcontourmodel->GetSpline_i_Point(i,&x,&y,&z);
00265                 if (x<minPoint[0]){ minPoint[0]=(int)x; }
00266                 if (y<minPoint[1]){ minPoint[1]=(int)y; }
00267                 if (x>maxPoint[0]){ maxPoint[0]=(int)x; }
00268                 if (y>maxPoint[1]){ maxPoint[1]=(int)y; }
00269         }
00270 //------------------------------------------------------------------------------------------------------
00271 }
00272 
00273 //------------------------------------------------------------------------
00274 
00275 int wxMaracasCoutourTool::AnalisisContourInside(int x, 
00276                                                                                                 int y, 
00277                                                                                                 manualViewBaseContour *manualviewbaseecontour,
00278                                                                                                 manualContourModel *manualcontourmodel
00279                                                                                                 )
00280 {
00281         int result = 0;
00282         int i;
00283         int     np  = manualviewbaseecontour->GetNumberOfPoints( );  // number of control points
00284 
00285 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
00286         //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline
00287         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
00288         //double x1,y1,z1,x2,y2,z2,t;
00289         double x1,y1,z1,x2,y2,z2;
00290         double xx1, yy1,xx2, yy2;
00291         //double delta=( double ) ( np  ) / ( double ) ( nps  );
00292         manualcontourmodel->UpdateSpline();
00293 //------------------------------------------------------------------------------------------------------
00294         double d;
00295         bool ok;
00296         if (np>=2)
00297         {
00298 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
00299                 nps--;
00300                 //manualcontourmodel->GetSplinePoint(0,x1,y1,z1);
00301                 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
00302                 for (i=1; i<=nps; i++)
00303                 {
00304                         ok=false;
00305                         //t= delta * (double)(i%nps);
00306                         //manualcontourmodel->GetSplinePoint(t,x2,y2,z2);
00307                         manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
00308 //------------------------------------------------------------------------------------------------------
00309                         //by triangle similarity
00310                         if ( ((y1<y2)&&(y>=y1)&&(y<y2)) || ((y1>y2)&&(y<=y1)&&(y>y2)) )
00311                         {
00312                                 if (y1<y2) { xx1=x1; yy1=y1; xx2=x2; yy2=y2;} else { xx1=x2; yy1=y2; xx2=x1; yy2=y1; } 
00313                                 d = ( fabs(xx2-xx1)*(y-yy1) ) / (yy2-yy1) ;
00314                                 if (  ((xx1<xx2)&&(x<(xx1+d)))  ||  ((xx1>xx2)&&(x<(xx1-d)))  ) { result++; }
00315                         }
00316                         x1=x2; y1=y2; z1=z2;
00317                 }
00318         }
00319         return result;
00320 }
00321 
00322 //------------------------------------------------------------------------
00323 
00324 
00325 bool wxMaracasCoutourTool::isInside(int x, int y)
00326 {
00327         bool result=false;
00328 
00329         int ext[6];
00330         imagedataValueResult->GetExtent(ext);
00331 
00332         if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3]))
00333         {
00334                 int numberLeftA=AnalisisContourInside(x,y,_mViewContour_1, _mContourModel_1); 
00335                 int numberLeftB=AnalisisContourInside(x,y,_mViewContour_2, _mContourModel_2);
00336                 if ( (numberLeftA+numberLeftB) % 2 ==1){        result = true;  } 
00337         }
00338 
00339         return result;
00340 }
00341 
00342 //------------------------------------------------------------------------
00343 
00344 double wxMaracasCoutourTool::GetDataValue(int x, int y)
00345 {
00346         unsigned short *p;
00347         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
00348         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
00349         //JSTG 13-03-08-----
00350         _zz = z;
00351         //------------------
00352         p = (unsigned short *)imagedata->GetScalarPointer(x,y,z);
00353         return (double)(*p);
00354 }
00355 
00356 //------------------------------------------------------------------------
00357 
00358 void wxMaracasCoutourTool::PutVtkImageDataResultValue( int x, int y, double value )
00359 {
00360         unsigned short *pValue;
00361         unsigned short *pMask;
00362         pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,0);
00363         pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,0);
00364         *pMask  = 255;
00365         *pValue = (unsigned short)value;
00366 }
00367 
00368 //------------------------------------------------------------------------
00369 void wxMaracasCoutourTool::ResetImageResult()
00370 {
00371         unsigned short *pValue;
00372         unsigned short *pMask;
00373         pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,0);
00374         pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,0);
00375         
00376         int ext[6];
00377         imagedataValueResult->GetExtent(ext);
00378 
00379         int i,size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 
00380         for(i=0; i<size; i++)
00381         {
00382                 *pMask  = 0;
00383                 *pValue = 0;
00384                 pMask++;
00385                 pValue++;
00386         }
00387 }
00388 //------------------------------------------------------------------------
00389 
00390 void wxMaracasCoutourTool::GetValuesInsideCrown(std::vector<double> *pLstValue,
00391                                                                                                 std::vector<double> *pLstValuePosX,
00392                                                                                                 std::vector<double> *pLstValuePosY,
00393                                                                                                 std::vector<double> *pLstValuePosZ)
00394 {
00395   pLstValue->clear();
00396   pLstValuePosX->clear();
00397   pLstValuePosY->clear();
00398   pLstValuePosZ->clear();
00399   ResetImageResult();
00400   
00401         int minPoint[2];
00402         int maxPoint[2];
00403         int i,j;
00404         double value;
00405 
00406 
00407         minPoint[0]=999999;
00408         minPoint[1]=999999;
00409         maxPoint[0]=-999999;
00410         maxPoint[1]=-999999;
00411 
00412         GetMinMaxPoint(minPoint,maxPoint, _mViewContour_1, _mContourModel_1);
00413         GetMinMaxPoint(minPoint,maxPoint, _mViewContour_2, _mContourModel_2);
00414 
00415         for (j=minPoint[1]; j<maxPoint[1]; j++)
00416         {
00417                 for (i=minPoint[0]; i<maxPoint[0]; i++)
00418                 {
00419                         if (isInside(i,j)==true)
00420                         {
00421                                 value = GetDataValue(i,j);
00422                                 PutVtkImageDataResultValue(i,j,  value );
00423                                 pLstValue               -> push_back( value );
00424                                 pLstValuePosX   -> push_back( i );
00425                                 pLstValuePosY   -> push_back( j );
00426                                 pLstValuePosZ   -> push_back( -1 );
00427                         } // if
00428                 } // for
00429         } // for
00430 
00431         imagedataValueResult->Modified();
00432         imagedataMaskResult->Modified();
00433 }
00434 
00435 //------------------------------------------------------------------------
00436 
00437 vtkImageData *wxMaracasCoutourTool::GetVtkImageValueResult()
00438 {
00439         return imagedataValueResult;
00440 }
00441 //------------------------------------------------------------------------
00442 vtkImageData *wxMaracasCoutourTool::GetVtkImageMaskResult()
00443 {
00444         return imagedataMaskResult;
00445 }
00446 // ------------------------------------------------------------------------
00447 void wxMaracasCoutourTool::InitVtkImagesResult()
00448   {
00449           int ext[6];
00450           int newDim[3];
00451           double spc[3];
00452           int scalartype;
00453 
00454           imagedata->GetSpacing(spc);
00455           imagedata->GetExtent(ext);
00456           newDim[0]=ext[1]-ext[0]+1;
00457           newDim[1]=ext[3]-ext[2]+1;
00458           newDim[2]=1;
00459           scalartype = imagedata->GetScalarType();
00460 
00461           imagedataValueResult = vtkImageData::New();
00462 //        imagedataValueResult->SetScalarType(scalartype);
00463           imagedataValueResult->SetScalarTypeToUnsignedShort();
00464           imagedataValueResult->SetSpacing(spc);
00465           imagedataValueResult->SetDimensions( newDim );
00466           imagedataValueResult->AllocateScalars();
00467 
00468           imagedataMaskResult  = vtkImageData::New();
00469 //        imagedataMaskResult->SetScalarType(scalartype);
00470           imagedataMaskResult->SetScalarTypeToUnsignedShort();
00471           imagedataMaskResult->SetSpacing(spc);
00472           imagedataMaskResult->SetDimensions( newDim );
00473           imagedataMaskResult->AllocateScalars();
00474 
00475   }
00476 
00477 //JSTG 21-03-08 -------------------------------------------------------------------
00478 void wxMaracasCoutourTool::OnSaveContour(wxCommandEvent& event)
00479 {
00480         //For write the actual time and date
00481         /*
00482         time_t timer;
00483         struct tm *tblock;
00484         timer = time(NULL);
00485         tblock = localtime(&timer);
00486         */
00487 
00488         FILE *fd;
00489         
00490         //WHERE CAN I MAKE THEM DELETE!!!
00491         _mpoint = new manualPoint();
00492 
00493         std::vector<double> tempX;
00494         std::vector<double> tempY;
00495         std::vector<double> tempZ;
00496         tempX.clear();
00497         tempY.clear();
00498         tempZ.clear();
00499 
00500         int size = _mContourModel_1->GetNumberOfPointsSpline();
00501         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
00502         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
00503         double xx, yy, zz;
00504 
00505         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","a");
00506         //fprintf(fd,"Date %s", asctime(tblock) );
00507         fprintf(fd,"\nPointsContour %d", size );
00508         for(int i=0; i<size; i++)
00509         {
00510                 _mContourModel_1->GetSpline_i_Point(i,&xx,&yy,&zz);
00511                 fprintf(fd,"\n%f %f %d",xx,yy,z);       //z -> Contain the true value || zz -> Contain the cheating value for visualitation 
00512                 tempX.push_back(xx);
00513                 tempY.push_back(yy);
00514                 tempZ.push_back(z);
00515         }
00516         fclose(fd);
00517 
00518 //JSTG 16-06-08
00519         _contprop->appendContour(&tempX,&tempY,&tempZ);
00520 }
00521 
00522 //JSTG 21-03-08 --------------------------------------------------------------------
00523 void wxMaracasCoutourTool::OnSaveControlPoints(wxCommandEvent& event)
00524 {
00525         //For write the actual time and date
00526         /*
00527         time_t timer;
00528         struct tm *tblock;
00529         timer = time(NULL);
00530         tblock = localtime(&timer);
00531         */
00532         FILE *fd;
00533         _mpoint = new manualPoint();
00534         int size = _mContourModel_1->GetSizeLstPoints();
00535         wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
00536         int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
00537 
00538         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","a");
00539         //fprintf(fd,"Date %s", asctime(tblock) );
00540         fprintf(fd,"\nNumberOfControlPoints %d", size );
00541         for(int i=0; i<size; i++)
00542         {
00543                 _mpoint = _mContourModel_1->GetManualPoint(i);
00544                 fprintf(fd,"\n%f %f %d",_mpoint->GetX(),_mpoint->GetY(),z);
00545         }
00546         fclose(fd);
00547 }
00548 //----------------------------------------------------------------------------------
00549 void wxMaracasCoutourTool::EreaseLastContour(wxCommandEvent& event)
00550 {
00551         char firstline[30];
00552         int     size = 0,i,j;
00553         double x,y;
00554         int z;          
00555         
00556         _tempCX.clear();
00557         _tempCY.clear();
00558         _tempCZ.clear();
00559         _tempCPX.clear();
00560         _tempCPY.clear();
00561         _tempCPZ.clear();
00562         _SizesC.clear();
00563         _SizesCP.clear();
00564 
00565         FILE* fd;
00566         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
00567         if(fd!=NULL)
00568         {
00569                 while(!feof(fd))        
00570                 {
00571 //              //fscanf(fd," %s %d",&firstline,&size); // JPRx
00572                         fscanf(fd," %s %d",firstline,&size);
00573 
00574                         _SizesC.push_back(size);
00575                         for(j=0; j<size; j++)
00576                         {
00577                                 fscanf(fd,"%lf %lf %d",&x,&y,&z);
00578                                 _tempCX.push_back(x);
00579                                 _tempCY.push_back(y);
00580                                 _tempCZ.push_back(z);
00581                         }
00582                 }
00583         }
00584         else
00585         {
00586                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
00587         }
00588         fclose(fd);
00589 
00590         for(i=0; i<size; i++)
00591         {
00592                 _tempCX.pop_back();
00593                 _tempCY.pop_back();
00594                 _tempCZ.pop_back();
00595         }
00596         _SizesC.pop_back();
00597         
00598         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","w");
00599         if(fd!=NULL)
00600         {
00601                 int cont = 0;
00602                 for(i=0; i<(int)(_SizesC.size()); i++)
00603                 {
00604                         fprintf(fd,"\nNumberOfPoints %d", _SizesC[i] );
00605                         for(j=0; j<_SizesC[i]; j++)
00606                         {
00607                                 fprintf(fd,"\n%f %f %d",_tempCX[j+cont],_tempCY[j+cont],_tempCZ[j+cont]);
00608                         }
00609                         cont = _SizesC[i];
00610                 }
00611         }
00612         else
00613         {
00614                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
00615         }
00616         fclose(fd);
00617 
00618 }
00619 //----------------------------------------------------------------------------------
00620 void wxMaracasCoutourTool::EreaseLastCP(wxCommandEvent& event)
00621 {
00622         char firstline[30];
00623         int     size = 0,i,j;
00624         double x,y;
00625         int z;          
00626         
00627         _tempCX.clear();
00628         _tempCY.clear();
00629         _tempCZ.clear();
00630         _tempCPX.clear();
00631         _tempCPY.clear();
00632         _tempCPZ.clear();
00633         _SizesC.clear();
00634         _SizesCP.clear();
00635 
00636         FILE* fd;
00637         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","r");
00638         if(fd!=NULL)
00639         {
00640                 while(!feof(fd))        
00641                 {
00642                         //fscanf(fd,"");  // ?? JPRx
00643                         //fscanf(fd," %s %d",&firstline,&size);// JPRx
00644                         fscanf(fd," %s %d",firstline,&size); 
00645                         _SizesC.push_back(size);
00646                         for(j=0; j<size; j++)
00647                         {
00648                                 fscanf(fd,"%lf %lf %d",&x,&y,&z);
00649                                 _tempCX.push_back(x);
00650                                 _tempCY.push_back(y);
00651                                 _tempCZ.push_back(z);
00652                         }
00653                 }
00654         }
00655         else
00656         {
00657                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
00658         }
00659         fclose(fd);
00660 
00661         for(i=0; i<size; i++)
00662         {
00663                 _tempCX.pop_back();
00664                 _tempCY.pop_back();
00665                 _tempCZ.pop_back();
00666         }
00667         _SizesC.pop_back();
00668         
00669         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","w");
00670         if(fd!=NULL)
00671         {
00672                 int cont = 0;
00673                 for(i=0; i<(int)(_SizesC.size()); i++)
00674                 {
00675                         fprintf(fd,"\nNumberOfControlPoints %d", _SizesC[i] );
00676                         for(j=0; j<_SizesC[i]; j++)
00677                         {
00678                                 fprintf(fd,"\n%f %f %d",_tempCX[j+cont],_tempCY[j+cont],_tempCZ[j+cont]);
00679                         }
00680                         cont = _SizesC[i];
00681                 }
00682         }
00683         else
00684         {
00685                 printf("\nJSTG - wxMaracasCoutourTool::EreaseLastContour - FILE NOT FOUND");
00686         }
00687         fclose(fd);
00688 }
00689 //----------------------------------------------------------------------------------

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1