1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "vtkInteractorStyle3DView.h"
28 #include "vtkPointPicker.h"
29 #include "UtilVtk3DGeometriSelection.h"
31 vtkInteractorStyle3DView::vtkInteractorStyle3DView()
34 //---------------------------------------------------------------------------
35 vtkInteractorStyle3DView::~vtkInteractorStyle3DView()
38 //---------------------------------------------------------------------------
39 bool vtkInteractorStyle3DView::OnLeftDClick()
41 SelectMarchibCubePoint();
44 //---------------------------------------------------------------------------
45 bool vtkInteractorStyle3DView::SelectMarchibCubePoint()
48 gtm::TVector< double > pO( 3 ), pF( 3 ), pp( 3 ), cp( 3 );
49 gtm::TVector< double > xc( 3 );
50 gtm::TVector< double > x1( 3 ), n1( 3 );
51 gtm::TVector< double > x2( 3 ), n2( 3 );
53 double pickPoint[ 3 ], cameraPos[ 3 ];
55 vtkPointPicker* picker = vtkPointPicker::New( );
56 eventrwi[0]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
57 eventrwi[1]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
58 vtkRenderer *pRenderer = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetRenderer();
59 picker->Pick( eventrwi[0], eventrwi[1], 0.0, pRenderer );
60 pRenderer->GetActiveCamera( )->GetPosition( cameraPos );
61 picker->GetPickPosition( pickPoint );
64 pp( 0 ) = pickPoint[ 0 ]; pp( 1 ) = pickPoint[ 1 ]; pp( 2 ) = pickPoint[ 2 ];
65 cp( 0 ) = cameraPos[ 0 ]; cp( 1 ) = cameraPos[ 1 ]; cp( 2 ) = cameraPos[ 2 ];
68 //EED 27 sep 2006 (1/2)
69 // wxVtkMPR3DView *wxvtkmpr3Dview = (wxVtkMPR3DView *)_vtkInteractorStyleBaseView->GetWxVtk3DBaseView();
71 // wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetSpacing(spc);
74 vtkImageData *imageData = GetWxVtkMPR3DView()->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
77 imageData->GetDimensions(dim);
78 imageData->GetSpacing(spc);
81 vtkMarchingCubes *mcubes = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetMCubes(0);
84 UtilVtk3DGeometriSelection utilVtk3DGeometriSelection;
85 utilVtk3DGeometriSelection.SetDimentions(dim[0],dim[1],dim[2]);
87 utilVtk3DGeometriSelection.SetMarchingCube(mcubes);
90 fac = GTM_MAX( dim[0], dim[2] );
93 if( utilVtk3DGeometriSelection.FindCubePointsFromPoints(
94 pO.GetAnsiRef( ), pF.GetAnsiRef( ),
95 pp.GetAnsiRef( ), cp.GetAnsiRef( ) ) )
98 if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
99 x1.GetAnsiRef( ), n1.GetAnsiRef( ),
100 pO.GetAnsiRef( ), pF.GetAnsiRef( ) ) )
102 if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
103 x2.GetAnsiRef( ), n2.GetAnsiRef( ),
104 ( x1 - n1 ).GetAnsiRef( ), ( x1 - ( n1 * fac ) ).GetAnsiRef( ) ) )
106 xc = ( x2 + x1 ) * 0.5;
107 //EED 27 sep 2006 (2/2)
108 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xc(0)/spc[0]);
109 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xc(1)/spc[1]);
110 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xc(2)/spc[2]);
111 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
112 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
113 #if wxMAJOR_VERSION <= 2
114 this->_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
116 this->_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
127 //-------------------------------------------------------------------
128 void vtkInteractorStyle3DView::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
130 _wxvtkmpr3Dview = wxvtkmpr3Dview;
132 //-------------------------------------------------------------------
133 wxVtkMPR3DView *vtkInteractorStyle3DView::GetWxVtkMPR3DView()
135 return _wxvtkmpr3Dview;
137 //-------------------------------------------------------------------
138 wxVtkClipping3DView *vtkInteractorStyle3DView::GetWxVtkClipping3DView()
140 return _wxvtkclipping3Dview;
142 //-------------------------------------------------------------------
143 void vtkInteractorStyle3DView::SetWxVtkClipping3DView( wxVtkClipping3DView *wxvtkclipping3Dview)
145 _wxvtkclipping3Dview = wxvtkclipping3Dview;