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