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 *******
59 vtkConeSource *cone = vtkConeSource::New();
61 cone->SetResolution(10);
63 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
64 map->SetInput(cone->GetOutput());
66 vtkActor *act = vtkActor::New();
70 vtkPoints *_pts = vtkPoints::New();
71 _pts->SetNumberOfPoints(4);
73 _pts->SetPoint(0, -100 , -100 , 900 );
74 _pts->SetPoint(1, 100 , -100 , 900 );
75 _pts->SetPoint(2, 100 , 100 , 900 );
76 _pts->SetPoint(3, -100 , 100 , 900 );
78 vtkCellArray *lines = vtkCellArray::New();
79 lines->InsertNextCell(5);
80 lines->InsertCellPoint(0);
81 lines->InsertCellPoint(1);
82 lines->InsertCellPoint(2);
83 lines->InsertCellPoint(3);
84 lines->InsertCellPoint(0);
86 vtkPolyData *_pd = vtkPolyData::New();
87 _pd->SetPoints( _pts );
88 _pd->SetLines( lines );
90 vtkActor *_pointVtkActor = vtkActor::New();
91 vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
93 _bboxMapper->SetInput(_pd);
94 _pointVtkActor->SetMapper(_bboxMapper);
96 getRenderer()->AddActor(_pointVtkActor);
101 vtkPoints *_pts2 = vtkPoints::New();
102 _pts2->SetNumberOfPoints(4);
104 _pts2->SetPoint(0, -105 , -100 , -50 );
105 _pts2->SetPoint(1, 100 , -100 , -50 );
106 _pts2->SetPoint(2, 100 , 100 , -50 );
107 _pts2->SetPoint(3, -105 , 100 , -50 );
109 vtkCellArray *lines2 = vtkCellArray::New();
110 lines2->InsertNextCell(5);
111 lines2->InsertCellPoint(0);
112 lines2->InsertCellPoint(1);
113 lines2->InsertCellPoint(2);
114 lines2->InsertCellPoint(3);
115 lines2->InsertCellPoint(0);
117 vtkPolyData *_pd2 = vtkPolyData::New();
118 _pd2->SetPoints( _pts2 );
119 _pd2->SetLines( lines2 );
121 vtkActor *_pointVtkActor2 = vtkActor::New();
122 vtkPolyDataMapper* _bboxMapper2 = vtkPolyDataMapper::New();
124 _bboxMapper2->SetInput(_pd2);
125 _pointVtkActor2->SetMapper(_bboxMapper2);
127 getRenderer()->AddActor(_pointVtkActor2);
130 // ******* TO ERASE *******
131 /////////////////////
137 //=========================================================================
138 void wxVtkSceneManager::disconnectDrop()
140 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
142 //=========================================================================
143 wxVtkSceneManager::~wxVtkSceneManager()
146 //=========================================================================
148 void wxVtkSceneManager::configureBaseView()
150 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
152 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
154 // Important to activate the 2D interaction system
155 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
156 interactorstylebaseview->SetInteractor ( iren );
157 iren->SetInteractorStyle(interactorstylebaseview);
158 interactorstylebaseview->SetwxVtkBaseView(_baseView);
160 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
161 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,900);
164 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
165 _baseView->GetRenderer()->GradientBackgroundOff();
166 _baseView->Refresh();
169 //=========================================================================
171 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
174 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
175 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
177 int type = GBLACKBOX;
179 //Create the MVC Objects
181 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
182 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
183 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
185 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
187 //Prepares the initial model
188 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
191 double yy = windowHeight-y;
193 //z value is not important yet, because it is only used a parallel projection
196 _baseView->TransCoordScreenToWorld(xx,yy,zz);
197 model->setInicPoint(xx,yy,zz);
199 int cantObjects = _objects.size();
201 std::stringstream stream;
202 stream << "Box:Algo " << cantObjects;
203 std::string arraystring = stream.str();
205 model->setBBTKName(arraystring);
206 model->setBBTKType(boxName);
208 model->addObserver(view);
209 model->addObserver(this);
211 //Iterate and create the input ports
212 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
213 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
216 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
218 BlackBoxInputDescriptor *desc = itInput->second;
219 createGInputPort(desc,model,i);
223 //Iterate and create the output ports
224 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
225 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
228 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
230 BlackBoxOutputDescriptor *desc = itOutput->second;
231 createGOutputPort(desc,model,i);
236 //Associates the view with the correspondent renderer and the model.
237 //(NOTE: Refresh is only made by the view)
238 view->setModel(model);
239 view->setBaseView(_baseView);
240 view->initVtkObjects();
242 //Associates the controller with the correspondent model and view
243 controller->setModelAndView(model,view);
245 //Resgiter change to the observers of the actual model
247 model->notifyObservers();
249 //Register the controller of the new object
250 registerController((InteractorStyleMaracas*) controller);
252 //Add the object to the objects list (only boxes and connectors)
253 _objects.push_back(model);
257 //=========================================================================
259 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
263 //Create the MVC Objects
264 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
265 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
266 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
268 model->registerInBox(blackBox,GOUTPUTPORT, pos);
269 blackBox->addOutputPort(model);
271 model->addObserver(view);
272 model->addObserver(this);
274 //Associates the view with the correspondent renderer and the model.
275 //(NOTE: Refresh is only made by the view)
276 view->setModel(model);
277 view->setBaseView(_baseView);
278 view->initVtkObjects();
280 //Associates the controller with the correspondent model and view
281 controller->setModelAndView(model,view);
283 //Register the controller of the new object
284 registerController((InteractorStyleMaracas*) controller);
287 //=========================================================================
289 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
293 //Create the MVC Objects
294 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
295 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
296 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
298 model->registerInBox(blackBox,GINPUTPORT,pos);
299 blackBox->addInputPort(model);
301 model->addObserver(view);
302 model->addObserver(this);
304 //Associates the view with the correspondent renderer and the model.
305 //(NOTE: Refresh is only made by the view)
306 view->setModel(model);
307 view->setBaseView(_baseView);
308 view->initVtkObjects();
310 //Associates the controller with the correspondent model and view
311 controller->setModelAndView(model,view);
313 //Register the controller of the new object
314 registerController((InteractorStyleMaracas*) controller);
317 //=========================================================================
319 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
321 manualContourControler* manContourControl = new manualContourControler();
322 GConnectorView* manViewerContour = new GConnectorView();
323 manualContourModel* manContourModel = new manualContourModel();
324 manContourModel->SetCloseContour(false);
326 manViewerContour->SetModel( manContourModel );
327 manViewerContour->SetWxVtkBaseView( _baseView );
328 manViewerContour->SetRange( 0.5 );
329 manViewerContour->SetZ( 900 );
331 manViewerContour->SetColorNormalContour(0, 0, 1);
332 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
333 manViewerContour->SetColorSelectContour(1, 0.8, 0);
334 manViewerContour->SetWidthLine(1);
336 manContourControl->SetModelView( manContourModel , manViewerContour );
337 manContourControl->Configure();
338 int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
340 for ( i=0; i<sizeLstPoints; i++ )
342 manViewerContour->AddPoint();
345 manContourControl->CreateNewManualContour();
347 manViewerContour->RefreshContour();
349 registerController((InteractorStyleMaracas*) manContourControl);
353 //=========================================================================
355 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
357 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
358 baseViewControlManager->AddInteractorStyleMaracas( param );
361 //=========================================================================
363 vtkRenderer* wxVtkSceneManager::getRenderer()
365 return _baseView->GetRenderer();
368 //=========================================================================
370 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
372 return _baseView->GetRenWin();
374 //=========================================================================
376 bool wxVtkSceneManager::OnMouseMove()
381 //=========================================================================
383 void wxVtkSceneManager::update(int command)
386 if(command==INIT_CREATION_CONTOUR)
388 for(int i = 0; i<_objects.size();i++)
390 if(_objects[i]->getGObjectType() == GBLACKBOX)
393 GPortModel* startOutputPort=((GBlackBoxModel*)_objects[i])->getStartOutputPort();
394 createGConnector(startOutputPort);
399 // The others must not react to events
405 //=========================================================================
407 } // EO namespace bbtk