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