X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FwxMPRWidget.cxx;h=e1901a1c0dd4a619b2f33a78ce78646cb2b66275;hb=47d49bceea4f93ff4f57c40596960d042171abb4;hp=13a93481dc55c866945757aca37fef6aa73b0d69;hpb=bd3d13602a749b74d531c24bdc36a9cc1e47d189;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx index 13a9348..e1901a1 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx @@ -1,10 +1,35 @@ +/*# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ */ + /*========================================================================= Program: wxMaracas Module: $RCSfile: wxMPRWidget.cxx,v $ Language: C++ - Date: $Date: 2009/03/30 15:31:15 $ - Version: $Revision: 1.6 $ + Date: $Date: 2012/11/15 14:14:35 $ + Version: $Revision: 1.17 $ Copyright: (c) 2002, 2003 License: @@ -13,5351 +38,71 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. -=========================================================================*/ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -#include "vtkClosePolyData.h" -#include -#include -#include - -// EED 25 Janvier 2007 - TestLoic -#include -#include -#include -#include - - - -#include "wxMPRWidget.h" -#include "wxVTKRenderWindowInteractor.h" -#include "UtilVtk3DGeometriSelection.h" -#include "../kernel/marDicomBase.h" - - -#include -#include -#include - -#include "matrix.h" -#include - - -#include "pPlotter/HistogramDialog.h" - -//------------------------------------------------------------------- -//------------------------------------------------------------------- -//------------------------------------------------------------------- - -idAlBeRa::idAlBeRa(int id, double radio,int deltavoxel) -{ - _id = id; - _radio = radio; - _deltavoxel = deltavoxel; -} - - -//------------------------------------------------------------------- -//------------------------------------------------------------------- -//------------------------------------------------------------------- - -vtkInteractorStyleSphere::vtkInteractorStyleSphere() -{ - _stateRadio = false; - _stateRotate = false; -} - -//--------------------------------------------------------------------------- - -vtkInteractorStyleSphere::~vtkInteractorStyleSphere() -{ -} - - -//--------------------------------------------------------------------------- - -bool vtkInteractorStyleSphere::OnRightButtonDown() -{ - if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) && (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) - { - _stateRadio = true; - //_fordwareX = this->Interactor->GetEventPosition()[0]; - _fordwareY = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1]; - - wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()); - - _radio = wxsphereview->GetRadio(); - } - - return true; -} - -//--------------------------------------------------------------------------- - -bool vtkInteractorStyleSphere::OnRightButtonUp() -{ - if (_stateRadio==true) - { - wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()); - wxsphereview->SetDeltaVoxel(1); - double radio=wxsphereview->GetRadio(); - wxsphereview->GetIdOfImage(radio+0.1); - wxsphereview->GetIdOfImage(radio+0.2); - wxsphereview->GetIdOfImage(radio-0.1); - wxsphereview->GetIdOfImage(radio-0.2); - - wxsphereview->RefreshView(); - _stateRadio = false; - } - - return true; -} -//--------------------------------------------------------------------------- - -bool vtkInteractorStyleSphere::OnLeftButtonDown() -{ - _stateRotate = true; - _fordwareX = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0]; - _fordwareY = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1]; - return true; -} - - -//--------------------------------------------------------------------------- - -bool vtkInteractorStyleSphere::OnLeftButtonUp() -{ - wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()); - if (_stateRotate==true){ - int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0]; - int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1]; - - if ((_fordwareX==fx)&&(_fordwareY==fy)){ - double x=fx,y=fy,z=1; - _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z); - wxsphereview->SetXYZtoParent(x,y); - wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121); - wxsphereview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent); - } else { - wxsphereview->RotationEnd(); - } - wxsphereview->RefreshView(); - _stateRotate = false; - } - - return true; -} - - -//--------------------------------------------------------------------------- - -bool vtkInteractorStyleSphere::OnMouseMove () -{ - wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()); - if (_stateRotate==true) - { - bool ok_v, ok_ang; - ok_v=false; - ok_ang=false; - if (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==1) - { - ok_v = true; - } - if (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==1) - { - ok_ang = true; - } - int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0]; - int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1]; - wxsphereview->RotationStart( fx - _fordwareX , -(fy - _fordwareY) , ok_v, ok_ang); - wxsphereview->RefreshView(); - } - if (_stateRadio==true) - { - //int fx = this->Interactor->GetEventPosition()[0]; - int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1]; - double dif=(fy-_fordwareY) / 10.0; - wxsphereview->SetRadio( _radio + dif ); - wxsphereview->SetDeltaVoxel(3); - wxsphereview->RefreshView(); - } - - return true; -} - - - -//------------------------------------------------------------------- -//------------------------------------------------------------------- -//------------------------------------------------------------------- - -wxSphereView::wxSphereView( wxWindow *parent, vtkMPRBaseData *vtkmprbasedata, vtkImageData *imageData ) -: wxVtk2DBaseView(parent) -{ - _delta = 1; - _vtkmprbasedata = vtkmprbasedata; - _imageDataOriginal = imageData; - - _imageSphere = vtkImageData::New(); - _imageSphere->SetDimensions (150,150,500); - _imageSphere->SetScalarTypeToUnsignedShort(); - _imageSphere->AllocateScalars(); - _imageSphere->Update(); - - - vtkBaseData *vtkbasedata = new vtkBaseData(); - vtkbasedata->SetMarImageData( new marImageData(_imageSphere) ); - this->SetVtkBaseData(vtkbasedata); - - _transform = vtkTransform::New(); - _transform1 = vtkTransform::New(); - _transform2 = vtkTransform::New(); - _transform ->Identity(); - _transform1->Identity(); - _transform2->Identity(); - - _radio=25; -} - -//------------------------------------------------------------------- - -wxSphereView::~wxSphereView() -{ - _transform -> Delete(); - _transform1 -> Delete(); - _transform2 -> Delete(); - ResetlstId(); -} - -//---------------------------------------------------------------------------- - -double wxSphereView::GetRadio() -{ - return _radio; -} - -//---------------------------------------------------------------------------- - -void wxSphereView::SetRadio(double radio) -{ - if (radio<0) - { - radio=0; - } - _radio=radio; -} - -//---------------------------------------------------------------------------- - -void wxSphereView::Configure() -{ - wxVtk2DBaseView::Configure(); - - _vtkinteractorstylesphere = new vtkInteractorStyleSphere(); - GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _vtkinteractorstylesphere ); - double points[4][3]; - -// EED purify 12/sep/2006 - int i,j; - for (i=0;i<4;i++) - { - for (j=0;j<3;j++) - { - points[i][j]=0; - } - } - - InitSphere(points); - DefineImageSphere(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::RefreshPoint() -{ - double x = _vtkmprbasedata->GetX() - _centerX; - double y = _vtkmprbasedata->GetY() - _centerY; - double z = _vtkmprbasedata->GetZ() - _centerZ; - double alpha= atan2(x,z); - double beta = atan2( y , sqrt(z*z+x*x) ); - - alpha = alpha*180/3.1416; - beta = beta*180/3.1416; - - _transform1->Identity(); - _transform1->RotateY(alpha); - _transform1->RotateX(-beta); - - _radio= sqrt(x*x + y*y +z*z); - - RefreshView(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::RefreshView() -{ - DefineImageSphere(); - wxVtk2DBaseView::Refresh(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::RotationEnd() -{ - _transform1->RotateWXYZ(_ang,_vxb,_vyb,0); - _transform2->Identity(); - SetDeltaVoxel(1); - ResetlstId(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::RotationStart(double vx, double vy, bool ok_v, bool ok_ang) -{ - if (ok_ang==false) - { - _ang = -sqrt( vx*vx + vy*vy ) / 1.0; - } - - if (ok_v==false){ - _vxb=-vy; - _vyb=vx; - } - - _transform2->Identity(); - _transform2->RotateWXYZ(_ang,_vxb,_vyb,0); - SetDeltaVoxel(3); - ResetlstId(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::GetPointSphere(double p[3],double r1,double angA,double angB) -{ - double in[3],out[3]; - in[0]=0; - in[1]=r1; - in[2]=0; - vtkTransform *transform = vtkTransform::New(); - transform->Identity(); - transform->RotateX(angB); - transform->RotateZ(angA); - transform->TransformPoint(in,out); - p[0]=out[0]; - p[1]=out[1]; - p[2]=out[2]; - transform->Delete(); -} - -//---------------------------------------------------------------------------- - -void wxSphereView::RotatePointOverTheSphere( double pp[3], double p[3],double cc[3]) -{ - - double out[3]; - _transform->TransformPoint(p,out); - pp[0] = out[0] + cc[0]; - pp[1] = out[1] + cc[1]; - pp[2] = out[2] + cc[2]; - -} - -//---------------------------------------------------------------------------- - -void wxSphereView::TransferePoints(double pp1[3],double pp2[3],double AngX,double AngY,vtkImageData *image) -{ - double t; - double difX = pp2[0]-pp1[0]; - double difY = pp2[1]-pp1[1]; - double difZ = pp2[2]-pp1[2]; - - double max = 200; - - int dimOrg[3]; - int dimRes[3]; - int z; - _imageDataOriginal->GetDimensions(dimOrg); - image->GetDimensions(dimRes); - - int i; - double x1=pp1[0]; - double y1=pp1[1]; - double z1=pp1[2]; - int xx=-1,yy=-1,zz=-1; - - for (i=0;i=0) && (xx=0) && (yy=0) && (zz=0) && (AngX=0) && (AngY=0) && (zGetScalarPointer (xx,yy,zz); - unsigned short *pRes=(unsigned short*)image->GetScalarPointer( (int)AngX , (int)AngY , z ); - *pRes=*pOrg; - } - } -} - -//---------------------------------------------------------------------------- - -void wxSphereView::ResetlstId() -{ - int i,size=_lstId.size(); - for (i=size-1;i>=0;i--) - { - delete _lstId[i]; - } - _lstId.clear(); -} - -//---------------------------------------------------------------------------- - -int wxSphereView::GetIdOfImage(double radio) -{ - int id=0; - int dim[3]; - _imageSphere->GetDimensions(dim); - int sizeMaxList = dim[2]; - // Search in list >> alpha beta radio - int i,size=_lstId.size(); - for (i=0; i_radio==radio) && (_lstId[i]->_deltavoxel==_delta)) - { - return _lstId[i]->_id; - } - } - if (size>sizeMaxList) - { - delete _lstId[size-1]; - _lstId.pop_back(); - } - if (size!=0){ - id=_lstId[0]->_id+1; - id = id % sizeMaxList; - } else { - id = 0; - } - - FiltreImage(id,radio); - _lstId.insert(_lstId.begin(),1,new idAlBeRa(id,radio,_delta) ); - - return id; -} - -//---------------------------------------------------------------------------- - -void wxSphereView::DefineImageSphere() -{ - int id; - id=GetIdOfImage( _radio ); - GetVtkBaseData()->SetZ( id ); -} - - -//---------------------------------------------------------------------------- -void wxSphereView::SetDeltaVoxel(int delta) -{ - _delta=delta; -} - -//---------------------------------------------------------------------------- -void wxSphereView::SetVoxel(double i, double j, int delta,double id, unsigned short gris) -{ - int ii,jj,delta2; - unsigned short *pRes; - int dimRes[3]; - _imageSphere->GetDimensions(dimRes); - - delta2=delta-1; - for ( ii=(int)(i-delta2) ; ii<=(int)(i+delta2) ; ii++ ) - { - for ( jj=(int)(j-delta2) ; jj<=(int)(j+delta2) ; jj++ ) - { - if ( (ii>=0)&&(ii=0)&&(jjGetScalarPointer( ii , jj , (int)id ); - *pRes=gris; - } - } - } - -} - -//---------------------------------------------------------------------------- - -void wxSphereView::SetXYZtoParent(double i, double j) -{ - - double factor = 0.75; - double radio2 = _radio*_radio; - double pxx,pyy,d2x,d2y; - double cc[3],p[3],pp[3]; - cc[0]=_centerX; - cc[1]=_centerY; - cc[2]=_centerZ; - double aa; - int dimRes[3],dimOrig[3]; - _imageSphere->GetDimensions(dimRes); - d2x=dimRes[0]/2; - d2y=dimRes[1]/2; - _imageDataOriginal->GetDimensions(dimOrig); - - p[0] = (i - d2x)*factor; - pxx=p[0]*p[0]; - p[1] = (j - d2y)*factor; - pyy=p[1]*p[1]; - aa = pxx + pyy; - if (radio2>aa){ - aa=radio2-aa; - p[2] = sqrt(aa); - RotatePointOverTheSphere( pp, p,cc); - if ( (pp[0]>=0) && (pp[0]=0) && (pp[1]=0) && (pp[2]SetX(pp[0]); - _vtkmprbasedata->SetY(pp[1]); - _vtkmprbasedata->SetZ(pp[2]); - } - } - } -} - - -//---------------------------------------------------------------------------- - -void wxSphereView::FiltreImageB(int id, double radio, bool ok,int deltaTMP) -{ - double factor = 0.75; - double radioB = radio/3; - double radio2 = radio*radio; - double pxx,pyy,d2x,d2y; - double cc[3],p[3],pp[3]; - cc[0]=_centerX; - cc[1]=_centerY; - cc[2]=_centerZ; - double aa; - unsigned short *pOrig; - int dimRes[3],dimOrig[3]; - double i,j; - _imageSphere->GetDimensions(dimRes); - _imageSphere->SetExtent(0,dimRes[0]-1,0,dimRes[1]-1,0,dimRes[2]-1); - d2x=dimRes[0]/2; - d2y=dimRes[1]/2; -// double deltaTMP=_delta; - _imageDataOriginal->GetDimensions(dimOrig); - - int start,end; - int limitA,limitB; - limitA = (int) ( (-radioB/factor)+d2x ); - limitB = (int) ( (radioB/factor)+d2x ); - if (ok==true){ - start = limitA; - end = limitB; - } else { - start=0; - end=dimRes[0]; - } - - for ( i=start ; ilimitA) && (ilimitA) && (jaa){ - aa=radio2-aa; - p[2] = sqrt(aa); - RotatePointOverTheSphere( pp, p,cc); - if ( (pp[0]>=0) && (pp[0]=0) && (pp[1]=0) && (pp[2]GetScalarPointer( (int)(pp[0]) , (int)(pp[1]) , (int)(pp[2]) ); - SetVoxel(i,j,deltaTMP,id,*pOrig); - } else { - SetVoxel(i,j,deltaTMP,id,2000); - } - } else { - SetVoxel(i,j,deltaTMP,id,0); - } - } - } - } - - _imageSphere->Modified(); - _imageSphere->Update(); -} - - - - -//---------------------------------------------------------------------------- - -void wxSphereView::FiltreImage(int id, double radio) -{ - - _transform -> Identity(); - _transform -> Concatenate(_transform1); - _transform -> Concatenate(_transform2); - - FiltreImageB(id,radio,false, _delta); - FiltreImageB(id,radio,true, 1); -} - - -//---------------------------------------------------------------------------- - -/* -void wxSphereView::FiltreImage(int id, double radio) -{ - double radio2 = radio*radio; - double radio2TMP= (radio/2)*(radio/2); - double pxx,pyy,d2x,d2y; - double cc[3],p[3],pp[3]; - cc[0]=_centerX; - cc[1]=_centerY; - cc[2]=_centerZ; - double aa; - unsigned short *pOrig; - int dimRes[3],dimOrig[3]; - double i,j; - _imageSphere->GetDimensions(dimRes); - _imageSphere->SetExtent(0,dimRes[0]-1,0,dimRes[1]-1,0,dimRes[2]-1); - d2x=dimRes[0]/2; - d2y=dimRes[1]/2; - double deltaTMP=_delta; - _imageDataOriginal->GetDimensions(dimOrig); - - for ( i=0 ; iradio2TMP) - { - if (radio2>aa){ - aa=radio2-aa; - p[2] = sqrt(aa); - RotatePointOverTheSphere( pp, p,cc); - if ( (pp[0]>=0) && (pp[0]=0) && (pp[1]=0) && (pp[2]GetScalarPointer( pp[0] , pp[1] , pp[2] ); - SetVoxel(i,j,deltaTMP,id,*pOrig); - } else { - SetVoxel(i,j,deltaTMP,id,2000); - } - } else { - SetVoxel(i,j,deltaTMP,id,0); - } - } - } - } - - - deltaTMP=1; - for ( i=0 ; iaa){ - aa=radio2-aa; - p[2] = sqrt(aa); - RotatePointOverTheSphere( pp, p,cc); - if ( (pp[0]>=0) && (pp[0]=0) && (pp[1]=0) && (pp[2]GetScalarPointer( pp[0] , pp[1] , pp[2] ); - SetVoxel(i,j,deltaTMP,id,*pOrig); - } else { - SetVoxel(i,j,deltaTMP,id,2000); - } - } else { - SetVoxel(i,j,deltaTMP,id,0); - } - } - } - } - - _imageSphere->Modified(); - _imageSphere->Update(); -} -*/ -/* -void wxSphereView::FiltreImage(vtkImageData *imageSphere) -{ - int dim[3],i,j,k; - imageSphere->GetDimensions(dim); - for (i=0;iGetScalarPointer (i,j,k); - *pRes=0; - } - } - } - - double deltaA=90; - double cc[3],p1[3],p2[3],pp1[3],pp2[3]; - cc[0]=_centerX; - cc[1]=_centerY; - cc[2]=_centerZ; - double r1 = _sl_radio->GetValue() - _sl_thickness->GetValue()/2; - double r2 = _sl_radio->GetValue() + _sl_thickness->GetValue()/2; - if (r1<10) - { - r1=10; - } - double alpha= _sl_alpha->GetValue(); - double beta = _sl_beta->GetValue(); - - double angA,angB; - for (angA=-deltaA;angA 0) - { - _centerX = (int)(cc[0]); - _centerY = (int)(cc[1]); - _centerZ = (int)(cc[2]); - } else { - int dim[3]; - _imageDataOriginal->GetDimensions(dim); - _centerX = (int)(dim[0]/2); - _centerY = (int)(dim[1]/2); - _centerZ = (int)(dim[2]/2); - } -} - -//---------------------------------------------------------------------------- - -// Calculate center and radius of sphere given four points -// http://home.att.net/~srschmitt/script_sphere_solver.html -// source code HTML