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 );
111 vtkCellArray *stripTrianglesInputs = vtkCellArray::New();
112 vtkPolyData *pdTrianglesInputs = vtkPolyData::New();
113 _TrianglesInputsPolyMapper = vtkPolyDataMapper::New();
114 _TrianglesInputsActor = vtkActor::New();
115 // RaC In the actual version, zInic=zFin=GPOSITION_Z
116 for (int i=0 ; i<numberOfTriangles; i++)
118 stripTrianglesInputs->InsertNextCell( 3 );
119 stripTrianglesInputs->InsertCellPoint(i*3+0);
120 stripTrianglesInputs->InsertCellPoint(i*3+1);
121 stripTrianglesInputs->InsertCellPoint(i*3+2);
125 _cellDataInputTriangles = vtkUnsignedCharArray::New();
126 _cellDataInputTriangles->SetNumberOfComponents(3);
127 _cellDataInputTriangles->SetNumberOfTuples(numberOfTriangles);
128 for (int i = 0; i < numberOfTriangles; i++)
133 _cellDataInputTriangles->SetTuple(i, rgb);
135 pdTrianglesInputs->GetCellData()->SetScalars( _cellDataInputTriangles );
137 pdTrianglesInputs->SetPoints( _TrianglesInputsPts );
138 pdTrianglesInputs->SetStrips( stripTrianglesInputs );
140 //EED 2017-01-01 Migration VTK7
141 #if VTK_MAJOR_VERSION <= 5
142 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
144 _TrianglesInputsPolyMapper->SetInputData( pdTrianglesInputs );
147 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
148 _TrianglesInputsPolyMapper->Modified();
151 ///************************* Inputs Fill (triangles) *************************
153 ///************************* Outputs Fill (triangles) *************************
154 numberOfTriangles = boxModel->getNumOutputPorts();
155 _TrianglesOutputsPts = vtkPoints::New();
156 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
158 vtkCellArray *stripTrianglesOutputs = vtkCellArray::New();
159 vtkPolyData *pdTrianglesOutputs = vtkPolyData::New();
160 _TrianglesOutputsPolyMapper = vtkPolyDataMapper::New();
161 _TrianglesOutputsActor = vtkActor::New();
162 // RaC In the actual version, zInic=zFin=GPOSITION_Z
163 for (int i=0 ; i<numberOfTriangles; i++)
165 stripTrianglesOutputs->InsertNextCell( 3 );
166 stripTrianglesOutputs->InsertCellPoint(i*3+0);
167 stripTrianglesOutputs->InsertCellPoint(i*3+1);
168 stripTrianglesOutputs->InsertCellPoint(i*3+2);
171 _cellDataOutputTriangles = vtkUnsignedCharArray::New();
172 _cellDataOutputTriangles->SetNumberOfComponents(3);
173 _cellDataOutputTriangles->SetNumberOfTuples(numberOfTriangles);
174 for (int i = 0; i < numberOfTriangles; i++)
179 _cellDataOutputTriangles->SetTuple(i, rgb);
181 pdTrianglesOutputs->GetCellData()->SetScalars( _cellDataOutputTriangles );
182 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
183 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
185 //EED 2017-01-01 Migration VTK7
186 #if VTK_MAJOR_VERSION <= 5
187 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
189 _TrianglesOutputsPolyMapper->SetInputData( pdTrianglesOutputs );
192 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
193 _TrianglesOutputsPolyMapper->Modified();
194 ///************************* Inputs Fill (triangles) *************************
198 //=========================================================================
200 void vtkGBoxView::createVtkObjects() //virtual
203 _pts = vtkPoints::New();
204 // vtkCellArray *lines = vtkCellArray::New();
205 // vtkPolyData *_pd = vtkPolyData::New();
206 // _borderPolyMapper = vtkPolyDataMapper::New();
207 // _borderObjectActor = vtkActor::New();
209 _pts->SetNumberOfPoints(4);
211 double xInic, yInic,zInic,xFin, yFin,zFin;
212 _model->getInicPoint(xInic,yInic,zInic);
213 _model->getFinalPoint(xFin, yFin,zFin);
215 // RaC In the actual version, zInic=zFin=GPOSITION_Z
217 //EED _pts->SetPoint(0, xInic, yInic, zInic );
218 //EED _pts->SetPoint(1, xInic, yFin, zInic );
219 //EED _pts->SetPoint(2, xFin, yFin, zFin );
220 //EED _pts->SetPoint(3, xFin, yInic, zFin );
223 // _pts->SetPoint(0, -1000, -1000, -1000 );
224 // _pts->SetPoint(1, xInic, yFin, zInic );
225 // _pts->SetPoint(2, 1000, 1000, 1000 );
226 // _pts->SetPoint(3, xFin, yInic, zFin );
228 // lines->InsertNextCell(5);
229 // lines->InsertCellPoint(0);
230 // lines->InsertCellPoint(1);
231 // lines->InsertCellPoint(2);
232 // lines->InsertCellPoint(3);
233 // lines->InsertCellPoint(0);
234 // _pd->SetPoints( _pts );
235 // _pd->SetLines( lines );
236 // _borderPolyMapper->SetInput(_pd);
237 // _borderObjectActor->SetMapper(_borderPolyMapper);
238 // _borderPolyMapper->Modified();
241 ///************************* FILL *************************
243 vtkCellArray *strip = vtkCellArray::New();
244 vtkPolyData *pdFill = vtkPolyData::New();
245 _fillPolyMapper = vtkPolyDataMapper::New();
246 _fillObjectActor = vtkActor::New();
248 // RaC In the actual version, zInic=zFin=GPOSITION_Z
250 strip->InsertNextCell(5);
251 strip->InsertCellPoint(0);
252 strip->InsertCellPoint(1);
253 strip->InsertCellPoint(2);
254 strip->InsertCellPoint(0);
255 strip->InsertCellPoint(3);
257 pdFill->SetPoints( _pts );
258 pdFill->SetStrips( strip );
260 //EED 2017-01-01 Migration VTK7
261 #if VTK_MAJOR_VERSION <= 5
262 _fillPolyMapper->SetInput(pdFill);
264 _fillPolyMapper->SetInputData(pdFill);
266 _fillObjectActor->SetMapper(_fillPolyMapper);
267 _fillPolyMapper->Modified();
269 ///************************* FILL *************************
272 //=========================================================================
274 void vtkGBoxView::addVtkActors()//virtual
276 // _baseView->GetRenderer()->AddActor(_borderObjectActor);
277 vtkGObjectView::addVtkActors();
278 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
279 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
282 //=========================================================================
284 void vtkGBoxView::removeVtkActors()//virtual
286 // _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
287 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
288 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
289 vtkGObjectView::removeVtkActors();
292 //=========================================================================
294 void vtkGBoxView::updateColors()
296 printf("EED vtkGBoxView::updateColors\n");
297 _fillObjectActor->GetProperty()->SetAmbient(0.6);
299 if(_state==NOTHING_HAPPENS)
301 // _borderObjectActor->GetProperty()->SetLineWidth(1);
302 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
303 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
306 else if(_state==HIGHLIGHTED)
308 // _borderObjectActor->GetProperty()->SetLineWidth(2);
309 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
310 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
312 else if(_state==DRAG)
314 // _borderObjectActor->GetProperty()->SetLineWidth(1.2);
315 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
316 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
318 else if(_state==SELECTED)
320 // _borderObjectActor->GetProperty()->SetLineWidth(2);
321 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
322 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
329 //=========================================================================
330 void vtkGBoxView::updateColorsPorts()
334 vtkGPortView *portView;
335 GBoxModel *boxModel = (GBoxModel*)_model;
336 int numberOfTriangles = boxModel->getNumInputPorts();
337 for (int i=0 ; i<numberOfTriangles; i++)
339 portView = _inputsG[i];
340 portView->getColors(rgb);
344 _cellDataInputTriangles->SetTuple(i, rgb);
347 numberOfTriangles = boxModel->getNumOutputPorts();
348 for (int i=0 ; i<numberOfTriangles; i++)
350 portView = _outputsG[i];
351 portView->getColors(rgb);
355 _cellDataOutputTriangles->SetTuple(i, rgb);
360 //=========================================================================
361 void vtkGBoxView::updatePorts()
363 double xInic, yInic,zInic,xFin, yFin,zFin;
365 GBoxModel* boxModel = (GBoxModel*)_model;
366 boxModel->updatePorts();
368 // update position for one Actor that represents all InputPorts
369 GPortModel *portModel;
370 int numberOfTriangles = boxModel->getNumInputPorts();
371 for (int i=0;i<numberOfTriangles;i++)
373 portModel = boxModel->getInputPort(i);
374 portModel->getInicPoint( xInic , yInic , zInic ) ;
375 portModel->getFinalPoint( xFin , yFin , zFin ) ;
376 // RaC In the actual version, zInic=zFin=GPOSITION_Z
377 _TrianglesInputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
378 _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
379 _TrianglesInputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
381 _TrianglesInputsPts->Modified();
382 _TrianglesInputsPolyMapper->Modified( ) ;
384 // update position for one Actor that represents all OutputPorts
385 numberOfTriangles = boxModel->getNumOutputPorts();
386 for (int i=0;i<numberOfTriangles;i++)
388 portModel= boxModel->getOutputPort(i);
389 portModel->getInicPoint( xInic , yInic , zInic ) ;
390 portModel->getFinalPoint( xFin , yFin , zFin ) ;
391 // RaC In the actual version, zInic=zFin=GPOSITION_Z
392 _TrianglesOutputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
393 _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
394 _TrianglesOutputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
396 _TrianglesOutputsPts->Modified();
397 _TrianglesOutputsPolyMapper->Modified( ) ;
403 //=========================================================================
404 void vtkGBoxView::addInputPort(vtkGPortView *inputport)
406 _inputsG.push_back(inputport);
409 //=========================================================================
410 void vtkGBoxView::addOutputPort(vtkGPortView *outputport)
412 _outputsG.push_back(outputport);
416 } // EO namespace bbtk