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 //=========================================================================
139 void wxVtkSceneManager::disconnectDrop()
141 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
144 //=========================================================================
146 wxVtkSceneManager::~wxVtkSceneManager()
150 //=========================================================================
152 void wxVtkSceneManager::configureBaseView()
154 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
156 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
158 // Important to activate the 2D interaction system
159 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
160 interactorstylebaseview->SetInteractor ( iren );
161 iren->SetInteractorStyle(interactorstylebaseview);
162 interactorstylebaseview->SetwxVtkBaseView(_baseView);
164 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
165 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
167 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
168 _baseView->GetRenderer()->GradientBackgroundOff();
169 _baseView->Refresh();
172 //=========================================================================
174 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
177 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
178 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
180 int type = GBLACKBOX;
182 //Create the MVC Objects
184 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
185 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
186 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
188 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
190 //Prepares the initial model
191 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
194 double yy = windowHeight-y;
196 //z value is not important yet, because it is only used a parallel projection
199 _baseView->TransCoordScreenToWorld(xx,yy,zz);
200 model->setInicPoint(xx,yy,zz);
202 int cantObjects = _objects.size();
204 std::stringstream stream;
208 stream << "Box0" << cantObjects;
212 stream << "Box" << cantObjects;
214 std::string arraystring = stream.str();
216 model->setBBTKName(arraystring);
217 model->setBBTKType(boxName);
219 model->addObserver(view);
220 model->addObserver(this);
222 //Iterate and create the input ports
223 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
224 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
227 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
229 BlackBoxInputDescriptor *desc = itInput->second;
230 createGInputPort(GINPUTPORT,i,model,desc);
234 //Iterate and create the output ports
235 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
236 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
239 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
241 BlackBoxOutputDescriptor *desc = itOutput->second;
242 createGOutputPort(GOUTPUTPORT,i,model,desc);
247 //Associates the view with the correspondent renderer and the model.
248 //(NOTE: Refresh is only made by the view)
249 view->setModel(model);
250 view->setBaseView(_baseView);
251 view->initVtkObjects();
253 //Associates the controller with the correspondent model and view
254 controller->setModelAndView(model,view);
256 //Resgiter change to the observers of the actual model
258 model->notifyObservers();
260 //Register the controller of the new object
261 registerController((InteractorStyleMaracas*) controller);
263 //Add the object to the objects list
264 _objects.push_back(controller);
266 int newId = _controllers.size();
267 controller->setId(newId);
268 _controllers[newId] = controller;
272 //=========================================================================
274 void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
276 createGPort(portType,posinBox,blackBox);
279 //=========================================================================
281 void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
283 createGPort(portType,posinBox,blackBox);
286 //=========================================================================
288 void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
292 //Create the MVC Objects
293 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
294 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
295 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
297 model->registerInBox(blackBox,portType, posInBox);
298 blackBox->addOutputPort(model);
300 model->addObserver(view);
301 model->addObserver(this);
303 //Associates the view with the correspondent renderer and the model.
304 //(NOTE: Refresh is only made by the view)
305 view->setModel(model);
306 view->setBaseView(_baseView);
307 view->initVtkObjects();
309 //Associates the controller with the correspondent model and view
310 controller->setModelAndView(model,view);
312 model->notifyObservers();
314 //Register the controller of the new object
315 registerController((InteractorStyleMaracas*) controller);
317 int newId = _controllers.size();
318 controller->setId(newId);
319 _controllers[newId] = controller;
322 //=========================================================================
324 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
326 manualContourControler* manContourControl = new manualContourControler();
327 GConnectorView* manViewerContour = new GConnectorView();
328 manualContourModel* manContourModel = new manualContourModel();
329 manContourModel->SetCloseContour(false);
331 manViewerContour->SetModel( manContourModel );
332 manViewerContour->SetWxVtkBaseView( _baseView );
333 manViewerContour->SetRange( 0.5 );
334 manViewerContour->SetZ( 900 );
336 manViewerContour->SetColorNormalContour(0, 0, 1);
337 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
338 manViewerContour->SetColorSelectContour(1, 0.8, 0);
339 manViewerContour->SetWidthLine(1);
341 manContourControl->SetModelView( manContourModel , manViewerContour );
342 manContourControl->Configure();
343 int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
345 for ( i=0; i<sizeLstPoints; i++ )
347 manViewerContour->AddPoint();
350 manContourControl->CreateNewManualContour();
352 manViewerContour->RefreshContour();
356 startPort->getCenter(x,y,z);
358 manContourControl->SetState(1);
359 manContourModel->SetCloseContour(false);
361 manContourModel->AddPoint(x,y,z);
362 manViewerContour->AddPoint();
364 manContourModel->AddPoint(x,y,z);
365 manViewerContour->AddPoint();
367 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
368 manContourControl->_bakIdPoint=bak;
369 manViewerContour->Refresh();
371 manContourControl->SetMoving( false );
373 registerController((InteractorStyleMaracas*) manContourControl);
377 //=========================================================================
379 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
381 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
382 baseViewControlManager->AddInteractorStyleMaracas( param );
385 //=========================================================================
387 vtkRenderer* wxVtkSceneManager::getRenderer()
389 return _baseView->GetRenderer();
392 //=========================================================================
394 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
396 return _baseView->GetRenWin();
398 //=========================================================================
400 bool wxVtkSceneManager::OnMouseMove()
405 //=========================================================================
407 void wxVtkSceneManager::update(int idController,int command)
410 if(command==INIT_CREATION_CONTOUR)
412 GObjectController* cont = _controllers[idController];
413 if(cont->getGObjectType() == GPORT)
415 GPortController* controller = (GPortController*)cont;
416 vtkGPortView* view = (vtkGPortView*)controller->getView();
418 if(view->getState() == CREATING_CONTOUR)
420 //pre: The port in this state is an output port
421 GPortModel* startOutputPort = (GPortModel*)controller->getModel();
422 createGConnector(startOutputPort);
429 //=========================================================================
431 } // EO namespace bbtk