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::vtkGBoxView
62 #include "vtkGBoxView.h"
63 #include "vtkUnsignedCharArray.h"
64 #include "vtkCellData.h"
70 //=========================================================================
71 vtkGBoxView::vtkGBoxView()
75 //=========================================================================
76 vtkGBoxView::~vtkGBoxView()
80 //=========================================================================
81 void vtkGBoxView::update(int idController,int command)
84 double xInic, yInic,zInic,xFin, yFin,zFin;
85 _model->getInicPoint(xInic,yInic,zInic);
86 _model->getFinalPoint(xFin, yFin,zFin);
87 // RaC In the actual version, zInic=zFin=GPOSITION_Z
88 _pts->SetPoint(0, xInic, yInic, zInic );
89 _pts->SetPoint(1, xInic, yFin, zInic );
90 _pts->SetPoint(2, xFin, yFin, zFin );
91 _pts->SetPoint(3, xFin, yInic, zFin );
94 // _borderPolyMapper->Modified();
95 _fillPolyMapper->Modified();
100 //=========================================================================
102 void vtkGBoxView::createVtkInputOutputPorts()
104 ///************************* Inputs Fill (triangles) *************************
106 GBoxModel* boxModel =(GBoxModel*)_model;
107 int numberOfTriangles = boxModel->getNumInputPorts();
108 _TrianglesInputsPts = vtkPoints::New();
109 _TrianglesInputsPts->SetNumberOfPoints( 3*numberOfTriangles );
112 // if (numberOfTriangles>0)
114 // _TrianglesInputsPts->SetPoint(0, -1000, -1000, -1000 );
115 // _TrianglesInputsPts->SetPoint(1, 1000, 1000, 1000 );
118 vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
119 vtkPolyData *pdTrianglesInputs = vtkPolyData::New();
120 _TrianglesInputsPolyMapper = vtkPolyDataMapper::New();
121 _TrianglesInputsActor = vtkActor::New();
122 // RaC In the actual version, zInic=zFin=GPOSITION_Z
123 for (int i=0 ; i<numberOfTriangles; i++)
125 stripTrianglesInputs->InsertNextCell( 3 );
126 stripTrianglesInputs->InsertCellPoint(i*3+0);
127 stripTrianglesInputs->InsertCellPoint(i*3+1);
128 stripTrianglesInputs->InsertCellPoint(i*3+2);
132 vtkUnsignedCharArray *cellDataInputTriangles = vtkUnsignedCharArray::New();
133 cellDataInputTriangles->SetNumberOfComponents(3);
134 cellDataInputTriangles->SetNumberOfTuples(numberOfTriangles);
135 for (int i = 0; i < numberOfTriangles; i++)
140 cellDataInputTriangles->SetTuple(i, rgb);
142 pdTrianglesInputs->GetCellData()->SetScalars(cellDataInputTriangles);
144 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
145 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
146 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
147 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
148 _TrianglesInputsPolyMapper->Modified();
152 ///************************* Inputs Fill (triangles) *************************
154 ///************************* Outputs Fill (triangles) *************************
155 numberOfTriangles = boxModel->getNumOutputPorts();
156 _TrianglesOutputsPts = vtkPoints::New();
157 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
160 // if (numberOfTriangles>0)
162 // _TrianglesOutputsPts->SetPoint(0, -1000, -1000, -1000 );
163 // _TrianglesOutputsPts->SetPoint(1, 1000, 1000, 1000 );
166 vtkCellArray *stripTrianglesOutputs = vtkCellArray::New();
167 vtkPolyData *pdTrianglesOutputs = vtkPolyData::New();
168 _TrianglesOutputsPolyMapper = vtkPolyDataMapper::New();
169 _TrianglesOutputsActor = vtkActor::New();
170 // RaC In the actual version, zInic=zFin=GPOSITION_Z
171 for (int i=0 ; i<numberOfTriangles; i++)
173 stripTrianglesOutputs->InsertNextCell( 3 );
174 stripTrianglesOutputs->InsertCellPoint(i*3+0);
175 stripTrianglesOutputs->InsertCellPoint(i*3+1);
176 stripTrianglesOutputs->InsertCellPoint(i*3+2);
179 vtkUnsignedCharArray *cellDataOutputTriangle = vtkUnsignedCharArray::New();
180 cellDataOutputTriangle->SetNumberOfComponents(3);
181 cellDataOutputTriangle->SetNumberOfTuples(numberOfTriangles);
182 for (int i = 0; i < numberOfTriangles; i++)
187 cellDataOutputTriangle->SetTuple(i, rgb);
189 pdTrianglesOutputs->GetCellData()->SetScalars(cellDataOutputTriangle);
190 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
191 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
192 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
193 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
194 _TrianglesOutputsPolyMapper->Modified();
195 ///************************* Inputs Fill (triangles) *************************
199 //=========================================================================
201 void vtkGBoxView::createVtkObjects() //virtual
204 _pts = vtkPoints::New();
205 // vtkCellArray *lines = vtkCellArray::New();
206 // vtkPolyData *_pd = vtkPolyData::New();
207 // _borderPolyMapper = vtkPolyDataMapper::New();
208 // _borderObjectActor = vtkActor::New();
210 _pts->SetNumberOfPoints(4);
212 double xInic, yInic,zInic,xFin, yFin,zFin;
213 _model->getInicPoint(xInic,yInic,zInic);
214 _model->getFinalPoint(xFin, yFin,zFin);
216 // RaC In the actual version, zInic=zFin=GPOSITION_Z
218 //EED _pts->SetPoint(0, xInic, yInic, zInic );
219 //EED _pts->SetPoint(1, xInic, yFin, zInic );
220 //EED _pts->SetPoint(2, xFin, yFin, zFin );
221 //EED _pts->SetPoint(3, xFin, yInic, zFin );
224 // _pts->SetPoint(0, -1000, -1000, -1000 );
225 // _pts->SetPoint(1, xInic, yFin, zInic );
226 // _pts->SetPoint(2, 1000, 1000, 1000 );
227 // _pts->SetPoint(3, xFin, yInic, zFin );
229 // lines->InsertNextCell(5);
230 // lines->InsertCellPoint(0);
231 // lines->InsertCellPoint(1);
232 // lines->InsertCellPoint(2);
233 // lines->InsertCellPoint(3);
234 // lines->InsertCellPoint(0);
235 // _pd->SetPoints( _pts );
236 // _pd->SetLines( lines );
237 // _borderPolyMapper->SetInput(_pd);
238 // _borderObjectActor->SetMapper(_borderPolyMapper);
239 // _borderPolyMapper->Modified();
242 ///************************* FILL *************************
244 vtkCellArray *strip = vtkCellArray::New();
245 vtkPolyData *pdFill = vtkPolyData::New();
246 _fillPolyMapper = vtkPolyDataMapper::New();
247 _fillObjectActor = vtkActor::New();
249 // RaC In the actual version, zInic=zFin=GPOSITION_Z
251 strip->InsertNextCell(5);
252 strip->InsertCellPoint(0);
253 strip->InsertCellPoint(1);
254 strip->InsertCellPoint(2);
255 strip->InsertCellPoint(0);
256 strip->InsertCellPoint(3);
258 pdFill->SetPoints( _pts );
259 pdFill->SetStrips( strip );
261 _fillPolyMapper->SetInput(pdFill);
262 _fillObjectActor->SetMapper(_fillPolyMapper);
263 _fillPolyMapper->Modified();
265 ///************************* FILL *************************
268 //=========================================================================
270 void vtkGBoxView::addVtkActors()//virtual
272 // _baseView->GetRenderer()->AddActor(_borderObjectActor);
273 vtkGObjectView::addVtkActors();
274 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
275 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
278 //=========================================================================
280 void vtkGBoxView::removeVtkActors()//virtual
282 // _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
283 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
284 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
285 vtkGObjectView::removeVtkActors();
288 //=========================================================================
290 void vtkGBoxView::updateColors()
292 _fillObjectActor->GetProperty()->SetAmbient(0.6);
294 if(_state==NOTHING_HAPPENS)
296 // _borderObjectActor->GetProperty()->SetLineWidth(1);
297 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
298 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
301 else if(_state==HIGHLIGHTED)
303 // _borderObjectActor->GetProperty()->SetLineWidth(2);
304 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
305 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
307 else if(_state==DRAG)
309 // _borderObjectActor->GetProperty()->SetLineWidth(1.2);
310 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
311 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
313 else if(_state==SELECTED)
315 // _borderObjectActor->GetProperty()->SetLineWidth(2);
316 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
317 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
321 //=========================================================================
323 void vtkGBoxView::updatePorts()
325 double xInic, yInic,zInic,xFin, yFin,zFin;
327 GBoxModel* boxModel =(GBoxModel*)_model;
328 boxModel->updatePorts();
330 // update position for one Actor that represents all InputPorts
331 GPortModel *portModel;
332 int numberOfTriangles = boxModel->getNumInputPorts();
333 for (int i=0;i<numberOfTriangles;i++)
335 portModel= boxModel->getInputPort(i);
336 portModel->getInicPoint( xInic , yInic , zInic ) ;
337 portModel->getFinalPoint( xFin , yFin , zFin ) ;
338 // RaC In the actual version, zInic=zFin=GPOSITION_Z
339 _TrianglesInputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
340 _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
341 _TrianglesInputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
343 _TrianglesInputsPts->Modified();
344 _TrianglesInputsPolyMapper->Modified( ) ;
346 // update position for one Actor that represents all OutputPorts
347 numberOfTriangles = boxModel->getNumOutputPorts();
348 for (int i=0;i<numberOfTriangles;i++)
350 portModel= boxModel->getOutputPort(i);
351 portModel->getInicPoint( xInic , yInic , zInic ) ;
352 portModel->getFinalPoint( xFin , yFin , zFin ) ;
353 // RaC In the actual version, zInic=zFin=GPOSITION_Z
354 _TrianglesOutputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
355 _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
356 _TrianglesOutputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
358 _TrianglesOutputsPts->Modified();
359 _TrianglesOutputsPolyMapper->Modified( ) ;
365 //=========================================================================
367 } // EO namespace bbtk