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);
55 ///// ******* TO ERASE *******
58 vtkConeSource *cone = vtkConeSource::New();
60 cone->SetResolution(10);
62 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
63 map->SetInput(cone->GetOutput());
65 vtkActor *act = vtkActor::New();
69 vtkPoints *_pts = vtkPoints::New();
70 _pts->SetNumberOfPoints(4);
72 _pts->SetPoint(0, -1 , -1 , 0 );
73 _pts->SetPoint(1, 1 , -1 , 0 );
74 _pts->SetPoint(2, 1 , 1 , 0 );
75 _pts->SetPoint(3, -1 , 1 , 0 );
77 vtkCellArray *lines = vtkCellArray::New();
78 lines->InsertNextCell(5);
79 lines->InsertCellPoint(0);
80 lines->InsertCellPoint(1);
81 lines->InsertCellPoint(2);
82 lines->InsertCellPoint(3);
83 lines->InsertCellPoint(0);
85 vtkPolyData *_pd = vtkPolyData::New();
86 _pd->SetPoints( _pts );
87 _pd->SetLines( lines );
89 vtkActor *_pointVtkActor = vtkActor::New();
90 vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
92 _bboxMapper->SetInput(_pd);
93 _pointVtkActor->SetMapper(_bboxMapper);
95 getRenderer()->AddActor(_pointVtkActor);
97 // ******* TO ERASE *******
103 //=========================================================================
104 void wxVtkSceneManager::disconnectDrop()
106 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
108 //=========================================================================
109 wxVtkSceneManager::~wxVtkSceneManager()
112 //=========================================================================
114 void wxVtkSceneManager::configureBaseView()
116 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
118 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
120 // Important to activate the 2D interaction system
121 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
122 interactorstylebaseview->SetInteractor ( iren );
123 iren->SetInteractorStyle(interactorstylebaseview);
124 interactorstylebaseview->SetwxVtkBaseView(_baseView);
126 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
127 _baseView->GetRenderer()->GradientBackgroundOff();
128 _baseView->Refresh();
132 //=========================================================================
134 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
137 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
138 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
140 int type = GBLACKBOX;
142 //Create the MVC Objects
144 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
145 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
146 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
148 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
150 //Prepares the initial model
151 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
154 double yy = windowHeight-y;
156 //z value is not important yet, because it is only used a parallel projection
159 _baseView->TransCoordScreenToWorld(xx,yy,zz);
160 model->setInicPoint(xx,yy,zz);
162 model->addObserver(view);
164 //Iterate and create the input ports
165 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
166 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
168 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
170 BlackBoxInputDescriptor *desc = itInput->second;
171 createGInputPort(desc,model);
174 //Iterate and create the output ports
175 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
176 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
179 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
181 BlackBoxOutputDescriptor *desc = itOutput->second;
182 createGOutputPort(desc,model);
187 //Associates the view with the correspondent renderer and the model.
188 //(NOTE: Refresh is only made by the view)
189 view->setModel(model);
190 view->setBaseView(_baseView);
191 view->initVtkObjects();
193 //Associates the controller with the correspondent model and view
194 controller->setModelAndView(model,view);
196 //Resgiter change to the observers of the actual model
198 model->notifyObservers();
200 //Register the controller of the new object
201 registerController((InteractorStyleMaracas*) controller);
203 //Add the object to the objects list (only boxes and connectors)
204 objects.push_back(model);
208 //=========================================================================
210 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
214 //Create the MVC Objects
215 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
216 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
217 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
219 model->registerInBox(blackBox,GOUTPUTPORT);
220 blackBox->addOutputPort(model);
222 //Associates the view with the correspondent renderer and the model.
223 //(NOTE: Refresh is only made by the view)
224 view->setModel(model);
225 view->setBaseView(_baseView);
226 view->initVtkObjects();
228 //Associates the controller with the correspondent model and view
229 controller->setModelAndView(model,view);
231 //Register the controller of the new object
232 registerController((InteractorStyleMaracas*) controller);
235 //=========================================================================
237 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
241 //Create the MVC Objects
242 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
243 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
244 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
246 model->registerInBox(blackBox,GINPUTPORT);
247 blackBox->addInputPort(model);
250 //Associates the view with the correspondent renderer and the model.
251 //(NOTE: Refresh is only made by the view)
252 view->setModel(model);
253 view->setBaseView(_baseView);
254 view->initVtkObjects();
256 //Associates the controller with the correspondent model and view
257 controller->setModelAndView(model,view);
259 //Register the controller of the new object
260 registerController((InteractorStyleMaracas*) controller);
263 //=========================================================================
265 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
267 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
268 baseViewControlManager->AddInteractorStyleMaracas( param );
271 //=========================================================================
273 vtkRenderer* wxVtkSceneManager::getRenderer()
275 return _baseView->GetRenderer();
278 //=========================================================================
280 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
282 return _baseView->GetRenWin();
284 //=========================================================================
286 bool wxVtkSceneManager::OnMouseMove()
290 //=========================================================================
291 } // EO namespace bbtk