]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
24db98a14240ae4e82838753eaeee126b2b84d16
[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 //EED 2017-03-02
112 //              if (numberOfTriangles>0)
113 //              {
114 //                      _TrianglesInputsPts->SetPoint(0, -1000, -1000, -1000 );
115 //                      _TrianglesInputsPts->SetPoint(1, 1000, 1000, 1000 );
116 //              }
117
118                 vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
119                 vtkPolyData *pdTrianglesInputs  = vtkPolyData::New();
120                 _TrianglesInputsPolyMapper              = vtkPolyDataMapper::New();
121                 _TrianglesInputsActor                   = vtkActor::New();
122                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
123                 for (int i=0 ; i<numberOfTriangles; i++)
124                 {
125                                 stripTrianglesInputs->InsertNextCell( 3 );
126                                 stripTrianglesInputs->InsertCellPoint(i*3+0);
127                                 stripTrianglesInputs->InsertCellPoint(i*3+1);
128                                 stripTrianglesInputs->InsertCellPoint(i*3+2);
129                 }
130
131                 // Create cell data
132                 vtkUnsignedCharArray *cellDataInputTriangles = vtkUnsignedCharArray::New();
133                 cellDataInputTriangles->SetNumberOfComponents(3);
134                 cellDataInputTriangles->SetNumberOfTuples(numberOfTriangles);
135                 for (int i = 0; i < numberOfTriangles; i++)
136                 {
137                         rgb[0] = 100;
138                         rgb[1] = 100;
139                         rgb[2] = 100;
140                         cellDataInputTriangles->SetTuple(i, rgb);
141                 } // for colors  
142                 pdTrianglesInputs->GetCellData()->SetScalars(cellDataInputTriangles);
143
144                 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
145                 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
146                 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
147                 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
148                 _TrianglesInputsPolyMapper->Modified();
149
150
151
152                 ///************************* Inputs Fill (triangles) *************************
153
154                 ///************************* Outputs Fill (triangles) *************************
155                 numberOfTriangles                                               = boxModel->getNumOutputPorts();
156                 _TrianglesOutputsPts                                    = vtkPoints::New();
157                 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
158
159 //EED 2017-03-02
160 //              if (numberOfTriangles>0)
161 //              {
162 //                      _TrianglesOutputsPts->SetPoint(0, -1000, -1000, -1000 );
163 //                      _TrianglesOutputsPts->SetPoint(1, 1000, 1000, 1000 );
164 //              }
165
166                 vtkCellArray *stripTrianglesOutputs     = vtkCellArray::New();
167                 vtkPolyData *pdTrianglesOutputs                 = vtkPolyData::New();
168                 _TrianglesOutputsPolyMapper                             = vtkPolyDataMapper::New();
169                 _TrianglesOutputsActor                                  = vtkActor::New();
170                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
171                 for (int i=0 ; i<numberOfTriangles; i++)
172                 {
173                         stripTrianglesOutputs->InsertNextCell( 3 );
174                         stripTrianglesOutputs->InsertCellPoint(i*3+0);
175                         stripTrianglesOutputs->InsertCellPoint(i*3+1);
176                         stripTrianglesOutputs->InsertCellPoint(i*3+2);
177                 } // for
178                 // Create cell data
179                 vtkUnsignedCharArray *cellDataOutputTriangle = vtkUnsignedCharArray::New();
180                 cellDataOutputTriangle->SetNumberOfComponents(3);
181                 cellDataOutputTriangle->SetNumberOfTuples(numberOfTriangles);
182                 for (int i = 0; i < numberOfTriangles; i++)
183                 {
184                         rgb[0] = 000;
185                         rgb[1] = 255;
186                         rgb[2] = 255;
187                         cellDataOutputTriangle->SetTuple(i, rgb);
188                 } // for colors  
189                 pdTrianglesOutputs->GetCellData()->SetScalars(cellDataOutputTriangle);
190                 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
191                 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
192                 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
193                 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
194                 _TrianglesOutputsPolyMapper->Modified();
195                 ///************************* Inputs Fill (triangles) *************************
196         }
197
198
199         //=========================================================================
200
201         void vtkGBoxView::createVtkObjects() //virtual
202         {
203                 //------------
204                 _pts                            = vtkPoints::New();     
205 //              vtkCellArray *lines = vtkCellArray::New();
206 //              vtkPolyData *_pd        = vtkPolyData::New();
207 //              _borderPolyMapper       = vtkPolyDataMapper::New();
208 //              _borderObjectActor      = vtkActor::New();
209                                 
210                 _pts->SetNumberOfPoints(4);
211
212                 double xInic, yInic,zInic,xFin, yFin,zFin;
213                 _model->getInicPoint(xInic,yInic,zInic);
214                 _model->getFinalPoint(xFin, yFin,zFin);
215
216                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
217
218 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
219 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
220 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
221 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
222
223 //EED 2017-03-02
224 //              _pts->SetPoint(0, -1000, -1000, -1000 );
225 //              _pts->SetPoint(1, xInic, yFin, zInic );
226 //              _pts->SetPoint(2, 1000, 1000, 1000 );
227 //              _pts->SetPoint(3, xFin, yInic, zFin );
228                                 
229 //              lines->InsertNextCell(5);
230 //              lines->InsertCellPoint(0);
231 //              lines->InsertCellPoint(1);
232 //              lines->InsertCellPoint(2);
233 //              lines->InsertCellPoint(3);
234 //              lines->InsertCellPoint(0);                      
235 //              _pd->SetPoints( _pts );
236 //              _pd->SetLines( lines );
237 //              _borderPolyMapper->SetInput(_pd);
238 //              _borderObjectActor->SetMapper(_borderPolyMapper);
239 //              _borderPolyMapper->Modified();
240
241                 
242                 ///************************* FILL *************************
243
244                 vtkCellArray *strip             = vtkCellArray::New();
245                 vtkPolyData *pdFill             = vtkPolyData::New();
246                 _fillPolyMapper                 = vtkPolyDataMapper::New();
247                 _fillObjectActor                = vtkActor::New();
248
249                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
250
251                 strip->InsertNextCell(5);
252                 strip->InsertCellPoint(0);
253                 strip->InsertCellPoint(1);
254                 strip->InsertCellPoint(2);
255                 strip->InsertCellPoint(0);
256                 strip->InsertCellPoint(3);
257                         
258                 pdFill->SetPoints( _pts );
259                 pdFill->SetStrips( strip );
260
261                 _fillPolyMapper->SetInput(pdFill);
262                 _fillObjectActor->SetMapper(_fillPolyMapper);
263                 _fillPolyMapper->Modified();
264
265                 ///************************* FILL *************************
266         }
267
268         //=========================================================================
269
270         void vtkGBoxView::addVtkActors()//virtual
271         {
272 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
273                 vtkGObjectView::addVtkActors();
274                 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
275                 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
276         }
277
278         //=========================================================================
279
280         void vtkGBoxView::removeVtkActors()//virtual
281         {
282 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
283                 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
284                 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
285                 vtkGObjectView::removeVtkActors();
286         }
287
288         //=========================================================================
289
290         void vtkGBoxView::updateColors()
291         {
292                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
293
294                 if(_state==NOTHING_HAPPENS)
295                 {
296 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
297 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
298                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
299                         
300                 }
301                 else if(_state==HIGHLIGHTED)
302                 {
303 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);                     
304 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
305                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
306                 }
307                 else if(_state==DRAG)
308                 {
309 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
310 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
311                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
312                 }
313                 else if(_state==SELECTED)
314                 {
315 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
316 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
317                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
318                 }
319         }
320
321         //=========================================================================
322
323         void vtkGBoxView::updatePorts()
324         {
325                 double xInic, yInic,zInic,xFin, yFin,zFin;
326
327                 GBoxModel* boxModel =(GBoxModel*)_model;
328                 boxModel->updatePorts();
329
330 // update position for one Actor that represents all InputPorts
331                 GPortModel      *portModel;
332                 int numberOfTriangles                   = boxModel->getNumInputPorts();
333                 for (int i=0;i<numberOfTriangles;i++)
334                 {
335                         portModel= boxModel->getInputPort(i);
336                 portModel->getInicPoint( xInic , yInic , zInic ) ;
337                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
338                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
339                         _TrianglesInputsPts->SetPoint(i*3+0, xInic                                      , yInic , zInic );
340                         _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2       , yFin  , zInic );
341                         _TrianglesInputsPts->SetPoint(i*3+2, xFin                                       , yInic , zFin );
342                 }
343                 _TrianglesInputsPts->Modified();
344         _TrianglesInputsPolyMapper->Modified( ) ;
345
346 // update position for one Actor that represents all OutputPorts
347                 numberOfTriangles                       = boxModel->getNumOutputPorts();
348                 for (int i=0;i<numberOfTriangles;i++)
349                 {
350                         portModel= boxModel->getOutputPort(i);
351                 portModel->getInicPoint( xInic , yInic , zInic ) ;
352                 portModel->getFinalPoint( xFin , yFin , zFin ) ;
353                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
354                         _TrianglesOutputsPts->SetPoint(i*3+0, xInic                                     , yInic , zInic );
355                         _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2      , yFin  , zInic );
356                         _TrianglesOutputsPts->SetPoint(i*3+2, xFin                                      , yInic , zFin );
357                 }
358                 _TrianglesOutputsPts->Modified();
359         _TrianglesOutputsPolyMapper->Modified( ) ;
360
361
362
363         }
364
365         //=========================================================================
366
367 }  // EO namespace bbtk
368
369 // EOF
370