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