]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkBaseView.cxx
BUG histogram
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkBaseView.cxx
index a090ea23019315d69916de4cc57bf8774743dbc9..7bbda0afddaf0f87117dbe6ac11cff696a48df19 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "wxVtkBaseView.h"
 
+
 vtkStandardNewMacro(vtkInteractorStyleBaseView);
 vtkStandardNewMacro(vtkInteractorStyleBaseView2D);
 vtkStandardNewMacro(vtkInteractorStyleBaseView3D);
@@ -29,7 +30,7 @@ vtkImageViewer2_XYZ::vtkImageViewer2_XYZ()
 //-------------------------------------------------------------------
 vtkImageViewer2_XYZ::~vtkImageViewer2_XYZ()
 {
-       _vtkimageviewer2->Delete();
+       //_vtkimageviewer2->Delete();
 }
 //-------------------------------------------------------------------
 void vtkImageViewer2_XYZ::SetExtentDimension(int x1,int x2,
@@ -190,10 +191,15 @@ wxVtkBaseView::wxVtkBaseView(wxWindow *parent)
 wxVtkBaseView::~wxVtkBaseView()
 {
  //    _iren -> Delete();
+       _iren=NULL;
 }
 //-------------------------------------------------------------------
-wxVTKRenderWindowInteractor* wxVtkBaseView::GetWxVTKRenderWindowInteractor()
+wxVTKRenderWindowInteractor* wxVtkBaseView::GetWxVTKRenderWindowInteractor() throw (char*)
 {
+
+       if(_iren==NULL){
+               throw "wxVtkBaseView::GetWxVTKRenderWindowInteractor() _iren wxVTKRenderWindowInteractorPlus =NULL";
+       }
    return _iren;
 }
 //-------------------------------------------------------------------
@@ -208,7 +214,13 @@ void wxVtkBaseView::Refresh()  // virtual
        #if defined(WIN32)
                _iren->Refresh(false);
        #else
-               _iren->Render();
+       
+//EED 01Avril2009
+//             _iren->Render();        
+       vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
+       vri->vtkRenderWindowInteractor::Render();
+       
+       
                //_iren->Refresh();
        #endif
 
@@ -533,7 +545,7 @@ bool vtkInteractorScrollZ::OnRightButtonUp()
 bool vtkInteractorScrollZ::OnMouseMove () 
 {
        if (_stateFordware==true){
-           int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
+           //int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];  // JPRx
         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
                int delta = (_fordwareY - fy)/3;
                _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->SetActualSlice( _sliceZ + delta);
@@ -1015,16 +1027,16 @@ void  vtkInteractorStyleBaseView3D::OnMouseMove ()
 
 //             this->vtkInteractorStyleTrackballCamera::OnMouseMove();
 
-  int x = this->Interactor->GetEventPosition()[0];
-  int y = this->Interactor->GetEventPosition()[1];
+ // int x = this->Interactor->GetEventPosition()[0]; // JPRx
+ // int y = this->Interactor->GetEventPosition()[1]; // JPRx
 
 
-  vtkRenderWindowInteractor *rwi = this->Interactor;
// vtkRenderWindowInteractor *rwi = this->Interactor;
 
-  int lx =  rwi->GetLastEventPosition()[0];
-  int ly =  rwi->GetLastEventPosition()[1];
-  int dx = rwi->GetEventPosition()[0] ;
-  int dy = rwi->GetEventPosition()[1] ;
+ // int lx =  rwi->GetLastEventPosition()[0]; // JPRx
+ // int ly =  rwi->GetLastEventPosition()[1]; // JPRx
+ // int dx = rwi->GetEventPosition()[0] ; // JPRx
+ // int dy = rwi->GetEventPosition()[1] ; // JPRx
 
 
   switch (this->State) 
@@ -1200,7 +1212,7 @@ vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
        // Text Window Level
        vtkTextActor *textActor = vtkTextActor::New();
        textActor->SetDisplayPosition(px, py);
-       textActor->SetInput("--");
+       textActor->SetInput("0");
 
        // Set coordinates to match the old vtkScaledTextActor default value
        textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
@@ -1340,14 +1352,112 @@ void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
        
        char zTzxt[20];
        char resultText[50];
-       strcpy(resultText,"NG: ");
-       if (ok==true) {
-               unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
-//             itoa (*pOrg,zTzxt,10);
-               int tmp=*pOrg;
-               sprintf(zTzxt,"%d",tmp);
-
-       } else {
+       strcpy(resultText,"GL: ");
+       if (ok==true) 
+       {
+               if (imagedata->GetScalarType()==VTK_BIT)
+               {
+                       char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       if(*pOrg==0)
+                       {
+                               sprintf(zTzxt,"%d",0);
+                       }
+                       else
+                       {
+                               sprintf(zTzxt,"%d",1);
+                       }
+               }
+       
+               if (imagedata->GetScalarType()==VTK_CHAR)
+               {
+                       char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
+               {
+                       signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
+               {
+                       unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_SHORT)
+               {
+                       short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
+               {
+                       unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+       
+               if (imagedata->GetScalarType()==VTK_INT)
+               {
+                       int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       sprintf(zTzxt,"%d",*pOrg);
+               }
+
+               if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
+               {
+                       unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       int tmp=*pOrg;
+                       sprintf(zTzxt,"%d",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_LONG)
+               {
+                       long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       double tmp=*pOrg;
+                       sprintf(zTzxt,"%3.2f",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
+               {
+                       unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       double tmp=*pOrg;
+                       sprintf(zTzxt,"%3.2f",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_FLOAT)
+               {
+                       long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       double tmp=*pOrg;
+                       sprintf(zTzxt,"%3.2f",tmp);
+               }
+
+               if (imagedata->GetScalarType()==VTK_DOUBLE)
+               {
+                       double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
+       //              itoa (*pOrg,zTzxt,10);
+                       double tmp=*pOrg;
+                       sprintf(zTzxt,"%3.2f",tmp);
+               }
+       } 
+       else 
+       {
                strcpy(zTzxt,"---");
        }
        strcat(resultText,zTzxt);
@@ -1388,6 +1498,7 @@ bool vtkInfoTextImageInteractor::OnMouseMove()
        double xx=X,yy=Y,zz=z;
        _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->TransfromeCoordScreenToWorld(xx,yy,zz);
 
+       
        GetVtkInfoTextImage()->PutWindowLevel();
        GetVtkInfoTextImage()->PutColorLevel();
        GetVtkInfoTextImage()->PutPosition( (int)xx , (int)yy , (int)zz );
@@ -1416,17 +1527,19 @@ wxVtk2DBaseView::wxVtk2DBaseView(wxWindow *parent)
        _vtkIinfoTextImage      = NULL;
 }
 
+//EED 5mai2009
 //-------------------------------------------------------------------
 wxVtk2DBaseView::~wxVtk2DBaseView()
-{
-       if (_imageViewer2XYZ!=NULL) {
-               delete _imageViewer2XYZ; 
-       }
-
-       if (_imageViewer2XYZ!=NULL) {
+{      
+       if (_vtkIinfoTextImage!=NULL) 
+       {
                delete _vtkIinfoTextImage; 
        }
 
+       if (_imageViewer2XYZ!=NULL) 
+       {
+               delete _imageViewer2XYZ; 
+       }
 }
 
 //-------------------------------------------------------------------
@@ -1476,10 +1589,7 @@ void wxVtk2DBaseView::ResetView()
        _imageViewer2XYZ -> SetExtentDimension(x1,x2,y1,y2,z1,z2);
        _imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
 
-printf("EED wxVtk2DBaseView::ResetView podemos 01\n ");        
        _imageViewer2XYZ->GetVtkImageViewer2()->Render();
-printf("EED wxVtk2DBaseView::ResetView podemos 02\n ");        
-
        SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
        
 }
@@ -1542,13 +1652,22 @@ void wxVtk2DBaseView::Configure(bool okimage)
 
                        vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2();
                        vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera();
+
+//EED 17Avril2009      
+/*                     
                        camera->SetViewUp               ( spx*0                 , -spy*1                        , spz*0         );
                        camera->SetPosition             ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , -spz*10000    ); 
                        camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0         ); 
+*/ 
+                       camera->SetViewUp               ( spx*0                 , spy*1                 , spz*0         );
+                       camera->SetPosition             ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*10000     ); 
+                       camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0         ); 
+                       
+                       
                        camera->SetClippingRange( 0.01                  , 1000000 );
                        camera->ComputeViewPlaneNormal();
                        camera->SetParallelScale( spx*(x2-x1)/3.0 );
-
+                       
                        // text information over the graphic window
                        _vtkIinfoTextImage                              = new vtkInfoTextImage();
                        _vtkIinfoTextImageInteractor    = new vtkInfoTextImageInteractor();
@@ -1610,7 +1729,7 @@ void wxVtk2DBaseView::SetInteractorStyleImage(vtkInteractorStyleBaseView *intera
        iren->SetInteractorStyle(interactorstylebaseview);
        interactorstylebaseview->SetwxVtkBaseView(this);        
 
-       vtkMaracasImageViewer2Callback *cbk = vtkMaracasImageViewer2Callback::New();
+       vtkMaracasImageViewer2Callback * cbk = vtkMaracasImageViewer2Callback::New();
        cbk->IV = _imageViewer2XYZ->GetVtkImageViewer2();
        interactorstylebaseview->AddObserver( vtkCommand::WindowLevelEvent, cbk );
        interactorstylebaseview->AddObserver( vtkCommand::StartWindowLevelEvent, cbk );
@@ -1687,7 +1806,7 @@ void wxVtk3DBaseView::Configure()
        if (_configure==false)
        {
                _configure=true;
-               wxVtkBaseView::Configure();
+               //wxVtkBaseView::Configure();
                _aRenderer      = vtkRenderer::New();
                _renWin         = vtkRenderWindow::New();
                _renWin->AddRenderer(_aRenderer);
@@ -1721,10 +1840,18 @@ void wxVtk3DBaseView::Configure()
                // (ResetCamera() method) this vector is used to position the camera
                // to look at the data in this direction.
                _aCamera = vtkCamera::New();
+
+//EED 17Avril2009      
+/*
                _aCamera->SetViewUp (0, 0, -1);
                _aCamera->SetPosition (0, 1, 0);
+ */
+               _aCamera->SetViewUp (0, 1, 0);
+               _aCamera->SetPosition (0, 0, 1);
+               
                _aCamera->SetFocalPoint (0, 0, 0);
                _aCamera->ComputeViewPlaneNormal();
+
        }
 }
 //-------------------------------------------------------------------