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

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1