X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FThresholdImageView%2FLayerImageBase.cxx;h=a90e7348b627ad847a9c3895c11f0db14977ff9e;hb=9d8709b5e9d72b9f0034224bb4c00281264fb28d;hp=ee8a7fc05c54faee672f02d9ba9ce1a757f41369;hpb=965c602117e9de99019d49bd78ca1d707a1a6bd2;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx index ee8a7fc..a90e734 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx @@ -1,3 +1,27 @@ +/*# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ /** * \file @@ -6,15 +30,125 @@ #include "LayerImageBase.h" +#include "wxVtk2DBaseView.h" +#include "wxVTKRenderWindowInteractor.h" + + +//--------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------- + +ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase) +{ + _state=false; + _stateKey=false; + _layerImageBase=layerImageBase; + +} + +//--------------------------------------------------------------------------------------------- +ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor() +{ +} + +//--------------------------------------------------------------------------------------------- +bool ColorLayerImageBasevtkInteractor::OnChar() +{ + return true; +} + + +//--------------------------------------------------------------------------------------------- +bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual +{ + printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove start \n"); + + vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor(); + + // For example in ManualPaint Action + // This is not working, because the order of insertion events mecanism (_vtkInteractorStyleBaseView) + // Layer first Paint after. + // the only way to make it works is to take the axes an paint. this force a first SetParent_refresh_waiting() +// if ( this->_vtkInteractorStyleBaseView->GetParent_refresh_waiting() == true ) + + if ( interactor->GetControlKey()==1 ) // EED This if for ManaulPaint Interaction compatibility + { + printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove need Refresh \n" ); + _layerImageBase->onThreshold(); + _layerImageBase->GetvtkImageReslice()->Modified(); + } + else { + printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove NOT need Refresh \n" ); + } + + + if (_state==true) + { + wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView(); + wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor(); + int px, py; + wxVTKiren->GetEventPosition(px, py); + +// int typeView = 1; + double X = (double) px; + double Y = (double) py; + double Z = wxvtk2Dbaseview->GetActualSlice(); +// wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView); + wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true); + +// _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z); + + _layerImageBase->SetX( (int)X ); + _layerImageBase->SetY( (int)Y ); + _layerImageBase->SetZ( (int)Z ); + _layerImageBase->onThreshold(); +// _layerImageBase->Refresh(); + + this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting(); + + if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true) + { + _layerImageBase->GetvtkImageReslice()->Modified(); + } + printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n"); + } + return true; +} + +//--------------------------------------------------------------------------------------------- +bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual +{ + printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n"); + _state=true; + return true; +} + +//--------------------------------------------------------------------------------------------- +bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual +{ + printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n"); + _state=false; + return true; +} + + +//--------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------- + + + LayerImageBase::LayerImageBase() { _actorPresent = false; - _Z = 0; + _X = 0; + _Y = 0; + _Z = 0; _thresholdTable = NULL; _thresholdMapper = NULL; _thresholdActor = NULL; - _image = NULL; - _baseView = NULL; + _image = NULL; + _baseView = NULL; _imageReslicer = vtkImageReslice::New(); } @@ -24,18 +158,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() { @@ -59,7 +217,14 @@ void LayerImageBase::SetImage(vtkImageData* image) //---------------------------------------------------------------------------- void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview) { - _baseView = baseview; + printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview); + if (_baseView==NULL) + { + _baseView = baseview; + vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView()); + isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) ); + } // if _baseView + printf("EED LayerImageBase::SetwxVtkBaseView end \n"); } //---------------------------------------------------------------------------- @@ -71,6 +236,7 @@ wxVtkBaseView *LayerImageBase::GetwxVtkBaseView() //---------------------------------------------------------------------------- void LayerImageBase::Refresh() { + printf("EED LayerImageBase::Refresh\n"); if (_baseView!=NULL) { _baseView->Refresh(); @@ -85,31 +251,78 @@ 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; + } //---------------------------------------------------------------------------- void LayerImageBase::onThreshold() { + printf("EED LayerImageBase::onThreshold start \n"); + if ((_image!=NULL) && (_baseView!=NULL)) { - int z=CleanZ( GetZ() ); + double spc[3]; + GetImage()-> GetSpacing(spc); + 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()) { @@ -129,7 +342,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; @@ -138,10 +364,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->SetResliceAxesOrigin(0,0,z); +// _imageReslicer->SetInterpolationModeToLinear(); + _imageReslicer->SetInterpolationModeToNearestNeighbor(); vtkImageData *img = _imageReslicer->GetOutput(); // img->Update(); @@ -150,7 +395,12 @@ void LayerImageBase::onThreshold() _thresholdMapper->SetInput( img ); _thresholdMapper->SetLookupTable( _thresholdTable ); _thresholdActor->SetInput( _thresholdMapper->GetOutput() ); + + printf("EED LayerImageBase::onThreshold working \n"); + + } // _image + printf("EED LayerImageBase::onThreshold end \n"); } @@ -200,6 +450,16 @@ void LayerImageBase::onThresholdRemove() } } +//---------------------------------------------------------------------------- +vtkLookupTable *LayerImageBase::GetvtkLookupTable() +{ + return _thresholdTable; +} + +vtkImageReslice *LayerImageBase::GetvtkImageReslice() +{ + return _imageReslicer; +}