]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
Updated Version with the moving of the objects updated and the background doesn't...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBlackBoxView.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::vtkGBlackBoxView 
34 */
35
36
37 #include "vtkGBlackBoxView.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         vtkGBlackBoxView::vtkGBlackBoxView()
45         {                       
46         }
47
48         //=========================================================================
49         vtkGBlackBoxView::~vtkGBlackBoxView()
50         {
51         }
52
53         //=========================================================================
54         void vtkGBlackBoxView::update(int idController,int command)
55         {
56                 updateColors();
57                 
58                 double xInic, yInic,zInic,xFin, yFin,zFin;
59                 _model->getInicPoint(xInic,yInic,zInic);
60                 _model->getFinalPoint(xFin, yFin,zFin);
61
62                 // RaC In the actual version, zInic=zFin=900
63
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 );
68
69
70                 _ptsFill->SetPoint(0, xInic, yInic, zInic-0.01 );
71                 _ptsFill->SetPoint(1, xInic, yFin, zInic-0.01 );
72                 _ptsFill->SetPoint(2, xFin, yFin, zFin-0.01 );
73                 _ptsFill->SetPoint(3, xFin, yInic, zFin-0.01 );
74
75
76                 //-----------
77
78                 updatePositionTextActors(xInic, yInic,zInic);
79
80                 //-----------
81                 setRefreshWaiting();
82         }
83
84         //=========================================================================
85
86         void vtkGBlackBoxView::createVtkObjects() //virtual
87         {
88
89                 //------------
90                 _pts = vtkPoints::New();        
91                 vtkCellArray *lines = vtkCellArray::New();
92                 vtkPolyData *_pd = vtkPolyData::New();
93                 vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New();
94                 _objectBorderActor=vtkActor::New();
95                                 
96                 _pts->SetNumberOfPoints(4);
97
98                 double xInic, yInic,zInic,xFin, yFin,zFin;
99                 _model->getInicPoint(xInic,yInic,zInic);
100                 _model->getFinalPoint(xFin, yFin,zFin);
101
102                 // RaC In the actual version, zInic=zFin=900
103
104                 _pts->SetPoint(0, xInic, yInic, zInic );
105                 _pts->SetPoint(1, xInic, yFin, zInic );
106                 _pts->SetPoint(2, xFin, yFin, zFin );
107                 _pts->SetPoint(3, xFin, yInic, zFin );
108                                 
109                 lines->InsertNextCell(5);
110                 lines->InsertCellPoint(0);
111                 lines->InsertCellPoint(1);
112                 lines->InsertCellPoint(2);
113                 lines->InsertCellPoint(3);
114                 lines->InsertCellPoint(0);
115                         
116                 _pd->SetPoints( _pts );
117                 _pd->SetLines( lines );
118
119                 _bboxMapper->SetInput(_pd);
120                 _objectBorderActor->SetMapper(_bboxMapper);
121
122                 _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
123
124                 
125                 ///************************* FILL *************************
126
127                 _ptsFill = vtkPoints::New();
128                 vtkCellArray *strip = vtkCellArray::New();
129                 vtkPolyData *pdFill = vtkPolyData::New();
130                 vtkPolyDataMapper* bboxMapperFill=vtkPolyDataMapper::New();
131                 _fillBorderActor=vtkActor::New();
132
133                 _ptsFill->SetNumberOfPoints(4);
134
135                 // RaC In the actual version, zInic=zFin=900
136
137                 _ptsFill->SetPoint(0, xInic, yInic, zInic-0.01 );
138                 _ptsFill->SetPoint(1, xInic, yFin, zInic-0.01 );
139                 _ptsFill->SetPoint(2, xFin, yFin, zFin-0.01 );
140                 _ptsFill->SetPoint(3, xFin, yInic, zFin-0.01 );
141
142                 strip->InsertNextCell(5);
143                 strip->InsertCellPoint(0);
144                 strip->InsertCellPoint(1);
145                 strip->InsertCellPoint(2);
146                 strip->InsertCellPoint(0);
147                 strip->InsertCellPoint(3);
148                         
149                 pdFill->SetPoints( _pts );
150                 pdFill->SetStrips( strip );
151
152                 bboxMapperFill->SetInput(pdFill);
153                 _fillBorderActor->SetMapper(bboxMapperFill);
154                 _fillBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
155
156                 ///************************* FILL *************************
157
158                 //------------
159
160                 _nameActor = vtkTextActor3D::New();
161                 std::string temp = _model->getBBTKName();
162                 _nameActor->GetTextProperty()->SetFontSize(80);
163                 _nameActor->GetTextProperty()->BoldOn();
164                 _nameActor->SetInput(temp.c_str());
165
166                 //------------
167
168                 _typeActor = vtkTextActor3D::New();
169                 temp = _model->getBBTKType();
170                 _typeActor->GetTextProperty()->SetFontSize(80);
171                 _typeActor->GetTextProperty()->BoldOn();
172                 _typeActor->SetInput(temp.c_str());
173
174                 //------------
175
176                 updatePositionTextActors( xInic,  yInic,  zInic);
177         }
178
179         //=========================================================================
180
181         void vtkGBlackBoxView::addVtkActors()//virtual
182         {
183                 _baseView->GetRenderer()->AddActor(_nameActor);
184
185                 _baseView->GetRenderer()->AddActor(_typeActor);
186
187                 vtkGObjectView::addVtkActors();
188         }
189
190         //=========================================================================
191
192         void vtkGBlackBoxView::updatePositionTextActors(double xInic, double yInic, double zInic)
193         {
194                 _nameActor->SetPosition(xInic+4,yInic-5,zInic);
195                 _nameActor->SetScale(0.04,0.04,1);
196                                         
197                 _typeActor->SetPosition(xInic+4,yInic-10,zInic);
198                 _typeActor->SetScale(0.04,0.04,1);
199         }
200
201         //=========================================================================
202
203         void vtkGBlackBoxView::updateColors()
204         {
205                 _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
206                 _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
207                 _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
208                 _fillBorderActor->GetProperty()->SetColor(1,.5,.3);
209
210                 if(_state==NOTHING_HAPPENS)
211                 {
212                         _objectBorderActor->GetProperty()->SetLineWidth(1);
213                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
214                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
215                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
216                 }
217                 else if(_state==HIGHLIGHTED)
218                 {
219                         _objectBorderActor->GetProperty()->SetLineWidth(2);
220                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
221                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
222                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
223                 }
224                 else if(_state==DRAG)
225                 {
226                         _objectBorderActor->GetProperty()->SetLineWidth(1.2);
227                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
228                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
229                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
230                 }
231                 else if(_state==SELECTED)
232                 {
233                         _objectBorderActor->GetProperty()->SetLineWidth(2);
234                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
235                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
236                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
237                 }
238         }
239
240         //=========================================================================
241
242 }  // EO namespace bbtk
243
244 // EOF
245