]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
#3057 bbGEditor Feature New Normal - optimizing of vtk actors management (input...
[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                 
83                 double xInic, yInic,zInic,xFin, yFin,zFin;
84                 _model->getInicPoint(xInic,yInic,zInic);
85                 _model->getFinalPoint(xFin, yFin,zFin);
86
87                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
88
89                 _pts->SetPoint(0, xInic, yInic, zInic );
90                 _pts->SetPoint(1, xInic, yFin, zInic );
91                 _pts->SetPoint(2, xFin, yFin, zFin );
92                 _pts->SetPoint(3, xFin, yInic, zFin );
93
94                 updatePorts();
95
96 //              _borderPolyMapper->Modified();
97                 _fillPolyMapper->Modified();
98                 //-----------
99
100                 //-----------
101                 setRefreshWaiting();
102         }
103
104
105
106         //=========================================================================
107 //EED2017
108         void vtkGBoxView::createVtkInputOutputPorts()
109         {
110                 ///************************* Inputs Fill (triangles) *************************
111                 GBoxModel* boxModel                     =(GBoxModel*)_model;
112                 int numberOfTriangles                   = boxModel->getNumInputPorts();
113                 _TrianglesInputsPts                             = vtkPoints::New();
114                 _TrianglesInputsPts->SetNumberOfPoints( 3*numberOfTriangles );
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                 vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
139                 vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
140                 _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
141                 _TrianglesOutputsActor                                  = vtkActor::New();
142                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
143                 for (int i=0 ; i<numberOfTriangles; i++)
144                 {
145                                 stripTrianglesOutputs->InsertNextCell( 3 );
146                                 stripTrianglesOutputs->InsertCellPoint(i*3+0);
147                                 stripTrianglesOutputs->InsertCellPoint(i*3+1);
148                                 stripTrianglesOutputs->InsertCellPoint(i*3+2);
149                 }
150                 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
151                 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
152                 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
153                 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
154                 _TrianglesOutputsPolyMapper->Modified();
155                 ///************************* Inputs Fill (triangles) *************************
156         }
157
158
159         //=========================================================================
160
161         void vtkGBoxView::createVtkObjects() //virtual
162         {
163                 //------------
164                 _pts                            = vtkPoints::New();     
165 //              vtkCellArray *lines = vtkCellArray::New();
166 //              vtkPolyData *_pd        = vtkPolyData::New();
167 //              _borderPolyMapper       = vtkPolyDataMapper::New();
168 //              _borderObjectActor      = vtkActor::New();
169                                 
170                 _pts->SetNumberOfPoints(4);
171
172                 double xInic, yInic,zInic,xFin, yFin,zFin;
173                 _model->getInicPoint(xInic,yInic,zInic);
174                 _model->getFinalPoint(xFin, yFin,zFin);
175
176                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
177
178 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
179 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
180 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
181 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
182                 _pts->SetPoint(0, -1000, -1000, -1000 );
183                 _pts->SetPoint(1, xInic, yFin, zInic );
184                 _pts->SetPoint(2, 1000, 1000, 1000 );
185                 _pts->SetPoint(3, xFin, yInic, zFin );
186                                 
187 //              lines->InsertNextCell(5);
188 //              lines->InsertCellPoint(0);
189 //              lines->InsertCellPoint(1);
190 //              lines->InsertCellPoint(2);
191 //              lines->InsertCellPoint(3);
192 //              lines->InsertCellPoint(0);                      
193 //              _pd->SetPoints( _pts );
194 //              _pd->SetLines( lines );
195 //              _borderPolyMapper->SetInput(_pd);
196 //              _borderObjectActor->SetMapper(_borderPolyMapper);
197 //              _borderPolyMapper->Modified();
198
199                 
200                 ///************************* FILL *************************
201
202                 vtkCellArray *strip             = vtkCellArray::New();
203                 vtkPolyData *pdFill             = vtkPolyData::New();
204                 _fillPolyMapper                 = vtkPolyDataMapper::New();
205                 _fillObjectActor                = vtkActor::New();
206
207                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
208
209                 strip->InsertNextCell(5);
210                 strip->InsertCellPoint(0);
211                 strip->InsertCellPoint(1);
212                 strip->InsertCellPoint(2);
213                 strip->InsertCellPoint(0);
214                 strip->InsertCellPoint(3);
215                         
216                 pdFill->SetPoints( _pts );
217                 pdFill->SetStrips( strip );
218
219                 _fillPolyMapper->SetInput(pdFill);
220                 _fillObjectActor->SetMapper(_fillPolyMapper);
221                 _fillPolyMapper->Modified();
222
223                 ///************************* FILL *************************
224         }
225
226         //=========================================================================
227
228         void vtkGBoxView::addVtkActors()//virtual
229         {
230 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
231                 vtkGObjectView::addVtkActors();
232                 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
233                 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
234         }
235
236         //=========================================================================
237
238         void vtkGBoxView::removeVtkActors()//virtual
239         {
240 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
241                 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
242                 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
243                 vtkGObjectView::removeVtkActors();
244         }
245
246         //=========================================================================
247
248         void vtkGBoxView::updateColors()
249         {
250                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
251
252                 if(_state==NOTHING_HAPPENS)
253                 {
254 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
255 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
256                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
257                         
258                 }
259                 else if(_state==HIGHLIGHTED)
260                 {
261 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);                     
262 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
263                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
264                 }
265                 else if(_state==DRAG)
266                 {
267 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
268 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
269                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
270                 }
271                 else if(_state==SELECTED)
272                 {
273 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
274 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
275                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
276                 }
277         }
278
279         //=========================================================================
280
281         void vtkGBoxView::updatePorts()
282         {
283                 double xInic, yInic,zInic,xFin, yFin,zFin;
284
285                 GBoxModel* boxModel =(GBoxModel*)_model;
286                 boxModel->updatePorts();
287
288 // update position for one Actor that represents all InputPorts
289                 GPortModel      *portModel;
290                 int numberOfTriangles                   = boxModel->getNumInputPorts();
291                 for (int i=0;i<numberOfTriangles;i++)
292                 {
293                         portModel= boxModel->getInputPort(i);
294                 portModel->getInicPoint( xInic , yInic , zInic ) ;
295                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
296                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
297                         _TrianglesInputsPts->SetPoint(i*3+0, xInic                                      , yInic , zInic );
298                         _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2       , yFin  , zInic );
299                         _TrianglesInputsPts->SetPoint(i*3+2, xFin                                       , yInic , zFin );
300                 }
301         _TrianglesInputsPolyMapper->Modified( ) ;
302
303 // update position for one Actor that represents all OutputPorts
304                 numberOfTriangles                       = boxModel->getNumOutputPorts();
305                 for (int i=0;i<numberOfTriangles;i++)
306                 {
307                         portModel= boxModel->getOutputPort(i);
308                 portModel->getInicPoint( xInic , yInic , zInic ) ;
309                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
310                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
311                         _TrianglesOutputsPts->SetPoint(i*3+0, xInic                                     , yInic , zInic );
312                         _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2      , yFin  , zInic );
313                         _TrianglesOutputsPts->SetPoint(i*3+2, xFin                                      , yInic , zFin );
314                 }
315         _TrianglesOutputsPolyMapper->Modified( ) ;
316
317
318
319         }
320
321         //=========================================================================
322
323 }  // EO namespace bbtk
324
325 // EOF
326