]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuViewerNV.cxx
262107d1ba0ee8f63f44fd481b6970533d8d7e64
[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
139 /* Borrame
140                 if (wvbv1!=NULL) 
141                 {
142                         wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
143                         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
144                         #if wxMAJOR_VERSION <= 2
145                                 wvbv1->GetWxVTKRenderWindowInteractor ()->GetParent()->ProcessEvent( newevent );
146                         #else
147                                 wvbv1->GetWxVTKRenderWindowInteractor ()->GetParent()->ProcessWindowEvent( newevent );
148                         #endif                          
149                 }
150
151 */
152
153
154
155
156         }//  mwxwidget != NULL
157 }
158
159 //-------------------------------------------------------------
160 void ViewerNV::CreateWidget(wxWindow* parent)
161 {
162     bbtkDebugMessageInc("Core",9,"ViewerNV::CreateWidget()"<<std::endl);
163         _mwxwidget = new bbwxMaracas_N_ViewersWidget( this, parent );
164         bbtkDebugDecTab("Core",9);
165     bbSetOutputWidget( _mwxwidget );
166         //this->bbSignalOutputModification();
167         //Process();
168 }
169
170 //-------------------------------------------------------------
171 void ViewerNV::bbUserSetDefaultValues()
172 {
173         _currentimg                             =       NULL;
174         _mwxwidget                              =       NULL;
175         bbSetInputIn(NULL);
176
177         bbSetInputObs1(NULL);
178         bbSetInputObs2(NULL);
179         bbSetInputObs3(NULL);
180         bbSetInputObs4(NULL);
181         bbSetInputObs5(NULL);
182         bbSetInputInterpolate(true);
183
184         std::vector<int> vecNTypeViwer;
185         vecNTypeViwer.push_back(5);
186         vecNTypeViwer.push_back(1);
187         vecNTypeViwer.push_back(2);
188         vecNTypeViwer.push_back(0);
189         bbSetInputnTypeView(vecNTypeViwer);
190
191         bbSetOutputwxVtkBaseView1( NULL );
192         bbSetOutputwxVtkBaseView2( NULL );
193         bbSetOutputwxVtkBaseView3( NULL );
194         bbSetOutputwxVtkBaseView4( NULL );
195         bbSetOutputRenderer1( NULL );
196         bbSetOutputRenderer2( NULL );
197         bbSetOutputRenderer3( NULL );
198         bbSetOutputRenderer4( NULL );
199         bbSetInputColorFunction(NULL);
200         bbSetInputWindowLevel(-1);
201         bbSetInputColorLevel(-1);
202 }
203
204 //-----------------------------------------------------------------
205 void ViewerNV::bbUserInitializeProcessing()
206 {
207 }
208
209 //-----------------------------------------------------------------
210 void ViewerNV::bbUserFinalizeProcessing()
211 {
212 }
213
214 //-----------------------------------------------------------------
215
216
217
218 bool ViewerNV::compareVectors(std::vector<int> type,std::vector<int> currenttype){
219
220         bool ret = true;
221
222         if(type.size()==currenttype.size()){
223                 for(int i = 0; i < (int)(type.size()) && ret; i++){
224                         if(type[i]!=currenttype[i]){
225                                 ret = false;
226                         }
227                 }
228         }else{
229                 ret=false;
230         }
231         return ret;
232 }
233
234 void ViewerNV::updateObservers(){
235         vtkRenderWindowInteractor* interactor;
236         interactor = bbGetOutputInteractor1();
237         if(interactor){
238                 if (bbGetInputObs1()!=NULL){
239                   bbGetInputObs1()->SetInteractor(interactor);
240                   bbGetInputObs1()->EnabledOn();
241                 }
242                 if (bbGetInputObs2()!=NULL)
243                 {
244                   bbGetInputObs2()->SetInteractor(interactor);
245                   bbGetInputObs2()->EnabledOn();
246                 }
247                 if (bbGetInputObs3()!=NULL)
248                 {
249                   bbGetInputObs3()->SetInteractor(interactor);
250                   bbGetInputObs3()->EnabledOn();
251                 }
252                 if (bbGetInputObs4()!=NULL)
253                 {
254                   bbGetInputObs4()->SetInteractor(interactor);
255                   bbGetInputObs4()->EnabledOn();
256                 }
257                 if (bbGetInputObs5()!=NULL)
258                 {
259                   bbGetInputObs5()->SetInteractor(interactor);
260                   bbGetInputObs5()->EnabledOn();
261                 }
262         }
263 }
264
265 }
266 // EO namespace bbcreaMaracasVisu
267