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