]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[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 #include "vtkUnsignedCharArray.h"
64 #include "vtkCellData.h"
65
66 namespace bbtk
67 {
68
69
70         //=========================================================================
71         vtkGBoxView::vtkGBoxView()
72         {                       
73         }
74
75         //=========================================================================
76         vtkGBoxView::~vtkGBoxView()
77         {
78         }
79
80         //=========================================================================
81         void vtkGBoxView::update(int idController,int command)
82         {
83                 updateColors();         
84                 double xInic, yInic,zInic,xFin, yFin,zFin;
85                 _model->getInicPoint(xInic,yInic,zInic);
86                 _model->getFinalPoint(xFin, yFin,zFin);
87                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
88                 _pts->SetPoint(0, xInic, yInic, zInic );
89                 _pts->SetPoint(1, xInic, yFin, zInic );
90                 _pts->SetPoint(2, xFin, yFin, zFin );
91                 _pts->SetPoint(3, xFin, yInic, zFin );
92                 _pts->Modified();
93                 updatePorts();
94 //              _borderPolyMapper->Modified();
95                 _fillPolyMapper->Modified();
96                 setRefreshWaiting();
97         }
98
99
100         //=========================================================================
101 //EED2017
102         void vtkGBoxView::createVtkInputOutputPorts()
103         {
104                 ///************************* Inputs Fill (triangles) *************************
105                 float rgb[3];
106                 GBoxModel* boxModel                     =(GBoxModel*)_model;
107                 int numberOfTriangles                   = boxModel->getNumInputPorts();
108                 _TrianglesInputsPts                             = vtkPoints::New();
109                 _TrianglesInputsPts->SetNumberOfPoints( 3*numberOfTriangles );
110
111                 vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
112                 vtkPolyData *pdTrianglesInputs  = vtkPolyData::New();
113                 _TrianglesInputsPolyMapper              = vtkPolyDataMapper::New();
114                 _TrianglesInputsActor                   = vtkActor::New();
115                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
116                 for (int i=0 ; i<numberOfTriangles; i++)
117                 {
118                                 stripTrianglesInputs->InsertNextCell( 3 );
119                                 stripTrianglesInputs->InsertCellPoint(i*3+0);
120                                 stripTrianglesInputs->InsertCellPoint(i*3+1);
121                                 stripTrianglesInputs->InsertCellPoint(i*3+2);
122                 }
123
124                 // Create cell data
125                 _cellDataInputTriangles = vtkUnsignedCharArray::New();
126                 _cellDataInputTriangles->SetNumberOfComponents(3);
127                 _cellDataInputTriangles->SetNumberOfTuples(numberOfTriangles);
128                 for (int i = 0; i < numberOfTriangles; i++)
129                 {
130                         rgb[0] = 100;
131                         rgb[1] = 100;
132                         rgb[2] = 100;
133                         _cellDataInputTriangles->SetTuple(i, rgb);
134                 } // for colors  
135                 pdTrianglesInputs->GetCellData()->SetScalars( _cellDataInputTriangles );
136
137                 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
138                 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
139                 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
140                 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
141                 _TrianglesInputsPolyMapper->Modified();
142
143
144                 ///************************* Inputs Fill (triangles) *************************
145
146                 ///************************* Outputs Fill (triangles) *************************
147                 numberOfTriangles                                               = boxModel->getNumOutputPorts();
148                 _TrianglesOutputsPts                                    = vtkPoints::New();
149                 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
150
151                 vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
152                 vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
153                 _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
154                 _TrianglesOutputsActor                                  = vtkActor::New();
155                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
156                 for (int i=0 ; i<numberOfTriangles; i++)
157                 {
158                         stripTrianglesOutputs->InsertNextCell( 3 );
159                         stripTrianglesOutputs->InsertCellPoint(i*3+0);
160                         stripTrianglesOutputs->InsertCellPoint(i*3+1);
161                         stripTrianglesOutputs->InsertCellPoint(i*3+2);
162                 } // for
163                 // Create cell data
164                 _cellDataOutputTriangles = vtkUnsignedCharArray::New();
165                 _cellDataOutputTriangles->SetNumberOfComponents(3);
166                 _cellDataOutputTriangles->SetNumberOfTuples(numberOfTriangles);
167                 for (int i = 0; i < numberOfTriangles; i++)
168                 {
169                         rgb[0] = 000;
170                         rgb[1] = 255;
171                         rgb[2] = 255;
172                         _cellDataOutputTriangles->SetTuple(i, rgb);
173                 } // for colors  
174                 pdTrianglesOutputs->GetCellData()->SetScalars( _cellDataOutputTriangles );
175                 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
176                 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
177                 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
178                 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
179                 _TrianglesOutputsPolyMapper->Modified();
180                 ///************************* Inputs Fill (triangles) *************************
181         }
182
183
184         //=========================================================================
185
186         void vtkGBoxView::createVtkObjects() //virtual
187         {
188                 //------------
189                 _pts                            = vtkPoints::New();     
190 //              vtkCellArray *lines = vtkCellArray::New();
191 //              vtkPolyData *_pd        = vtkPolyData::New();
192 //              _borderPolyMapper       = vtkPolyDataMapper::New();
193 //              _borderObjectActor      = vtkActor::New();
194                                 
195                 _pts->SetNumberOfPoints(4);
196
197                 double xInic, yInic,zInic,xFin, yFin,zFin;
198                 _model->getInicPoint(xInic,yInic,zInic);
199                 _model->getFinalPoint(xFin, yFin,zFin);
200
201                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
202
203 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
204 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
205 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
206 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
207
208 //EED 2017-03-02
209 //              _pts->SetPoint(0, -1000, -1000, -1000 );
210 //              _pts->SetPoint(1, xInic, yFin, zInic );
211 //              _pts->SetPoint(2, 1000, 1000, 1000 );
212 //              _pts->SetPoint(3, xFin, yInic, zFin );
213                                 
214 //              lines->InsertNextCell(5);
215 //              lines->InsertCellPoint(0);
216 //              lines->InsertCellPoint(1);
217 //              lines->InsertCellPoint(2);
218 //              lines->InsertCellPoint(3);
219 //              lines->InsertCellPoint(0);                      
220 //              _pd->SetPoints( _pts );
221 //              _pd->SetLines( lines );
222 //              _borderPolyMapper->SetInput(_pd);
223 //              _borderObjectActor->SetMapper(_borderPolyMapper);
224 //              _borderPolyMapper->Modified();
225
226                 
227                 ///************************* FILL *************************
228
229                 vtkCellArray *strip             = vtkCellArray::New();
230                 vtkPolyData *pdFill             = vtkPolyData::New();
231                 _fillPolyMapper                 = vtkPolyDataMapper::New();
232                 _fillObjectActor                = vtkActor::New();
233
234                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
235
236                 strip->InsertNextCell(5);
237                 strip->InsertCellPoint(0);
238                 strip->InsertCellPoint(1);
239                 strip->InsertCellPoint(2);
240                 strip->InsertCellPoint(0);
241                 strip->InsertCellPoint(3);
242                         
243                 pdFill->SetPoints( _pts );
244                 pdFill->SetStrips( strip );
245
246                 _fillPolyMapper->SetInput(pdFill);
247                 _fillObjectActor->SetMapper(_fillPolyMapper);
248                 _fillPolyMapper->Modified();
249
250                 ///************************* FILL *************************
251         }
252
253         //=========================================================================
254
255         void vtkGBoxView::addVtkActors()//virtual
256         {
257 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
258                 vtkGObjectView::addVtkActors();
259                 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
260                 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
261         }
262
263         //=========================================================================
264
265         void vtkGBoxView::removeVtkActors()//virtual
266         {
267 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
268                 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
269                 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
270                 vtkGObjectView::removeVtkActors();
271         }
272
273         //=========================================================================
274
275         void vtkGBoxView::updateColors()
276         {
277                 printf("EED vtkGBoxView::updateColors\n");
278                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
279
280                 if(_state==NOTHING_HAPPENS)
281                 {
282 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
283 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
284                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
285                         
286                 }
287                 else if(_state==HIGHLIGHTED)
288                 {
289 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);                     
290 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
291                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
292                 }
293                 else if(_state==DRAG)
294                 {
295 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
296 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
297                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
298                 }
299                 else if(_state==SELECTED)
300                 {
301 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
302 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
303                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
304                 } // if state box
305
306                 updateColorsPorts();
307         }
308
309
310         //=========================================================================
311         void vtkGBoxView::updateColorsPorts()
312         {
313                 // Input ports
314                 float rgb[3];
315                 vtkGPortView    *portView;
316                 GBoxModel               *boxModel       = (GBoxModel*)_model;
317                 int numberOfTriangles           = boxModel->getNumInputPorts();
318                 for (int i=0 ; i<numberOfTriangles; i++)
319                 {
320                         portView = _inputsG[i];
321                         portView->getColors(rgb);
322                         rgb[0]=rgb[0]*255;
323                         rgb[1]=rgb[1]*255;
324                         rgb[2]=rgb[2]*255;
325                         _cellDataInputTriangles->SetTuple(i, rgb);
326                 } // for
327
328                 numberOfTriangles               = boxModel->getNumOutputPorts();
329                 for (int i=0 ; i<numberOfTriangles; i++)
330                 {
331                         portView = _outputsG[i];
332                         portView->getColors(rgb);
333                         rgb[0]=rgb[0]*255;
334                         rgb[1]=rgb[1]*255;
335                         rgb[2]=rgb[2]*255;
336                         _cellDataOutputTriangles->SetTuple(i, rgb);
337                 } // for
338         }
339
340
341         //=========================================================================
342         void vtkGBoxView::updatePorts()
343         {
344                 double xInic, yInic,zInic,xFin, yFin,zFin;
345
346                 GBoxModel* boxModel = (GBoxModel*)_model;
347                 boxModel->updatePorts();
348
349 // update position for one Actor that represents all InputPorts
350                 GPortModel              *portModel;
351                 int numberOfTriangles                   = boxModel->getNumInputPorts();
352                 for (int i=0;i<numberOfTriangles;i++)
353                 {
354                         portModel = boxModel->getInputPort(i);
355                 portModel->getInicPoint( xInic , yInic , zInic ) ;
356                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
357                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
358                         _TrianglesInputsPts->SetPoint(i*3+0, xInic                                      , yInic , zInic );
359                         _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2       , yFin  , zInic );
360                         _TrianglesInputsPts->SetPoint(i*3+2, xFin                                       , yInic , zFin );
361                 }
362                 _TrianglesInputsPts->Modified();
363         _TrianglesInputsPolyMapper->Modified( ) ;
364
365 // update position for one Actor that represents all OutputPorts
366                 numberOfTriangles                       = boxModel->getNumOutputPorts();
367                 for (int i=0;i<numberOfTriangles;i++)
368                 {
369                         portModel= boxModel->getOutputPort(i);
370                 portModel->getInicPoint( xInic , yInic , zInic ) ;
371                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
372                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
373                         _TrianglesOutputsPts->SetPoint(i*3+0, xInic                                     , yInic , zInic );
374                         _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2      , yFin  , zInic );
375                         _TrianglesOutputsPts->SetPoint(i*3+2, xFin                                      , yInic , zFin );
376                 }
377                 _TrianglesOutputsPts->Modified();
378         _TrianglesOutputsPolyMapper->Modified( ) ;
379
380
381
382         }
383
384         //=========================================================================
385         void vtkGBoxView::addInputPort(vtkGPortView *inputport)
386         {
387                 _inputsG.push_back(inputport);
388         }
389
390         //=========================================================================
391         void vtkGBoxView::addOutputPort(vtkGPortView *outputport)
392         {
393                 _outputsG.push_back(outputport);
394         }
395
396
397 }  // EO namespace bbtk
398
399 // EOF
400