]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
6457cf456125ce7a115b02415858e39d4a68aaa7
[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                 bboxMapperFill->Modified();
77                 //-----------
78
79                 updatePositionTextActors(xInic, yInic,zInic);
80
81                 //-----------
82                 setRefreshWaiting();
83         }
84
85         //=========================================================================
86
87         void vtkGBlackBoxView::createVtkObjects() //virtual
88         {
89
90                 //------------
91                 _pts = vtkPoints::New();        
92                 vtkCellArray *lines = vtkCellArray::New();
93                 vtkPolyData *_pd = vtkPolyData::New();
94                 vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New();
95                 _objectBorderActor=vtkActor::New();
96                                 
97                 _pts->SetNumberOfPoints(4);
98
99                 double xInic, yInic,zInic,xFin, yFin,zFin;
100                 _model->getInicPoint(xInic,yInic,zInic);
101                 _model->getFinalPoint(xFin, yFin,zFin);
102
103                 // RaC In the actual version, zInic=zFin=900
104
105                 _pts->SetPoint(0, xInic, yInic, zInic );
106                 _pts->SetPoint(1, xInic, yFin, zInic );
107                 _pts->SetPoint(2, xFin, yFin, zFin );
108                 _pts->SetPoint(3, xFin, yInic, zFin );
109                                 
110                 lines->InsertNextCell(5);
111                 lines->InsertCellPoint(0);
112                 lines->InsertCellPoint(1);
113                 lines->InsertCellPoint(2);
114                 lines->InsertCellPoint(3);
115                 lines->InsertCellPoint(0);
116                         
117                 _pd->SetPoints( _pts );
118                 _pd->SetLines( lines );
119
120                 _bboxMapper->SetInput(_pd);
121                 _objectBorderActor->SetMapper(_bboxMapper);
122
123                 _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
124
125                 
126                 ///************************* FILL *************************
127
128                 _ptsFill = vtkPoints::New();
129                 vtkCellArray *strip = vtkCellArray::New();
130                 vtkPolyData *pdFill = vtkPolyData::New();
131                 bboxMapperFill=vtkPolyDataMapper::New();
132                 _fillBorderActor=vtkActor::New();
133
134                 _ptsFill->SetNumberOfPoints(4);
135
136                 // RaC In the actual version, zInic=zFin=900
137
138                 _ptsFill->SetPoint(0, xInic, yInic, zInic-0.01 );
139                 _ptsFill->SetPoint(1, xInic, yFin, zInic-0.01 );
140                 _ptsFill->SetPoint(2, xFin, yFin, zFin-0.01 );
141                 _ptsFill->SetPoint(3, xFin, yInic, zFin-0.01 );
142
143                 strip->InsertNextCell(5);
144                 strip->InsertCellPoint(0);
145                 strip->InsertCellPoint(1);
146                 strip->InsertCellPoint(2);
147                 strip->InsertCellPoint(0);
148                 strip->InsertCellPoint(3);
149                         
150                 pdFill->SetPoints( _ptsFill );
151                 pdFill->SetStrips( strip );
152
153                 bboxMapperFill->SetInput(pdFill);
154                 _fillBorderActor->SetMapper(bboxMapperFill);
155                 bboxMapperFill->Modified();
156                 
157
158                 ///************************* FILL *************************
159
160                 //------------
161
162                 _nameActor = vtkTextActor3D::New();
163                 std::string temp = _model->getBBTKName();
164                 _nameActor->GetTextProperty()->SetFontSize(80);
165                 _nameActor->GetTextProperty()->BoldOn();
166                 _nameActor->SetInput(temp.c_str());
167
168                 //------------
169
170                 _typeActor = vtkTextActor3D::New();
171                 temp = _model->getBBTKType();
172                 _typeActor->GetTextProperty()->SetFontSize(80);
173                 _typeActor->GetTextProperty()->BoldOn();
174                 _typeActor->SetInput(temp.c_str());
175
176                 //------------
177
178                 updatePositionTextActors( xInic,  yInic,  zInic);
179         }
180
181         //=========================================================================
182
183         void vtkGBlackBoxView::addVtkActors()//virtual
184         {
185                 _baseView->GetRenderer()->AddActor(_nameActor);
186
187                 _baseView->GetRenderer()->AddActor(_typeActor);
188
189                 vtkGObjectView::addVtkActors();
190         }
191
192         //=========================================================================
193
194         void vtkGBlackBoxView::updatePositionTextActors(double xInic, double yInic, double zInic)
195         {
196                 _nameActor->SetPosition(xInic+4,yInic-5,zInic);
197                 _nameActor->SetScale(0.04,0.04,1);
198                                         
199                 _typeActor->SetPosition(xInic+4,yInic-10,zInic);
200                 _typeActor->SetScale(0.04,0.04,1);
201         }
202
203         //=========================================================================
204
205         void vtkGBlackBoxView::updateColors()
206         {
207                 _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
208                 _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
209                 _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
210                 _fillBorderActor->GetProperty()->SetColor(0.2,0.8,0.2);
211
212                 if(_state==NOTHING_HAPPENS)
213                 {
214                         _objectBorderActor->GetProperty()->SetLineWidth(1);
215                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
216                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
217                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
218                         _fillBorderActor->GetProperty()->SetColor(0.2,0.8,0.2);
219                 }
220                 else if(_state==HIGHLIGHTED)
221                 {
222                         _objectBorderActor->GetProperty()->SetLineWidth(2);
223                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
224                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
225                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
226                         _fillBorderActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R+.1,BOXCONTOUR_HIGHLIGHTED_G+.1,BOXCONTOUR_HIGHLIGHTED_B+.1);
227                 }
228                 else if(_state==DRAG)
229                 {
230                         _objectBorderActor->GetProperty()->SetLineWidth(1.2);
231                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
232                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
233                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
234                         _fillBorderActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
235                 }
236                 else if(_state==SELECTED)
237                 {
238                         _objectBorderActor->GetProperty()->SetLineWidth(2);
239                         _objectBorderActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
240                         _nameActor->GetTextProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
241                         _typeActor->GetTextProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
242                         _fillBorderActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
243                 }
244         }
245
246         //=========================================================================
247
248 }  // EO namespace bbtk
249
250 // EOF
251