]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuViewerNV.cxx
b5a0e89b00cb363ad9a646e09566cb2ea983f9c2
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuViewerNV.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 "bbmaracasvisuViewerNV.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 namespace bbcreaMaracasVisu
29 {
30
31 BEGIN_EVENT_TABLE( bbwxMaracas_N_ViewersWidget, wxPanel )
32         EVT_MENU( 12121, bbwxMaracas_N_ViewersWidget::OnRefreshView )
33         EVT_MENU( 12122, bbwxMaracas_N_ViewersWidget::OnDClickLeft  )
34 END_EVENT_TABLE( );
35
36
37 //-------------------------------------------------------------
38 //-------------------------------------------------------------
39 //-------------------------------------------------------------
40
41 bbwxMaracas_N_ViewersWidget::bbwxMaracas_N_ViewersWidget(ViewerNV* box,
42                                                          wxWindow *parent,
43                                                          vtkImageData* imagedata,
44                                                          std::vector<int> *nTypeView)
45 :wxMaracas_N_ViewersWidget(parent,imagedata,nTypeView)
46 {
47         mbbViewerNV=box;
48 }
49
50 //-------------------------------------------------------------
51 bbwxMaracas_N_ViewersWidget::~bbwxMaracas_N_ViewersWidget()
52 {
53 }
54
55 //-------------------------------------------------------------
56 void bbwxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
57 {
58         //printf("CPR: bbwxMaracas_N_ViewersWidget::OnRefreshView -> actualiza X, Y y Z\n");
59         mbbViewerNV->_point.clear();
60         mbbViewerNV->_point.push_back( (int)GetX() );
61         mbbViewerNV->_point.push_back( (int)GetY() );
62         mbbViewerNV->_point.push_back( (int)GetZ() );
63         mbbViewerNV->bbSetOutputPoint( mbbViewerNV->_point );
64         mbbViewerNV->bbSignalOutputModification(std::string("Point"));
65         wxMaracas_N_ViewersWidget::OnRefreshView(event);
66 }
67
68 //-------------------------------------------------------------
69 void bbwxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
70 {
71         wxMaracas_N_ViewersWidget::OnDClickLeft(event);
72         mbbViewerNV->bbSignalOutputModification(std::string("Point"));
73 }
74
75 //-------------------------------------------------------------
76 //-------------------------------------------------------------
77 //-------------------------------------------------------------
78
79
80
81 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ViewerNV)
82 BBTK_BLACK_BOX_IMPLEMENTATION(ViewerNV,bbtk::WxBlackBox);
83 //-------------------------------------------------------------
84 void ViewerNV::Process()
85 {
86         vtkImageData* img               = bbGetInputIn();
87         std::vector<int> type   = bbGetInputnTypeView();
88         if(img != NULL && _mwxwidget != NULL)
89         {
90                 if(!compareVectors(type, _currenttype))
91                 {
92                         _mwxwidget->SetType(&type);
93                         _mwxwidget->UpdateLayout(img);
94                 }else if (img != _currentimg){
95                         _mwxwidget->SetImage(img);
96                 }
97 //              _mwxwidget->RefreshView();
98                 _currenttype    = type;
99                 _currentimg     = img;
100                 _point.clear();
101                 _point.push_back( (int)_mwxwidget->GetX() );
102                 _point.push_back( (int)_mwxwidget->GetY() );
103                 _point.push_back( (int)_mwxwidget->GetZ() );
104                 bbSetOutputPoint( _point                                  );
105
106                 wxVtkBaseView *wvbv1 = _mwxwidget->GetwxVtkBaseView( 1 );
107                 wxVtkBaseView *wvbv2 = _mwxwidget->GetwxVtkBaseView( 2 );
108                 wxVtkBaseView *wvbv3 = _mwxwidget->GetwxVtkBaseView( 3 );
109                 wxVtkBaseView *wvbv4 = _mwxwidget->GetwxVtkBaseView( 4 );
110                 //wxwidget->RefreshView();
111                 bbSetOutputwxVtkBaseView1( wvbv1 );
112                 bbSetOutputwxVtkBaseView2( wvbv2 );
113                 bbSetOutputwxVtkBaseView3( wvbv3 );
114                 bbSetOutputwxVtkBaseView4( wvbv4 );
115                 if (wvbv1!=NULL) { bbSetOutputRenderer1( wvbv1->GetRenderer() ); }
116                 if (wvbv2!=NULL) { bbSetOutputRenderer2( wvbv2->GetRenderer() ); }
117                 if (wvbv3!=NULL) { bbSetOutputRenderer3( wvbv3->GetRenderer() ); }
118                 if (wvbv4!=NULL) { bbSetOutputRenderer4( wvbv4->GetRenderer() ); }
119                 if (wvbv1!=NULL)
120                 {
121                         bbSetOutputInteractor1( wvbv1->GetWxVTKRenderWindowInteractor() );
122                         updateObservers();
123                 }
124                 if(bbGetInputColorFunction()!=NULL)
125                 {
126                         _mwxwidget->setColorTransferFunction(bbGetInputColorFunction());
127                 }
128                 if( (bbGetInputColorLevel()!=-1) && (bbGetInputWindowLevel()!=-1))
129                 {
130                         if(bbGetInputColorLevel() == 0)
131                         {
132                                 _mwxwidget->SetColorWindowLevel( bbGetInputWindowLevel() , 0.1 );
133                         }else{
134                                 _mwxwidget->SetColorWindowLevel( bbGetInputWindowLevel() , bbGetInputColorLevel() );
135                         }
136                 }
137                 _mwxwidget->SetInterpolate( bbGetInputInterpolate() );
138 /* Borrame
139                 if (wvbv1!=NULL) 
140                 {
141                         wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
142                         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
143                         #if wxMAJOR_VERSION <= 2
144                                 wvbv1->GetWxVTKRenderWindowInteractor ()->GetParent()->ProcessEvent( newevent );
145                         #else
146                                 wvbv1->GetWxVTKRenderWindowInteractor ()->GetParent()->ProcessWindowEvent( newevent );
147                         #endif                          
148                 }
149
150 */
151         }//  mwxwidget != NULL
152 }
153
154 //-------------------------------------------------------------
155 void ViewerNV::CreateWidget(wxWindow* parent)
156 {
157     bbtkDebugMessageInc("Core",9,"ViewerNV::CreateWidget()"<<std::endl);
158         _mwxwidget = new bbwxMaracas_N_ViewersWidget( this, parent );
159         bbtkDebugDecTab("Core",9);
160     bbSetOutputWidget( _mwxwidget );
161         //this->bbSignalOutputModification();
162         //Process();
163 }
164
165 //-------------------------------------------------------------
166 void ViewerNV::bbUserSetDefaultValues()
167 {
168         _currentimg                             =       NULL;
169         _mwxwidget                              =       NULL;
170         bbSetInputIn(NULL);
171
172         bbSetInputObs1(NULL);
173         bbSetInputObs2(NULL);
174         bbSetInputObs3(NULL);
175         bbSetInputObs4(NULL);
176         bbSetInputObs5(NULL);
177         bbSetInputInterpolate(true);
178
179         std::vector<int> vecNTypeViwer;
180         vecNTypeViwer.push_back(5);
181         vecNTypeViwer.push_back(1);
182         vecNTypeViwer.push_back(2);
183         vecNTypeViwer.push_back(0);
184         bbSetInputnTypeView(vecNTypeViwer);
185
186         bbSetOutputwxVtkBaseView1( NULL );
187         bbSetOutputwxVtkBaseView2( NULL );
188         bbSetOutputwxVtkBaseView3( NULL );
189         bbSetOutputwxVtkBaseView4( NULL );
190         bbSetOutputRenderer1( NULL );
191         bbSetOutputRenderer2( NULL );
192         bbSetOutputRenderer3( NULL );
193         bbSetOutputRenderer4( NULL );
194         bbSetInputColorFunction(NULL);
195         bbSetInputWindowLevel(-1);
196         bbSetInputColorLevel(-1);
197 }
198
199 //-----------------------------------------------------------------
200 void ViewerNV::bbUserInitializeProcessing()
201 {
202 }
203
204 //-----------------------------------------------------------------
205 void ViewerNV::bbUserFinalizeProcessing()
206 {
207 }
208
209 //-----------------------------------------------------------------
210
211 bool ViewerNV::compareVectors(std::vector<int> type,std::vector<int> currenttype)
212 {
213         bool ret = true;
214         if(type.size()==currenttype.size())
215         {
216                 for(int i = 0; i < (int)(type.size()) && ret; i++)
217                 {
218                         if(type[i]!=currenttype[i])
219                         {
220                                 ret = false;
221                         } // if
222                 } // for
223         }else{
224                 ret=false;
225         } // type size
226         return ret;
227 }
228
229 void ViewerNV::updateObservers()
230 {
231         vtkRenderWindowInteractor* interactor;
232         interactor = bbGetOutputInteractor1();
233         if(interactor)
234         {
235                 if (bbGetInputObs1()!=NULL)
236                 {
237                   bbGetInputObs1()->SetInteractor(interactor);
238                   bbGetInputObs1()->EnabledOn();
239                 }
240                 if (bbGetInputObs2()!=NULL)
241                 {
242                   bbGetInputObs2()->SetInteractor(interactor);
243                   bbGetInputObs2()->EnabledOn();
244                 }
245                 if (bbGetInputObs3()!=NULL)
246                 {
247                   bbGetInputObs3()->SetInteractor(interactor);
248                   bbGetInputObs3()->EnabledOn();
249                 }
250                 if (bbGetInputObs4()!=NULL)
251                 {
252                   bbGetInputObs4()->SetInteractor(interactor);
253                   bbGetInputObs4()->EnabledOn();
254                 }
255                 if (bbGetInputObs5()!=NULL)
256                 {
257                   bbGetInputObs5()->SetInteractor(interactor);
258                   bbGetInputObs5()->EnabledOn();
259                 }
260         } // if interactor
261 }
262
263 }
264 // EO namespace bbcreaMaracasVisu
265