]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
73dcda3d84d0856026e6eda7b2dce6c55391ee62
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.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::wxVtkSceneManager . 
34 */
35
36
37 #include "wxVtkSceneManager.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id)
45         {
46                 _id=id;
47                 _baseView=baseView;
48                 if( _baseView!=NULL )
49                 {
50                         
51                         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
52                         registerController(this);
53
54                         configureBaseView();
55
56                         /* JUST TO TEST
57                         vtkConeSource *cone = vtkConeSource::New();
58         
59                    cone->SetResolution(10);
60                         
61                    vtkPolyDataMapper *map = vtkPolyDataMapper::New();
62                    map->SetInput(cone->GetOutput());
63                         
64                    vtkActor *act = vtkActor::New();
65                         
66                    act->SetMapper(map);
67                         
68                         /////////////////////
69
70
71                    vtkPoints *_pts = vtkPoints::New();
72                         _pts->SetNumberOfPoints(4);
73
74                         _pts->SetPoint(0, -1    , -1    , 0 );
75                         _pts->SetPoint(1,  1    , -1    , 0 );
76                         _pts->SetPoint(2,  1    ,  1    , 0 );
77                         _pts->SetPoint(3, -1    ,  1    , 0 );
78         
79                         vtkCellArray *lines = vtkCellArray::New();
80                         lines->InsertNextCell(5);
81                         lines->InsertCellPoint(0);
82                         lines->InsertCellPoint(1);
83                         lines->InsertCellPoint(2);
84                         lines->InsertCellPoint(3);
85                         lines->InsertCellPoint(0);
86
87                         vtkPolyData *_pd = vtkPolyData::New();
88                         _pd->SetPoints( _pts );
89                         _pd->SetLines( lines );
90
91                         vtkActor *_pointVtkActor        =       vtkActor::New();
92                         vtkPolyDataMapper* _bboxMapper          =       vtkPolyDataMapper::New();
93
94                         _bboxMapper->SetInput(_pd);
95                         _pointVtkActor->SetMapper(_bboxMapper);
96
97                         getRenderer()->AddActor(_pointVtkActor);
98
99                         */
100
101                         /////////////////////
102
103                    //getRenderer()->AddActor(act);
104                 
105                    //getRenderer()->Render();
106
107
108                 }
109         }
110
111         //=========================================================================
112         void wxVtkSceneManager::disconnectDrop()
113         {
114                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
115         }
116         //=========================================================================
117         wxVtkSceneManager::~wxVtkSceneManager()
118         {
119         }
120         //=========================================================================
121
122         void wxVtkSceneManager::configureBaseView()
123         {
124                 vtkInteractorStyleImage *style = vtkInteractorStyleImage::New();
125                 _baseView->GetWxVTKRenderWindowInteractor()->SetInteractorStyle(style);
126                 //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
127             //_baseView->GetRenderer()->ResetCamera ();
128                 //_baseView->GetCamera()->SetParallelProjection(true);
129                 
130                 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
131                 _baseView->GetRenderer()->GradientBackgroundOff();
132                 _baseView->Refresh();
133         }
134
135         //=========================================================================
136
137         void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
138         {
139                 int type = GBLACKBOX;
140
141                 //Create the MVC Objects
142                 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
143                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
144                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
145                 
146                 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
147                 
148                 //Prepares the initial model
149                 double xx = x;
150                 double yy =  _baseView->GetRenWin()->GetSize()[1]-y;
151                 double zz = 0;
152                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
153                 model->setInicPoint(xx,yy,zz);
154                 //model->addObserver(view);
155
156                 //Iterate and create the input ports
157                 std::map<std::string, BlackBoxInputDescriptor*> descriptorMap = descriptor->GetInputDescriptorMap();
158                 std::map<std::string, BlackBoxInputDescriptor*>::iterator it;
159
160                 //ERASE
161                 cantTemp=0;
162
163                 for(it = descriptorMap.begin(); it != descriptorMap.end(); ++it)
164                 {
165                         BlackBoxInputDescriptor *desc = it->second;
166                         createGInputPort(desc,model);
167                         
168                         //ERASE
169                         cantTemp+=2;
170                 }
171
172
173                 //Associates the view with the correspondent renderer and the  model.
174                 //(NOTE: Refresh is only made by the view)
175                 view->setModel(model);
176                 view->setBaseView(_baseView);
177                 view->initVtkObjects();
178                 
179                 //Associates the controller with the correspondent model and view
180                 controller->setModelAndView(model,view);
181
182                 //Refresh renderwindow with new objects
183                 refreshRenderWindow();
184                 
185                 registerController((InteractorStyleMaracas*) controller);
186
187         }
188
189         //=========================================================================
190
191         void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
192         {
193                 int type = GPORT;
194
195                 //Create the MVC Objects
196                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
197                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
198                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
199
200                 model->registerInBox(blackBox);
201                 blackBox->addInputPort(model);
202
203                 
204                 //Prepares the initial model
205                 double xx = 0;
206                 double yy = 0;
207                 double zz = 0;
208                 blackBox->getInicPoint(xx,yy,zz);
209
210                 xx++;
211                 yy+=cantTemp;
212                 model->setInicPoint(xx,yy,zz);
213
214                 //Associates the view with the correspondent renderer and the  model.
215                 //(NOTE: Refresh is only made by the view)
216                 view->setModel(model);
217                 view->setBaseView(_baseView);
218                 view->initVtkObjects();
219                 
220                 //Associates the controller with the correspondent model and view
221                 controller->setModelAndView(model,view);
222         }
223
224         //=========================================================================
225
226         void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
227         {
228                 int type = GPORT;
229
230                 //Create the MVC Objects
231                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
232                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
233                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
234
235                 model->registerInBox(blackBox);
236                 blackBox->addOutputPort(model);
237         }
238
239         //=========================================================================
240
241         void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
242         {
243                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
244                 baseViewControlManager->AddInteractorStyleMaracas( param );
245         }
246
247         //=========================================================================
248
249         vtkRenderer* wxVtkSceneManager::getRenderer()
250         {
251                 return _baseView->GetRenderer();
252         }
253
254         //=========================================================================
255
256         vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
257         {
258                 return _baseView->GetRenWin();
259         }
260         //=========================================================================
261         
262         void wxVtkSceneManager::refreshRenderWindow()
263         {
264                 _baseView->GetRenWin()->Render();
265         }
266         //=========================================================================
267
268         bool wxVtkSceneManager::OnMouseMove()
269         {
270                 //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
271                 return true;
272         }
273         //=========================================================================
274 }  // EO namespace bbtk
275
276 // EOF
277