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 );
139 _TrianglesInputsPolyMapper->SetInput( pdTrianglesInputs );
140 _TrianglesInputsActor->SetMapper(_TrianglesInputsPolyMapper);
141 _TrianglesInputsPolyMapper->Modified();
144 ///************************* Inputs Fill (triangles) *************************
146 ///************************* Outputs Fill (triangles) *************************
147 numberOfTriangles = boxModel->getNumOutputPorts();
148 _TrianglesOutputsPts = vtkPoints::New();
149 _TrianglesOutputsPts->SetNumberOfPoints( 3*numberOfTriangles );
151 vtkCellArray *stripTrianglesOutputs = vtkCellArray::New();
152 vtkPolyData *pdTrianglesOutputs = vtkPolyData::New();
153 _TrianglesOutputsPolyMapper = vtkPolyDataMapper::New();
154 _TrianglesOutputsActor = vtkActor::New();
155 // RaC In the actual version, zInic=zFin=GPOSITION_Z
156 for (int i=0 ; i<numberOfTriangles; i++)
158 stripTrianglesOutputs->InsertNextCell( 3 );
159 stripTrianglesOutputs->InsertCellPoint(i*3+0);
160 stripTrianglesOutputs->InsertCellPoint(i*3+1);
161 stripTrianglesOutputs->InsertCellPoint(i*3+2);
164 _cellDataOutputTriangles = vtkUnsignedCharArray::New();
165 _cellDataOutputTriangles->SetNumberOfComponents(3);
166 _cellDataOutputTriangles->SetNumberOfTuples(numberOfTriangles);
167 for (int i = 0; i < numberOfTriangles; i++)
172 _cellDataOutputTriangles->SetTuple(i, rgb);
174 pdTrianglesOutputs->GetCellData()->SetScalars( _cellDataOutputTriangles );
175 pdTrianglesOutputs->SetPoints( _TrianglesOutputsPts );
176 pdTrianglesOutputs->SetStrips( stripTrianglesOutputs );
177 _TrianglesOutputsPolyMapper->SetInput( pdTrianglesOutputs );
178 _TrianglesOutputsActor->SetMapper(_TrianglesOutputsPolyMapper);
179 _TrianglesOutputsPolyMapper->Modified();
180 ///************************* Inputs Fill (triangles) *************************
184 //=========================================================================
186 void vtkGBoxView::createVtkObjects() //virtual
189 _pts = vtkPoints::New();
190 // vtkCellArray *lines = vtkCellArray::New();
191 // vtkPolyData *_pd = vtkPolyData::New();
192 // _borderPolyMapper = vtkPolyDataMapper::New();
193 // _borderObjectActor = vtkActor::New();
195 _pts->SetNumberOfPoints(4);
197 double xInic, yInic,zInic,xFin, yFin,zFin;
198 _model->getInicPoint(xInic,yInic,zInic);
199 _model->getFinalPoint(xFin, yFin,zFin);
201 // RaC In the actual version, zInic=zFin=GPOSITION_Z
203 //EED _pts->SetPoint(0, xInic, yInic, zInic );
204 //EED _pts->SetPoint(1, xInic, yFin, zInic );
205 //EED _pts->SetPoint(2, xFin, yFin, zFin );
206 //EED _pts->SetPoint(3, xFin, yInic, zFin );
209 // _pts->SetPoint(0, -1000, -1000, -1000 );
210 // _pts->SetPoint(1, xInic, yFin, zInic );
211 // _pts->SetPoint(2, 1000, 1000, 1000 );
212 // _pts->SetPoint(3, xFin, yInic, zFin );
214 // lines->InsertNextCell(5);
215 // lines->InsertCellPoint(0);
216 // lines->InsertCellPoint(1);
217 // lines->InsertCellPoint(2);
218 // lines->InsertCellPoint(3);
219 // lines->InsertCellPoint(0);
220 // _pd->SetPoints( _pts );
221 // _pd->SetLines( lines );
222 // _borderPolyMapper->SetInput(_pd);
223 // _borderObjectActor->SetMapper(_borderPolyMapper);
224 // _borderPolyMapper->Modified();
227 ///************************* FILL *************************
229 vtkCellArray *strip = vtkCellArray::New();
230 vtkPolyData *pdFill = vtkPolyData::New();
231 _fillPolyMapper = vtkPolyDataMapper::New();
232 _fillObjectActor = vtkActor::New();
234 // RaC In the actual version, zInic=zFin=GPOSITION_Z
236 strip->InsertNextCell(5);
237 strip->InsertCellPoint(0);
238 strip->InsertCellPoint(1);
239 strip->InsertCellPoint(2);
240 strip->InsertCellPoint(0);
241 strip->InsertCellPoint(3);
243 pdFill->SetPoints( _pts );
244 pdFill->SetStrips( strip );
246 _fillPolyMapper->SetInput(pdFill);
247 _fillObjectActor->SetMapper(_fillPolyMapper);
248 _fillPolyMapper->Modified();
250 ///************************* FILL *************************
253 //=========================================================================
255 void vtkGBoxView::addVtkActors()//virtual
257 // _baseView->GetRenderer()->AddActor(_borderObjectActor);
258 vtkGObjectView::addVtkActors();
259 _baseView->GetRenderer()->AddActor(_TrianglesInputsActor);
260 _baseView->GetRenderer()->AddActor(_TrianglesOutputsActor);
263 //=========================================================================
265 void vtkGBoxView::removeVtkActors()//virtual
267 // _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
268 _baseView->GetRenderer()->RemoveActor(_TrianglesInputsActor);
269 _baseView->GetRenderer()->RemoveActor(_TrianglesOutputsActor);
270 vtkGObjectView::removeVtkActors();
273 //=========================================================================
275 void vtkGBoxView::updateColors()
277 printf("EED vtkGBoxView::updateColors\n");
278 _fillObjectActor->GetProperty()->SetAmbient(0.6);
280 if(_state==NOTHING_HAPPENS)
282 // _borderObjectActor->GetProperty()->SetLineWidth(1);
283 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
284 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
287 else if(_state==HIGHLIGHTED)
289 // _borderObjectActor->GetProperty()->SetLineWidth(2);
290 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
291 _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
293 else if(_state==DRAG)
295 // _borderObjectActor->GetProperty()->SetLineWidth(1.2);
296 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
297 _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
299 else if(_state==SELECTED)
301 // _borderObjectActor->GetProperty()->SetLineWidth(2);
302 // _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
303 _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
310 //=========================================================================
311 void vtkGBoxView::updateColorsPorts()
315 vtkGPortView *portView;
316 GBoxModel *boxModel = (GBoxModel*)_model;
317 int numberOfTriangles = boxModel->getNumInputPorts();
318 for (int i=0 ; i<numberOfTriangles; i++)
320 portView = _inputsG[i];
321 portView->getColors(rgb);
325 _cellDataInputTriangles->SetTuple(i, rgb);
328 numberOfTriangles = boxModel->getNumOutputPorts();
329 for (int i=0 ; i<numberOfTriangles; i++)
331 portView = _outputsG[i];
332 portView->getColors(rgb);
336 _cellDataOutputTriangles->SetTuple(i, rgb);
341 //=========================================================================
342 void vtkGBoxView::updatePorts()
344 double xInic, yInic,zInic,xFin, yFin,zFin;
346 GBoxModel* boxModel = (GBoxModel*)_model;
347 boxModel->updatePorts();
349 // update position for one Actor that represents all InputPorts
350 GPortModel *portModel;
351 int numberOfTriangles = boxModel->getNumInputPorts();
352 for (int i=0;i<numberOfTriangles;i++)
354 portModel = boxModel->getInputPort(i);
355 portModel->getInicPoint( xInic , yInic , zInic ) ;
356 portModel->getFinalPoint( xFin , yFin , zFin ) ;
357 // RaC In the actual version, zInic=zFin=GPOSITION_Z
358 _TrianglesInputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
359 _TrianglesInputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
360 _TrianglesInputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
362 _TrianglesInputsPts->Modified();
363 _TrianglesInputsPolyMapper->Modified( ) ;
365 // update position for one Actor that represents all OutputPorts
366 numberOfTriangles = boxModel->getNumOutputPorts();
367 for (int i=0;i<numberOfTriangles;i++)
369 portModel= boxModel->getOutputPort(i);
370 portModel->getInicPoint( xInic , yInic , zInic ) ;
371 portModel->getFinalPoint( xFin , yFin , zFin ) ;
372 // RaC In the actual version, zInic=zFin=GPOSITION_Z
373 _TrianglesOutputsPts->SetPoint(i*3+0, xInic , yInic , zInic );
374 _TrianglesOutputsPts->SetPoint(i*3+1, ( xInic + xFin ) / 2 , yFin , zInic );
375 _TrianglesOutputsPts->SetPoint(i*3+2, xFin , yInic , zFin );
377 _TrianglesOutputsPts->Modified();
378 _TrianglesOutputsPolyMapper->Modified( ) ;
384 //=========================================================================
385 void vtkGBoxView::addInputPort(vtkGPortView *inputport)
387 _inputsG.push_back(inputport);
390 //=========================================================================
391 void vtkGBoxView::addOutputPort(vtkGPortView *outputport)
393 _outputsG.push_back(outputport);
397 } // EO namespace bbtk