]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyle3DView.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkInteractorStyle3DView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "vtkInteractorStyle3DView.h"
27 #include "matrix.h"
28 #include "vtkPointPicker.h"
29 #include "UtilVtk3DGeometriSelection.h"
30
31 vtkInteractorStyle3DView::vtkInteractorStyle3DView()
32 {
33 }
34 //---------------------------------------------------------------------------
35 vtkInteractorStyle3DView::~vtkInteractorStyle3DView()
36 {
37 }
38 //---------------------------------------------------------------------------
39 bool vtkInteractorStyle3DView::OnLeftDClick()
40 {
41         SelectMarchibCubePoint();
42         return true;
43 }
44 //---------------------------------------------------------------------------
45 bool vtkInteractorStyle3DView::SelectMarchibCubePoint()
46 {
47         bool ok=false;
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 );
52
53         double pickPoint[ 3 ], cameraPos[ 3 ];
54         int eventrwi[2];
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 );
62         picker->Delete( );
63
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 ];
66
67
68 //EED 27 sep 2006  (1/2)
69 //      wxVtkMPR3DView *wxvtkmpr3Dview = (wxVtkMPR3DView *)_vtkInteractorStyleBaseView->GetWxVtk3DBaseView();
70 //      double spc[3];
71 //      wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetSpacing(spc);
72
73
74         vtkImageData *imageData = GetWxVtkMPR3DView()->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
75         int dim[3];
76         double spc[3];
77         imageData->GetDimensions(dim);
78         imageData->GetSpacing(spc);
79
80
81         vtkMarchingCubes *mcubes = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetMCubes(0);
82         
83
84         UtilVtk3DGeometriSelection utilVtk3DGeometriSelection;
85         utilVtk3DGeometriSelection.SetDimentions(dim[0],dim[1],dim[2]);
86
87         utilVtk3DGeometriSelection.SetMarchingCube(mcubes);
88
89     double fac;
90     fac = GTM_MAX( dim[0], dim[2] );
91
92
93     if( utilVtk3DGeometriSelection.FindCubePointsFromPoints(
94       pO.GetAnsiRef( ), pF.GetAnsiRef( ),
95       pp.GetAnsiRef( ), cp.GetAnsiRef( ) )  ) 
96         {
97
98                 if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
99                             x1.GetAnsiRef( ), n1.GetAnsiRef( ),
100                                 pO.GetAnsiRef( ), pF.GetAnsiRef( ) ) ) 
101                 {
102                     if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
103                               x2.GetAnsiRef( ), n2.GetAnsiRef( ),
104                                  ( x1 - n1 ).GetAnsiRef( ), ( x1 - ( n1 * fac ) ).GetAnsiRef( )   ) ) 
105                         {
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                                 this->_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
113                                 ok=true;
114                         }
115                 }
116         }
117
118
119         return ok;
120 }
121 //-------------------------------------------------------------------
122 void vtkInteractorStyle3DView::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
123 {
124         _wxvtkmpr3Dview = wxvtkmpr3Dview;
125 }
126 //-------------------------------------------------------------------
127 wxVtkMPR3DView *vtkInteractorStyle3DView::GetWxVtkMPR3DView()
128 {
129         return _wxvtkmpr3Dview;
130 }
131 //-------------------------------------------------------------------
132 wxVtkClipping3DView *vtkInteractorStyle3DView::GetWxVtkClipping3DView()
133 {
134         return _wxvtkclipping3Dview;
135 }
136 //-------------------------------------------------------------------
137 void vtkInteractorStyle3DView::SetWxVtkClipping3DView( wxVtkClipping3DView *wxvtkclipping3Dview)
138 {
139         _wxvtkclipping3Dview = wxvtkclipping3Dview;
140 }
141