]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
e509662f64fdbdf9b64fcf135671889eeecc9ad7
[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 command)
55         {
56                 _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
57
58                 if(_model->getState()==NOTHING_HAPPENS)
59                 {
60                         _objectActor->GetProperty()->SetLineWidth(1);
61                         _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
62                         //_nameActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
63                         _typeActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
64                 }
65                 else if(_model->getState()==HIGHLIGHTED)
66                 {
67                         _objectActor->GetProperty()->SetLineWidth(2);
68                         _objectActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
69                         //_nameActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
70                         _typeActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
71                 }
72                 else if(_model->getState()==DRAG)
73                 {
74                         _objectActor->GetProperty()->SetLineWidth(1.2);
75                         _objectActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
76                         //_nameActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
77                         _typeActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
78                 }
79                 else if(_model->getState()==SELECTED)
80                 {
81                         _objectActor->GetProperty()->SetLineWidth(2);
82                         _objectActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
83                         //_nameActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
84                         _typeActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
85                 }
86
87                 double xInic, yInic,zInic,xFin, yFin,zFin;
88                 _model->getInicPoint(xInic,yInic,zInic);
89                 _model->getFinalPoint(xFin, yFin,zFin);
90
91                 // RaC In the actual version, zInic=zFin=900
92
93                 _pts->SetPoint(0, xInic, yInic, zInic );
94                 _pts->SetPoint(1, xInic, yFin, zInic );
95                 _pts->SetPoint(2, xFin, yFin, zFin );
96                 _pts->SetPoint(3, xFin, yInic, zFin );
97
98                 //-----------
99
100                 updatePositionTextActors(xInic, yInic,zInic);
101
102                 //-----------
103
104                 _baseView->RefreshView();
105                 _baseView->Refresh();
106         }
107
108         //=========================================================================
109
110         void vtkGBlackBoxView::createVtkObjects() //virtual
111         {
112
113                 //------------
114                 _pts = vtkPoints::New();        
115                 vtkCellArray *lines = vtkCellArray::New();
116                 vtkPolyData *_pd = vtkPolyData::New();
117                 vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New();
118                 _objectActor=vtkActor::New();
119                 
120                 _pts->SetNumberOfPoints(4);
121
122                 double xInic, yInic,zInic,xFin, yFin,zFin;
123                 _model->getInicPoint(xInic,yInic,zInic);
124                 _model->getFinalPoint(xFin, yFin,zFin);
125
126                 // RaC In the actual version, zInic=zFin=900
127
128                 _pts->SetPoint(0, xInic, yInic, zInic );
129                 _pts->SetPoint(1, xInic, yFin, zInic );
130                 _pts->SetPoint(2, xFin, yFin, zFin );
131                 _pts->SetPoint(3, xFin, yInic, zFin );
132                                 
133                 lines->InsertNextCell(5);
134                 lines->InsertCellPoint(0);
135                 lines->InsertCellPoint(1);
136                 lines->InsertCellPoint(2);
137                 lines->InsertCellPoint(3);
138                 lines->InsertCellPoint(0);
139                         
140                 _pd->SetPoints( _pts );
141                 _pd->SetLines( lines );
142
143                 _bboxMapper->SetInput(_pd);
144                 _objectActor->SetMapper(_bboxMapper);
145
146                 _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
147
148                 //------------
149
150                 /*
151                 _vectorNameText = vtkVectorText::New();
152                 std::string temp = _model->getBBTKName();
153                 _vectorNameText->SetText(temp.c_str());
154
155                 vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();
156                 txtMapper->SetInputConnection( _vectorNameText->GetOutputPort());
157                 _nameActor = vtkActor::New();
158                 _nameActor->SetMapper(txtMapper);
159                 */
160
161                 _vectorNameText = vtkTextActor3D::New();
162                 std::string temp = _model->getBBTKName();
163                 _vectorNameText->SetInput( temp.c_str()  );
164
165
166                 //------------
167
168                 _vectorTypeText = vtkVectorText::New();
169                 temp = _model->getBBTKType();
170                 _vectorTypeText->SetText(temp.c_str());
171
172                 vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();
173                 txtMapper->SetInputConnection( _vectorTypeText->GetOutputPort());
174                 _typeActor = vtkActor::New();
175                 _typeActor->SetMapper(txtMapper);
176
177                 //------------
178
179                 updatePositionTextActors( xInic,  yInic,  zInic);
180
181                 //_nameActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
182                 _vectorNameText->GetTextProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
183                 _vectorNameText->GetTextProperty()->SetFontSize(75);//SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
184                 _vectorNameText->GetTextProperty()->BoldOn();
185                 _vectorNameText->SetScale(0.05,0.05,1);
186                 _typeActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
187
188         }
189
190         //=========================================================================
191
192         void vtkGBlackBoxView::addVtkActors()//virtual
193         {
194                 //_baseView->GetRenderer()->AddActor(_nameActor);
195
196                 _baseView->GetRenderer()->AddActor(_vectorNameText);
197
198                 _baseView->GetRenderer()->AddActor(_typeActor);
199
200                 vtkGObjectView::addVtkActors();
201         }
202
203         //=========================================================================
204
205         void vtkGBlackBoxView::updatePositionTextActors(double xInic, double yInic, double zInic)
206         {
207                 //_nameActor->SetPosition(xInic+4,yInic-5,zInic);
208                 //_nameActor->SetScale(2,2,1);
209                 _vectorNameText->SetPosition(xInic+4,yInic-5,zInic);
210                                         
211                 _typeActor->SetPosition(xInic+4,yInic-10,zInic);
212                 _typeActor->SetScale(2,2,1);
213         }
214
215         //=========================================================================
216
217 }  // EO namespace bbtk
218
219 // EOF
220