1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::vtkGBlackBoxView
37 #include "vtkGBlackBoxView.h"
43 //=========================================================================
44 vtkGBlackBoxView::vtkGBlackBoxView()
48 //=========================================================================
49 vtkGBlackBoxView::~vtkGBlackBoxView()
53 //=========================================================================
54 void vtkGBlackBoxView::update_X_Fin()
56 double xInic, yInic,zInic,xFin, yFin,zFin;
57 _model->getInicPoint(xInic,yInic,zInic);
58 double *bounds = _boxTextActor->GetBounds();
59 _model->getFinalPoint(xFin, yFin,zFin);
61 double xFin1,xFin2,xFin3;
62 // position referens from box name
63 xFin1 = xInic+(bounds[1]-bounds[0])/2 + 20;
66 // position referens from input ports
67 GBoxModel* gbm=(GBoxModel*)_model;
68 if ( gbm->getNumInputPorts()>0 )
70 GPortModel* gpm = gbm->getInputPort( gbm->getNumInputPorts()-1 );
71 double xpFin, ypFin, zpFin;
72 gpm->getFinalPoint(xpFin, ypFin, zpFin);
75 // position referens from output ports
76 if ( gbm->getNumOutputPorts()>0 )
78 GPortModel* gpm = gbm->getOutputPort( gbm->getNumOutputPorts()-1 );
79 double xpFin, ypFin, zpFin;
80 gpm->getFinalPoint(xpFin, ypFin, zpFin);
84 if (xFin2>xFin) xFin=xFin2;
85 if (xFin3>xFin) xFin=xFin3;
86 _model->setFinalPoint( xFin , yFin , zFin );
89 //=========================================================================
90 void vtkGBlackBoxView::update(int idController,int command)
94 double xInic, yInic,zInic,xFin, yFin,zFin;
95 _model->getInicPoint(xInic,yInic,zInic);
97 updatePositionTextActor(xInic, yInic,zInic);
99 _model->getFinalPoint(xFin, yFin,zFin);
101 // RaC In the actual version, zInic=zFin=900
103 _pts->SetPoint(0, xInic, yInic, zInic );
104 _pts->SetPoint(1, xInic, yFin, zInic );
105 _pts->SetPoint(2, xFin, yFin, zFin );
106 _pts->SetPoint(3, xFin, yInic, zFin );
110 _borderPolyMapper->Modified();
111 _fillPolyMapper->Modified();
118 //=========================================================================
120 void vtkGBlackBoxView::createVtkObjects() //virtual
124 _pts = vtkPoints::New();
125 vtkCellArray *lines = vtkCellArray::New();
126 vtkPolyData *_pd = vtkPolyData::New();
127 _borderPolyMapper = vtkPolyDataMapper::New();
128 _borderObjectActor = vtkActor::New();
130 _pts->SetNumberOfPoints(4);
132 double xInic, yInic,zInic,xFin, yFin,zFin;
133 _model->getInicPoint(xInic,yInic,zInic);
134 _model->getFinalPoint(xFin, yFin,zFin);
136 // RaC In the actual version, zInic=zFin=900
138 //EED _pts->SetPoint(0, xInic, yInic, zInic );
139 //EED _pts->SetPoint(1, xInic, yFin, zInic );
140 //EED _pts->SetPoint(2, xFin, yFin, zFin );
141 //EED _pts->SetPoint(3, xFin, yInic, zFin );
143 _pts->SetPoint(0, -1000, -1000, -1000 );
144 _pts->SetPoint(1, xInic, yFin, zInic );
145 _pts->SetPoint(2, 1000, 1000, 1000 );
146 _pts->SetPoint(3, xFin, yInic, zFin );
150 lines->InsertNextCell(5);
151 lines->InsertCellPoint(0);
152 lines->InsertCellPoint(1);
153 lines->InsertCellPoint(2);
154 lines->InsertCellPoint(3);
155 lines->InsertCellPoint(0);
157 _pd->SetPoints( _pts );
158 _pd->SetLines( lines );
160 _borderPolyMapper->SetInput(_pd);
161 _borderObjectActor->SetMapper(_borderPolyMapper);
162 _borderPolyMapper->Modified();
165 ///************************* FILL *************************
167 vtkCellArray *strip = vtkCellArray::New();
168 vtkPolyData *pdFill = vtkPolyData::New();
169 _fillPolyMapper = vtkPolyDataMapper::New();
170 _fillObjectActor = vtkActor::New();
172 // RaC In the actual version, zInic=zFin=900
174 strip->InsertNextCell(5);
175 strip->InsertCellPoint(0);
176 strip->InsertCellPoint(1);
177 strip->InsertCellPoint(2);
178 strip->InsertCellPoint(0);
179 strip->InsertCellPoint(3);
181 pdFill->SetPoints( _pts );
182 pdFill->SetStrips( strip );
184 _fillPolyMapper->SetInput(pdFill);
185 _fillObjectActor->SetMapper(_fillPolyMapper);
186 _fillPolyMapper->Modified();
188 ///************************* FILL *************************
192 _boxTextActor = vtkTextActor3D::New();
193 vtkTextProperty *prop = vtkTextProperty::New();
195 prop->SetFontFamilyToArial();
196 prop->SetFontSize(100);
197 _boxTextActor->SetTextProperty(prop);
198 //_boxTextActor->GetTextProperty()->SetFontSize(80);
199 //_boxTextActor->GetTextProperty()->BoldOn();
203 updatePositionTextActor( xInic, yInic, zInic);
206 //=========================================================================
208 void vtkGBlackBoxView::addVtkActors()//virtual
210 _baseView->GetRenderer()->AddActor(_borderObjectActor);
211 _baseView->GetRenderer()->AddActor(_boxTextActor);
212 vtkGObjectView::addVtkActors();
215 //=========================================================================
217 void vtkGBlackBoxView::removeVtkActors()//virtual
219 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
220 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
221 vtkGObjectView::removeVtkActors();
224 //=========================================================================
226 void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
228 std::string temp = _model->getBBTKType();
230 temp+=_model->getBBTKName();
231 _boxTextActor->SetInput(temp.c_str());
232 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic);
233 _boxTextActor->SetScale(0.05,0.05,1);
236 //=========================================================================
238 void vtkGBlackBoxView::updateColors()
240 _fillObjectActor->GetProperty()->SetAmbient(0.6);
242 if(_state==NOTHING_HAPPENS)
244 _borderObjectActor->GetProperty()->SetLineWidth(1);
245 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
246 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
247 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
249 GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
250 if(bbmodel->isExecutable())
252 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
253 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
257 else if(_state==HIGHLIGHTED)
259 _borderObjectActor->GetProperty()->SetLineWidth(2);
261 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
262 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
263 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
265 else if(_state==DRAG)
267 _borderObjectActor->GetProperty()->SetLineWidth(1.2);
268 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
269 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
270 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
272 else if(_state==SELECTED)
274 _borderObjectActor->GetProperty()->SetLineWidth(2);
275 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
276 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
277 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
281 //=========================================================================
284 } // EO namespace bbtk