2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
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.
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
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 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::vtkGBlackBoxView
62 #include "vtkGBlackBoxView.h"
68 //=========================================================================
69 vtkGBlackBoxView::vtkGBlackBoxView()
73 //=========================================================================
74 vtkGBlackBoxView::~vtkGBlackBoxView()
78 //=========================================================================
79 void vtkGBlackBoxView::update_X_Fin()
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);
86 double xFin1,xFin2,xFin3;
87 // position referens from box name
88 xFin1 = xInic+(bounds[1]-bounds[0])/2 + 20;
91 // position referens from input ports
92 GBoxModel* gbm=(GBoxModel*)_model;
93 if ( gbm->getNumInputPorts()>0 )
95 GPortModel* gpm = gbm->getInputPort( gbm->getNumInputPorts()-1 );
96 double xpFin, ypFin, zpFin;
97 gpm->getFinalPoint(xpFin, ypFin, zpFin);
100 // position referens from output ports
101 if ( gbm->getNumOutputPorts()>0 )
103 GPortModel* gpm = gbm->getOutputPort( gbm->getNumOutputPorts()-1 );
104 double xpFin, ypFin, zpFin;
105 gpm->getFinalPoint(xpFin, ypFin, zpFin);
109 if (xFin2>xFin) xFin=xFin2;
110 if (xFin3>xFin) xFin=xFin3;
111 _model->setFinalPoint( xFin , yFin , zFin );
114 //=========================================================================
115 void vtkGBlackBoxView::update(int idController,int command)
119 double xInic, yInic,zInic,xFin, yFin,zFin;
120 _model->getInicPoint(xInic,yInic,zInic);
122 updatePositionTextActor(xInic, yInic,zInic);
124 _model->getFinalPoint(xFin, yFin,zFin);
126 // RaC In the actual version, zInic=zFin=GPOSITION_Z
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 );
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++)
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 );
150 _TrianglesInputsPolyMapper->Modified( ) ;
152 // update position for one Actor that represents all OutputPorts
153 numberOfTriangles = boxModel->getNumOutputPorts();
154 for (int i=0;i<numberOfTriangles;i++)
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 );
164 _TrianglesOutputsPolyMapper->Modified( ) ;
168 // update position for one Actor that represents all OutputPorts
171 _borderPolyMapper->Modified();
172 _fillPolyMapper->Modified();
179 //=========================================================================
181 void vtkGBlackBoxView::createVtkObjects() //virtual
185 _pts = vtkPoints::New();
186 vtkCellArray *lines = vtkCellArray::New();
187 vtkPolyData *_pd = vtkPolyData::New();
188 _borderPolyMapper = vtkPolyDataMapper::New();
189 _borderObjectActor = vtkActor::New();
191 _pts->SetNumberOfPoints(4);
193 double xInic, yInic,zInic,xFin, yFin,zFin;
194 _model->getInicPoint(xInic,yInic,zInic);
195 _model->getFinalPoint(xFin, yFin,zFin);
197 // RaC In the actual version, zInic=zFin=GPOSITION_Z
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 );
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 );
211 lines->InsertNextCell(5);
212 lines->InsertCellPoint(0);
213 lines->InsertCellPoint(1);
214 lines->InsertCellPoint(2);
215 lines->InsertCellPoint(3);
216 lines->InsertCellPoint(0);
218 _pd->SetPoints( _pts );
219 _pd->SetLines( lines );
221 _borderPolyMapper->SetInput(_pd);
222 _borderObjectActor->SetMapper(_borderPolyMapper);
223 _borderPolyMapper->Modified();
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 *************************
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++)
259 stripTrianglesInputs->InsertNextCell( 3 );
260 stripTrianglesInputs->InsertCellPoint(i*3+0);
261 stripTrianglesInputs->InsertCellPoint(i*3+1);
262 stripTrianglesInputs->InsertCellPoint(i*3+2);
264 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
265 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
266 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
267 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
268 _TrianglesInputsPolyMapper->Modified();
269 ///************************* Inputs Fill (triangles) *************************
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++)
283 stripTrianglesOutputs->InsertNextCell( 3 );
284 stripTrianglesOutputs->InsertCellPoint(i*3+0);
285 stripTrianglesOutputs->InsertCellPoint(i*3+1);
286 stripTrianglesOutputs->InsertCellPoint(i*3+2);
288 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
289 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
290 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
291 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
292 _TrianglesOutputsPolyMapper->Modified();
293 ///************************* Inputs Fill (triangles) *************************
299 _boxTextActor = vtkTextActor3D::New();
300 vtkTextProperty *prop = vtkTextProperty::New();
302 prop->SetFontFamilyToArial();
303 _boxTextActor->GetTextProperty()->BoldOn();
304 prop->SetFontSize(80);
305 _boxTextActor->SetTextProperty(prop);
307 // _boxTextActor->GetTextProperty()->SetFontSize(80);
312 updatePositionTextActor( xInic, yInic, zInic);
315 //=========================================================================
317 void vtkGBlackBoxView::addVtkActors()//virtual
320 _baseView->GetRenderer()->AddActor(_borderObjectActor);
321 vtkGObjectView::addVtkActors();
322 _baseView->GetRenderer()->AddActor(_boxTextActor);
324 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
325 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
330 //=========================================================================
332 void vtkGBlackBoxView::removeVtkActors()//virtual
334 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
335 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
336 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
337 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
338 vtkGObjectView::removeVtkActors();
341 //=========================================================================
343 void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
345 std::string temp = _model->getBBTKType();
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);
353 //=========================================================================
355 void vtkGBlackBoxView::updateColors()
357 _fillObjectActor->GetProperty()->SetAmbient(0.6);
359 if(_state==NOTHING_HAPPENS)
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);
366 GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
367 if(bbmodel->isExecutable())
369 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
370 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
374 else if(_state==HIGHLIGHTED)
376 _borderObjectActor->GetProperty()->SetLineWidth(2);
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);
382 else if(_state==DRAG)
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);
389 else if(_state==SELECTED)
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);
398 //=========================================================================
401 } // EO namespace bbtk