]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
2339 creaMaracasVisu Feature New Normal ColorLayer in perpendicular planes
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
index 0a2ccf959eab243e9f9b3b602fe1fca641fa28d9..f8c66939b65e5f5ee5423a0d4747430bc1616f68 100644 (file)
@@ -73,6 +73,8 @@ bool ColorLayerImageBasevtkInteractor::OnMouseMove()   // vitual
 
 //             _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
 
+               _layerImageBase->SetX( (int)X );
+               _layerImageBase->SetY( (int)Y );
                _layerImageBase->SetZ( (int)Z );
                _layerImageBase->onThreshold();
 //             _layerImageBase->Refresh();
@@ -114,6 +116,8 @@ bool  ColorLayerImageBasevtkInteractor::OnRightButtonUp()  // virtual
 LayerImageBase::LayerImageBase()
 {
        _actorPresent                   =       false;
+       _X                              =       0;
+       _Y                              =       0;
        _Z                              =       0;
        _thresholdTable                 =       NULL;
        _thresholdMapper                =       NULL;
@@ -129,18 +133,42 @@ LayerImageBase::LayerImageBase()
   {
   }
 
+//----------------------------------------------------------------------------
+void LayerImageBase::SetX(int x)
+{
+       _X = x;
+}
+
+//----------------------------------------------------------------------------
+void LayerImageBase::SetY(int y)
+{
+       _Y = y;
+}
+
 //----------------------------------------------------------------------------
 void LayerImageBase::SetZ(int z)
 {
        _Z = z;
 }
 
+//----------------------------------------------------------------------------
+int LayerImageBase::GetX()  // virtual
+{
+       return _X;
+}
+
+//----------------------------------------------------------------------------
+int LayerImageBase::GetY()  // virtual
+{
+       return _Y;
+}
 //----------------------------------------------------------------------------
 int LayerImageBase::GetZ()  // virtual
 {
        return _Z;
 }
 
+
 //----------------------------------------------------------------------------
 vtkImageData* LayerImageBase::GetImage()
 {
@@ -165,12 +193,12 @@ void LayerImageBase::SetImage(vtkImageData* image)
 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
 {
        printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
-
-       _baseView = baseview;
-
-    vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
-    isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
-       
+       if (_baseView==NULL)
+       {
+         _baseView = baseview;
+         vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
+         isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
+       } // if _baseView
        printf("EED LayerImageBase::SetwxVtkBaseView end \n");
 }
 
@@ -198,22 +226,42 @@ vtkLookupTable* LayerImageBase::GetThresholdTable()
 }
 
 //----------------------------------------------------------------------------
-int LayerImageBase::CleanZ(int z)
+void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
 {
        int ext[6];
        _image->GetWholeExtent(ext);
 
+       if (x<0)
+       {
+               x=0;
+       }
+
+       if (y<0)
+       {
+               y=0;
+       }
+
        if (z<0)
        {
                z=0;
        }
 
+       if ( x > (ext[1]-ext[0]) )
+       {
+               z=ext[1]-ext[0];
+       }
+
+       if ( y > (ext[3]-ext[2]) )
+       {
+               z=ext[3]-ext[2];
+       }
+
        if ( z > (ext[5]-ext[4]) )
        {
                z=ext[5]-ext[4];
        }
 
-       return z;
+
 }
 
 //----------------------------------------------------------------------------
@@ -226,12 +274,30 @@ void LayerImageBase::onThreshold()
        {
                double spc[3];
                GetImage()-> GetSpacing(spc);
-               double  z = CleanZ( GetZ() );
-                       z = z*spc[2];
+               double x=GetX();
+               double y=GetY();
+               double z=GetZ();
+               CleanXYZ(x,y,z);
+
+               x = x*spc[0];
+               y = y*spc[1];
+               z = z*spc[2];
+               
 
        printf("EED LayerImageBase::onThreshold z = %d   spcZ%f\n" , z, spc[2]);
                
 
+               vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
+               int directionViewer=0;
+               if (camera->GetParallelProjection()==1)
+               {
+                       wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
+                       directionViewer =  wxvtk2dbasevie->GetDirection();
+               } // ParallelProjection
+
+printf("EED LayerImageBase::onThreshold projection = %d\n" , camera->GetParallelProjection() );
+printf("EED LayerImageBase::onThreshold direction = %d\n" , directionViewer );
+
 
                if (!GetActorPresent())
                {
@@ -251,7 +317,20 @@ void LayerImageBase::onThreshold()
                                _thresholdActor = vtkImageActor::New( );
                                _thresholdActor->SetOpacity( 0.6 );
                                _thresholdActor->InterpolateOn(  );
-                               _thresholdActor->SetPosition( 0,0, -900-1 );
+                               if (directionViewer==0)
+                               {
+                                       _thresholdActor->SetPosition( 900-1,0,0 );
+                                       _thresholdActor->RotateY( -90 );
+                               }
+                               if (directionViewer==1)
+                               {
+                                       _thresholdActor->SetPosition( 0,-900-1, 0 );
+                                       _thresholdActor->RotateX( 90 );
+                               }
+                               if (directionViewer==2)
+                               {
+                                       _thresholdActor->SetPosition( 0,0, -900-1 );
+                               }
                        } // _thresholdActor
                        _baseView->GetRenderer()->AddActor( _thresholdActor );
                        _actorPresent = true;
@@ -260,11 +339,29 @@ void LayerImageBase::onThreshold()
                ConfigLookupTable();  // virtual method
                _imageReslicer->SetInput( GetImage() );
                _imageReslicer->SetInformationInput( GetImage() );
-               _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
+
+               if (directionViewer==0)
+               {
+                       _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0,  -1,0,0 );
+                       _imageReslicer->SetResliceAxesOrigin(x,0,0);
+               }
+
+               if (directionViewer==1)
+               {
+                       _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1,  0,-1,0 );
+                       _imageReslicer->SetResliceAxesOrigin(0,y,0);
+               }
+
+               if (directionViewer==2)
+               {
+                       _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
+                       _imageReslicer->SetResliceAxesOrigin(0,0,z);
+               }
+
+
                _imageReslicer->SetOutputDimensionality(2);
 //             _imageReslicer->SetInterpolationModeToLinear();
                _imageReslicer->SetInterpolationModeToNearestNeighbor();
-               _imageReslicer->SetResliceAxesOrigin(0,0,z);
 
                vtkImageData *img = _imageReslicer->GetOutput();
 //             img->Update();