wxVtkMPR2DView.cxx

Go to the documentation of this file.
00001 #include "wxVtkMPR2DView.h"
00002 
00003 #include "vtkInteractorStyleBaseView.h"
00004 
00005 #include "vtkCellArray.h"
00006 
00007 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
00008  :wxVtk2DBaseView(parent)
00009 {
00010         _backX                  = -99999;
00011         _backY                  = -99999;
00012         _backZ                  = -99999;
00013         _direction              = direction;
00014         _ptsA                   = NULL;
00015         _lineAActor             = NULL;
00016         _lineAMapper    = NULL;
00017         _pdA                    = NULL;
00018         _ptsB                   = NULL;
00019         _lineBActor             = NULL;
00020         _lineBMapper    = NULL;
00021         _pdB                    = NULL;
00022         _interactorstylemprview = NULL;
00023 }
00024 
00025 //-------------------------------------------------------------------
00026 wxVtkMPR2DView::~wxVtkMPR2DView()
00027 {
00028         if (_ptsA!=NULL)        { _ptsA         -> Delete(); }
00029         if (_lineAActor!=NULL)  { _lineAActor   -> Delete(); }
00030         if (_lineAMapper!=NULL) { _lineAMapper  -> Delete(); }
00031         if (_pdA!=NULL)         { _pdA          -> Delete(); }
00032         if (_ptsB!=NULL)        { _ptsB         -> Delete(); }
00033         if (_lineBActor!=NULL)  { _lineBActor   -> Delete(); }
00034         if (_lineBMapper!=NULL) { _lineBMapper  -> Delete(); }
00035         if (_pdB!=NULL)         { _pdB          -> Delete(); }
00036 }
00037 //-------------------------------------------------------------------
00038 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
00039 {
00040         return (vtkMPRBaseData*)GetVtkBaseData();
00041 }
00042 //-------------------------------------------------------------------
00043 void wxVtkMPR2DView::Configure(){
00044         wxVtk2DBaseView::Configure();
00045         
00046 
00047         int x1,x2,y1,y2,z1,z2;
00048         GetVtkmprbasedata()     -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
00049 
00050         double spc[3];
00051         vtkImageData* img =  GetVtkmprbasedata()->GetImageData();
00052         if(_interactorstylemprview==NULL)       
00053         {
00054                 _interactorstylemprview = new vtkInteractorStyleMPRView();
00055                 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
00056         }
00057         
00058         if(img!=NULL){
00059                 double* origin = img->GetOrigin();
00060                 img->GetExtent(x1,x2,y1,y2,z1,z2);
00061                 img->GetSpacing(spc);
00062                 x1 += origin[0];
00063                 x2 += origin[0];
00064                 y1 += origin[1];
00065                 y2 += origin[1];
00066                 z1 += origin[2];
00067                 z2 += origin[2];
00068                 x1 = (int)(x1*spc[0]);
00069                 y1 = (int)(y1*spc[1]);
00070                 z1 = (int)(z1*spc[2]);
00071 
00072                 x2 = (int)(x2*spc[0]);
00073                 y2 = (int)(y2*spc[1]);
00074                 z2 = (int)(z2*spc[2]);
00075 
00076                 _visibleAxis = true;
00077                 
00078                 
00079                 
00080         }
00081         
00082         // Axe A
00083         if(_lineAActor==NULL){
00084                 _lineAActor = vtkActor::New();
00085                 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
00086                 _lineAActor->GetProperty()->SetLineWidth(2);
00087                 
00088                 _ptsA = vtkPoints::New();
00089                 _ptsA->SetNumberOfPoints(2);
00090                 _ptsA->SetPoint(0, -1000        , -1000 , -1000 );
00091                 _ptsA->SetPoint(1,  1000        ,  1000 ,  1000 );
00092                 
00093                 _pdA = vtkPolyData::New();
00094                 
00095                 _lineAMapper = vtkPolyDataMapper::New();
00096                 
00097                 _lineAMapper->SetInput(_pdA);
00098                 _lineAMapper->ImmediateModeRenderingOn();
00099                 _lineAActor->SetMapper(_lineAMapper);
00100         }       
00101         
00102         vtkCellArray *linesA = vtkCellArray::New();
00103         linesA->InsertNextCell(2);
00104         linesA->InsertCellPoint(0);
00105         linesA->InsertCellPoint(1);
00106         _pdA->SetPoints( _ptsA );
00107         _pdA->SetLines( linesA );
00108         linesA->Delete();  //do not delete lines ??
00109 //              _lineAActor->GetProperty()->BackfaceCullingOn();
00110         
00111 
00112 // Axe B
00113         if(_lineBActor==NULL){
00114                 _lineBActor                                             =       vtkActor::New();
00115                 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
00116                 _lineBActor->GetProperty()->SetLineWidth(2);
00117                 _lineBMapper                                    =       vtkPolyDataMapper::New();               
00118                 _lineBActor->SetMapper(_lineBMapper);
00119                 
00120                 _ptsB = vtkPoints::New();
00121                 _ptsB->SetNumberOfPoints(2);
00122                 _ptsB->SetPoint(0, -1000        , -1000 , -1000 );
00123                 _ptsB->SetPoint(1,  1000        ,  1000 ,  1000 );
00124                 
00125 //              _lineBActor->GetProperty()->BackfaceCullingOn();
00126         }
00127         
00128         vtkCellArray *linesB;
00129         linesB = vtkCellArray::New();
00130         linesB->InsertNextCell(2);
00131         linesB->InsertCellPoint(0);
00132         linesB->InsertCellPoint(1);
00133         _pdB = vtkPolyData::New();
00134         _pdB->SetPoints( _ptsB );
00135         _pdB->SetLines( linesB );
00136         linesB->Delete();  //do not delete lines ??
00137         
00138         
00139         _lineBMapper->SetInput(_pdB);
00140         _lineBMapper->ImmediateModeRenderingOn();
00141 
00142 
00143         if(_imageViewer2XYZ){
00144                 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
00145                 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
00146                 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
00147                 
00148         //EED 17Avril2009
00149         /*              
00150                 if (_direction==0) {
00151                         camera->SetViewUp               (   0   ,    -1         ,     0         );
00152                         camera->SetPosition             ( -10000,(y1+y2)/2      , (z1+z2)/2     ); 
00153                         camera->SetFocalPoint   (   0   , (y1+y2)/2     , (z1+z2)/2     );
00154                         camera->SetParallelScale( (z2-z1)/3.0 );
00155                 }
00156 
00157                 if (_direction==1) { 
00158                         camera->SetViewUp               (       0               ,       0       ,       -1              );
00159                         camera->SetPosition             ((x1+x2)/2      , 10000 , (z1+z2)/2     ); 
00160                         camera->SetFocalPoint   ((x1+x2)/2      ,   0   , (z1+z2)/2     );
00161                         camera->SetParallelScale( (x2-x1)/3.0 );
00162                 }
00163 
00164                 if (_direction==2) { 
00165                         camera->SetViewUp               (       0               ,       -1              ,       0       );
00166                         camera->SetPosition             ((x1+x2)/2      , (y1+y2)/2     , -10000); 
00167                         camera->SetFocalPoint   ((x1+x2)/2      , (y1+y2)/2     ,       0       ); 
00168                         camera->SetParallelScale( (x2-x1)/3.0 );
00169                 }
00170         */
00171 
00172                 if (_direction==0) {    // YZ
00173                         camera->SetViewUp               (   0   ,     1         ,     0         );
00174                         camera->SetPosition             (  10000,(y1+y2)/2      , (z1+z2)/2     ); 
00175                         camera->SetFocalPoint   (   0   , (y1+y2)/2     , (z1+z2)/2     );
00176                         camera->SetParallelScale( (z2-z1)/3.0 );
00177                 }
00178                 
00179                 if (_direction==1) {    // XZ
00180                         camera->SetViewUp               (       0               ,       0       ,       -1              );
00181                         camera->SetPosition             ((x1+x2)/2      , 10000 , (z1+z2)/2     ); 
00182                         camera->SetFocalPoint   ((x1+x2)/2      ,   0   , (z1+z2)/2     );
00183                         camera->SetParallelScale( (x2-x1)/3.0 );
00184                 }
00185                 
00186                 if (_direction==2) {    // XY
00187                         camera->SetViewUp               (       0               ,       1               ,       0       );
00188                         camera->SetPosition             ((x1+x2)/2      , (y1+y2)/2     ,  10000); 
00189                         camera->SetFocalPoint   ((x1+x2)/2      , (y1+y2)/2     ,       0       ); 
00190                         camera->SetParallelScale( (x2-x1)/3.0 );
00191                 }
00192                 
00193 
00194         //      _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
00195         //      _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
00196         }
00197 
00198 }
00199 
00200 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
00201 {
00202         if (ok!=_visibleAxis)
00203         {
00204                 _visibleAxis=ok;
00205                 if (_visibleAxis==true)
00206                 {
00207                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
00208                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
00209                 }
00210                 if (_visibleAxis==false)
00211                 {
00212                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
00213                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
00214                 }
00215 
00216         }
00217 }
00218 
00219 //-------------------------------------------------------------------
00220 void wxVtkMPR2DView::Refresh() 
00221 {
00222         //wxVtk2DBaseView::Refresh();
00223 
00224 
00225         //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
00226         //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
00227 
00228 
00229 
00230         int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0, x = 0, y = 0, z = 0;
00231         double *spc = 0;
00232         double *origin = 0;
00233         
00234         
00235         //GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
00236         
00237         
00238         vtkImageData* img = GetVtkmprbasedata()->GetImageData();
00239         if(img!=NULL){
00240                 origin = img->GetOrigin();
00241                 img->GetExtent(x1,x2,y1,y2,z1,z2);
00242                 spc = img->GetSpacing();
00243                 x1 += origin[0];
00244                 x2 += origin[0];
00245                 y1 += origin[1];
00246                 y2 += origin[1];
00247                 z1 += origin[2];
00248                 z2 += origin[2];
00249                 x1 = (int)(x1*spc[0]);
00250                 y1 = (int)(y1*spc[1]);
00251                 z1 = (int)(z1*spc[2]);
00252 
00253                 x2 = (int)(x2*spc[0]);
00254                 y2 = (int)(y2*spc[1]);
00255                 z2 = (int)(z2*spc[2]);
00256 
00257                 x = (int)(GetVtkmprbasedata()->GetX());
00258                 y = (int)(GetVtkmprbasedata()->GetY());
00259                 z = (int)(GetVtkmprbasedata()->GetZ());
00260 
00261                 x =  (int)(x*spc[0]);
00262                 y =  (int)(y*spc[1]);
00263                 z =  (int)(z*spc[2]);
00264 
00265                 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
00266 
00267                         if (_direction==0) {    // YZ 
00268                                 if(_imageViewer2XYZ)
00269                                         _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) ); 
00270                                 _ptsA->SetPoint(0, x2, y1  , z );
00271                                 _ptsA->SetPoint(1, x2, y2  , z );
00272                                 _ptsB->SetPoint(0, x2, y   , z1);
00273                                 _ptsB->SetPoint(1, x2, y   , z2);
00274                         }
00275                         if (_direction==1) {    // XZ
00276                                 if(_imageViewer2XYZ)
00277                                         _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) ); 
00278                             _ptsA->SetPoint(0, x1 , y2 , z );
00279                                 _ptsA->SetPoint(1, x2 , y2 , z );
00280                                 _ptsB->SetPoint(0, x  , y2 , z1);
00281                                 _ptsB->SetPoint(1, x  , y2 , z2);
00282                         }
00283                         if (_direction==2) {    // XY
00284                                 if(_imageViewer2XYZ)
00285                                         _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) ); 
00286                         //      _ptsA->SetPoint(0, x1 , y , -z2 );
00287                         //      _ptsA->SetPoint(1, x2 , y , -z2 );
00288                         //      _ptsB->SetPoint(0, x  , y1, -z2 );
00289                         //      _ptsB->SetPoint(1, x  , y2, -z2 );
00290                                 
00291                                 _ptsA->SetPoint(0, x1 , y , z2 );
00292                                 _ptsA->SetPoint(1, x2 , y , z2 );
00293                                 _ptsB->SetPoint(0, x  , y1, z2 );
00294                                 _ptsB->SetPoint(1, x  , y2, z2 );
00295                         }
00296                         _backX=x;
00297                         _backY=y;
00298                         _backZ=z;
00299                 }
00300                 wxVtkBaseView::Refresh();
00301         }
00302 }
00303 //-------------------------------------------------------------------
00304 int wxVtkMPR2DView::GetActualSlice()   // virtual
00305 {
00306         int result;
00307         if (_direction==0) 
00308         { 
00309                 result = (int)(GetVtkmprbasedata()->GetX());
00310         }
00311         if (_direction==1) 
00312         { 
00313                 result = (int)(GetVtkmprbasedata()->GetY());
00314         }
00315         if (_direction==2) 
00316         { 
00317                 result = (int)(GetVtkmprbasedata()->GetZ());
00318         }
00319         return result;
00320 }
00321 //-------------------------------------------------------------------
00322 void wxVtkMPR2DView::SetActualSlice(int slice)   // virtual
00323 {
00324         if (_direction==0) 
00325         { 
00326                 GetVtkmprbasedata()->SetX(slice);
00327         }
00328         if (_direction==1) 
00329         { 
00330                 GetVtkmprbasedata()->SetY(slice);
00331         }
00332         if (_direction==2) 
00333         { 
00334                 GetVtkmprbasedata()->SetZ(slice);
00335         }
00336 }
00337 //-------------------------------------------------------------------
00338 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
00339 {
00340         double delta=5;
00341         bool result=false;
00342         if (_direction==0) 
00343         { 
00344         }
00345         if (_direction==1) 
00346         { 
00347                 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
00348                 {
00349                         result = true;
00350                 }
00351         }
00352         if (_direction==2) 
00353         { 
00354                 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
00355                 {
00356                         result = true;
00357                 }
00358         }
00359         return result;
00360 }
00361 //-------------------------------------------------------------------
00362 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
00363 {
00364         double delta=5;
00365         bool result=false;
00366         if (_direction==0) 
00367         { 
00368                 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
00369                 {
00370                         result = true;
00371                 }
00372         }
00373         if (_direction==1) 
00374         { 
00375         }
00376         if (_direction==2) 
00377         { 
00378                 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
00379                 {
00380                         result = true;
00381                 }
00382         }
00383         return result;
00384 }
00385 //-------------------------------------------------------------------
00386 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
00387 {
00388         double delta=5;
00389         bool result=false;
00390         if (_direction==0) 
00391         { 
00392                 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
00393                 {
00394                         result = true;
00395                 }
00396         }
00397         if (_direction==1) 
00398         { 
00399                 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
00400                 {
00401                         result = true;
00402                 }
00403         }
00404         if (_direction==2) 
00405         { 
00406         }
00407         return result;
00408 }
00409 //-------------------------------------------------------------------
00410 void wxVtkMPR2DView::MoveX(double x, double y, double z)
00411 {
00412         if (_direction==0) 
00413         { 
00414         }
00415         if (_direction==1) 
00416         { 
00417                 GetVtkmprbasedata()->SetX(x);
00418         }
00419         if (_direction==2) 
00420         { 
00421                 GetVtkmprbasedata()->SetX(x);
00422         }
00423 }
00424 //-------------------------------------------------------------------
00425 void wxVtkMPR2DView::MoveY(double x, double y, double z)
00426 {
00427         if (_direction==0) 
00428         { 
00429                 GetVtkmprbasedata()->SetY(y);
00430         }
00431         if (_direction==1) 
00432         { 
00433         }
00434         if (_direction==2) 
00435         { 
00436                 GetVtkmprbasedata()->SetY(y);
00437         }
00438 }
00439 //-------------------------------------------------------------------
00440 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
00441 {
00442         if (_direction==0) 
00443         { 
00444                 GetVtkmprbasedata()->SetZ(z);
00445         }
00446         if (_direction==1) 
00447         { 
00448                 GetVtkmprbasedata()->SetZ(z);
00449         }
00450         if (_direction==2) 
00451         { 
00452         }
00453 }
00454 //-------------------------------------------------------------------
00455 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
00456 {
00457         double c1r=1,c1g=1,c1b=0;
00458         double c2r=1,c2g=0,c2b=0;
00459 
00460         if (_direction==0) 
00461         { 
00462                 if (IfMouseTouchY(x,y,z)==true)
00463                 {
00464                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00465                 } else {
00466                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00467                 }
00468                 if (IfMouseTouchZ(x,y,z)==true)
00469                 {
00470                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00471                 } else {
00472                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00473                 }
00474         }
00475 
00476         if (_direction==1) 
00477         { 
00478                 if (IfMouseTouchX(x,y,z)==true)
00479                 {
00480                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00481                 } else {
00482                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00483                 }
00484                 if (IfMouseTouchZ(x,y,z)==true)
00485                 {
00486                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00487                 } else {
00488                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00489                 }
00490         }
00491 
00492         if (_direction==2) 
00493         { 
00494                 if (IfMouseTouchX(x,y,z)==true)
00495                 {
00496                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00497                 } else {
00498                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00499                 }
00500                 if (IfMouseTouchY(x,y,z)==true)
00501                 {
00502                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
00503                 } else {
00504                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
00505                 }
00506         }
00507         Refresh();
00508 }
00509 
00510 
00511 //EED 5 juin 2009
00512 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual 
00513 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
00514 {
00515                 
00516         wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
00517 
00518         if ((_direction==0) && (keepNormalDirection==true) )
00519         {
00520                 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
00521         }
00522         
00523         if ((_direction==1) && (keepNormalDirection==true) )
00524         {
00525                 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
00526         }
00527         
00528         if ((_direction==2) && (keepNormalDirection==true) )
00529         {
00530                 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
00531         }
00532         
00533 }
00534 
00535 
00536 //-------------------------------------------------------------------
00537 //-------------------------------------------------------------------
00538 //-------------------------------------------------------------------
00539 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
00540 //      if (eventId==vtkCommand::StartInteractionEvent){
00541 //              _renWin->SetDesiredUpdateRate(10);
00542 //      }
00543 //      if (eventId==vtkCommand::InteractionEvent){
00544 //              _renWin->SetDesiredUpdateRate(0.001);
00545 //      }
00546 //      if (eventId==vtkCommand::EndInteractionEvent){
00547 //              vtkPlanes *planes = vtkPlanes::New();
00548 //              vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
00549 //              boxwidget->GetPlanes(planes);
00550 //              _volumeMapper->SetClippingPlanes(planes);
00551 //              planes -> Delete();
00552 //      }
00553 //}
00554 
00555 //-------------------------------------------------------------------
00556 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
00557 //      _renWin = renWin;
00558 //}
00559 //-------------------------------------------------------------------
00560 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
00561 //      _volumeMapper = volumeMapper;
00562 //}

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1