]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
*** empty log message ***
[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                 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
125
126                 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
127
128                 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
129                 interactorstylebaseview->SetInteractor ( iren );
130                 iren->SetInteractorStyle(interactorstylebaseview);
131                 interactorstylebaseview->SetwxVtkBaseView(_baseView);
132
133                 //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
134             //_baseView->GetRenderer()->ResetCamera ();
135                 //_baseView->GetCamera()->SetParallelProjection(true);
136                 
137                 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
138                 _baseView->GetRenderer()->GradientBackgroundOff();
139                 _baseView->Refresh();
140         }
141
142         //=========================================================================
143
144         void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
145         {
146                 int type = GBLACKBOX;
147
148                 //Create the MVC Objects
149                 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
150                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
151                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
152                 
153                 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
154                 
155                 //Prepares the initial model
156                 double xx = x;
157                 double yy =  _baseView->GetRenWin()->GetSize()[1]-y;
158                 double zz = 0;
159                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
160                 model->setInicPoint(xx,yy,zz);
161                 model->addObserver(view);
162
163                 //Iterate and create the input ports
164                 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
165                 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
166
167                 //ERASE
168                 cantTemp=0;
169
170                 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
171                 {
172                         BlackBoxInputDescriptor *desc = itInput->second;
173                         createGInputPort(desc,model);
174                         
175                         //ERASE
176                         cantTemp+=2;
177                 }
178
179
180                 //Iterate and create the output ports
181                 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
182                 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
183
184                 //ERASE
185                 cantTemp=0;
186
187                 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
188                 {
189                         BlackBoxOutputDescriptor *desc = itOutput->second;
190                         createGOutputPort(desc,model);
191                         
192                         //ERASE
193                         cantTemp+=2;
194                 }
195
196
197                 //Associates the view with the correspondent renderer and the  model.
198                 //(NOTE: Refresh is only made by the view)
199                 view->setModel(model);
200                 view->setBaseView(_baseView);
201                 view->initVtkObjects();
202                 
203                 //Associates the controller with the correspondent model and view
204                 controller->setModelAndView(model,view);
205
206                 //Refresh renderwindow with new objects
207                 refreshRenderWindow();
208                 
209                 //Register the controller of the new object
210                 registerController((InteractorStyleMaracas*) controller);
211
212                 //Add the object to the objects list (only boxes and connectors)
213                 objects.push_back(model);
214
215         }
216
217         //=========================================================================
218
219         void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
220         {
221                 int type = GPORT;
222
223                 //Create the MVC Objects
224                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
225                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
226                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
227
228                 model->registerInBox(blackBox);
229                 blackBox->addOutputPort(model);
230                 
231                 //Prepares the initial model
232                 double xx = 0;
233                 double yy = 0;
234                 double zz = 0;
235                 blackBox->getInicPoint(xx,yy,zz);
236
237                 xx++;
238                 yy+=cantTemp;
239                 model->setInicPoint(xx,yy,zz);
240
241                 //Associates the view with the correspondent renderer and the  model.
242                 //(NOTE: Refresh is only made by the view)
243                 view->setModel(model);
244                 view->setBaseView(_baseView);
245                 view->initVtkObjects();
246                 
247                 //Associates the controller with the correspondent model and view
248                 controller->setModelAndView(model,view);
249
250                 //Register the controller of the new object
251                 registerController((InteractorStyleMaracas*) controller);
252         }
253
254         //=========================================================================
255
256         void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
257         {
258                 int type = GPORT;
259
260                 //Create the MVC Objects
261                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
262                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
263                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
264
265                 model->registerInBox(blackBox);
266                 blackBox->addInputPort(model);
267
268                 
269                 //Prepares the initial model
270                 double xx = 0;
271                 double yy = 0;
272                 double zz = 0;
273                 blackBox->getInicPoint(xx,yy,zz);
274
275                 xx--;
276                 yy+=cantTemp;
277                 model->setInicPoint(xx,yy,zz);
278
279                 //Associates the view with the correspondent renderer and the  model.
280                 //(NOTE: Refresh is only made by the view)
281                 view->setModel(model);
282                 view->setBaseView(_baseView);
283                 view->initVtkObjects();
284                 
285                 //Associates the controller with the correspondent model and view
286                 controller->setModelAndView(model,view);
287
288                 //Register the controller of the new object
289                 registerController((InteractorStyleMaracas*) controller);
290         }
291
292         //=========================================================================
293
294         void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
295         {
296                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
297                 baseViewControlManager->AddInteractorStyleMaracas( param );
298         }
299
300         //=========================================================================
301
302         vtkRenderer* wxVtkSceneManager::getRenderer()
303         {
304                 return _baseView->GetRenderer();
305         }
306
307         //=========================================================================
308
309         vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
310         {
311                 return _baseView->GetRenWin();
312         }
313         //=========================================================================
314         
315         void wxVtkSceneManager::refreshRenderWindow()
316         {
317                 _baseView->GetRenWin()->Render();
318         }
319         //=========================================================================
320
321         bool wxVtkSceneManager::OnMouseMove()
322         {
323                 //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
324                 return true;
325         }
326         //=========================================================================
327 }  // EO namespace bbtk
328
329 // EOF
330