]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
#3075 bbGEditor Bug New Normal - comboBox for message configuration
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBoxView.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================                                                                               
27 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and 
40 *  abiding by the rules of distribution of free software. You can  use, 
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
42 *  license as circulated by CEA, CNRS and INRIA at the following URL 
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability. 
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */                                                                         
55
56 /**
57 *  \file 
58 *  \brief Class bbtk::vtkGBoxView 
59 */
60
61
62 #include "vtkGBoxView.h"
63
64 namespace bbtk
65 {
66
67
68         //=========================================================================
69         vtkGBoxView::vtkGBoxView()
70         {                       
71         }
72
73         //=========================================================================
74         vtkGBoxView::~vtkGBoxView()
75         {
76         }
77
78         //=========================================================================
79         void vtkGBoxView::update(int idController,int command)
80         {
81                 updateColors();         
82                 double xInic, yInic,zInic,xFin, yFin,zFin;
83                 _model->getInicPoint(xInic,yInic,zInic);
84                 _model->getFinalPoint(xFin, yFin,zFin);
85                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
86                 _pts->SetPoint(0, xInic, yInic, zInic );
87                 _pts->SetPoint(1, xInic, yFin, zInic );
88                 _pts->SetPoint(2, xFin, yFin, zFin );
89                 _pts->SetPoint(3, xFin, yInic, zFin );
90                 _pts->Modified();
91                 updatePorts();
92 //              _borderPolyMapper->Modified();
93                 _fillPolyMapper->Modified();
94                 setRefreshWaiting();
95         }
96
97
98         //=========================================================================
99 //EED2017
100         void vtkGBoxView::createVtkInputOutputPorts()
101         {
102                 ///************************* Inputs Fill (triangles) *************************
103                 GBoxModel* boxModel                     =(GBoxModel*)_model;
104                 int numberOfTriangles                   = boxModel->getNumInputPorts();
105                 _TrianglesInputsPts                             = vtkPoints::New();
106                 _TrianglesInputsPts->SetNumberOfPoints( 3*numberOfTriangles );
107
108 //EED 2017-03-02
109 //              if (numberOfTriangles>0)
110 //              {
111 //                      _TrianglesInputsPts->SetPoint(0, -1000, -1000, -1000 );
112 //                      _TrianglesInputsPts->SetPoint(1, 1000, 1000, 1000 );
113 //              }
114
115                 vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
116                 vtkPolyData *pdTrianglesInputs  = vtkPolyData::New();
117                 _TrianglesInputsPolyMapper              = vtkPolyDataMapper::New();
118                 _TrianglesInputsActor                   = vtkActor::New();
119                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
120                 for (int i=0 ; i<numberOfTriangles; i++)
121                 {
122                                 stripTrianglesInputs->InsertNextCell( 3 );
123                                 stripTrianglesInputs->InsertCellPoint(i*3+0);
124                                 stripTrianglesInputs->InsertCellPoint(i*3+1);
125                                 stripTrianglesInputs->InsertCellPoint(i*3+2);
126                 }
127                 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
128                 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
129                 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
130                 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
131                 _TrianglesInputsPolyMapper->Modified();
132                 ///************************* Inputs Fill (triangles) *************************
133
134                 ///************************* Outputs Fill (triangles) *************************
135                 numberOfTriangles                                               = boxModel->getNumOutputPorts();
136                 _TrianglesOutputsPts                                    = vtkPoints::New();
137                 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
138
139 //EED 2017-03-02
140 //              if (numberOfTriangles>0)
141 //              {
142 //                      _TrianglesOutputsPts->SetPoint(0, -1000, -1000, -1000 );
143 //                      _TrianglesOutputsPts->SetPoint(1, 1000, 1000, 1000 );
144 //              }
145
146                 vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
147                 vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
148                 _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
149                 _TrianglesOutputsActor                                  = vtkActor::New();
150                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
151                 for (int i=0 ; i<numberOfTriangles; i++)
152                 {
153                                 stripTrianglesOutputs->InsertNextCell( 3 );
154                                 stripTrianglesOutputs->InsertCellPoint(i*3+0);
155                                 stripTrianglesOutputs->InsertCellPoint(i*3+1);
156                                 stripTrianglesOutputs->InsertCellPoint(i*3+2);
157                 }
158                 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
159                 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
160                 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
161                 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
162                 _TrianglesOutputsPolyMapper->Modified();
163                 ///************************* Inputs Fill (triangles) *************************
164         }
165
166
167         //=========================================================================
168
169         void vtkGBoxView::createVtkObjects() //virtual
170         {
171                 //------------
172                 _pts                            = vtkPoints::New();     
173 //              vtkCellArray *lines = vtkCellArray::New();
174 //              vtkPolyData *_pd        = vtkPolyData::New();
175 //              _borderPolyMapper       = vtkPolyDataMapper::New();
176 //              _borderObjectActor      = vtkActor::New();
177                                 
178                 _pts->SetNumberOfPoints(4);
179
180                 double xInic, yInic,zInic,xFin, yFin,zFin;
181                 _model->getInicPoint(xInic,yInic,zInic);
182                 _model->getFinalPoint(xFin, yFin,zFin);
183
184                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
185
186 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
187 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
188 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
189 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
190
191 //EED 2017-03-02
192 //              _pts->SetPoint(0, -1000, -1000, -1000 );
193 //              _pts->SetPoint(1, xInic, yFin, zInic );
194 //              _pts->SetPoint(2, 1000, 1000, 1000 );
195 //              _pts->SetPoint(3, xFin, yInic, zFin );
196                                 
197 //              lines->InsertNextCell(5);
198 //              lines->InsertCellPoint(0);
199 //              lines->InsertCellPoint(1);
200 //              lines->InsertCellPoint(2);
201 //              lines->InsertCellPoint(3);
202 //              lines->InsertCellPoint(0);                      
203 //              _pd->SetPoints( _pts );
204 //              _pd->SetLines( lines );
205 //              _borderPolyMapper->SetInput(_pd);
206 //              _borderObjectActor->SetMapper(_borderPolyMapper);
207 //              _borderPolyMapper->Modified();
208
209                 
210                 ///************************* FILL *************************
211
212                 vtkCellArray *strip             = vtkCellArray::New();
213                 vtkPolyData *pdFill             = vtkPolyData::New();
214                 _fillPolyMapper                 = vtkPolyDataMapper::New();
215                 _fillObjectActor                = vtkActor::New();
216
217                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
218
219                 strip->InsertNextCell(5);
220                 strip->InsertCellPoint(0);
221                 strip->InsertCellPoint(1);
222                 strip->InsertCellPoint(2);
223                 strip->InsertCellPoint(0);
224                 strip->InsertCellPoint(3);
225                         
226                 pdFill->SetPoints( _pts );
227                 pdFill->SetStrips( strip );
228
229                 _fillPolyMapper->SetInput(pdFill);
230                 _fillObjectActor->SetMapper(_fillPolyMapper);
231                 _fillPolyMapper->Modified();
232
233                 ///************************* FILL *************************
234         }
235
236         //=========================================================================
237
238         void vtkGBoxView::addVtkActors()//virtual
239         {
240 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
241                 vtkGObjectView::addVtkActors();
242                 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
243                 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
244         }
245
246         //=========================================================================
247
248         void vtkGBoxView::removeVtkActors()//virtual
249         {
250 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
251                 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
252                 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
253                 vtkGObjectView::removeVtkActors();
254         }
255
256         //=========================================================================
257
258         void vtkGBoxView::updateColors()
259         {
260                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
261
262                 if(_state==NOTHING_HAPPENS)
263                 {
264 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
265 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
266                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
267                         
268                 }
269                 else if(_state==HIGHLIGHTED)
270                 {
271 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);                     
272 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
273                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
274                 }
275                 else if(_state==DRAG)
276                 {
277 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
278 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
279                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
280                 }
281                 else if(_state==SELECTED)
282                 {
283 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
284 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
285                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
286                 }
287         }
288
289         //=========================================================================
290
291         void vtkGBoxView::updatePorts()
292         {
293                 double xInic, yInic,zInic,xFin, yFin,zFin;
294
295                 GBoxModel* boxModel =(GBoxModel*)_model;
296                 boxModel->updatePorts();
297
298 // update position for one Actor that represents all InputPorts
299                 GPortModel      *portModel;
300                 int numberOfTriangles                   = boxModel->getNumInputPorts();
301                 for (int i=0;i<numberOfTriangles;i++)
302                 {
303                         portModel= boxModel->getInputPort(i);
304                 portModel->getInicPoint( xInic , yInic , zInic ) ;
305                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
306                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
307                         _TrianglesInputsPts->SetPoint(i*3+0, xInic                                      , yInic , zInic );
308                         _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2       , yFin  , zInic );
309                         _TrianglesInputsPts->SetPoint(i*3+2, xFin                                       , yInic , zFin );
310                 }
311                 _TrianglesInputsPts->Modified();
312         _TrianglesInputsPolyMapper->Modified( ) ;
313
314 // update position for one Actor that represents all OutputPorts
315                 numberOfTriangles                       = boxModel->getNumOutputPorts();
316                 for (int i=0;i<numberOfTriangles;i++)
317                 {
318                         portModel= boxModel->getOutputPort(i);
319                 portModel->getInicPoint( xInic , yInic , zInic ) ;
320                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
321                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
322                         _TrianglesOutputsPts->SetPoint(i*3+0, xInic                                     , yInic , zInic );
323                         _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2      , yFin  , zInic );
324                         _TrianglesOutputsPts->SetPoint(i*3+2, xFin                                      , yInic , zFin );
325                 }
326                 _TrianglesOutputsPts->Modified();
327         _TrianglesOutputsPolyMapper->Modified( ) ;
328
329
330
331         }
332
333         //=========================================================================
334
335 }  // EO namespace bbtk
336
337 // EOF
338