]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
#3114 bbGEditor Bug New Normal - branch vtk7itk4 compilation with vtk7
[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
140 //EED 2017-01-01 Migration VTK7
141 #if VTK_MAJOR_VERSION <= 5
142                 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
143 #else
144                 _TrianglesInputsPolyMapper->SetInputData( pdTrianglesInputs );
145 #endif
146
147                 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
148                 _TrianglesInputsPolyMapper->Modified();
149
150
151                 ///************************* Inputs Fill (triangles) *************************
152
153                 ///************************* Outputs Fill (triangles) *************************
154                 numberOfTriangles                                               = boxModel->getNumOutputPorts();
155                 _TrianglesOutputsPts                                    = vtkPoints::New();
156                 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
157
158                 vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
159                 vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
160                 _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
161                 _TrianglesOutputsActor                                  = vtkActor::New();
162                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
163                 for (int i=0 ; i<numberOfTriangles; i++)
164                 {
165                         stripTrianglesOutputs->InsertNextCell( 3 );
166                         stripTrianglesOutputs->InsertCellPoint(i*3+0);
167                         stripTrianglesOutputs->InsertCellPoint(i*3+1);
168                         stripTrianglesOutputs->InsertCellPoint(i*3+2);
169                 } // for
170                 // Create cell data
171                 _cellDataOutputTriangles = vtkUnsignedCharArray::New();
172                 _cellDataOutputTriangles->SetNumberOfComponents(3);
173                 _cellDataOutputTriangles->SetNumberOfTuples(numberOfTriangles);
174                 for (int i = 0; i < numberOfTriangles; i++)
175                 {
176                         rgb[0] = 000;
177                         rgb[1] = 255;
178                         rgb[2] = 255;
179                         _cellDataOutputTriangles->SetTuple(i, rgb);
180                 } // for colors  
181                 pdTrianglesOutputs->GetCellData()->SetScalars( _cellDataOutputTriangles );
182                 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
183                 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
184
185 //EED 2017-01-01 Migration VTK7
186 #if VTK_MAJOR_VERSION <= 5
187                 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
188 #else
189                 _TrianglesOutputsPolyMapper->SetInputData( pdTrianglesOutputs );
190 #endif
191
192                 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
193                 _TrianglesOutputsPolyMapper->Modified();
194                 ///************************* Inputs Fill (triangles) *************************
195         }
196
197
198         //=========================================================================
199
200         void vtkGBoxView::createVtkObjects() //virtual
201         {
202                 //------------
203                 _pts                            = vtkPoints::New();     
204 //              vtkCellArray *lines = vtkCellArray::New();
205 //              vtkPolyData *_pd        = vtkPolyData::New();
206 //              _borderPolyMapper       = vtkPolyDataMapper::New();
207 //              _borderObjectActor      = vtkActor::New();
208                                 
209                 _pts->SetNumberOfPoints(4);
210
211                 double xInic, yInic,zInic,xFin, yFin,zFin;
212                 _model->getInicPoint(xInic,yInic,zInic);
213                 _model->getFinalPoint(xFin, yFin,zFin);
214
215                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
216
217 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
218 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
219 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
220 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
221
222 //EED 2017-03-02
223 //              _pts->SetPoint(0, -1000, -1000, -1000 );
224 //              _pts->SetPoint(1, xInic, yFin, zInic );
225 //              _pts->SetPoint(2, 1000, 1000, 1000 );
226 //              _pts->SetPoint(3, xFin, yInic, zFin );
227                                 
228 //              lines->InsertNextCell(5);
229 //              lines->InsertCellPoint(0);
230 //              lines->InsertCellPoint(1);
231 //              lines->InsertCellPoint(2);
232 //              lines->InsertCellPoint(3);
233 //              lines->InsertCellPoint(0);                      
234 //              _pd->SetPoints( _pts );
235 //              _pd->SetLines( lines );
236 //              _borderPolyMapper->SetInput(_pd);
237 //              _borderObjectActor->SetMapper(_borderPolyMapper);
238 //              _borderPolyMapper->Modified();
239
240                 
241                 ///************************* FILL *************************
242
243                 vtkCellArray *strip             = vtkCellArray::New();
244                 vtkPolyData *pdFill             = vtkPolyData::New();
245                 _fillPolyMapper                 = vtkPolyDataMapper::New();
246                 _fillObjectActor                = vtkActor::New();
247
248                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
249
250                 strip->InsertNextCell(5);
251                 strip->InsertCellPoint(0);
252                 strip->InsertCellPoint(1);
253                 strip->InsertCellPoint(2);
254                 strip->InsertCellPoint(0);
255                 strip->InsertCellPoint(3);
256                         
257                 pdFill->SetPoints( _pts );
258                 pdFill->SetStrips( strip );
259
260 //EED 2017-01-01 Migration VTK7
261 #if VTK_MAJOR_VERSION <= 5
262                 _fillPolyMapper->SetInput(pdFill);
263 #else
264                 _fillPolyMapper->SetInputData(pdFill);
265 #endif
266                 _fillObjectActor->SetMapper(_fillPolyMapper);
267                 _fillPolyMapper->Modified();
268
269                 ///************************* FILL *************************
270         }
271
272         //=========================================================================
273
274         void vtkGBoxView::addVtkActors()//virtual
275         {
276 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
277                 vtkGObjectView::addVtkActors();
278                 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
279                 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
280         }
281
282         //=========================================================================
283
284         void vtkGBoxView::removeVtkActors()//virtual
285         {
286 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
287                 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
288                 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
289                 vtkGObjectView::removeVtkActors();
290         }
291
292         //=========================================================================
293
294         void vtkGBoxView::updateColors()
295         {
296                 printf("EED vtkGBoxView::updateColors\n");
297                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
298
299                 if(_state==NOTHING_HAPPENS)
300                 {
301 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
302 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
303                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
304                         
305                 }
306                 else if(_state==HIGHLIGHTED)
307                 {
308 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);                     
309 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
310                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
311                 }
312                 else if(_state==DRAG)
313                 {
314 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
315 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
316                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
317                 }
318                 else if(_state==SELECTED)
319                 {
320 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
321 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
322                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
323                 } // if state box
324
325                 updateColorsPorts();
326         }
327
328
329         //=========================================================================
330         void vtkGBoxView::updateColorsPorts()
331         {
332                 // Input ports
333                 float rgb[3];
334                 vtkGPortView    *portView;
335                 GBoxModel               *boxModel       = (GBoxModel*)_model;
336                 int numberOfTriangles           = boxModel->getNumInputPorts();
337                 for (int i=0 ; i<numberOfTriangles; i++)
338                 {
339                         portView = _inputsG[i];
340                         portView->getColors(rgb);
341                         rgb[0]=rgb[0]*255;
342                         rgb[1]=rgb[1]*255;
343                         rgb[2]=rgb[2]*255;
344                         _cellDataInputTriangles->SetTuple(i, rgb);
345                 } // for
346
347                 numberOfTriangles               = boxModel->getNumOutputPorts();
348                 for (int i=0 ; i<numberOfTriangles; i++)
349                 {
350                         portView = _outputsG[i];
351                         portView->getColors(rgb);
352                         rgb[0]=rgb[0]*255;
353                         rgb[1]=rgb[1]*255;
354                         rgb[2]=rgb[2]*255;
355                         _cellDataOutputTriangles->SetTuple(i, rgb);
356                 } // for
357         }
358
359
360         //=========================================================================
361         void vtkGBoxView::updatePorts()
362         {
363                 double xInic, yInic,zInic,xFin, yFin,zFin;
364
365                 GBoxModel* boxModel = (GBoxModel*)_model;
366                 boxModel->updatePorts();
367
368 // update position for one Actor that represents all InputPorts
369                 GPortModel              *portModel;
370                 int numberOfTriangles                   = boxModel->getNumInputPorts();
371                 for (int i=0;i<numberOfTriangles;i++)
372                 {
373                         portModel = boxModel->getInputPort(i);
374                 portModel->getInicPoint( xInic , yInic , zInic ) ;
375                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
376                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
377                         _TrianglesInputsPts->SetPoint(i*3+0, xInic                                      , yInic , zInic );
378                         _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2       , yFin  , zInic );
379                         _TrianglesInputsPts->SetPoint(i*3+2, xFin                                       , yInic , zFin );
380                 }
381                 _TrianglesInputsPts->Modified();
382         _TrianglesInputsPolyMapper->Modified( ) ;
383
384 // update position for one Actor that represents all OutputPorts
385                 numberOfTriangles                       = boxModel->getNumOutputPorts();
386                 for (int i=0;i<numberOfTriangles;i++)
387                 {
388                         portModel= boxModel->getOutputPort(i);
389                 portModel->getInicPoint( xInic , yInic , zInic ) ;
390                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
391                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
392                         _TrianglesOutputsPts->SetPoint(i*3+0, xInic                                     , yInic , zInic );
393                         _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2      , yFin  , zInic );
394                         _TrianglesOutputsPts->SetPoint(i*3+2, xFin                                      , yInic , zFin );
395                 }
396                 _TrianglesOutputsPts->Modified();
397         _TrianglesOutputsPolyMapper->Modified( ) ;
398
399
400
401         }
402
403         //=========================================================================
404         void vtkGBoxView::addInputPort(vtkGPortView *inputport)
405         {
406                 _inputsG.push_back(inputport);
407         }
408
409         //=========================================================================
410         void vtkGBoxView::addOutputPort(vtkGPortView *outputport)
411         {
412                 _outputsG.push_back(outputport);
413         }
414
415
416 }  // EO namespace bbtk
417
418 // EOF
419