1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id)
51 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
52 registerController(this);
57 vtkConeSource *cone = vtkConeSource::New();
59 cone->SetResolution(10);
61 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
62 map->SetInput(cone->GetOutput());
64 vtkActor *act = vtkActor::New();
71 vtkPoints *_pts = vtkPoints::New();
72 _pts->SetNumberOfPoints(4);
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 );
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);
87 vtkPolyData *_pd = vtkPolyData::New();
88 _pd->SetPoints( _pts );
89 _pd->SetLines( lines );
91 vtkActor *_pointVtkActor = vtkActor::New();
92 vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
94 _bboxMapper->SetInput(_pd);
95 _pointVtkActor->SetMapper(_bboxMapper);
97 getRenderer()->AddActor(_pointVtkActor);
101 /////////////////////
103 //getRenderer()->AddActor(act);
105 //getRenderer()->Render();
111 //=========================================================================
112 void wxVtkSceneManager::disconnectDrop()
114 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
116 //=========================================================================
117 wxVtkSceneManager::~wxVtkSceneManager()
120 //=========================================================================
122 void wxVtkSceneManager::configureBaseView()
124 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
126 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
128 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
129 interactorstylebaseview->SetInteractor ( iren );
130 iren->SetInteractorStyle(interactorstylebaseview);
131 interactorstylebaseview->SetwxVtkBaseView(_baseView);
133 //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
134 //_baseView->GetRenderer()->ResetCamera ();
135 //_baseView->GetCamera()->SetParallelProjection(true);
137 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
138 _baseView->GetRenderer()->GradientBackgroundOff();
139 _baseView->Refresh();
142 //=========================================================================
144 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
146 int type = GBLACKBOX;
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);
153 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
155 //Prepares the initial model
157 double yy = _baseView->GetRenWin()->GetSize()[1]-y;
159 _baseView->TransCoordScreenToWorld(xx,yy,zz);
160 model->setInicPoint(xx,yy,zz);
161 model->addObserver(view);
163 //Iterate and create the input ports
164 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
165 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
170 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
172 BlackBoxInputDescriptor *desc = itInput->second;
173 createGInputPort(desc,model);
180 //Iterate and create the output ports
181 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
182 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
187 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
189 BlackBoxOutputDescriptor *desc = itOutput->second;
190 createGOutputPort(desc,model);
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();
203 //Associates the controller with the correspondent model and view
204 controller->setModelAndView(model,view);
206 //Refresh renderwindow with new objects
207 refreshRenderWindow();
209 //Register the controller of the new object
210 registerController((InteractorStyleMaracas*) controller);
212 //Add the object to the objects list (only boxes and connectors)
213 objects.push_back(model);
217 //=========================================================================
219 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
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);
228 model->registerInBox(blackBox);
229 blackBox->addOutputPort(model);
231 //Prepares the initial model
235 blackBox->getInicPoint(xx,yy,zz);
239 model->setInicPoint(xx,yy,zz);
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();
247 //Associates the controller with the correspondent model and view
248 controller->setModelAndView(model,view);
250 //Register the controller of the new object
251 registerController((InteractorStyleMaracas*) controller);
254 //=========================================================================
256 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
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);
265 model->registerInBox(blackBox);
266 blackBox->addInputPort(model);
269 //Prepares the initial model
273 blackBox->getInicPoint(xx,yy,zz);
277 model->setInicPoint(xx,yy,zz);
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();
285 //Associates the controller with the correspondent model and view
286 controller->setModelAndView(model,view);
288 //Register the controller of the new object
289 registerController((InteractorStyleMaracas*) controller);
292 //=========================================================================
294 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
296 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
297 baseViewControlManager->AddInteractorStyleMaracas( param );
300 //=========================================================================
302 vtkRenderer* wxVtkSceneManager::getRenderer()
304 return _baseView->GetRenderer();
307 //=========================================================================
309 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
311 return _baseView->GetRenWin();
313 //=========================================================================
315 void wxVtkSceneManager::refreshRenderWindow()
317 _baseView->GetRenWin()->Render();
319 //=========================================================================
321 bool wxVtkSceneManager::OnMouseMove()
323 //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
326 //=========================================================================
327 } // EO namespace bbtk