]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuViewerNV.cxx
#2855 creaMaracasVisu Bug New Normal - ColorLayer box spacing size not identified
[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
61         mbbViewerNV->_point.push_back( (int)GetX() );
62         mbbViewerNV->_point.push_back( (int)GetY() );
63         mbbViewerNV->_point.push_back( (int)GetZ() );
64         mbbViewerNV->bbSetOutputPoint( mbbViewerNV->_point );
65         mbbViewerNV->bbSignalOutputModification(std::string("Point"));
66
67         wxMaracas_N_ViewersWidget::OnRefreshView(event);
68 }
69
70 //-------------------------------------------------------------
71 void bbwxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
72 {
73         wxMaracas_N_ViewersWidget::OnDClickLeft(event);
74         mbbViewerNV->bbSignalOutputModification(std::string("Point"));
75 }
76
77 //-------------------------------------------------------------
78 //-------------------------------------------------------------
79 //-------------------------------------------------------------
80
81
82
83 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ViewerNV)
84 BBTK_BLACK_BOX_IMPLEMENTATION(ViewerNV,bbtk::WxBlackBox);
85 //-------------------------------------------------------------
86 void ViewerNV::Process()
87 {
88         vtkImageData* img = bbGetInputIn();
89
90
91         std::vector<int> type = bbGetInputnTypeView();
92
93
94         if(img != NULL && _mwxwidget != NULL){
95                 if(!compareVectors(type, _currenttype)){
96                         _mwxwidget->SetType(&type);
97                         _mwxwidget->UpdateLayout(img);
98                 }else if (img != _currentimg){
99                         _mwxwidget->SetImage(img);
100                 }
101                 _mwxwidget->RefreshView();
102
103                 _currenttype    = type;
104                 _currentimg     = img;
105
106                 _point.clear();
107                 _point.push_back((int)_mwxwidget->GetX());
108                 _point.push_back((int)_mwxwidget->GetY());
109                 _point.push_back((int)_mwxwidget->GetZ());
110                 bbSetOutputPoint(_point);
111
112         //    WxBlackBox::Process();
113 //              mwxwidget->SetImage(img );
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
119                 //wxwidget->RefreshView();
120
121                 bbSetOutputwxVtkBaseView1( wvbv1 );
122                 bbSetOutputwxVtkBaseView2( wvbv2 );
123                 bbSetOutputwxVtkBaseView3( wvbv3 );
124                 bbSetOutputwxVtkBaseView4( wvbv4 );
125                 if (wvbv1!=NULL) { bbSetOutputRenderer1( wvbv1->GetRenderer() ); }
126                 if (wvbv2!=NULL) { bbSetOutputRenderer2( wvbv2->GetRenderer() ); }
127                 if (wvbv3!=NULL) { bbSetOutputRenderer3( wvbv3->GetRenderer() ); }
128                 if (wvbv4!=NULL) { bbSetOutputRenderer4( wvbv4->GetRenderer() ); }
129
130                 if (wvbv1!=NULL)
131                 {
132                         bbSetOutputInteractor1( wvbv1->GetWxVTKRenderWindowInteractor() );
133                         updateObservers();
134                 }
135
136                 if(bbGetInputColorFunction()!=NULL)
137                 {
138                         _mwxwidget->setColorTransferFunction(bbGetInputColorFunction());
139                 }
140
141
142                 if( (bbGetInputColorLevel()!=-1) && (bbGetInputWindowLevel()!=-1))
143                 {
144                         if(bbGetInputColorLevel() == 0)
145                         {
146                                 _mwxwidget->SetColorWindowLevel( bbGetInputWindowLevel() , 0.1 );
147                         }else{
148                                 _mwxwidget->SetColorWindowLevel( bbGetInputWindowLevel() , bbGetInputColorLevel() );
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
178         std::vector<int> vecNTypeViwer;
179         vecNTypeViwer.push_back(5);
180         vecNTypeViwer.push_back(1);
181         vecNTypeViwer.push_back(2);
182         vecNTypeViwer.push_back(0);
183         bbSetInputnTypeView(vecNTypeViwer);
184
185         bbSetOutputwxVtkBaseView1( NULL );
186         bbSetOutputwxVtkBaseView2( NULL );
187         bbSetOutputwxVtkBaseView3( NULL );
188         bbSetOutputwxVtkBaseView4( NULL );
189         bbSetOutputRenderer1( NULL );
190         bbSetOutputRenderer2( NULL );
191         bbSetOutputRenderer3( NULL );
192         bbSetOutputRenderer4( NULL );
193         bbSetInputColorFunction(NULL);
194         bbSetInputWindowLevel(-1);
195         bbSetInputColorLevel(-1);
196 }
197
198 //-----------------------------------------------------------------
199 void ViewerNV::bbUserInitializeProcessing()
200 {
201 }
202
203 //-----------------------------------------------------------------
204 void ViewerNV::bbUserFinalizeProcessing()
205 {
206 }
207
208 //-----------------------------------------------------------------
209
210
211
212 bool ViewerNV::compareVectors(std::vector<int> type,std::vector<int> currenttype){
213
214         bool ret = true;
215
216         if(type.size()==currenttype.size()){
217                 for(int i = 0; i < (int)(type.size()) && ret; i++){
218                         if(type[i]!=currenttype[i]){
219                                 ret = false;
220                         }
221                 }
222         }else{
223                 ret=false;
224         }
225         return ret;
226 }
227
228 void ViewerNV::updateObservers(){
229         vtkRenderWindowInteractor* interactor;
230         interactor = bbGetOutputInteractor1();
231         if(interactor){
232                 if (bbGetInputObs1()!=NULL){
233                   bbGetInputObs1()->SetInteractor(interactor);
234                   bbGetInputObs1()->EnabledOn();
235                 }
236                 if (bbGetInputObs2()!=NULL)
237                 {
238                   bbGetInputObs2()->SetInteractor(interactor);
239                   bbGetInputObs2()->EnabledOn();
240                 }
241                 if (bbGetInputObs3()!=NULL)
242                 {
243                   bbGetInputObs3()->SetInteractor(interactor);
244                   bbGetInputObs3()->EnabledOn();
245                 }
246                 if (bbGetInputObs4()!=NULL)
247                 {
248                   bbGetInputObs4()->SetInteractor(interactor);
249                   bbGetInputObs4()->EnabledOn();
250                 }
251                 if (bbGetInputObs5()!=NULL)
252                 {
253                   bbGetInputObs5()->SetInteractor(interactor);
254                   bbGetInputObs5()->EnabledOn();
255                 }
256         }
257 }
258
259 }
260 // EO namespace bbcreaMaracasVisu
261