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

Generated on Wed Jul 29 16:35:31 2009 for creaMaracasVisu_lib by  doxygen 1.5.3