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
89 // xFin1 = xInic+(bounds[1]-bounds[0])/2 + 20;
90 xFin1 = xInic+(bounds[1]-bounds[0])/10 + 20;
93 // position referens from input ports
94 GBoxModel* gbm=(GBoxModel*)_model;
95 if ( gbm->getNumInputPorts()>0 )
97 GPortModel* gpm = gbm->getInputPort( gbm->getNumInputPorts()-1 );
98 double xpFin, ypFin, zpFin;
99 gpm->getFinalPoint(xpFin, ypFin, zpFin);
102 // position referens from output ports
103 if ( gbm->getNumOutputPorts()>0 )
105 GPortModel* gpm = gbm->getOutputPort( gbm->getNumOutputPorts()-1 );
106 double xpFin, ypFin, zpFin;
107 gpm->getFinalPoint(xpFin, ypFin, zpFin);
111 if (xFin2>xFin) xFin=xFin2;
112 if (xFin3>xFin) xFin=xFin3;
113 _model->setFinalPoint( xFin , yFin , zFin );
116 //=========================================================================
117 void vtkGBlackBoxView::update(int idController,int command)
121 vtkGBoxView::update(idController,command);
122 double xInic, yInic,zInic,xFin, yFin,zFin;
123 _model->getInicPoint(xInic,yInic,zInic);
124 updatePositionTextActor(xInic, yInic,zInic);
128 //=========================================================================
130 void vtkGBlackBoxView::createVtkObjects() //virtual
134 _pts = vtkPoints::New();
135 // vtkCellArray *lines = vtkCellArray::New();
136 // vtkPolyData *_pd = vtkPolyData::New();
137 // _borderPolyMapper = vtkPolyDataMapper::New();
138 // _borderObjectActor = vtkActor::New();
140 _pts->SetNumberOfPoints(4);
142 double xInic, yInic,zInic,xFin, yFin,zFin;
143 _model->getInicPoint(xInic,yInic,zInic);
144 _model->getFinalPoint(xFin, yFin,zFin);
146 // RaC In the actual version, zInic=zFin=GPOSITION_Z
148 //EED _pts->SetPoint(0, xInic, yInic, zInic );
149 //EED _pts->SetPoint(1, xInic, yFin, zInic );
150 //EED _pts->SetPoint(2, xFin, yFin, zFin );
151 //EED _pts->SetPoint(3, xFin, yInic, zFin );
154 // _pts->SetPoint(0, -1000, -1000, -1000 );
155 // _pts->SetPoint(1, xInic, yFin, zInic );
156 // _pts->SetPoint(2, 1000, 1000, 1000 );
157 // _pts->SetPoint(3, xFin, yInic, zFin );
160 // lines->InsertNextCell(5);
161 // lines->InsertCellPoint(0);
162 // lines->InsertCellPoint(1);
163 // lines->InsertCellPoint(2);
164 // lines->InsertCellPoint(3);
165 // lines->InsertCellPoint(0);
167 // _pd->SetPoints( _pts );
168 // _pd->SetLines( lines );
169 // _borderPolyMapper->SetInput(_pd);
170 // _borderObjectActor->SetMapper(_borderPolyMapper);
171 // _borderPolyMapper->Modified();
174 ///************************* FILL *************************
175 vtkCellArray *strip = vtkCellArray::New();
176 vtkPolyData *pdFill = vtkPolyData::New();
177 _fillPolyMapper = vtkPolyDataMapper::New();
178 _fillObjectActor = vtkActor::New();
179 // RaC In the actual version, zInic=zFin=GPOSITION_Z
180 strip->InsertNextCell(5);
181 strip->InsertCellPoint(0);
182 strip->InsertCellPoint(1);
183 strip->InsertCellPoint(2);
184 strip->InsertCellPoint(0);
185 strip->InsertCellPoint(3);
186 pdFill->SetPoints( _pts );
187 pdFill->SetStrips( strip );
190 //EED 2017-01-01 Migration VTK7
191 #if VTK_MAJOR_VERSION <= 5
192 _fillPolyMapper->SetInput(pdFill);
194 _fillPolyMapper->SetInputData(pdFill);
198 _fillObjectActor->SetMapper(_fillPolyMapper);
199 _fillPolyMapper->Modified();
200 ///************************* FILL *************************
204 createVtkInputOutputPorts();
210 // _boxTextActor = vtkTextActor::New(); // for actor 2D
211 _boxTextActor = vtkTextActor3D::New();
212 vtkTextProperty *prop = vtkTextProperty::New();
214 prop->SetFontFamilyToArial();
217 // prop->SetFontSize(80);
218 // prop->SetFontSize(15);
219 prop->SetFontSize(40);
220 _boxTextActor->SetTextProperty(prop);
223 updatePositionTextActor( xInic, yInic, zInic);
226 //===============BoundaryEdgesOn==========================================================
228 void vtkGBlackBoxView::addVtkActors()//virtual
231 // _baseView->GetRenderer()->AddActor(_borderObjectActor);
232 vtkGBoxView::addVtkActors();
233 _baseView->GetRenderer()->AddActor(_boxTextActor);
237 //=========================================================================
239 void vtkGBlackBoxView::removeVtkActors()//virtual
241 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
242 // _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
243 vtkGBoxView::removeVtkActors();
246 //=========================================================================
248 void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
250 std::string temp = _model->getBBTKType();
252 temp+=_model->getBBTKName();
253 _boxTextActor->SetInput(temp.c_str());
254 // _boxTextActor->SetPosition(xInic+4,yInic-7); // for actor 2D
256 // _boxTextActor->SetPosition(xInic+4,yInic-7,zInic+1);
257 _boxTextActor->SetPosition(xInic+1.1,yInic-BOX_HEIGHT,zInic+1);
258 _boxTextActor->SetScale(0.05,0.05,1);
261 //=========================================================================
263 void vtkGBlackBoxView::updateColors()
265 _fillObjectActor->GetProperty()->SetAmbient(0.6);
267 if(_state==NOTHING_HAPPENS)
269 // _borderObjectActor->GetProperty()->SetLineWidth(1);
270 /// _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
271 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
272 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
274 GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
275 if(bbmodel->isExecutable())
277 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
278 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
282 else if(_state==HIGHLIGHTED)
284 // _borderObjectActor->GetProperty()->SetLineWidth(2);
285 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
286 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
287 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
289 else if(_state==DRAG)
291 // _borderObjectActor->GetProperty()->SetLineWidth(1.2);
292 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
293 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
294 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
296 else if(_state==SELECTED)
298 // _borderObjectActor->GetProperty()->SetLineWidth(2);
299 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
300 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
301 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
308 //=========================================================================
311 } // EO namespace bbtk