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

Generated on Fri Jun 12 00:08:34 2009 for creaMaracasVisu by  doxygen 1.5.7.1