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(int idController,int command)
58 double xInic, yInic,zInic,xFin, yFin,zFin;
59 _model->getInicPoint(xInic,yInic,zInic);
60 _model->getFinalPoint(xFin, yFin,zFin);
62 // RaC In the actual version, zInic=zFin=900
64 _pts->SetPoint(0, xInic, yInic, zInic );
65 _pts->SetPoint(1, xInic, yFin, zInic );
66 _pts->SetPoint(2, xFin, yFin, zFin );
67 _pts->SetPoint(3, xFin, yInic, zFin );
71 _borderPolyMapper->Modified();
72 _fillPolyMapper->Modified();
75 updatePositionTextActor(xInic, yInic,zInic);
81 //=========================================================================
83 void vtkGBlackBoxView::createVtkObjects() //virtual
87 _pts = vtkPoints::New();
88 vtkCellArray *lines = vtkCellArray::New();
89 vtkPolyData *_pd = vtkPolyData::New();
90 _borderPolyMapper=vtkPolyDataMapper::New();
91 _borderObjectActor=vtkActor::New();
93 _pts->SetNumberOfPoints(4);
95 double xInic, yInic,zInic,xFin, yFin,zFin;
96 _model->getInicPoint(xInic,yInic,zInic);
97 _model->getFinalPoint(xFin, yFin,zFin);
99 // RaC In the actual version, zInic=zFin=900
101 _pts->SetPoint(0, xInic, yInic, zInic );
102 _pts->SetPoint(1, xInic, yFin, zInic );
103 _pts->SetPoint(2, xFin, yFin, zFin );
104 _pts->SetPoint(3, xFin, yInic, zFin );
106 lines->InsertNextCell(5);
107 lines->InsertCellPoint(0);
108 lines->InsertCellPoint(1);
109 lines->InsertCellPoint(2);
110 lines->InsertCellPoint(3);
111 lines->InsertCellPoint(0);
113 _pd->SetPoints( _pts );
114 _pd->SetLines( lines );
116 _borderPolyMapper->SetInput(_pd);
117 _borderObjectActor->SetMapper(_borderPolyMapper);
118 _borderPolyMapper->Modified();
121 ///************************* FILL *************************
123 vtkCellArray *strip = vtkCellArray::New();
124 vtkPolyData *pdFill = vtkPolyData::New();
125 _fillPolyMapper=vtkPolyDataMapper::New();
126 _fillObjectActor=vtkActor::New();
128 // RaC In the actual version, zInic=zFin=900
130 strip->InsertNextCell(5);
131 strip->InsertCellPoint(0);
132 strip->InsertCellPoint(1);
133 strip->InsertCellPoint(2);
134 strip->InsertCellPoint(0);
135 strip->InsertCellPoint(3);
137 pdFill->SetPoints( _pts );
138 pdFill->SetStrips( strip );
140 _fillPolyMapper->SetInput(pdFill);
141 _fillObjectActor->SetMapper(_fillPolyMapper);
142 _fillPolyMapper->Modified();
144 ///************************* FILL *************************
148 _boxTextActor = vtkTextActor3D::New();
149 std::string temp = _model->getBBTKType();
151 temp+=_model->getBBTKName();
152 _boxTextActor->GetTextProperty()->SetFontSize(80);
153 _boxTextActor->GetTextProperty()->BoldOn();
154 _boxTextActor->SetInput(temp.c_str());
158 updatePositionTextActor( xInic, yInic, zInic);
161 //=========================================================================
163 void vtkGBlackBoxView::addVtkActors()//virtual
165 _baseView->GetRenderer()->AddActor(_borderObjectActor);
166 _baseView->GetRenderer()->AddActor(_boxTextActor);
167 vtkGObjectView::addVtkActors();
170 //=========================================================================
172 void vtkGBlackBoxView::removeVtkActors()//virtual
174 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
175 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
176 vtkGObjectView::removeVtkActors();
179 //=========================================================================
181 void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
183 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic);
184 _boxTextActor->SetScale(0.05,0.05,1);
187 //=========================================================================
189 void vtkGBlackBoxView::updateColors()
191 _fillObjectActor->GetProperty()->SetAmbient(0.6);
193 if(_state==NOTHING_HAPPENS)
195 _borderObjectActor->GetProperty()->SetLineWidth(1);
196 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
197 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
198 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
200 GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
201 if(bbmodel->isExecutable())
203 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
204 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
208 else if(_state==HIGHLIGHTED)
210 _borderObjectActor->GetProperty()->SetLineWidth(2);
212 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
213 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
214 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
216 else if(_state==DRAG)
218 _borderObjectActor->GetProperty()->SetLineWidth(1.2);
219 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
220 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
221 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
223 else if(_state==SELECTED)
225 _borderObjectActor->GetProperty()->SetLineWidth(2);
226 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
227 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
228 _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
232 //=========================================================================
234 void vtkGBlackBoxView::updatePorts()
236 GBlackBoxModel* bmod =(GBlackBoxModel*)_model;
240 //=========================================================================
242 } // EO namespace bbtk